Commit 726762113dbcbe64bb983dd7f11a5eead32825cd

Authored by Ednara Oliveira
1 parent d72e319d
Exists in master

Testes com valores nulos e com erro de conversão

impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/AbstractPrimitiveOrWrapperFieldConfig.java
@@ -40,8 +40,16 @@ public abstract class AbstractPrimitiveOrWrapperFieldConfig { @@ -40,8 +40,16 @@ public abstract class AbstractPrimitiveOrWrapperFieldConfig {
40 40
41 private int primitiveInteger; 41 private int primitiveInteger;
42 42
  43 + private int nullPrimitiveInteger;
  44 +
  45 + private int errorPrimitiveInteger;
  46 +
43 private Integer wrappedInteger; 47 private Integer wrappedInteger;
44 48
  49 + private Integer nullWrappedInteger;
  50 +
  51 + private Integer errorWrappedInteger;
  52 +
45 public Integer getWrappedInteger() { 53 public Integer getWrappedInteger() {
46 return wrappedInteger; 54 return wrappedInteger;
47 } 55 }
@@ -49,4 +57,20 @@ public abstract class AbstractPrimitiveOrWrapperFieldConfig { @@ -49,4 +57,20 @@ public abstract class AbstractPrimitiveOrWrapperFieldConfig {
49 public int getPrimitiveInteger() { 57 public int getPrimitiveInteger() {
50 return primitiveInteger; 58 return primitiveInteger;
51 } 59 }
  60 +
  61 + public int getNullPrimitiveInteger() {
  62 + return nullPrimitiveInteger;
  63 + }
  64 +
  65 + public Integer getNullWrappedInteger() {
  66 + return nullWrappedInteger;
  67 + }
  68 +
  69 + public int getErrorPrimitiveInteger() {
  70 + return errorPrimitiveInteger;
  71 + }
  72 +
  73 + public Integer getErrorWrappedInteger() {
  74 + return errorWrappedInteger;
  75 + }
52 } 76 }
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/ConfigurationPrimitiveOrWrapperFieldTest.java
@@ -37,20 +37,26 @@ @@ -37,20 +37,26 @@
37 package br.gov.frameworkdemoiselle.configuration.field.primitiveorwrapper; 37 package br.gov.frameworkdemoiselle.configuration.field.primitiveorwrapper;
38 38
39 import static junit.framework.Assert.assertEquals; 39 import static junit.framework.Assert.assertEquals;
  40 +import static junit.framework.Assert.fail;
40 41
41 import java.io.File; 42 import java.io.File;
42 43
43 import javax.inject.Inject; 44 import javax.inject.Inject;
44 45
  46 +import junit.framework.Assert;
  47 +
  48 +import org.apache.commons.configuration.ConversionException;
45 import org.jboss.arquillian.container.test.api.Deployment; 49 import org.jboss.arquillian.container.test.api.Deployment;
46 import org.jboss.arquillian.junit.Arquillian; 50 import org.jboss.arquillian.junit.Arquillian;
47 import org.jboss.shrinkwrap.api.asset.FileAsset; 51 import org.jboss.shrinkwrap.api.asset.FileAsset;
48 import org.jboss.shrinkwrap.api.spec.JavaArchive; 52 import org.jboss.shrinkwrap.api.spec.JavaArchive;
49 import org.junit.BeforeClass; 53 import org.junit.BeforeClass;
50 import org.junit.Test; 54 import org.junit.Test;
  55 +import org.junit.internal.runners.statements.Fail;
51 import org.junit.runner.RunWith; 56 import org.junit.runner.RunWith;
52 57
53 import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; 58 import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest;
  59 +import br.gov.frameworkdemoiselle.configuration.ConfigurationException;
54 60
55 @RunWith(Arquillian.class) 61 @RunWith(Arquillian.class)
56 public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurationTest { 62 public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurationTest {
@@ -70,7 +76,8 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat @@ -70,7 +76,8 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat
70 76
71 deployment.addPackages(true, ConfigurationPrimitiveOrWrapperFieldTest.class.getPackage()); 77 deployment.addPackages(true, ConfigurationPrimitiveOrWrapperFieldTest.class.getPackage());
72 deployment.addAsResource( 78 deployment.addAsResource(
73 - new FileAsset(new File("src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties")), 79 + new FileAsset(new File(
  80 + "src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties")),
74 "demoiselle.properties").addAsResource( 81 "demoiselle.properties").addAsResource(
75 new FileAsset(new File("src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml")), 82 new FileAsset(new File("src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml")),
76 "demoiselle.xml"); 83 "demoiselle.xml");
@@ -81,7 +88,11 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat @@ -81,7 +88,11 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat
81 @BeforeClass 88 @BeforeClass
82 public static void afterClass() { 89 public static void afterClass() {
83 System.setProperty("primitiveInteger", String.valueOf(1)); 90 System.setProperty("primitiveInteger", String.valueOf(1));
  91 + System.setProperty("nullPrimitiveInteger", String.valueOf(""));
  92 + System.setProperty("errorPrimitiveInteger", String.valueOf("a"));
84 System.setProperty("wrappedInteger", String.valueOf(2)); 93 System.setProperty("wrappedInteger", String.valueOf(2));
  94 + System.setProperty("nullWrappedInteger", String.valueOf(""));
  95 + System.setProperty("errorWrappedInteger", String.valueOf("a"));
85 } 96 }
86 97
87 @Test 98 @Test
@@ -101,4 +112,75 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat @@ -101,4 +112,75 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat
101 assertEquals(expected, propertiesConfig.getWrappedInteger()); 112 assertEquals(expected, propertiesConfig.getWrappedInteger());
102 assertEquals(expected, xmlConfig.getWrappedInteger()); 113 assertEquals(expected, xmlConfig.getWrappedInteger());
103 } 114 }
  115 +
  116 + @Test
  117 + public void loadNullPrimitiveInteger() {
  118 + int expected = 0;
  119 +
  120 + assertEquals(expected, systemConfig.getNullPrimitiveInteger());
  121 + assertEquals(expected, propertiesConfig.getNullPrimitiveInteger());
  122 + assertEquals(expected, xmlConfig.getNullPrimitiveInteger());
  123 + }
  124 +
  125 + @Test
  126 + public void loadNullWrappedInteger() {
  127 + Integer expected = null;
  128 +
  129 + assertEquals(expected, systemConfig.getNullWrappedInteger());
  130 + assertEquals(expected, propertiesConfig.getNullWrappedInteger());
  131 + assertEquals(expected, xmlConfig.getNullWrappedInteger());
  132 + }
  133 +
  134 + @Test
  135 + public void loadErrorPrimitiveInteger() {
  136 + int expected = 0;
  137 +
  138 + try {
  139 + assertEquals(expected, propertiesConfig.getErrorPrimitiveInteger());
  140 + fail();
  141 + } catch (ConversionException cause) {
  142 + Assert.assertEquals(ConversionException.class, cause.getCause().getClass());
  143 + }
  144 +
  145 + try {
  146 + assertEquals(expected, propertiesConfig.getErrorPrimitiveInteger());
  147 + fail();
  148 + } catch (ConversionException cause) {
  149 + Assert.assertEquals(ConversionException.class, cause.getCause().getClass());
  150 + }
  151 +
  152 + try {
  153 + assertEquals(expected, xmlConfig.getErrorPrimitiveInteger());
  154 + fail();
  155 + } catch (ConversionException cause) {
  156 + Assert.assertEquals(ConversionException.class, cause.getCause().getClass());
  157 + }
  158 +
  159 + }
  160 +
  161 + @Test
  162 + public void loadErrorWrappedInteger() {
  163 + Integer expected = 2;
  164 +
  165 + try {
  166 + assertEquals(expected, propertiesConfig.getErrorWrappedInteger());
  167 + fail();
  168 + } catch (ConversionException cause) {
  169 + Assert.assertEquals(ConversionException.class, cause.getCause().getClass());
  170 + }
  171 +
  172 + try {
  173 + assertEquals(expected, propertiesConfig.getErrorWrappedInteger());
  174 + fail();
  175 + } catch (ConversionException cause) {
  176 + Assert.assertEquals(ConversionException.class, cause.getCause().getClass());
  177 + }
  178 +
  179 + try {
  180 + assertEquals(expected, xmlConfig.getErrorWrappedInteger());
  181 + fail();
  182 + } catch (ConversionException cause) {
  183 + Assert.assertEquals(ConversionException.class, cause.getCause().getClass());
  184 + }
  185 + }
104 } 186 }
impl/core/src/test/resources/configuration/field/notnull/empty-field.properties
@@ -33,4 +33,4 @@ @@ -33,4 +33,4 @@
33 # ou escreva para a Fundação do Software Livre (FSF) Inc., 33 # ou escreva para a Fundação do Software Livre (FSF) Inc.,
34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. 34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
35 35
36 -integerNotNull= 36 +attibuteNotNull=
impl/core/src/test/resources/configuration/field/notnull/empty-field.xml
@@ -35,5 +35,5 @@ @@ -35,5 +35,5 @@
35 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. 35 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
36 --> 36 -->
37 <configurations> 37 <configurations>
38 - <integerNotNull></integerNotNull> 38 + <attibuteNotNull></attibuteNotNull>
39 </configurations> 39 </configurations>
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.properties
@@ -34,4 +34,8 @@ @@ -34,4 +34,8 @@
34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. 34 # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
35 35
36 primitiveInteger=1 36 primitiveInteger=1
37 -wrappedInteger=2  
38 \ No newline at end of file 37 \ No newline at end of file
  38 +nullPrimitiveInteger=
  39 +errorPrimitiveInteger=a
  40 +wrappedInteger=2
  41 +nullWrappedInteger=
  42 +errorWrappedInteger=a
39 \ No newline at end of file 43 \ No newline at end of file
impl/core/src/test/resources/configuration/field/primitiveorwrapper/demoiselle.xml
@@ -37,5 +37,9 @@ @@ -37,5 +37,9 @@
37 37
38 <configuration> 38 <configuration>
39 <primitiveInteger>1</primitiveInteger> 39 <primitiveInteger>1</primitiveInteger>
  40 + <nullPrimitiveInteger></nullPrimitiveInteger>
  41 + <errorPrimitiveInteger>a</errorPrimitiveInteger>
40 <wrappedInteger>2</wrappedInteger> 42 <wrappedInteger>2</wrappedInteger>
  43 + <nullWrappedInteger></nullWrappedInteger>
  44 + <errorWrappedInteger>a</errorWrappedInteger>
41 </configuration> 45 </configuration>