Commit de86ad8b82ca88a8bd9a1d7cb2d8d9f3531617f6

Authored by Dancovich
1 parent 53aeb669
Exists in master

Ajustado o padrão dos nomes dos testes de gerenciamento e monitoração.

impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
@@ -21,7 +21,6 @@ import br.gov.frameworkdemoiselle.internal.context.ContextManager; @@ -21,7 +21,6 @@ import br.gov.frameworkdemoiselle.internal.context.ContextManager;
21 import br.gov.frameworkdemoiselle.internal.context.ManagedContext; 21 import br.gov.frameworkdemoiselle.internal.context.ManagedContext;
22 import br.gov.frameworkdemoiselle.internal.management.ManagedType; 22 import br.gov.frameworkdemoiselle.internal.management.ManagedType;
23 import br.gov.frameworkdemoiselle.internal.management.Management; 23 import br.gov.frameworkdemoiselle.internal.management.Management;
24 -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;  
25 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; 24 import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
26 import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; 25 import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
27 import br.gov.frameworkdemoiselle.stereotype.ManagementController; 26 import br.gov.frameworkdemoiselle.stereotype.ManagementController;
@@ -48,7 +47,7 @@ public class ManagementBootstrap implements Extension { @@ -48,7 +47,7 @@ public class ManagementBootstrap implements Extension {
48 47
49 @SuppressWarnings("unchecked") 48 @SuppressWarnings("unchecked")
50 public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) { 49 public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) {
51 - ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-core-bundle", Locale.getDefault()); 50 + ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault());
52 51
53 Management monitoringManager = Beans.getReference(Management.class); 52 Management monitoringManager = Beans.getReference(Management.class);
54 for (AnnotatedType<?> type : types) { 53 for (AnnotatedType<?> type : types) {
impl/core/src/test/java/management/AnnotationTestCase.java
@@ -1,99 +0,0 @@ @@ -1,99 +0,0 @@
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 -package management;  
38 -  
39 -import java.io.File;  
40 -  
41 -import management.testclasses.DummyManagementExtension;  
42 -import management.testclasses.ManagedClassStore;  
43 -  
44 -import org.jboss.arquillian.container.test.api.Deployer;  
45 -import org.jboss.arquillian.container.test.api.Deployment;  
46 -import org.jboss.arquillian.junit.Arquillian;  
47 -import org.jboss.arquillian.test.api.ArquillianResource;  
48 -import org.jboss.shrinkwrap.api.ShrinkWrap;  
49 -import org.jboss.shrinkwrap.api.asset.FileAsset;  
50 -import org.jboss.shrinkwrap.api.spec.JavaArchive;  
51 -import org.junit.Assert;  
52 -import org.junit.Ignore;  
53 -import org.junit.Test;  
54 -import org.junit.runner.RunWith;  
55 -  
56 -import test.Tests;  
57 -  
58 -//TODO O arquillian está com um problema onde, embora os testes rodem todos individualmente,  
59 -//ao pedir para rodar todos este teste individual causa todos os testes executados após esse  
60 -//falharem. Até este problema ser resolvido este teste será ignorado.  
61 -@RunWith(Arquillian.class)  
62 -@Ignore  
63 -public class AnnotationTestCase {  
64 -  
65 - /**  
66 - * Deployment containing a malformed managed class. Tests using this deployment will check if deployment fails (it  
67 - * has to).  
68 - */  
69 - @Deployment(name = "wrong_annotation", managed = false)  
70 - public static JavaArchive createWrongAnnotationDeployment() {  
71 - return ShrinkWrap  
72 - .create(JavaArchive.class)  
73 - .addClass(Tests.class)  
74 - .addPackages(true, "br")  
75 - .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")  
76 - .addAsManifestResource(  
77 - new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),  
78 - "services/javax.enterprise.inject.spi.Extension")  
79 - .addPackages(false, ManagementBootstrapTestCase.class.getPackage())  
80 - //.addClasses(DummyManagementExtension.class, DummyManagedClassPropertyError.class, ManagedClassStore.class);  
81 - .addClasses(DummyManagementExtension.class, ManagedClassStore.class);  
82 - }  
83 -  
84 - @Test  
85 - public void testWrongAnnotation(@ArquillianResource Deployer deployer) {  
86 -  
87 - try {  
88 - deployer.deploy("wrong_annotation");  
89 -  
90 - // O processo de deploy precisa falhar, pois temos uma classe anotada com falhas.  
91 - Assert.fail();  
92 - } catch (Exception e) {  
93 - //SUCCESS  
94 - } finally {  
95 - deployer.undeploy("wrong_annotation");  
96 - }  
97 - }  
98 -  
99 -}  
impl/core/src/test/java/management/ManagementBootstrapTestCase.java
@@ -1,136 +0,0 @@ @@ -1,136 +0,0 @@
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 -package management;  
38 -  
39 -import java.io.File;  
40 -import java.util.List;  
41 -  
42 -import javax.enterprise.inject.spi.BeforeShutdown;  
43 -  
44 -import management.testclasses.DummyManagedClass;  
45 -import management.testclasses.DummyManagementExtension;  
46 -import management.testclasses.ManagedClassStore;  
47 -  
48 -import org.jboss.arquillian.container.test.api.Deployment;  
49 -import org.jboss.arquillian.junit.Arquillian;  
50 -import org.jboss.shrinkwrap.api.ShrinkWrap;  
51 -import org.jboss.shrinkwrap.api.asset.FileAsset;  
52 -import org.jboss.shrinkwrap.api.spec.JavaArchive;  
53 -import org.junit.Assert;  
54 -import org.junit.Ignore;  
55 -import org.junit.Test;  
56 -import org.junit.runner.RunWith;  
57 -  
58 -import test.Tests;  
59 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
60 -import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;  
61 -import br.gov.frameworkdemoiselle.util.Beans;  
62 -  
63 -@RunWith(Arquillian.class)  
64 -@Ignore  
65 -public class ManagementBootstrapTestCase {  
66 -  
67 - /**  
68 - * Deployment to test normal deployment behaviour  
69 - *  
70 - */  
71 - @Deployment  
72 - public static JavaArchive createDeployment() {  
73 - return ShrinkWrap  
74 - .create(JavaArchive.class)  
75 - .addClass(Tests.class)  
76 - .addPackages(true, "br")  
77 - .addAsResource(  
78 - new FileAsset(new File(  
79 - "src/test/resources/beans.xml")),  
80 - "beans.xml")  
81 - .addAsManifestResource(  
82 - new File(  
83 - "src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),  
84 - "services/javax.enterprise.inject.spi.Extension")  
85 - .addPackages(false,  
86 - ManagementBootstrapTestCase.class.getPackage())  
87 - .addClasses(DummyManagementExtension.class,  
88 - DummyManagedClass.class, ManagedClassStore.class);  
89 - }  
90 -  
91 - /**  
92 - * Test if a a management extension (a library that implements  
93 - * {@link ManagementExtension}) is correctly detected.  
94 - */  
95 - @Test  
96 - public void testManagementExtensionRegistration() {  
97 - // "store" é application scoped e é usado pelo DummyManagementExtension  
98 - // para  
99 - // armazenar todos os beans anotados com @ManagementController. Se o  
100 - // bootstrap rodou corretamente,  
101 - // ele chamou DummyManagementExtension.initialize e este store conterá o  
102 - // bean de teste que anotamos.  
103 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
104 -  
105 - Assert.assertEquals(1, store.getManagedTypes().size());  
106 - }  
107 -  
108 - /**  
109 - * Test if a a management extension's shutdown method is correctly called  
110 - * upon application shutdown.  
111 - */  
112 - @Test  
113 - public void testManagementExtensionShutdown() {  
114 - // "store" é application scoped e é usado pelo DummyManagementExtension  
115 - // para  
116 - // armazenar todos os beans anotados com @ManagementController. Se o  
117 - // bootstrap rodou corretamente,  
118 - // ele chamou DummyManagementExtension.initialize e este store conterá o  
119 - // bean de teste que anotamos.  
120 - // Nós então disparamos o evento de shutdown onde ele deverá limpar o  
121 - // store.  
122 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
123 -  
124 - // Detecta se a classe anotada foi detectada  
125 - List<ManagedType> managedTypes = store.getManagedTypes();  
126 - Assert.assertEquals(1, managedTypes.size());  
127 -  
128 - Beans.getBeanManager().fireEvent(new BeforeShutdown() {  
129 - });  
130 -  
131 - // Após o "undeploy", o ciclo de vida precisa ter removido a classe  
132 - // gerenciada da lista.  
133 - Assert.assertEquals(0, managedTypes.size());  
134 - }  
135 -  
136 -}  
impl/core/src/test/java/management/ManagementTestCase.java
@@ -1,195 +0,0 @@ @@ -1,195 +0,0 @@
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 -package management;  
38 -  
39 -import java.io.File;  
40 -  
41 -import junit.framework.Assert;  
42 -import management.testclasses.DummyManagedClass;  
43 -import management.testclasses.DummyManagementExtension;  
44 -import management.testclasses.ManagedClassStore;  
45 -import management.testclasses.RequestScopeBeanClient;  
46 -import management.testclasses.RequestScopedClass;  
47 -  
48 -import org.jboss.arquillian.container.test.api.Deployment;  
49 -import org.jboss.arquillian.junit.Arquillian;  
50 -import org.jboss.shrinkwrap.api.ShrinkWrap;  
51 -import org.jboss.shrinkwrap.api.asset.FileAsset;  
52 -import org.jboss.shrinkwrap.api.spec.JavaArchive;  
53 -import org.junit.Test;  
54 -import org.junit.runner.RunWith;  
55 -  
56 -import test.Tests;  
57 -import br.gov.frameworkdemoiselle.DemoiselleException;  
58 -import br.gov.frameworkdemoiselle.util.Beans;  
59 -  
60 -/**  
61 - * Test case that simulates a management extension and tests if properties and operations on a managed class can be  
62 - * easily accessed and invoked.  
63 - *  
64 - * @author serpro  
65 - */  
66 -@RunWith(Arquillian.class)  
67 -public class ManagementTestCase {  
68 -  
69 - @Deployment  
70 - public static JavaArchive createMultithreadedDeployment() {  
71 - return ShrinkWrap  
72 - .create(JavaArchive.class)  
73 - .addClass(Tests.class)  
74 - .addPackages(true, "br")  
75 - .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")  
76 - .addAsManifestResource(  
77 - new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),  
78 - "services/javax.enterprise.inject.spi.Extension")  
79 - .addPackages(false, ManagementTestCase.class.getPackage())  
80 - .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class,  
81 - RequestScopeBeanClient.class, RequestScopedClass.class);  
82 - }  
83 -  
84 - @Test  
85 - public void testReadProperty() {  
86 - DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);  
87 - managedClass.setName("Test Name");  
88 -  
89 - // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" acessando  
90 - // nosso tipo gerenciado DummyManagedClass remotamente.  
91 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
92 - Object name = store.getProperty(DummyManagedClass.class, "name");  
93 - Assert.assertEquals("Test Name", name);  
94 - }  
95 -  
96 - @Test  
97 - public void testWriteProperty() {  
98 - // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" definindo  
99 - // um novo valor em uma propriedade de nosso tipo gerenciado DummyManagedClass remotamente.  
100 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
101 - store.setProperty(DummyManagedClass.class, "name", "Test Name");  
102 -  
103 - DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);  
104 - Assert.assertEquals("Test Name", managedClass.getName());  
105 - }  
106 -  
107 - @Test  
108 - public void testReadAWriteOnly() {  
109 -  
110 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
111 -  
112 - try {  
113 - store.getProperty(DummyManagedClass.class, "writeOnlyProperty");  
114 - Assert.fail();  
115 - } catch (DemoiselleException de) {  
116 - // SUCCESS  
117 - }  
118 -  
119 - }  
120 -  
121 - @Test  
122 - public void testWriteAReadOnly() {  
123 -  
124 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
125 -  
126 - try {  
127 - store.setProperty(DummyManagedClass.class, "readOnlyProperty", "New Value");  
128 - Assert.fail();  
129 - } catch (DemoiselleException de) {  
130 - // SUCCESS  
131 - }  
132 -  
133 - }  
134 -  
135 - @Test  
136 - public void testInvokeOperation() {  
137 -  
138 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
139 -  
140 - try {  
141 - store.setProperty(DummyManagedClass.class, "firstFactor", new Integer(10));  
142 - store.setProperty(DummyManagedClass.class, "secondFactor", new Integer(15));  
143 - Integer response = (Integer) store.invoke(DummyManagedClass.class, "sumFactors");  
144 - Assert.assertEquals(new Integer(25), response);  
145 - } catch (DemoiselleException de) {  
146 - Assert.fail(de.getMessage());  
147 - }  
148 -  
149 - }  
150 -  
151 - @Test  
152 - public void testInvokeNonAnnotatedOperation() {  
153 -  
154 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
155 -  
156 - try {  
157 - // O método "nonOperationAnnotatedMethod" existe na classe DummyManagedClass, mas não está anotado como  
158 - // "@ManagedOperation", então  
159 - // ela não pode ser exposta para extensões.  
160 - store.invoke(DummyManagedClass.class, "nonOperationAnnotatedMethod");  
161 - Assert.fail();  
162 - } catch (DemoiselleException de) {  
163 - // SUCCESS  
164 - }  
165 -  
166 - }  
167 -  
168 - @Test  
169 - public void testAccessLevelControl() {  
170 - // tentamos escrever em uma propriedade que, apesar de ter método setter, está marcada como read-only.  
171 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
172 -  
173 - try {  
174 - store.setProperty(DummyManagedClass.class, "readOnlyPropertyWithSetMethod", "A Value");  
175 - Assert.fail();  
176 - } catch (DemoiselleException de) {  
177 - System.out.println(de.getMessage());  
178 - // success  
179 - }  
180 - }  
181 -  
182 - @Test  
183 - public void testRequestScopedOperation() {  
184 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
185 -  
186 - // Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem  
187 - // operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova  
188 - Object info = store.invoke(DummyManagedClass.class, "requestScopedOperation");  
189 - Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);  
190 -  
191 - // Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request.  
192 - info = store.invoke(DummyManagedClass.class, "requestScopedOperation");  
193 - Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);  
194 - }  
195 -}  
impl/core/src/test/java/management/NotificationTestCase.java
@@ -1,136 +0,0 @@ @@ -1,136 +0,0 @@
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 -package management;  
38 -  
39 -import java.io.File;  
40 -  
41 -import javax.inject.Inject;  
42 -  
43 -import junit.framework.Assert;  
44 -import management.testclasses.DummyManagedClass;  
45 -import management.testclasses.DummyNotificationListener;  
46 -  
47 -import org.jboss.arquillian.container.test.api.Deployment;  
48 -import org.jboss.arquillian.junit.Arquillian;  
49 -import org.jboss.shrinkwrap.api.ShrinkWrap;  
50 -import org.jboss.shrinkwrap.api.asset.FileAsset;  
51 -import org.jboss.shrinkwrap.api.spec.JavaArchive;  
52 -import org.junit.Test;  
53 -import org.junit.runner.RunWith;  
54 -  
55 -import test.Tests;  
56 -import br.gov.frameworkdemoiselle.annotation.Name;  
57 -import br.gov.frameworkdemoiselle.internal.management.ManagedType;  
58 -import br.gov.frameworkdemoiselle.internal.management.Management;  
59 -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;  
60 -import br.gov.frameworkdemoiselle.management.GenericNotification;  
61 -import br.gov.frameworkdemoiselle.management.NotificationManager;  
62 -import br.gov.frameworkdemoiselle.util.Beans;  
63 -import br.gov.frameworkdemoiselle.util.ResourceBundle;  
64 -  
65 -/**  
66 - * Test the {@link NotificationManager} with a dummy extension to check if notifications are correctly propagated  
67 - *  
68 - * @author serpro  
69 - */  
70 -@RunWith(Arquillian.class)  
71 -public class NotificationTestCase {  
72 -  
73 - @Inject  
74 - private NotificationManager manager;  
75 -  
76 - @Inject  
77 - @Name("demoiselle-core-bundle")  
78 - private ResourceBundle bundle;  
79 -  
80 - @Deployment  
81 - public static JavaArchive createDeployment() {  
82 - return ShrinkWrap  
83 - .create(JavaArchive.class)  
84 - .addClass(Tests.class)  
85 - .addPackages(true, "br")  
86 - .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")  
87 - .addAsManifestResource(  
88 - new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),  
89 - "services/javax.enterprise.inject.spi.Extension")  
90 - .addPackages(false, NotificationTestCase.class.getPackage())  
91 - .addClasses(DummyNotificationListener.class, DummyManagedClass.class);  
92 - }  
93 -  
94 - /**  
95 - * Test sending a normal notification  
96 - */  
97 - @Test  
98 - public void testSendGenericNotification() {  
99 - manager.sendNotification(new GenericNotification("Test Message"));  
100 - DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);  
101 - Assert.assertEquals("Test Message", listener.getMessage());  
102 - }  
103 -  
104 - /**  
105 - * Test sending a notification of change in attribute  
106 - */  
107 - @Test  
108 - public void testSendAttributeChangeNotification() {  
109 - manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old",  
110 - "new"));  
111 - DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);  
112 - Assert.assertEquals("Test Message - attribute", listener.getMessage());  
113 - }  
114 -  
115 - /**  
116 - * Test if notifications are automatically sent when an attribute from a managed class change values  
117 - */  
118 - @Test  
119 - public void testNotifyChangeManagedClass() {  
120 - Management manager = Beans.getReference(Management.class);  
121 -  
122 - for (ManagedType type : manager.getManagedTypes()) {  
123 - if (type.getType().equals(DummyManagedClass.class)) {  
124 - manager.setProperty(type, "id", new Integer(10));  
125 - break;  
126 - }  
127 - }  
128 -  
129 - DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);  
130 - Assert.assertEquals(  
131 - bundle.getString("management-notification-attribute-changed", "id",  
132 - DummyManagedClass.class.getCanonicalName())  
133 - + " - id", listener.getMessage());  
134 - }  
135 -  
136 -}  
impl/core/src/test/java/management/ValidationTestCase.java
@@ -1,92 +0,0 @@ @@ -1,92 +0,0 @@
1 -package management;  
2 -  
3 -import java.io.File;  
4 -  
5 -import management.testclasses.DummyManagedClass;  
6 -import management.testclasses.DummyManagementExtension;  
7 -import management.testclasses.DummyValidator;  
8 -import management.testclasses.DummyValidatorAnnotation;  
9 -import management.testclasses.ManagedClassStore;  
10 -  
11 -import org.jboss.arquillian.container.test.api.Deployment;  
12 -import org.jboss.arquillian.junit.Arquillian;  
13 -import org.jboss.shrinkwrap.api.ShrinkWrap;  
14 -import org.jboss.shrinkwrap.api.asset.FileAsset;  
15 -import org.jboss.shrinkwrap.api.spec.JavaArchive;  
16 -import org.junit.Assert;  
17 -import org.junit.Test;  
18 -import org.junit.runner.RunWith;  
19 -  
20 -import test.Tests;  
21 -import br.gov.frameworkdemoiselle.DemoiselleException;  
22 -import br.gov.frameworkdemoiselle.util.Beans;  
23 -  
24 -@RunWith(Arquillian.class)  
25 -public class ValidationTestCase {  
26 -  
27 - @Deployment  
28 - public static JavaArchive createDeployment() {  
29 - return ShrinkWrap  
30 - .create(JavaArchive.class)  
31 - .addClass(Tests.class)  
32 - .addPackages(true, "br")  
33 - .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")  
34 - .addAsManifestResource(  
35 - new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),  
36 - "services/javax.enterprise.inject.spi.Extension")  
37 - .addPackages(false, NotificationTestCase.class.getPackage())  
38 - .addClasses(DummyManagementExtension.class, ManagedClassStore.class, DummyManagedClass.class,  
39 - DummyValidator.class, DummyValidatorAnnotation.class);  
40 - }  
41 -  
42 - /**  
43 - * Test if a management controller accepts a valid value annotated with a core validation (from javax.validation)  
44 - * when a property is being set by a management client  
45 - */  
46 - @Test  
47 - public void testSetValidValue() {  
48 - // Testa se é possível definir um valor válido para uma propriedade.  
49 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
50 - store.setProperty(DummyManagedClass.class, "id", new Integer(1));  
51 - Assert.assertEquals(new Integer(1), store.getProperty(DummyManagedClass.class, "id"));  
52 - }  
53 -  
54 - /**  
55 - * Test if a management controller refuses a valid value annotated with a core validation (from javax.validation)  
56 - * when a property is being set by a management client  
57 - */  
58 - @Test  
59 - public void testSetInvalidValue() {  
60 - // Testa se é possível definir um valor válido para uma propriedade.  
61 - try {  
62 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
63 - store.setProperty(DummyManagedClass.class, "id", (Integer) null);  
64 -  
65 - Assert.fail();  
66 - } catch (DemoiselleException de) {  
67 - // Classes de gerenciamento disparam Demoiselle Exception quando uma validação falha  
68 - }  
69 - }  
70 -  
71 - /**  
72 - * Tests if custom validators (outside the javax.validation package) run as normal  
73 - */  
74 - @Test  
75 - public void testCustomValidation() {  
76 -  
77 - try {  
78 - ManagedClassStore store = Beans.getReference(ManagedClassStore.class);  
79 -  
80 - // Atributo "gender" deve aceitar apenas "M" ou "F", tanto maiúsculo quanto minúsculo. A anotação  
81 - // customizada DummyValidatorAnnotation é uma simples validação que testa se uma string passada está  
82 - // na lista de strings aceitas.  
83 - store.setProperty(DummyManagedClass.class, "gender", "J");  
84 -  
85 - Assert.fail();  
86 - } catch (DemoiselleException e) {  
87 - Assert.assertTrue(e.getMessage().contains("Test Message"));  
88 - }  
89 -  
90 - }  
91 -  
92 -}  
impl/core/src/test/java/management/annotation/AnnotationTest.java 0 → 100644
@@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
  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 +package management.annotation;
  38 +
  39 +import management.testclasses.DummyManagedClassPropertyError;
  40 +import management.testclasses.DummyManagementExtension;
  41 +import management.testclasses.ManagedClassStore;
  42 +
  43 +import org.jboss.arquillian.container.test.api.Deployer;
  44 +import org.jboss.arquillian.container.test.api.Deployment;
  45 +import org.jboss.arquillian.junit.Arquillian;
  46 +import org.jboss.arquillian.test.api.ArquillianResource;
  47 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  48 +import org.junit.Assert;
  49 +import org.junit.Test;
  50 +import org.junit.runner.RunWith;
  51 +
  52 +import test.Tests;
  53 +
  54 +@RunWith(Arquillian.class)
  55 +public class AnnotationTest {
  56 +
  57 + /**
  58 + * Deployment containing a malformed managed class. Tests using this deployment will check if deployment fails (it
  59 + * has to).
  60 + */
  61 + @Deployment(name = "wrong_annotation", managed = false)
  62 + public static JavaArchive createWrongAnnotationDeployment() {
  63 +
  64 + return Tests.createDeployment(AnnotationTest.class)
  65 + .addClasses(DummyManagementExtension.class, ManagedClassStore.class,DummyManagedClassPropertyError.class);
  66 + }
  67 +
  68 + @Test
  69 + public void wrongAnnotation(@ArquillianResource Deployer deployer) {
  70 +
  71 + try {
  72 + deployer.deploy("wrong_annotation");
  73 +
  74 + // O processo de deploy precisa falhar, pois temos uma classe anotada com falhas.
  75 + Assert.fail();
  76 + } catch (Exception e) {
  77 + //SUCCESS
  78 + } finally {
  79 + deployer.undeploy("wrong_annotation");
  80 + }
  81 + }
  82 +
  83 +}
