Commit 9d5f16bbba3f9d240a149e67642b93a1526d563b
1 parent
da25f57e
Exists in
master
Adicionado testes de resource das configurações
Showing
14 changed files
with
287 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/AbstractResourceConfig.java
0 → 100644
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +public abstract class AbstractResourceConfig { | ||
4 | + | ||
5 | + private int primitiveInteger; | ||
6 | + | ||
7 | + private String string; | ||
8 | + | ||
9 | + public int getPrimitiveInteger() { | ||
10 | + return primitiveInteger; | ||
11 | + } | ||
12 | + | ||
13 | + public void setPrimitiveInteger(int primitiveInteger) { | ||
14 | + this.primitiveInteger = primitiveInteger; | ||
15 | + } | ||
16 | + | ||
17 | + public String getStringWithComma() { | ||
18 | + return string; | ||
19 | + } | ||
20 | + | ||
21 | + public void setStringWithComma(String stringWithComma) { | ||
22 | + this.string = stringWithComma; | ||
23 | + } | ||
24 | +} | ||
0 | \ No newline at end of file | 25 | \ No newline at end of file |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/ConfigurationResourceTest.java
0 → 100644
@@ -0,0 +1,107 @@ | @@ -0,0 +1,107 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static junit.framework.Assert.assertEquals; | ||
4 | + | ||
5 | +import java.io.File; | ||
6 | + | ||
7 | +import javax.inject.Inject; | ||
8 | + | ||
9 | +import org.jboss.arquillian.container.test.api.Deployment; | ||
10 | +import org.jboss.arquillian.junit.Arquillian; | ||
11 | +import org.jboss.shrinkwrap.api.asset.FileAsset; | ||
12 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
13 | +import org.junit.Test; | ||
14 | +import org.junit.runner.RunWith; | ||
15 | + | ||
16 | +import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; | ||
17 | + | ||
18 | +@RunWith(Arquillian.class) | ||
19 | +public class ConfigurationResourceTest extends AbstractConfigurationTest{ | ||
20 | + | ||
21 | + @Inject | ||
22 | + private PropertiesDefaultFileConfig propDefault; | ||
23 | + | ||
24 | + @Inject | ||
25 | + private PropertiesNamedDefaultFileConfig propNamedDefault; | ||
26 | + | ||
27 | + @Inject | ||
28 | + private PropertiesNotDefaultFileConfig propNotDefault; | ||
29 | + | ||
30 | + @Inject | ||
31 | + private PropertiesWithoutFileConfig propWithoutFile; | ||
32 | + | ||
33 | + @Inject | ||
34 | + private XMLDefaultFileConfig xmlDefault; | ||
35 | + | ||
36 | + @Inject | ||
37 | + private XMLNamedDefaultFileConfig xmlNamedDefault; | ||
38 | + | ||
39 | + @Inject | ||
40 | + private XMLNotDefaultFileConfig xmlNotDefault; | ||
41 | + | ||
42 | + @Inject | ||
43 | + private XMLWithoutFileConfig xmlWithoutFile; | ||
44 | + | ||
45 | + @Deployment | ||
46 | + public static JavaArchive createDeployment() { | ||
47 | + JavaArchive deployment = createConfigurationDeployment(); | ||
48 | + | ||
49 | + deployment.addPackages(true, ConfigurationResourceTest.class.getPackage()); | ||
50 | + deployment.addAsResource(new FileAsset(new File( | ||
51 | + "src/test/resources/configuration/resource/demoiselle.properties")), "demoiselle.properties"). | ||
52 | + addAsResource(new FileAsset(new File( | ||
53 | + "src/test/resources/configuration/resource/demoiselle.xml")), "demoiselle.xml"). | ||
54 | + addAsResource(new FileAsset(new File( | ||
55 | + "src/test/resources/configuration/resource/resource.properties")), "resource.properties"). | ||
56 | + addAsResource(new FileAsset(new File( | ||
57 | + "src/test/resources/configuration/resource/resource.xml")), "resource.xml"); | ||
58 | + | ||
59 | + return deployment; | ||
60 | + } | ||
61 | + | ||
62 | + @Test | ||
63 | + public void loadFromDefaultFile(){ | ||
64 | + int expectedInt = 1; | ||
65 | + String expectedString = "demoiselle framework"; | ||
66 | + | ||
67 | + assertEquals(expectedInt, propDefault.getPrimitiveInteger()); | ||
68 | + assertEquals(expectedString, propDefault.getStringWithComma()); | ||
69 | + | ||
70 | + assertEquals(expectedInt, xmlDefault.getPrimitiveInteger()); | ||
71 | + assertEquals(expectedString, xmlDefault.getStringWithComma()); | ||
72 | + } | ||
73 | + | ||
74 | + @Test | ||
75 | + public void loadFromNamedDefaultFile(){ | ||
76 | + int expectedInt = 1; | ||
77 | + String expectedString = "demoiselle framework"; | ||
78 | + | ||
79 | + assertEquals(expectedInt, propNamedDefault.getPrimitiveInteger()); | ||
80 | + assertEquals(expectedString, propNamedDefault.getStringWithComma()); | ||
81 | + | ||
82 | + assertEquals(expectedInt, xmlNamedDefault.getPrimitiveInteger()); | ||
83 | + assertEquals(expectedString, xmlNamedDefault.getStringWithComma()); | ||
84 | + } | ||
85 | + | ||
86 | + @Test | ||
87 | + public void loadFromNotDefaultFile(){ | ||
88 | + int expectedInt = 2; | ||
89 | + String expectedString = "demoiselle framework from resource"; | ||
90 | + | ||
91 | + assertEquals(expectedInt, propNotDefault.getPrimitiveInteger()); | ||
92 | + assertEquals(expectedString, propNotDefault.getStringWithComma()); | ||
93 | + | ||
94 | + assertEquals(expectedInt, xmlNotDefault.getPrimitiveInteger()); | ||
95 | + assertEquals(expectedString, xmlNotDefault.getStringWithComma()); | ||
96 | + } | ||
97 | + | ||
98 | + @Test | ||
99 | + public void loadFromNonexistentFile(){ | ||
100 | + assertEquals(0, propWithoutFile.getPrimitiveInteger()); | ||
101 | + assertEquals(null, propWithoutFile.getStringWithComma()); | ||
102 | + | ||
103 | + assertEquals(0, xmlWithoutFile.getPrimitiveInteger()); | ||
104 | + assertEquals(null, xmlWithoutFile.getStringWithComma()); | ||
105 | + } | ||
106 | + | ||
107 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/PropertiesDefaultFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(type = PROPERTIES) | ||
7 | +public class PropertiesDefaultFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/PropertiesNamedDefaultFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(resource="demoiselle", type = PROPERTIES) | ||
7 | +public class PropertiesNamedDefaultFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/PropertiesNotDefaultFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(resource="resource", type = PROPERTIES) | ||
7 | +public class PropertiesNotDefaultFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/PropertiesWithoutFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.PROPERTIES; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(resource="nofile", type = PROPERTIES) | ||
7 | +public class PropertiesWithoutFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/XMLDefaultFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.XML; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(type = XML) | ||
7 | +public class XMLDefaultFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/XMLNamedDefaultFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.XML; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(resource="demoiselle", type = XML) | ||
7 | +public class XMLNamedDefaultFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/XMLNotDefaultFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.XML; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(resource="resource", type = XML) | ||
7 | +public class XMLNotDefaultFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/resource/XMLWithoutFileConfig.java
0 → 100644
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +package br.gov.frameworkdemoiselle.configuration.resource; | ||
2 | + | ||
3 | +import static br.gov.frameworkdemoiselle.configuration.ConfigType.XML; | ||
4 | +import br.gov.frameworkdemoiselle.configuration.Configuration; | ||
5 | + | ||
6 | +@Configuration(resource="nofile", type = XML) | ||
7 | +public class XMLWithoutFileConfig extends AbstractResourceConfig{ | ||
8 | + | ||
9 | +} |
impl/core/src/test/resources/configuration/resource/demoiselle.properties
0 → 100644
impl/core/src/test/resources/configuration/resource/demoiselle.xml
0 → 100644
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +<!-- | ||
2 | + Demoiselle Framework | ||
3 | + Copyright (C) 2010 SERPRO | ||
4 | + ============================================================================ | ||
5 | + This file is part of Demoiselle Framework. | ||
6 | + | ||
7 | + Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + as published by the Free Software Foundation. | ||
10 | + | ||
11 | + This program is distributed in the hope that it will be useful, | ||
12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + GNU General Public License for more details. | ||
15 | + | ||
16 | + You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + along with this program; if not, see <http://www.gnu.org/licenses /> | ||
18 | + or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + ============================================================================ | ||
21 | + Este arquivo é parte do Framework Demoiselle. | ||
22 | + | ||
23 | + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + do Software Livre (FSF). | ||
26 | + | ||
27 | + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + para maiores detalhes. | ||
31 | + | ||
32 | + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses /> | ||
34 | + ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | +--> | ||
37 | +<configuration> | ||
38 | + <primitiveInteger>1</primitiveInteger> | ||
39 | + <string>demoiselle framework</string> | ||
40 | +</configuration> | ||
0 | \ No newline at end of file | 41 | \ No newline at end of file |
impl/core/src/test/resources/configuration/resource/resource.properties
0 → 100644
impl/core/src/test/resources/configuration/resource/resource.xml
0 → 100644
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +<!-- | ||
2 | + Demoiselle Framework | ||
3 | + Copyright (C) 2010 SERPRO | ||
4 | + ============================================================================ | ||
5 | + This file is part of Demoiselle Framework. | ||
6 | + | ||
7 | + Demoiselle Framework is free software; you can redistribute it and/or | ||
8 | + modify it under the terms of the GNU Lesser General Public License version 3 | ||
9 | + as published by the Free Software Foundation. | ||
10 | + | ||
11 | + This program is distributed in the hope that it will be useful, | ||
12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | + GNU General Public License for more details. | ||
15 | + | ||
16 | + You should have received a copy of the GNU Lesser General Public License version 3 | ||
17 | + along with this program; if not, see <http://www.gnu.org/licenses /> | ||
18 | + or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
19 | + Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | + ============================================================================ | ||
21 | + Este arquivo é parte do Framework Demoiselle. | ||
22 | + | ||
23 | + O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
24 | + modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
25 | + do Software Livre (FSF). | ||
26 | + | ||
27 | + Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
28 | + GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
29 | + APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
30 | + para maiores detalhes. | ||
31 | + | ||
32 | + Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
33 | + "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses /> | ||
34 | + ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
35 | + 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
36 | +--> | ||
37 | +<configuration> | ||
38 | + <primitiveInteger>2</primitiveInteger> | ||
39 | + <string>demoiselle framework from resource</string> | ||
40 | +</configuration> | ||
0 | \ No newline at end of file | 41 | \ No newline at end of file |