impl/core/src/test/java/management/basic/ManagementTest.java 0 → 100644
@@ -0,0 +1,183 @@ @@ -0,0 +1,183 @@
  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 +package management.basic;
  38 +
  39 +import junit.framework.Assert;
  40 +import management.testclasses.DummyManagedClass;
  41 +import management.testclasses.DummyManagementExtension;
  42 +import management.testclasses.ManagedClassStore;
  43 +import management.testclasses.RequestScopeBeanClient;
  44 +import management.testclasses.RequestScopedClass;
  45 +
  46 +import org.jboss.arquillian.container.test.api.Deployment;
  47 +import org.jboss.arquillian.junit.Arquillian;
  48 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  49 +import org.junit.Test;
  50 +import org.junit.runner.RunWith;
  51 +
  52 +import test.Tests;
  53 +import br.gov.frameworkdemoiselle.DemoiselleException;
  54 +import br.gov.frameworkdemoiselle.util.Beans;
  55 +
  56 +/**
  57 + * Test case that simulates a management extension and tests if properties and operations on a managed class can be
  58 + * easily accessed and invoked.
  59 + *
  60 + * @author serpro
  61 + */
  62 +@RunWith(Arquillian.class)
  63 +public class ManagementTest {
  64 +
  65 + @Deployment
  66 + public static JavaArchive createMultithreadedDeployment() {
  67 +
  68 + return Tests.createDeployment(ManagementTest.class)
  69 + .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class,RequestScopeBeanClient.class, RequestScopedClass.class);
  70 + }
  71 +
  72 + @Test
  73 + public void readProperty() {
  74 + DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);
  75 + managedClass.setName("Test Name");
  76 +
  77 + // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" acessando
  78 + // nosso tipo gerenciado DummyManagedClass remotamente.
  79 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  80 + Object name = store.getProperty(DummyManagedClass.class, "name");
  81 + Assert.assertEquals("Test Name", name);
  82 + }
  83 +
  84 + @Test
  85 + public void writeProperty() {
  86 + // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" definindo
  87 + // um novo valor em uma propriedade de nosso tipo gerenciado DummyManagedClass remotamente.
  88 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  89 + store.setProperty(DummyManagedClass.class, "name", "Test Name");
  90 +
  91 + DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);
  92 + Assert.assertEquals("Test Name", managedClass.getName());
  93 + }
  94 +
  95 + @Test
  96 + public void readAWriteOnly() {
  97 +
  98 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  99 +
  100 + try {
  101 + store.getProperty(DummyManagedClass.class, "writeOnlyProperty");
  102 + Assert.fail();
  103 + } catch (DemoiselleException de) {
  104 + // SUCCESS
  105 + }
  106 +
  107 + }
  108 +
  109 + @Test
  110 + public void writeAReadOnly() {
  111 +
  112 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  113 +
  114 + try {
  115 + store.setProperty(DummyManagedClass.class, "readOnlyProperty", "New Value");
  116 + Assert.fail();
  117 + } catch (DemoiselleException de) {
  118 + // SUCCESS
  119 + }
  120 +
  121 + }
  122 +
  123 + @Test
  124 + public void invokeOperation() {
  125 +
  126 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  127 +
  128 + try {
  129 + store.setProperty(DummyManagedClass.class, "firstFactor", new Integer(10));
  130 + store.setProperty(DummyManagedClass.class, "secondFactor", new Integer(15));
  131 + Integer response = (Integer) store.invoke(DummyManagedClass.class, "sumFactors");
  132 + Assert.assertEquals(new Integer(25), response);
  133 + } catch (DemoiselleException de) {
  134 + Assert.fail(de.getMessage());
  135 + }
  136 +
  137 + }
  138 +
  139 + @Test
  140 + public void invokeNonAnnotatedOperation() {
  141 +
  142 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  143 +
  144 + try {
  145 + // O método "nonOperationAnnotatedMethod" existe na classe DummyManagedClass, mas não está anotado como
  146 + // "@ManagedOperation", então
  147 + // ela não pode ser exposta para extensões.
  148 + store.invoke(DummyManagedClass.class, "nonOperationAnnotatedMethod");
  149 + Assert.fail();
  150 + } catch (DemoiselleException de) {
  151 + // SUCCESS
  152 + }
  153 +
  154 + }
  155 +
  156 + @Test
  157 + public void accessLevelControl() {
  158 + // tentamos escrever em uma propriedade que, apesar de ter método setter, está marcada como read-only.
  159 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  160 +
  161 + try {
  162 + store.setProperty(DummyManagedClass.class, "readOnlyPropertyWithSetMethod", "A Value");
  163 + Assert.fail();
  164 + } catch (DemoiselleException de) {
  165 + System.out.println(de.getMessage());
  166 + // success
  167 + }
  168 + }
  169 +
  170 + @Test
  171 + public void requestScopedOperation() {
  172 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  173 +
  174 + // Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem
  175 + // operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova
  176 + Object info = store.invoke(DummyManagedClass.class, "requestScopedOperation");
  177 + Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);
  178 +
  179 + // Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request.
  180 + info = store.invoke(DummyManagedClass.class, "requestScopedOperation");
  181 + Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);
  182 + }
  183 +}
impl/core/src/test/java/management/bootstrap/ManagementBootstrapTest.java 0 → 100644
@@ -0,0 +1,117 @@ @@ -0,0 +1,117 @@
  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 +package management.bootstrap;
  38 +
  39 +import java.util.List;
  40 +
  41 +import management.testclasses.DummyManagedClass;
  42 +import management.testclasses.DummyManagementExtension;
  43 +import management.testclasses.ManagedClassStore;
  44 +
  45 +import org.jboss.arquillian.container.test.api.Deployment;
  46 +import org.jboss.arquillian.junit.Arquillian;
  47 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  48 +import org.junit.Assert;
  49 +import org.junit.Test;
  50 +import org.junit.runner.RunWith;
  51 +
  52 +import test.Tests;
  53 +import br.gov.frameworkdemoiselle.internal.management.ManagedType;
  54 +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
  55 +import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
  56 +import br.gov.frameworkdemoiselle.util.Beans;
  57 +
  58 +@RunWith(Arquillian.class)
  59 +public class ManagementBootstrapTest {
  60 +
  61 + /**
  62 + * Deployment to test normal deployment behaviour
  63 + *
  64 + */
  65 + @Deployment
  66 + public static JavaArchive createDeployment() {
  67 + return Tests.createDeployment(ManagementBootstrapTest.class)
  68 + .addClasses(DummyManagementExtension.class,
  69 + DummyManagedClass.class, ManagedClassStore.class);
  70 + }
  71 +
  72 + /**
  73 + * Test if a a management extension (a library that implements
  74 + * {@link ManagementExtension}) is correctly detected.
  75 + */
  76 + @Test
  77 + public void managementExtensionRegistration() {
  78 + // "store" é application scoped e é usado pelo DummyManagementExtension
  79 + // para
  80 + // armazenar todos os beans anotados com @ManagementController. Se o
  81 + // bootstrap rodou corretamente,
  82 + // ele chamou DummyManagementExtension.initialize e este store conterá o
  83 + // bean de teste que anotamos.
  84 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  85 +
  86 + Assert.assertEquals(1, store.getManagedTypes().size());
  87 + }
  88 +
  89 + /**
  90 + * Test if a a management extension's shutdown method is correctly called
  91 + * upon application shutdown.
  92 + */
  93 + @Test
  94 + public void managementExtensionShutdown() {
  95 + // "store" é application scoped e é usado pelo DummyManagementExtension
  96 + // para
  97 + // armazenar todos os beans anotados com @ManagementController. Se o
  98 + // bootstrap rodou corretamente,
  99 + // ele chamou DummyManagementExtension.initialize e este store conterá o
  100 + // bean de teste que anotamos.
  101 + // Nós então disparamos o evento de shutdown onde ele deverá limpar o
  102 + // store.
  103 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  104 +
  105 + // Detecta se a classe anotada foi detectada
  106 + List<ManagedType> managedTypes = store.getManagedTypes();
  107 + Assert.assertEquals(1, managedTypes.size());
  108 +
  109 + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() {
  110 + });
  111 +
  112 + // Após o "undeploy", o ciclo de vida precisa ter removido a classe
  113 + // gerenciada da lista.
  114 + Assert.assertEquals(0, managedTypes.size());
  115 + }
  116 +
  117 +}
impl/core/src/test/java/management/notification/NotificationTest.java 0 → 100644
@@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
  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 +package management.notification;
  38 +
  39 +import javax.inject.Inject;
  40 +
  41 +import junit.framework.Assert;
  42 +import management.testclasses.DummyManagedClass;
  43 +import management.testclasses.DummyNotificationListener;
  44 +
  45 +import org.jboss.arquillian.container.test.api.Deployment;
  46 +import org.jboss.arquillian.junit.Arquillian;
  47 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  48 +import org.junit.Test;
  49 +import org.junit.runner.RunWith;
  50 +
  51 +import test.Tests;
  52 +import br.gov.frameworkdemoiselle.annotation.Name;
  53 +import br.gov.frameworkdemoiselle.internal.management.ManagedType;
  54 +import br.gov.frameworkdemoiselle.internal.management.Management;
  55 +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
  56 +import br.gov.frameworkdemoiselle.management.GenericNotification;
  57 +import br.gov.frameworkdemoiselle.management.NotificationManager;
  58 +import br.gov.frameworkdemoiselle.util.Beans;
  59 +import br.gov.frameworkdemoiselle.util.ResourceBundle;
  60 +
  61 +/**
  62 + * Test the {@link NotificationManager} with a dummy extension to check if notifications are correctly propagated
  63 + *
  64 + * @author serpro
  65 + */
  66 +@RunWith(Arquillian.class)
  67 +public class NotificationTest {
  68 +
  69 + @Inject
  70 + private NotificationManager manager;
  71 +
  72 + @Inject
  73 + @Name("demoiselle-core-bundle")
  74 + private ResourceBundle bundle;
  75 +
  76 + @Deployment
  77 + public static JavaArchive createDeployment() {
  78 + return Tests.createDeployment(NotificationTest.class)
  79 + .addClasses(DummyNotificationListener.class, DummyManagedClass.class);
  80 + }
  81 +
  82 + /**
  83 + * Test sending a normal notification
  84 + */
  85 + @Test
  86 + public void sendGenericNotification() {
  87 + manager.sendNotification(new GenericNotification("Test Message"));
  88 + DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
  89 + Assert.assertEquals("Test Message", listener.getMessage());
  90 + }
  91 +
  92 + /**
  93 + * Test sending a notification of change in attribute
  94 + */
  95 + @Test
  96 + public void sendAttributeChangeNotification() {
  97 + manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old",
  98 + "new"));
  99 + DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
  100 + Assert.assertEquals("Test Message - attribute", listener.getMessage());
  101 + }
  102 +
  103 + /**
  104 + * Test if notifications are automatically sent when an attribute from a managed class change values
  105 + */
  106 + @Test
  107 + public void notifyChangeManagedClass() {
  108 + Management manager = Beans.getReference(Management.class);
  109 +
  110 + for (ManagedType type : manager.getManagedTypes()) {
  111 + if (type.getType().equals(DummyManagedClass.class)) {
  112 + manager.setProperty(type, "id", new Integer(10));
  113 + break;
  114 + }
  115 + }
  116 +
  117 + DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
  118 + Assert.assertEquals(
  119 + bundle.getString("management-notification-attribute-changed", "id",
  120 + DummyManagedClass.class.getCanonicalName())
  121 + + " - id", listener.getMessage());
  122 + }
  123 +
  124 +}
impl/core/src/test/java/management/validation/ValidationTest.java 0 → 100644
@@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
  1 +package management.validation;
  2 +
  3 +import management.testclasses.DummyManagedClass;
  4 +import management.testclasses.DummyManagementExtension;
  5 +import management.testclasses.DummyValidator;
  6 +import management.testclasses.DummyValidatorAnnotation;
  7 +import management.testclasses.ManagedClassStore;
  8 +
  9 +import org.jboss.arquillian.container.test.api.Deployment;
  10 +import org.jboss.arquillian.junit.Arquillian;
  11 +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  12 +import org.junit.Assert;
  13 +import org.junit.Test;
  14 +import org.junit.runner.RunWith;
  15 +
  16 +import test.Tests;
  17 +import br.gov.frameworkdemoiselle.DemoiselleException;
  18 +import br.gov.frameworkdemoiselle.util.Beans;
  19 +
  20 +@RunWith(Arquillian.class)
  21 +public class ValidationTest {
  22 +
  23 + @Deployment
  24 + public static JavaArchive createDeployment() {
  25 +
  26 + return Tests.createDeployment(ValidationTest.class)
  27 + .addClasses(DummyManagementExtension.class, ManagedClassStore.class, DummyManagedClass.class,DummyValidator.class, DummyValidatorAnnotation.class);
  28 +
  29 + }
  30 +
  31 + /**
  32 + * Test if a management controller accepts a valid value annotated with a core validation (from javax.validation)
  33 + * when a property is being set by a management client
  34 + */
  35 + @Test
  36 + public void setValidValue() {
  37 + // Testa se é possível definir um valor válido para uma propriedade.
  38 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  39 + store.setProperty(DummyManagedClass.class, "id", new Integer(1));
  40 + Assert.assertEquals(new Integer(1), store.getProperty(DummyManagedClass.class, "id"));
  41 + }
  42 +
  43 + /**
  44 + * Test if a management controller refuses a valid value annotated with a core validation (from javax.validation)
  45 + * when a property is being set by a management client
  46 + */
  47 + @Test
  48 + public void setInvalidValue() {
  49 + // Testa se é possível definir um valor válido para uma propriedade.
  50 + try {
  51 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  52 + store.setProperty(DummyManagedClass.class, "id", (Integer) null);
  53 +
  54 + Assert.fail();
  55 + } catch (DemoiselleException de) {
  56 + // Classes de gerenciamento disparam Demoiselle Exception quando uma validação falha
  57 + }
  58 + }
  59 +
  60 + /**
  61 + * Tests if custom validators (outside the javax.validation package) run as normal
  62 + */
  63 + @Test
  64 + public void customValidation() {
  65 +
  66 + try {
  67 + ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
  68 +
  69 + // Atributo "gender" deve aceitar apenas "M" ou "F", tanto maiúsculo quanto minúsculo. A anotação
  70 + // customizada DummyValidatorAnnotation é uma simples validação que testa se uma string passada está
  71 + // na lista de strings aceitas.
  72 + store.setProperty(DummyManagedClass.class, "gender", "J");
  73 +
  74 + Assert.fail();
  75 + } catch (DemoiselleException e) {
  76 + Assert.assertTrue(e.getMessage().contains("Test Message"));
  77 + }
  78 +
  79 + }
  80 +
  81 +}