Commit abb5cd6e6ae9e23134be36fc51b2e9b4ac31677f
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into
2.4.0 Conflicts: impl/extension/jpa/src/test/resources/arquillian.xml
Showing
45 changed files
with
2220 additions
and
1164 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
... | ... | @@ -21,7 +21,6 @@ import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
21 | 21 | import br.gov.frameworkdemoiselle.internal.context.ManagedContext; |
22 | 22 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; |
23 | 23 | import br.gov.frameworkdemoiselle.internal.management.Management; |
24 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
25 | 24 | import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; |
26 | 25 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; |
27 | 26 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
... | ... | @@ -48,7 +47,7 @@ public class ManagementBootstrap implements Extension { |
48 | 47 | |
49 | 48 | @SuppressWarnings("unchecked") |
50 | 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 | 52 | Management monitoringManager = Beans.getReference(Management.class); |
54 | 53 | for (AnnotatedType<?> type : types) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagedType.java
... | ... | @@ -40,6 +40,7 @@ import java.lang.annotation.Annotation; |
40 | 40 | import java.lang.reflect.Field; |
41 | 41 | import java.lang.reflect.Method; |
42 | 42 | import java.util.ArrayList; |
43 | +import java.util.Locale; | |
43 | 44 | import java.util.TreeMap; |
44 | 45 | |
45 | 46 | import javax.inject.Qualifier; |
... | ... | @@ -47,10 +48,9 @@ import javax.inject.Qualifier; |
47 | 48 | import br.gov.frameworkdemoiselle.DemoiselleException; |
48 | 49 | import br.gov.frameworkdemoiselle.annotation.ManagedOperation; |
49 | 50 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
50 | -import br.gov.frameworkdemoiselle.annotation.OperationType; | |
51 | 51 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty.ManagedPropertyAccess; |
52 | 52 | import br.gov.frameworkdemoiselle.annotation.OperationParameter; |
53 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
53 | +import br.gov.frameworkdemoiselle.annotation.OperationType; | |
54 | 54 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
55 | 55 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
56 | 56 | |
... | ... | @@ -77,7 +77,7 @@ public class ManagedType { |
77 | 77 | private String description; |
78 | 78 | |
79 | 79 | public ManagedType(Class<?> type) { |
80 | - bundle = new ResourceBundleProducer().create("demoiselle-core-bundle"); | |
80 | + bundle = new ResourceBundle("demoiselle-core-bundle",Locale.getDefault()); | |
81 | 81 | |
82 | 82 | if (type == null) { |
83 | 83 | throw new DemoiselleException(bundle.getString("management-null-class-defined")); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/AuthenticationException.java
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/Authenticator.java
... | ... | @@ -52,7 +52,7 @@ public interface Authenticator extends Serializable { |
52 | 52 | * @throws AuthenticationException |
53 | 53 | * When the authentication process fails, this exception is thrown. |
54 | 54 | */ |
55 | - void authenticate() throws AuthenticationException; | |
55 | + void authenticate(); | |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Executes the necessary steps to unauthenticate an user. | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/SecurityContext.java
... | ... | @@ -49,10 +49,10 @@ public interface SecurityContext extends Serializable { |
49 | 49 | /** |
50 | 50 | * Executes the login of a user to the application. |
51 | 51 | * |
52 | - * @throws AuthorizationException | |
52 | + * @throws AuthenticationException | |
53 | 53 | * When the logon process fails, this exception is thrown. |
54 | 54 | */ |
55 | - void login() throws AuthorizationException; | |
55 | + void login(); | |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Executes the logout of a user. |
... | ... | @@ -60,7 +60,7 @@ public interface SecurityContext extends Serializable { |
60 | 60 | * @throws NotLoggedInException |
61 | 61 | * if there is no user logged in a specific session |
62 | 62 | */ |
63 | - void logout() throws NotLoggedInException; | |
63 | + void logout(); | |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * Checks if a specific user is logged in. |
... | ... | @@ -69,7 +69,11 @@ public interface SecurityContext extends Serializable { |
69 | 69 | */ |
70 | 70 | boolean isLoggedIn(); |
71 | 71 | |
72 | - void checkLoggedIn() throws NotLoggedInException; | |
72 | + /** | |
73 | + * @throws NotLoggedInException | |
74 | + * if there is no user logged in a specific session | |
75 | + */ | |
76 | + void checkLoggedIn(); | |
73 | 77 | |
74 | 78 | /** |
75 | 79 | * Checks if the logged user has permission to execute an specific operation on a specific resource. |
... | ... | @@ -79,10 +83,11 @@ public interface SecurityContext extends Serializable { |
79 | 83 | * @param operation |
80 | 84 | * operation to be checked |
81 | 85 | * @return {@code true} if the user has the permission |
86 | + * | |
82 | 87 | * @throws NotLoggedInException |
83 | 88 | * if there is no user logged in a specific session. |
84 | 89 | */ |
85 | - boolean hasPermission(String resource, String operation) throws NotLoggedInException; | |
90 | + boolean hasPermission(String resource, String operation); | |
86 | 91 | |
87 | 92 | /** |
88 | 93 | * Checks if the logged user has an specific role |
... | ... | @@ -90,10 +95,11 @@ public interface SecurityContext extends Serializable { |
90 | 95 | * @param role |
91 | 96 | * role to be checked |
92 | 97 | * @return {@code true} if the user has the role |
98 | + * | |
93 | 99 | * @throws NotLoggedInException |
94 | 100 | * if there is no user logged in a specific session. |
95 | 101 | */ |
96 | - boolean hasRole(String role) throws NotLoggedInException; | |
102 | + boolean hasRole(String role); | |
97 | 103 | |
98 | 104 | /** |
99 | 105 | * Return the user logged in the session. | ... | ... |
impl/core/src/test/java/management/AnnotationTestCase.java
... | ... | @@ -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 | -/* | |
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 | -/* | |
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 | -/* | |
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 | -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,89 @@ |
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.Ignore; | |
50 | +import org.junit.Test; | |
51 | +import org.junit.runner.RunWith; | |
52 | + | |
53 | +import test.Tests; | |
54 | + | |
55 | +/* | |
56 | + * TODO Esse teste está impedindo outros de rodarem por fazer um deployment manual pelo arquillian (após esse teste nenhum mais roda). | |
57 | + * Por enquanto ele fica marcado como @Ignore, até esse problema ser resolvido. | |
58 | + */ | |
59 | +@RunWith(Arquillian.class) | |
60 | +@Ignore | |
61 | +public class AnnotationTest { | |
62 | + | |
63 | + /** | |
64 | + * Deployment containing a malformed managed class. Tests using this deployment will check if deployment fails (it | |
65 | + * has to). | |
66 | + */ | |
67 | + @Deployment(name = "wrong_annotation", managed = false) | |
68 | + public static JavaArchive createWrongAnnotationDeployment() { | |
69 | + | |
70 | + return Tests.createDeployment(AnnotationTest.class) | |
71 | + .addClasses(DummyManagementExtension.class, ManagedClassStore.class,DummyManagedClassPropertyError.class); | |
72 | + } | |
73 | + | |
74 | + @Test | |
75 | + public void wrongAnnotation(@ArquillianResource Deployer deployer) { | |
76 | + | |
77 | + try { | |
78 | + deployer.deploy("wrong_annotation"); | |
79 | + | |
80 | + // O processo de deploy precisa falhar, pois temos uma classe anotada com falhas. | |
81 | + Assert.fail(); | |
82 | + } catch (Exception e) { | |
83 | + //SUCCESS | |
84 | + } finally { | |
85 | + deployer.undeploy("wrong_annotation"); | |
86 | + } | |
87 | + } | |
88 | + | |
89 | +} | ... | ... |
impl/core/src/test/java/management/basic/ManagementTest.java
0 → 100644
... | ... | @@ -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 @@ |
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 @@ |
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 @@ |
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 | +} | ... | ... |
impl/core/src/test/java/security/athentication/credentials/AcceptOrDenyCredentialsTest.java
0 → 100644
... | ... | @@ -0,0 +1,111 @@ |
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 security.athentication.credentials; | |
38 | + | |
39 | +import javax.enterprise.context.RequestScoped; | |
40 | +import javax.inject.Inject; | |
41 | + | |
42 | +import junit.framework.Assert; | |
43 | + | |
44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
45 | +import org.jboss.arquillian.junit.Arquillian; | |
46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
47 | +import org.junit.Test; | |
48 | +import org.junit.runner.RunWith; | |
49 | + | |
50 | +import test.Tests; | |
51 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
52 | +import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; | |
53 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
54 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
55 | +import br.gov.frameworkdemoiselle.util.Beans; | |
56 | +import configuration.resource.ConfigurationResourceTest; | |
57 | + | |
58 | +@RunWith(Arquillian.class) | |
59 | +public class AcceptOrDenyCredentialsTest { | |
60 | + | |
61 | + @Inject | |
62 | + private SecurityContext context; | |
63 | + | |
64 | + @Deployment | |
65 | + public static JavaArchive createDeployment() { | |
66 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
67 | + deployment.addClass(StrictAuthenticator.class); | |
68 | + deployment.addClass(Credentials.class); | |
69 | + return deployment; | |
70 | + } | |
71 | + | |
72 | + @Test | |
73 | + public void denyWrongCredentials() { | |
74 | + ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | |
75 | + | |
76 | + Credentials credentials = Beans.getReference(Credentials.class); | |
77 | + credentials.setLogin("wronglogin"); | |
78 | + | |
79 | + try{ | |
80 | + context.login(); | |
81 | + Assert.fail("Authenticator aceitou credenciais erradas"); | |
82 | + } | |
83 | + catch(AuthenticationException ae){ | |
84 | + //Erro esperado | |
85 | + } | |
86 | + finally{ | |
87 | + ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | |
88 | + } | |
89 | + | |
90 | + } | |
91 | + | |
92 | + @Test | |
93 | + public void acceptRightCredentials() { | |
94 | + ContextManager.activate(ThreadLocalContext.class, RequestScoped.class); | |
95 | + | |
96 | + Credentials credentials = Beans.getReference(Credentials.class); | |
97 | + credentials.setLogin("demoiselle"); | |
98 | + | |
99 | + try{ | |
100 | + context.login(); | |
101 | + } | |
102 | + catch(AuthenticationException ae){ | |
103 | + Assert.fail("Authenticator negou credenciais corretas"); | |
104 | + } | |
105 | + finally{ | |
106 | + ContextManager.deactivate(ThreadLocalContext.class, RequestScoped.class); | |
107 | + } | |
108 | + | |
109 | + } | |
110 | + | |
111 | +} | ... | ... |
impl/core/src/test/java/security/athentication/credentials/Credentials.java
0 → 100644
... | ... | @@ -0,0 +1,25 @@ |
1 | +package security.athentication.credentials; | |
2 | + | |
3 | +import java.io.Serializable; | |
4 | + | |
5 | +import javax.enterprise.context.RequestScoped; | |
6 | + | |
7 | +@RequestScoped | |
8 | +public class Credentials implements Serializable { | |
9 | + | |
10 | + private static final long serialVersionUID = 1L; | |
11 | + private String login; | |
12 | + | |
13 | + | |
14 | + public String getLogin() { | |
15 | + return login; | |
16 | + } | |
17 | + | |
18 | + | |
19 | + public void setLogin(String login) { | |
20 | + this.login = login; | |
21 | + } | |
22 | + | |
23 | + | |
24 | + | |
25 | +} | ... | ... |
impl/core/src/test/java/security/athentication/credentials/StrictAuthenticator.java
0 → 100644
... | ... | @@ -0,0 +1,77 @@ |
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 security.athentication.credentials; | |
38 | + | |
39 | +import java.security.Principal; | |
40 | + | |
41 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
42 | +import br.gov.frameworkdemoiselle.security.Authenticator; | |
43 | +import br.gov.frameworkdemoiselle.util.Beans; | |
44 | + | |
45 | +public class StrictAuthenticator implements Authenticator { | |
46 | + | |
47 | + private static final long serialVersionUID = 1L; | |
48 | + | |
49 | + private Principal currentUser; | |
50 | + | |
51 | + @Override | |
52 | + public void authenticate() throws AuthenticationException { | |
53 | + | |
54 | + Credentials c = Beans.getReference(Credentials.class); | |
55 | + if ("demoiselle".equals(c.getLogin())){ | |
56 | + this.currentUser = new Principal() { | |
57 | + | |
58 | + public String getName() { | |
59 | + return "demoiselle"; | |
60 | + } | |
61 | + }; | |
62 | + } | |
63 | + else{ | |
64 | + throw new AuthenticationException("As credenciais fornecidas não são válidas"); | |
65 | + } | |
66 | + } | |
67 | + | |
68 | + @Override | |
69 | + public void unAuthenticate() { | |
70 | + this.currentUser = null; | |
71 | + } | |
72 | + | |
73 | + @Override | |
74 | + public Principal getUser() { | |
75 | + return this.currentUser; | |
76 | + } | |
77 | +} | ... | ... |
impl/core/src/test/java/security/athentication/error/ErrorAuthenticator.java
0 → 100644
... | ... | @@ -0,0 +1,64 @@ |
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 security.athentication.error; | |
38 | + | |
39 | +import java.security.Principal; | |
40 | + | |
41 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
42 | +import br.gov.frameworkdemoiselle.security.Authenticator; | |
43 | + | |
44 | +public class ErrorAuthenticator implements Authenticator { | |
45 | + | |
46 | + private static final long serialVersionUID = 1L; | |
47 | + | |
48 | + @Override | |
49 | + public void authenticate() throws AuthenticationException { | |
50 | + throw new RuntimeException(); | |
51 | + } | |
52 | + | |
53 | + @Override | |
54 | + public void unAuthenticate() { | |
55 | + throw new RuntimeException(); | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + public Principal getUser() { | |
60 | + return null; | |
61 | + } | |
62 | + | |
63 | + | |
64 | +} | ... | ... |
impl/core/src/test/java/security/athentication/error/ErrorAuthenticatorTest.java
0 → 100644
... | ... | @@ -0,0 +1,95 @@ |
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 security.athentication.error; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import junit.framework.Assert; | |
42 | + | |
43 | +import org.jboss.arquillian.container.test.api.Deployment; | |
44 | +import org.jboss.arquillian.junit.Arquillian; | |
45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
46 | +import org.junit.Test; | |
47 | +import org.junit.runner.RunWith; | |
48 | + | |
49 | +import test.Tests; | |
50 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
51 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
52 | +import configuration.resource.ConfigurationResourceTest; | |
53 | + | |
54 | +@RunWith(Arquillian.class) | |
55 | +public class ErrorAuthenticatorTest { | |
56 | + | |
57 | + @Inject | |
58 | + private SecurityContext context; | |
59 | + | |
60 | + @Deployment | |
61 | + public static JavaArchive createDeployment() { | |
62 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
63 | + deployment.addClass(ErrorAuthenticator.class); | |
64 | + return deployment; | |
65 | + } | |
66 | + | |
67 | + @Test | |
68 | + public void errorDuringLogin(){ | |
69 | + try{ | |
70 | + context.login(); | |
71 | + Assert.fail("Login deveria disparar exceção de runtime"); | |
72 | + } | |
73 | + catch(AuthenticationException ae){ | |
74 | + Assert.fail("A exceção disparada não foi a esperada"); | |
75 | + } | |
76 | + catch(RuntimeException e){ | |
77 | + //PASS | |
78 | + } | |
79 | + } | |
80 | + | |
81 | + @Test | |
82 | + public void errorDuringLogout(){ | |
83 | + try{ | |
84 | + context.login(); | |
85 | + Assert.fail("Logout deveria disparar exceção de runtime"); | |
86 | + } | |
87 | + catch(AuthenticationException ae){ | |
88 | + Assert.fail("A exceção disparada não foi a esperada"); | |
89 | + } | |
90 | + catch(RuntimeException e){ | |
91 | + //PASS | |
92 | + } | |
93 | + } | |
94 | + | |
95 | +} | ... | ... |
impl/core/src/test/java/security/authorization/ambiguity/AmbiguousAuthorizerTest.java
0 → 100644
... | ... | @@ -0,0 +1,92 @@ |
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 security.authorization.ambiguity; | |
38 | + | |
39 | +import static junit.framework.Assert.assertEquals; | |
40 | + | |
41 | +import javax.enterprise.inject.AmbiguousResolutionException; | |
42 | +import javax.inject.Inject; | |
43 | + | |
44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
45 | +import org.jboss.arquillian.junit.Arquillian; | |
46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
47 | +import org.junit.After; | |
48 | +import org.junit.Before; | |
49 | +import org.junit.Test; | |
50 | +import org.junit.runner.RunWith; | |
51 | + | |
52 | +import security.athentication.custom.CustomAuthenticator; | |
53 | +import security.authorization.custom.CustomAuthorizer; | |
54 | +import test.Tests; | |
55 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
56 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
57 | +import configuration.resource.ConfigurationResourceTest; | |
58 | + | |
59 | +@RunWith(Arquillian.class) | |
60 | +public class AmbiguousAuthorizerTest { | |
61 | + | |
62 | + @Inject | |
63 | + private SecurityContext context; | |
64 | + | |
65 | + @Deployment | |
66 | + public static JavaArchive createDeployment() { | |
67 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
68 | + deployment.addClass(CustomAuthenticator.class); | |
69 | + deployment.addClass(CustomAuthorizer.class); | |
70 | + deployment.addClass(DuplicatedCustomAuthorizer.class); | |
71 | + return deployment; | |
72 | + } | |
73 | + | |
74 | + @Before | |
75 | + public void loginToTest(){ | |
76 | + context.login(); | |
77 | + } | |
78 | + | |
79 | + @Test | |
80 | + public void ambiguousAuthorizerStrategy() { | |
81 | + try { | |
82 | + context.hasRole("role"); | |
83 | + } catch (DemoiselleException cause) { | |
84 | + assertEquals(AmbiguousResolutionException.class, cause.getCause().getClass()); | |
85 | + } | |
86 | + } | |
87 | + | |
88 | + @After | |
89 | + public void logoutAfterTest(){ | |
90 | + context.logout(); | |
91 | + } | |
92 | +} | ... | ... |
impl/core/src/test/java/security/authorization/ambiguity/DuplicatedCustomAuthorizer.java
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
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 security.authorization.ambiguity; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
40 | + | |
41 | +public class DuplicatedCustomAuthorizer implements Authorizer { | |
42 | + | |
43 | + private static final long serialVersionUID = 1L; | |
44 | + | |
45 | + @Override | |
46 | + public boolean hasRole(String role) { | |
47 | + return true; | |
48 | + } | |
49 | + | |
50 | + @Override | |
51 | + public boolean hasPermission(String resource, String operation) { | |
52 | + return true; | |
53 | + } | |
54 | +} | ... | ... |
impl/core/src/test/java/security/authorization/custom/CustomAuthorizer.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
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 security.authorization.custom; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
40 | + | |
41 | +public class CustomAuthorizer implements Authorizer { | |
42 | + | |
43 | + private static final long serialVersionUID = 1L; | |
44 | + | |
45 | + @Override | |
46 | + public boolean hasRole(String role) { | |
47 | + return "role".equals(role); | |
48 | + } | |
49 | + | |
50 | + @Override | |
51 | + public boolean hasPermission(String resource, String operation) { | |
52 | + return "resource".equals(resource); | |
53 | + } | |
54 | + | |
55 | + | |
56 | + | |
57 | +} | ... | ... |
impl/core/src/test/java/security/authorization/custom/CustomAuthorizerTest.java
0 → 100644
... | ... | @@ -0,0 +1,100 @@ |
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 security.authorization.custom; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import junit.framework.Assert; | |
42 | + | |
43 | +import org.jboss.arquillian.container.test.api.Deployment; | |
44 | +import org.jboss.arquillian.junit.Arquillian; | |
45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
46 | +import org.junit.After; | |
47 | +import org.junit.Before; | |
48 | +import org.junit.Test; | |
49 | +import org.junit.runner.RunWith; | |
50 | + | |
51 | +import security.athentication.custom.CustomAuthenticator; | |
52 | +import test.Tests; | |
53 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
54 | +import configuration.resource.ConfigurationResourceTest; | |
55 | + | |
56 | +@RunWith(Arquillian.class) | |
57 | +public class CustomAuthorizerTest { | |
58 | + | |
59 | + @Inject | |
60 | + private SecurityContext context; | |
61 | + | |
62 | + @Deployment | |
63 | + public static JavaArchive createDeployment() { | |
64 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
65 | + deployment.addClass(CustomAuthenticator.class); | |
66 | + deployment.addClass(CustomAuthorizer.class); | |
67 | + return deployment; | |
68 | + } | |
69 | + | |
70 | + @Before | |
71 | + public void loginToTest(){ | |
72 | + context.login(); | |
73 | + } | |
74 | + | |
75 | + @Test | |
76 | + public void hasPermission(){ | |
77 | + Assert.assertTrue(context.hasPermission("resource", "operation")); | |
78 | + } | |
79 | + | |
80 | + @Test | |
81 | + public void hasRole(){ | |
82 | + Assert.assertTrue(context.hasRole("role")); | |
83 | + } | |
84 | + | |
85 | + @Test | |
86 | + public void denyPermission(){ | |
87 | + Assert.assertFalse(context.hasPermission("falseresource", "falseoperation")); | |
88 | + } | |
89 | + | |
90 | + @Test | |
91 | + public void denyRole(){ | |
92 | + Assert.assertFalse(context.hasRole("falserole")); | |
93 | + } | |
94 | + | |
95 | + @After | |
96 | + public void logoutAfterTest(){ | |
97 | + context.logout(); | |
98 | + } | |
99 | + | |
100 | +} | ... | ... |
impl/core/src/test/java/security/authorization/error/ErrorAuthorizer.java
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
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 security.authorization.error; | |
38 | + | |
39 | +import br.gov.frameworkdemoiselle.security.Authorizer; | |
40 | + | |
41 | +public class ErrorAuthorizer implements Authorizer { | |
42 | + | |
43 | + private static final long serialVersionUID = 1L; | |
44 | + | |
45 | + @Override | |
46 | + public boolean hasRole(String role) { | |
47 | + throw new RuntimeException("Erro desconhecido ao obter papeis"); | |
48 | + } | |
49 | + | |
50 | + @Override | |
51 | + public boolean hasPermission(String resource, String operation) { | |
52 | + throw new RuntimeException("Erro desconhecido ao obter permissões"); | |
53 | + } | |
54 | + | |
55 | + | |
56 | + | |
57 | +} | ... | ... |
impl/core/src/test/java/security/authorization/error/ErrorAuthorizerTest.java
0 → 100644
... | ... | @@ -0,0 +1,110 @@ |
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 security.authorization.error; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import junit.framework.Assert; | |
42 | + | |
43 | +import org.jboss.arquillian.container.test.api.Deployment; | |
44 | +import org.jboss.arquillian.junit.Arquillian; | |
45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
46 | +import org.junit.After; | |
47 | +import org.junit.Before; | |
48 | +import org.junit.Test; | |
49 | +import org.junit.runner.RunWith; | |
50 | + | |
51 | +import security.athentication.custom.CustomAuthenticator; | |
52 | +import test.Tests; | |
53 | +import br.gov.frameworkdemoiselle.security.AuthorizationException; | |
54 | +import br.gov.frameworkdemoiselle.security.NotLoggedInException; | |
55 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
56 | +import configuration.resource.ConfigurationResourceTest; | |
57 | + | |
58 | +@RunWith(Arquillian.class) | |
59 | +public class ErrorAuthorizerTest { | |
60 | + | |
61 | + @Inject | |
62 | + private SecurityContext context; | |
63 | + | |
64 | + @Deployment | |
65 | + public static JavaArchive createDeployment() { | |
66 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
67 | + deployment.addClass(CustomAuthenticator.class); | |
68 | + deployment.addClass(ErrorAuthorizer.class); | |
69 | + return deployment; | |
70 | + } | |
71 | + | |
72 | + @Before | |
73 | + public void loginToTest(){ | |
74 | + context.login(); | |
75 | + } | |
76 | + | |
77 | + @Test | |
78 | + public void errorDuringCheckPermission(){ | |
79 | + try{ | |
80 | + context.hasPermission("resource", "operation"); | |
81 | + Assert.fail("Verificar permissão deveria disparar exceção de runtime"); | |
82 | + } | |
83 | + catch(NotLoggedInException ae){ | |
84 | + Assert.fail("A exceção disparada não foi a esperada"); | |
85 | + } | |
86 | + catch(RuntimeException e){ | |
87 | + //PASS | |
88 | + } | |
89 | + } | |
90 | + | |
91 | + @Test | |
92 | + public void errorDuringCheckRole(){ | |
93 | + try{ | |
94 | + context.hasRole("role"); | |
95 | + Assert.fail("Verificar papel deveria disparar exceção de runtime"); | |
96 | + } | |
97 | + catch(AuthorizationException ae){ | |
98 | + Assert.fail("A exceção disparada não foi a esperada"); | |
99 | + } | |
100 | + catch(RuntimeException e){ | |
101 | + //PASS | |
102 | + } | |
103 | + } | |
104 | + | |
105 | + @After | |
106 | + public void logoutAfterTest(){ | |
107 | + context.logout(); | |
108 | + } | |
109 | + | |
110 | +} | ... | ... |
impl/core/src/test/java/security/authorization/selection/SelectedAuthorizerTest.java
0 → 100644
... | ... | @@ -0,0 +1,90 @@ |
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 security.authorization.selection; | |
38 | + | |
39 | +import javax.inject.Inject; | |
40 | + | |
41 | +import org.jboss.arquillian.container.test.api.Deployment; | |
42 | +import org.jboss.arquillian.junit.Arquillian; | |
43 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
44 | +import org.junit.After; | |
45 | +import org.junit.Assert; | |
46 | +import org.junit.Before; | |
47 | +import org.junit.Test; | |
48 | +import org.junit.runner.RunWith; | |
49 | + | |
50 | +import security.athentication.custom.CustomAuthenticator; | |
51 | +import security.authorization.ambiguity.DuplicatedCustomAuthorizer; | |
52 | +import security.authorization.custom.CustomAuthorizer; | |
53 | +import test.Tests; | |
54 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
55 | +import configuration.resource.ConfigurationResourceTest; | |
56 | + | |
57 | +@RunWith(Arquillian.class) | |
58 | +public class SelectedAuthorizerTest { | |
59 | + | |
60 | + private static final String PATH = "src/test/resources/security/authorization/selection"; | |
61 | + | |
62 | + @Inject | |
63 | + private SecurityContext context; | |
64 | + | |
65 | + @Deployment | |
66 | + public static JavaArchive createDeployment() { | |
67 | + JavaArchive deployment = Tests.createDeployment(ConfigurationResourceTest.class); | |
68 | + deployment.addClass(CustomAuthenticator.class); | |
69 | + deployment.addClass(CustomAuthorizer.class); | |
70 | + deployment.addClass(DuplicatedCustomAuthorizer.class); | |
71 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/demoiselle.properties"), "demoiselle.properties"); | |
72 | + return deployment; | |
73 | + } | |
74 | + | |
75 | + @Before | |
76 | + public void loginToTest(){ | |
77 | + context.login(); | |
78 | + } | |
79 | + | |
80 | + @Test | |
81 | + public void selectedAuthorizerStrategy() { | |
82 | + context.login(); | |
83 | + Assert.assertTrue(context.hasRole("role")); | |
84 | + } | |
85 | + | |
86 | + @After | |
87 | + public void logoutAfterTest(){ | |
88 | + context.logout(); | |
89 | + } | |
90 | +} | ... | ... |
impl/core/src/test/java/security/authorization/undefined/UndefinedAuthorizerTest.java
0 → 100644
... | ... | @@ -0,0 +1,72 @@ |
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 security.authorization.undefined; | |
38 | + | |
39 | +import static junit.framework.Assert.assertEquals; | |
40 | + | |
41 | +import javax.inject.Inject; | |
42 | + | |
43 | +import org.jboss.arquillian.container.test.api.Deployment; | |
44 | +import org.jboss.arquillian.junit.Arquillian; | |
45 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
46 | +import org.junit.Test; | |
47 | +import org.junit.runner.RunWith; | |
48 | + | |
49 | +import test.Tests; | |
50 | +import br.gov.frameworkdemoiselle.security.AuthenticationException; | |
51 | +import br.gov.frameworkdemoiselle.security.SecurityContext; | |
52 | + | |
53 | +@RunWith(Arquillian.class) | |
54 | +public class UndefinedAuthorizerTest { | |
55 | + | |
56 | + @Inject | |
57 | + private SecurityContext context; | |
58 | + | |
59 | + @Deployment | |
60 | + public static JavaArchive createDeployment() { | |
61 | + return Tests.createDeployment(); | |
62 | + } | |
63 | + | |
64 | + @Test | |
65 | + public void undefinedAuthorizerStrategy() { | |
66 | + try { | |
67 | + context.hasRole("role"); | |
68 | + } catch (AuthenticationException cause) { | |
69 | + assertEquals(ClassNotFoundException.class, cause.getCause().getClass()); | |
70 | + } | |
71 | + } | |
72 | +} | ... | ... |
impl/core/src/test/resources/security/authorization/selection/demoiselle.properties
0 → 100644
... | ... | @@ -0,0 +1,36 @@ |
1 | +# Demoiselle Framework | |
2 | +# Copyright (C) 2010 SERPRO | |
3 | +# ---------------------------------------------------------------------------- | |
4 | +# This file is part of Demoiselle Framework. | |
5 | +# | |
6 | +# Demoiselle Framework is free software; you can redistribute it and/or | |
7 | +# modify it under the terms of the GNU Lesser General Public License version 3 | |
8 | +# as published by the Free Software Foundation. | |
9 | +# | |
10 | +# This program is distributed in the hope that it will be useful, | |
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | +# GNU General Public License for more details. | |
14 | +# | |
15 | +# You should have received a copy of the GNU Lesser General Public License version 3 | |
16 | +# along with this program; if not, see <http://www.gnu.org/licenses/> | |
17 | +# or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
18 | +# Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | +# ---------------------------------------------------------------------------- | |
20 | +# Este arquivo é parte do Framework Demoiselle. | |
21 | +# | |
22 | +# O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
23 | +# modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
24 | +# do Software Livre (FSF). | |
25 | +# | |
26 | +# Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
27 | +# GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
28 | +# APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
29 | +# para maiores detalhes. | |
30 | +# | |
31 | +# Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
32 | +# "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
33 | +# ou escreva para a Fundação do Software Livre (FSF) Inc., | |
34 | +# 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
35 | + | |
36 | +frameworkdemoiselle.security.authorizer.class=security.authorization.custom.CustomAuthorizer | |
0 | 37 | \ No newline at end of file | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/configuration/JDBCConfig.java
... | ... | @@ -41,7 +41,12 @@ import java.util.Map; |
41 | 41 | |
42 | 42 | import br.gov.frameworkdemoiselle.annotation.Name; |
43 | 43 | import br.gov.frameworkdemoiselle.configuration.Configuration; |
44 | - | |
44 | +/** | |
45 | + * Provide used to access the configurations of the JDBC connection | |
46 | + * | |
47 | + * @author SERPRO | |
48 | + * | |
49 | + */ | |
45 | 50 | @Configuration(prefix = "frameworkdemoiselle.persistence.") |
46 | 51 | public class JDBCConfig implements Serializable { |
47 | 52 | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/transaction/JDBCTransaction.java
... | ... | @@ -51,7 +51,7 @@ import br.gov.frameworkdemoiselle.internal.producer.ConnectionProducer; |
51 | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
52 | 52 | |
53 | 53 | /** |
54 | - * Represents the strategy destinated to manage JPA transactions. | |
54 | + * Represents the strategy destinated to manage JDBC transactions. | |
55 | 55 | * |
56 | 56 | * @author SERPRO |
57 | 57 | * @see Transaction |
... | ... | @@ -79,7 +79,7 @@ public class JDBCTransaction implements Transaction { |
79 | 79 | return producer; |
80 | 80 | } |
81 | 81 | |
82 | - public Collection<Connection> getDelegate() { | |
82 | + private Collection<Connection> getDelegate() { | |
83 | 83 | return getProducer().getCache().values(); |
84 | 84 | } |
85 | 85 | |
... | ... | @@ -92,6 +92,9 @@ public class JDBCTransaction implements Transaction { |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | + /** | |
96 | + * @throws DemoiselleException | |
97 | + */ | |
95 | 98 | @Override |
96 | 99 | public void commit() { |
97 | 100 | for (Connection connection : getDelegate()) { |
... | ... | @@ -103,6 +106,9 @@ public class JDBCTransaction implements Transaction { |
103 | 106 | } |
104 | 107 | } |
105 | 108 | |
109 | + /** | |
110 | + * @throws DemoiselleException | |
111 | + */ | |
106 | 112 | @Override |
107 | 113 | public void rollback() { |
108 | 114 | for (Connection connection : getDelegate()) { | ... | ... |
impl/extension/jmx/pom.xml
... | ... | @@ -69,7 +69,6 @@ |
69 | 69 | <dependency> |
70 | 70 | <groupId>org.jboss.shrinkwrap.resolver</groupId> |
71 | 71 | <artifactId>shrinkwrap-resolver-impl-maven</artifactId> |
72 | - <version>2.0.0-beta-3</version> | |
73 | 72 | <scope>test</scope> |
74 | 73 | </dependency> |
75 | 74 | <dependency> |
... | ... | @@ -87,6 +86,11 @@ |
87 | 86 | <artifactId>hibernate-validator</artifactId> |
88 | 87 | <scope>test</scope> |
89 | 88 | </dependency> |
89 | + <dependency> | |
90 | + <groupId>org.slf4j</groupId> | |
91 | + <artifactId>slf4j-log4j12</artifactId> | |
92 | + <scope>test</scope> | |
93 | + </dependency> | |
90 | 94 | </dependencies> |
91 | 95 | |
92 | 96 | <repositories> | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/DynamicMBeanProxy.java
... | ... | @@ -58,7 +58,6 @@ import br.gov.frameworkdemoiselle.internal.management.ManagedType.FieldDetail; |
58 | 58 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.MethodDetail; |
59 | 59 | import br.gov.frameworkdemoiselle.internal.management.ManagedType.ParameterDetail; |
60 | 60 | import br.gov.frameworkdemoiselle.internal.management.Management; |
61 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
62 | 61 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
63 | 62 | import br.gov.frameworkdemoiselle.util.Beans; |
64 | 63 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
... | ... | @@ -79,11 +78,11 @@ public class DynamicMBeanProxy implements DynamicMBean { |
79 | 78 | |
80 | 79 | private ManagedType managedType; |
81 | 80 | |
82 | - private ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-jmx-bundle", Locale.getDefault()); | |
81 | + private ResourceBundle bundle; | |
83 | 82 | |
84 | 83 | public DynamicMBeanProxy(ManagedType type) { |
85 | 84 | if (type == null) { |
86 | - throw new NullPointerException(bundle.getString("mbean-null-type-defined")); | |
85 | + throw new NullPointerException(getBundle().getString("mbean-null-type-defined")); | |
87 | 86 | } |
88 | 87 | managedType = type; |
89 | 88 | } |
... | ... | @@ -186,7 +185,7 @@ public class DynamicMBeanProxy implements DynamicMBean { |
186 | 185 | attributes.add(attributeInfo); |
187 | 186 | |
188 | 187 | } catch (javax.management.IntrospectionException e) { |
189 | - throw new DemoiselleException(bundle.getString("mbean-introspection-error", managedType.getType() | |
188 | + throw new DemoiselleException(getBundle().getString("mbean-introspection-error", managedType.getType() | |
190 | 189 | .getSimpleName())); |
191 | 190 | } |
192 | 191 | } |
... | ... | @@ -253,5 +252,13 @@ public class DynamicMBeanProxy implements DynamicMBean { |
253 | 252 | |
254 | 253 | return delegateInfo; |
255 | 254 | } |
255 | + | |
256 | + public ResourceBundle getBundle(){ | |
257 | + if (bundle==null){ | |
258 | + bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | |
259 | + } | |
260 | + | |
261 | + return bundle; | |
262 | + } | |
256 | 263 | |
257 | 264 | } | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/MBeanHelper.java
... | ... | @@ -47,7 +47,6 @@ import org.slf4j.Logger; |
47 | 47 | |
48 | 48 | import br.gov.frameworkdemoiselle.DemoiselleException; |
49 | 49 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
50 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
51 | 50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
52 | 51 | |
53 | 52 | /** |
... | ... | @@ -59,7 +58,7 @@ public class MBeanHelper { |
59 | 58 | |
60 | 59 | private static final Logger logger = LoggerProducer.create(MBeanHelper.class); |
61 | 60 | |
62 | - private static ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-jmx-bundle", Locale.getDefault()); | |
61 | + private static ResourceBundle bundle = new ResourceBundle("demoiselle-jmx-bundle", Locale.getDefault()); | |
63 | 62 | |
64 | 63 | private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
65 | 64 | ... | ... |
impl/extension/jmx/src/test/java/management/LocaleProducer.java
... | ... | @@ -1,51 +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.util.Locale; | |
40 | - | |
41 | -import javax.enterprise.inject.Default; | |
42 | -import javax.enterprise.inject.Produces; | |
43 | - | |
44 | -public class LocaleProducer { | |
45 | - | |
46 | - @Default | |
47 | - @Produces | |
48 | - public Locale create() { | |
49 | - return Locale.getDefault(); | |
50 | - } | |
51 | -} |
impl/extension/jmx/src/test/java/management/tests/Tests.java
0 → 100644
... | ... | @@ -0,0 +1,84 @@ |
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 | + | |
38 | +package management.tests; | |
39 | + | |
40 | +import java.io.File; | |
41 | +import java.util.Locale; | |
42 | + | |
43 | +import javax.enterprise.inject.Default; | |
44 | +import javax.enterprise.inject.Produces; | |
45 | + | |
46 | +import org.jboss.shrinkwrap.api.ShrinkWrap; | |
47 | +import org.jboss.shrinkwrap.api.asset.FileAsset; | |
48 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
49 | +import org.junit.Ignore; | |
50 | + | |
51 | +@Ignore | |
52 | +public final class Tests { | |
53 | + | |
54 | + private Tests() { | |
55 | + } | |
56 | + | |
57 | + public static JavaArchive createDeployment(final Class<?> baseClass) { | |
58 | + return createDeployment().addPackages(true, baseClass.getPackage()); | |
59 | + } | |
60 | + | |
61 | + public static JavaArchive createDeployment() { | |
62 | + return ShrinkWrap | |
63 | + .create(JavaArchive.class) | |
64 | + .addClass(Tests.class) | |
65 | + .addPackages(true, "br") | |
66 | + .addAsResource(Tests.createFileAsset("src/main/resources/demoiselle-jmx-bundle.properties") , "demoiselle-jmx-bundle.properties") | |
67 | + .addAsResource(Tests.createFileAsset("src/test/resources/log4j.properties"),"log4j.properties") | |
68 | + .addAsResource(Tests.createFileAsset("src/test/resources/configuration/demoiselle.properties"),"demoiselle.properties") | |
69 | + .addAsManifestResource(Tests.createFileAsset("src/test/resources/beans.xml"), "beans.xml") | |
70 | + .addAsManifestResource( | |
71 | + new File("src/test/resources/javax.enterprise.inject.spi.Extension"), | |
72 | + "services/javax.enterprise.inject.spi.Extension"); | |
73 | + } | |
74 | + | |
75 | + public static FileAsset createFileAsset(final String pathname) { | |
76 | + return new FileAsset(new File(pathname)); | |
77 | + } | |
78 | + | |
79 | + @Default | |
80 | + @Produces | |
81 | + public Locale create() { | |
82 | + return Locale.getDefault(); | |
83 | + } | |
84 | +} | ... | ... |
impl/extension/jmx/src/test/java/management/tests/basic/DynamicMBeanProxyTest.java
0 → 100644
... | ... | @@ -0,0 +1,187 @@ |
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.tests.basic; | |
38 | + | |
39 | +import java.lang.management.ManagementFactory; | |
40 | + | |
41 | +import javax.management.Attribute; | |
42 | +import javax.management.MBeanServer; | |
43 | +import javax.management.MalformedObjectNameException; | |
44 | +import javax.management.ObjectName; | |
45 | + | |
46 | +import junit.framework.Assert; | |
47 | +import management.domain.ManagedTestClass; | |
48 | +import management.tests.Tests; | |
49 | + | |
50 | +import org.jboss.arquillian.container.test.api.Deployment; | |
51 | +import org.jboss.arquillian.junit.Arquillian; | |
52 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
53 | +import org.junit.AfterClass; | |
54 | +import org.junit.BeforeClass; | |
55 | +import org.junit.Test; | |
56 | +import org.junit.runner.RunWith; | |
57 | + | |
58 | +import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
59 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | |
60 | +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | |
61 | +import br.gov.frameworkdemoiselle.util.Beans; | |
62 | + | |
63 | +@RunWith(Arquillian.class) | |
64 | +public class DynamicMBeanProxyTest { | |
65 | + | |
66 | + @Deployment | |
67 | + public static JavaArchive createDeployment() { | |
68 | + return Tests.createDeployment(DynamicMBeanProxyTest.class) | |
69 | + .addClasses(ManagedTestClass.class); | |
70 | + } | |
71 | + | |
72 | + @BeforeClass | |
73 | + public static void fireEventStartupProccess() { | |
74 | + Beans.getBeanManager().fireEvent(new AfterStartupProccess() { | |
75 | + }); | |
76 | + } | |
77 | + | |
78 | + @AfterClass | |
79 | + public static void fireEventShutdownProccess() { | |
80 | + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() { | |
81 | + }); | |
82 | + } | |
83 | + | |
84 | + /** | |
85 | + * Testa se o bootstrap está corretamente carregando e registrando classes anotadas com {@link Managed} como MBeans. | |
86 | + */ | |
87 | + @Test | |
88 | + public void initializeMBean() { | |
89 | + MBeanManager manager = Beans.getReference(MBeanManager.class); | |
90 | + | |
91 | + Assert.assertNotNull(manager); | |
92 | + Assert.assertNotNull(manager.listRegisteredMBeans()); | |
93 | + | |
94 | + // O componente demoiselle-jmx sempre tem pelo menos um MBean, que é | |
95 | + // o NotificationBroadcaster. Qualquer classe gerenciada criada pelo usuário | |
96 | + // será adicionada a ela, então esperamos 2 MBeans aqui. | |
97 | + Assert.assertEquals(2, manager.listRegisteredMBeans().size()); | |
98 | + | |
99 | + } | |
100 | + | |
101 | + @Test | |
102 | + public void attributeWrite() { | |
103 | + | |
104 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
105 | + | |
106 | + ObjectName name = null; | |
107 | + try { | |
108 | + name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
109 | + } catch (MalformedObjectNameException e) { | |
110 | + Assert.fail(); | |
111 | + } | |
112 | + | |
113 | + try { | |
114 | + server.setAttribute(name, new Attribute("attribute", "New Value")); | |
115 | + } catch (Exception e) { | |
116 | + Assert.fail(e.getMessage()); | |
117 | + } | |
118 | + | |
119 | + } | |
120 | + | |
121 | + @Test | |
122 | + public void attributeRead() { | |
123 | + | |
124 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
125 | + | |
126 | + ObjectName name = null; | |
127 | + try { | |
128 | + name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
129 | + } catch (MalformedObjectNameException e) { | |
130 | + Assert.fail(); | |
131 | + } | |
132 | + | |
133 | + try { | |
134 | + server.setAttribute(name, new Attribute("attribute", "New Value")); | |
135 | + | |
136 | + Object info = server.getAttribute(name, "attribute"); | |
137 | + | |
138 | + Assert.assertEquals("New Value", info); | |
139 | + } catch (Exception e) { | |
140 | + Assert.fail(); | |
141 | + } | |
142 | + | |
143 | + } | |
144 | + | |
145 | + @Test | |
146 | + public void operationInvocation() { | |
147 | + | |
148 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
149 | + | |
150 | + ObjectName name = null; | |
151 | + try { | |
152 | + name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
153 | + } catch (MalformedObjectNameException e) { | |
154 | + Assert.fail(); | |
155 | + } | |
156 | + | |
157 | + try { | |
158 | + server.setAttribute(name, new Attribute("attribute", "Defined Value")); | |
159 | + | |
160 | + Object info = server.invoke(name, "operation", new Object[] { "Test" }, new String[] { "String" }); | |
161 | + Assert.assertEquals("Operation called with parameter=Test. Current attribute value is Defined Value", info); | |
162 | + } catch (Exception e) { | |
163 | + Assert.fail(); | |
164 | + } | |
165 | + | |
166 | + } | |
167 | + | |
168 | + @Test | |
169 | + public void tryWriteOverReadOnly() { | |
170 | + | |
171 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
172 | + | |
173 | + ObjectName name = null; | |
174 | + try { | |
175 | + name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
176 | + } catch (MalformedObjectNameException e) { | |
177 | + Assert.fail(); | |
178 | + } | |
179 | + | |
180 | + try { | |
181 | + server.setAttribute(name, new Attribute("attribute", "New Value")); | |
182 | + } catch (Exception e) { | |
183 | + Assert.fail(e.getMessage()); | |
184 | + } | |
185 | + | |
186 | + } | |
187 | +} | ... | ... |
impl/extension/jmx/src/test/java/management/tests/internal/DynamicMBeanProxyTestCase.java
... | ... | @@ -1,197 +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.tests.internal; | |
38 | - | |
39 | -import java.io.File; | |
40 | -import java.lang.management.ManagementFactory; | |
41 | - | |
42 | -import javax.management.Attribute; | |
43 | -import javax.management.MBeanServer; | |
44 | -import javax.management.MalformedObjectNameException; | |
45 | -import javax.management.ObjectName; | |
46 | - | |
47 | -import junit.framework.Assert; | |
48 | -import management.LocaleProducer; | |
49 | -import management.domain.ManagedTestClass; | |
50 | - | |
51 | -import org.jboss.arquillian.container.test.api.Deployment; | |
52 | -import org.jboss.arquillian.junit.Arquillian; | |
53 | -import org.jboss.shrinkwrap.api.ShrinkWrap; | |
54 | -import org.jboss.shrinkwrap.api.asset.FileAsset; | |
55 | -import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
56 | -import org.junit.AfterClass; | |
57 | -import org.junit.BeforeClass; | |
58 | -import org.junit.Test; | |
59 | -import org.junit.runner.RunWith; | |
60 | - | |
61 | -import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
62 | -import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | |
63 | -import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | |
64 | -import br.gov.frameworkdemoiselle.util.Beans; | |
65 | - | |
66 | -@RunWith(Arquillian.class) | |
67 | -public class DynamicMBeanProxyTestCase { | |
68 | - | |
69 | - @Deployment | |
70 | - public static JavaArchive createDeployment() { | |
71 | - JavaArchive mainDeployment = ShrinkWrap.create(JavaArchive.class); | |
72 | - mainDeployment | |
73 | - .addPackages(true, "br") | |
74 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
75 | - .addAsResource(new FileAsset(new File("src/test/resources/configuration/demoiselle.properties")),"demoiselle.properties") | |
76 | - .addPackages(false, DynamicMBeanProxyTestCase.class.getPackage()) | |
77 | - .addClasses(LocaleProducer.class, ManagedTestClass.class); | |
78 | - | |
79 | - return mainDeployment; | |
80 | - } | |
81 | - | |
82 | - @BeforeClass | |
83 | - public static void fireEventStartupProccess() { | |
84 | - Beans.getBeanManager().fireEvent(new AfterStartupProccess() { | |
85 | - }); | |
86 | - } | |
87 | - | |
88 | - @AfterClass | |
89 | - public static void fireEventShutdownProccess() { | |
90 | - Beans.getBeanManager().fireEvent(new AfterShutdownProccess() { | |
91 | - }); | |
92 | - } | |
93 | - | |
94 | - /** | |
95 | - * Testa se o bootstrap está corretamente carregando e registrando classes anotadas com {@link Managed} como MBeans. | |
96 | - */ | |
97 | - @Test | |
98 | - public void testMBeanInitialization() { | |
99 | - MBeanManager manager = Beans.getReference(MBeanManager.class); | |
100 | - | |
101 | - Assert.assertNotNull(manager); | |
102 | - Assert.assertNotNull(manager.listRegisteredMBeans()); | |
103 | - | |
104 | - // O componente demoiselle-jmx sempre tem pelo menos um MBean, que é | |
105 | - // o NotificationBroadcaster. Qualquer classe gerenciada criada pelo usuário | |
106 | - // será adicionada a ela, então esperamos 2 MBeans aqui. | |
107 | - Assert.assertEquals(2, manager.listRegisteredMBeans().size()); | |
108 | - | |
109 | - } | |
110 | - | |
111 | - @Test | |
112 | - public void testAttributeWrite() { | |
113 | - | |
114 | - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
115 | - | |
116 | - ObjectName name = null; | |
117 | - try { | |
118 | - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
119 | - } catch (MalformedObjectNameException e) { | |
120 | - Assert.fail(); | |
121 | - } | |
122 | - | |
123 | - try { | |
124 | - server.setAttribute(name, new Attribute("attribute", "New Value")); | |
125 | - } catch (Exception e) { | |
126 | - Assert.fail(e.getMessage()); | |
127 | - } | |
128 | - | |
129 | - } | |
130 | - | |
131 | - @Test | |
132 | - public void testAttributeRead() { | |
133 | - | |
134 | - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
135 | - | |
136 | - ObjectName name = null; | |
137 | - try { | |
138 | - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
139 | - } catch (MalformedObjectNameException e) { | |
140 | - Assert.fail(); | |
141 | - } | |
142 | - | |
143 | - try { | |
144 | - server.setAttribute(name, new Attribute("attribute", "New Value")); | |
145 | - | |
146 | - Object info = server.getAttribute(name, "attribute"); | |
147 | - | |
148 | - Assert.assertEquals("New Value", info); | |
149 | - } catch (Exception e) { | |
150 | - Assert.fail(); | |
151 | - } | |
152 | - | |
153 | - } | |
154 | - | |
155 | - @Test | |
156 | - public void testOperationInvocation() { | |
157 | - | |
158 | - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
159 | - | |
160 | - ObjectName name = null; | |
161 | - try { | |
162 | - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
163 | - } catch (MalformedObjectNameException e) { | |
164 | - Assert.fail(); | |
165 | - } | |
166 | - | |
167 | - try { | |
168 | - server.setAttribute(name, new Attribute("attribute", "Defined Value")); | |
169 | - | |
170 | - Object info = server.invoke(name, "operation", new Object[] { "Test" }, new String[] { "String" }); | |
171 | - Assert.assertEquals("Operation called with parameter=Test. Current attribute value is Defined Value", info); | |
172 | - } catch (Exception e) { | |
173 | - Assert.fail(); | |
174 | - } | |
175 | - | |
176 | - } | |
177 | - | |
178 | - @Test | |
179 | - public void testTryWriteOverReadOnly() { | |
180 | - | |
181 | - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
182 | - | |
183 | - ObjectName name = null; | |
184 | - try { | |
185 | - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | |
186 | - } catch (MalformedObjectNameException e) { | |
187 | - Assert.fail(); | |
188 | - } | |
189 | - | |
190 | - try { | |
191 | - server.setAttribute(name, new Attribute("attribute", "New Value")); | |
192 | - } catch (Exception e) { | |
193 | - Assert.fail(e.getMessage()); | |
194 | - } | |
195 | - | |
196 | - } | |
197 | -} |
impl/extension/jmx/src/test/java/management/tests/internal/NotificationBroadcasterTestCase.java
... | ... | @@ -1,223 +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.tests.internal; | |
38 | - | |
39 | -import java.io.File; | |
40 | -import java.lang.management.ManagementFactory; | |
41 | - | |
42 | -import javax.management.InstanceNotFoundException; | |
43 | -import javax.management.MBeanServer; | |
44 | -import javax.management.MalformedObjectNameException; | |
45 | -import javax.management.NotificationListener; | |
46 | -import javax.management.ObjectInstance; | |
47 | -import javax.management.ObjectName; | |
48 | - | |
49 | -import junit.framework.Assert; | |
50 | -import management.LocaleProducer; | |
51 | -import management.domain.ManagedTestClass; | |
52 | - | |
53 | -import org.jboss.arquillian.container.test.api.Deployment; | |
54 | -import org.jboss.arquillian.junit.Arquillian; | |
55 | -import org.jboss.shrinkwrap.api.ShrinkWrap; | |
56 | -import org.jboss.shrinkwrap.api.asset.FileAsset; | |
57 | -import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
58 | -import org.junit.AfterClass; | |
59 | -import org.junit.BeforeClass; | |
60 | -import org.junit.Test; | |
61 | -import org.junit.runner.RunWith; | |
62 | - | |
63 | -import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | |
64 | -import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
65 | -import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | |
66 | -import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | |
67 | -import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | |
68 | -import br.gov.frameworkdemoiselle.management.GenericNotification; | |
69 | -import br.gov.frameworkdemoiselle.management.NotificationManager; | |
70 | -import br.gov.frameworkdemoiselle.util.Beans; | |
71 | - | |
72 | -@RunWith(Arquillian.class) | |
73 | -public class NotificationBroadcasterTestCase { | |
74 | - | |
75 | - @Deployment | |
76 | - public static JavaArchive createDeployment() { | |
77 | - JavaArchive mainDeployment = ShrinkWrap.create(JavaArchive.class); | |
78 | - mainDeployment | |
79 | - .addPackages(true, "br") | |
80 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
81 | - .addAsResource(new FileAsset(new File("src/test/resources/configuration/demoiselle.properties")), | |
82 | - "demoiselle.properties").addPackages(false, DynamicMBeanProxyTestCase.class.getPackage()) | |
83 | - .addClasses(LocaleProducer.class, ManagedTestClass.class); | |
84 | - | |
85 | - return mainDeployment; | |
86 | - } | |
87 | - | |
88 | - @BeforeClass | |
89 | - public static void fireEventStartupProccess() { | |
90 | - Beans.getBeanManager().fireEvent(new AfterStartupProccess() { | |
91 | - }); | |
92 | - } | |
93 | - | |
94 | - @AfterClass | |
95 | - public static void fireEventShutdownProccess() { | |
96 | - Beans.getBeanManager().fireEvent(new AfterShutdownProccess() { | |
97 | - }); | |
98 | - } | |
99 | - | |
100 | - /** | |
101 | - * Testa o envio de uma mensagem para clientes conectados | |
102 | - */ | |
103 | - @Test | |
104 | - public void sendMessageTest() { | |
105 | - JMXConfig config = Beans.getReference(JMXConfig.class); | |
106 | - | |
107 | - // Este será o lado cliente. Este manager é usado para enviar notificações a partir do código da aplicação | |
108 | - NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | |
109 | - | |
110 | - // Obtém o servidor MBean onde anexaremos um listener para a notificação | |
111 | - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
112 | - | |
113 | - // Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
114 | - StringBuffer notificationMBeanName = new StringBuffer() | |
115 | - .append(config.getNotificationDomain() != null ? config.getNotificationDomain() | |
116 | - : "br.gov.frameworkdemoiselle.jmx").append(":name=").append(config.getNotificationMBeanName()); | |
117 | - | |
118 | - ObjectName name = null; | |
119 | - try { | |
120 | - name = new ObjectName(notificationMBeanName.toString()); | |
121 | - } catch (MalformedObjectNameException e) { | |
122 | - Assert.fail(); | |
123 | - } | |
124 | - | |
125 | - // StringBuffer vazio | |
126 | - StringBuffer notificationBuffer = new StringBuffer(); | |
127 | - | |
128 | - // Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
129 | - // a mensagem enviada em "notificationBuffer" | |
130 | - NotificationListener listener = new TestNotificationListener(notificationBuffer); | |
131 | - | |
132 | - try { | |
133 | - // Anexa o listener no servidor MBean | |
134 | - server.addNotificationListener(name, listener, null, null); | |
135 | - } catch (InstanceNotFoundException e) { | |
136 | - Assert.fail(); | |
137 | - } | |
138 | - | |
139 | - // Manda a notificação pelo Demoiselle | |
140 | - GenericNotification n = new GenericNotification("Notification test successful"); | |
141 | - notificationManager.sendNotification(n); | |
142 | - | |
143 | - // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
144 | - // o StringBuffer com nossa mensagem. | |
145 | - Assert.assertEquals("Notification test successful", notificationBuffer.toString()); | |
146 | - | |
147 | - } | |
148 | - | |
149 | - /** | |
150 | - * Testa o envio de uma mensagem de mudança de atributo para clientes conectados | |
151 | - */ | |
152 | - @Test | |
153 | - public void sendAttributeChangedMessageTest() { | |
154 | - JMXConfig config = Beans.getReference(JMXConfig.class); | |
155 | - | |
156 | - // Obtém o servidor MBean onde anexaremos um listener para a notificação | |
157 | - MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
158 | - | |
159 | - NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | |
160 | - MBeanManager mBeanManager = Beans.getReference(MBeanManager.class); | |
161 | - | |
162 | - // Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
163 | - StringBuffer notificationMBeanName = new StringBuffer() | |
164 | - .append(config.getNotificationDomain() != null ? config.getNotificationDomain() | |
165 | - : "br.gov.frameworkdemoiselle.jmx").append(":name=").append(config.getNotificationMBeanName()); | |
166 | - ObjectInstance instance = mBeanManager.findMBeanInstance(notificationMBeanName.toString()); | |
167 | - | |
168 | - // StringBuffer vazio | |
169 | - StringBuffer notificationBuffer = new StringBuffer(); | |
170 | - | |
171 | - // Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
172 | - // a mensagem enviada em "notificationBuffer" | |
173 | - NotificationListener listener = new TestNotificationListener(notificationBuffer); | |
174 | - | |
175 | - try { | |
176 | - // Anexa o listener no servidor MBean | |
177 | - server.addNotificationListener(instance.getObjectName(), listener, null, null); | |
178 | - } catch (InstanceNotFoundException e) { | |
179 | - Assert.fail(); | |
180 | - } | |
181 | - | |
182 | - // Manda a notificação pelo Demoiselle | |
183 | - AttributeChangeNotification notification = new AttributeChangeNotification("Attribute Changed", "name", | |
184 | - String.class, "Demoiselle 1", "Demoiselle 2"); | |
185 | - notificationManager.sendNotification(notification); | |
186 | - | |
187 | - // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
188 | - // o StringBuffer com nossa mensagem. | |
189 | - Assert.assertEquals("Attribute Changed: name = Demoiselle 2", notificationBuffer.toString()); | |
190 | - | |
191 | - } | |
192 | - | |
193 | - /** | |
194 | - * Implementação do {@link NotificationListener} do Java que vai por qualquer notificação recebida em um | |
195 | - * StringBuffer. | |
196 | - * | |
197 | - * @author serpro | |
198 | - */ | |
199 | - class TestNotificationListener implements NotificationListener { | |
200 | - | |
201 | - StringBuffer message; | |
202 | - | |
203 | - public TestNotificationListener(StringBuffer testMessage) { | |
204 | - this.message = testMessage; | |
205 | - } | |
206 | - | |
207 | - @Override | |
208 | - public void handleNotification(javax.management.Notification notification, Object handback) { | |
209 | - if (message != null) { | |
210 | - message.append(notification.getMessage()); | |
211 | - | |
212 | - if (notification instanceof javax.management.AttributeChangeNotification) { | |
213 | - message.append(": ") | |
214 | - .append(((javax.management.AttributeChangeNotification) notification).getAttributeName()) | |
215 | - .append(" = ") | |
216 | - .append(((javax.management.AttributeChangeNotification) notification).getNewValue()); | |
217 | - } | |
218 | - } | |
219 | - } | |
220 | - | |
221 | - } | |
222 | - | |
223 | -} |
impl/extension/jmx/src/test/java/management/tests/notification/NotificationBroadcasterTest.java
0 → 100644
... | ... | @@ -0,0 +1,214 @@ |
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.tests.notification; | |
38 | + | |
39 | +import java.lang.management.ManagementFactory; | |
40 | + | |
41 | +import javax.management.InstanceNotFoundException; | |
42 | +import javax.management.MBeanServer; | |
43 | +import javax.management.MalformedObjectNameException; | |
44 | +import javax.management.NotificationListener; | |
45 | +import javax.management.ObjectInstance; | |
46 | +import javax.management.ObjectName; | |
47 | + | |
48 | +import junit.framework.Assert; | |
49 | +import management.domain.ManagedTestClass; | |
50 | +import management.tests.Tests; | |
51 | + | |
52 | +import org.jboss.arquillian.container.test.api.Deployment; | |
53 | +import org.jboss.arquillian.junit.Arquillian; | |
54 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
55 | +import org.junit.AfterClass; | |
56 | +import org.junit.BeforeClass; | |
57 | +import org.junit.Test; | |
58 | +import org.junit.runner.RunWith; | |
59 | + | |
60 | +import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; | |
61 | +import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; | |
62 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | |
63 | +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | |
64 | +import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; | |
65 | +import br.gov.frameworkdemoiselle.management.GenericNotification; | |
66 | +import br.gov.frameworkdemoiselle.management.NotificationManager; | |
67 | +import br.gov.frameworkdemoiselle.util.Beans; | |
68 | + | |
69 | +@RunWith(Arquillian.class) | |
70 | +public class NotificationBroadcasterTest { | |
71 | + | |
72 | + @Deployment | |
73 | + public static JavaArchive createDeployment() { | |
74 | + return Tests.createDeployment(NotificationBroadcasterTest.class) | |
75 | + .addClasses(ManagedTestClass.class); | |
76 | + } | |
77 | + | |
78 | + @BeforeClass | |
79 | + public static void fireEventStartupProccess() { | |
80 | + Beans.getBeanManager().fireEvent(new AfterStartupProccess() { | |
81 | + }); | |
82 | + } | |
83 | + | |
84 | + @AfterClass | |
85 | + public static void fireEventShutdownProccess() { | |
86 | + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() { | |
87 | + }); | |
88 | + } | |
89 | + | |
90 | + /** | |
91 | + * Testa o envio de uma mensagem para clientes conectados | |
92 | + */ | |
93 | + @Test | |
94 | + public void sendMessage() { | |
95 | + JMXConfig config = Beans.getReference(JMXConfig.class); | |
96 | + | |
97 | + // Este será o lado cliente. Este manager é usado para enviar notificações a partir do código da aplicação | |
98 | + NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | |
99 | + | |
100 | + // Obtém o servidor MBean onde anexaremos um listener para a notificação | |
101 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
102 | + | |
103 | + // Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
104 | + StringBuffer notificationMBeanName = new StringBuffer() | |
105 | + .append(config.getNotificationDomain() != null ? config.getNotificationDomain() | |
106 | + : "br.gov.frameworkdemoiselle.jmx").append(":name=").append(config.getNotificationMBeanName()); | |
107 | + | |
108 | + ObjectName name = null; | |
109 | + try { | |
110 | + name = new ObjectName(notificationMBeanName.toString()); | |
111 | + } catch (MalformedObjectNameException e) { | |
112 | + Assert.fail(); | |
113 | + } | |
114 | + | |
115 | + // StringBuffer vazio | |
116 | + StringBuffer notificationBuffer = new StringBuffer(); | |
117 | + | |
118 | + // Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
119 | + // a mensagem enviada em "notificationBuffer" | |
120 | + NotificationListener listener = new TestNotificationListener(notificationBuffer); | |
121 | + | |
122 | + try { | |
123 | + // Anexa o listener no servidor MBean | |
124 | + server.addNotificationListener(name, listener, null, null); | |
125 | + } catch (InstanceNotFoundException e) { | |
126 | + Assert.fail(); | |
127 | + } | |
128 | + | |
129 | + // Manda a notificação pelo Demoiselle | |
130 | + GenericNotification n = new GenericNotification("Notification test successful"); | |
131 | + notificationManager.sendNotification(n); | |
132 | + | |
133 | + // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
134 | + // o StringBuffer com nossa mensagem. | |
135 | + Assert.assertEquals("Notification test successful", notificationBuffer.toString()); | |
136 | + | |
137 | + } | |
138 | + | |
139 | + /** | |
140 | + * Testa o envio de uma mensagem de mudança de atributo para clientes conectados | |
141 | + */ | |
142 | + @Test | |
143 | + public void sendAttributeChangedMessage() { | |
144 | + | |
145 | + JMXConfig config = Beans.getReference(JMXConfig.class); | |
146 | + | |
147 | + // Obtém o servidor MBean onde anexaremos um listener para a notificação | |
148 | + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | |
149 | + | |
150 | + NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | |
151 | + MBeanManager mBeanManager = Beans.getReference(MBeanManager.class); | |
152 | + | |
153 | + // Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
154 | + StringBuffer notificationMBeanName = new StringBuffer() | |
155 | + .append(config.getNotificationDomain() != null ? config.getNotificationDomain() | |
156 | + : "br.gov.frameworkdemoiselle.jmx").append(":name=").append(config.getNotificationMBeanName()); | |
157 | + ObjectInstance instance = mBeanManager.findMBeanInstance(notificationMBeanName.toString()); | |
158 | + | |
159 | + // StringBuffer vazio | |
160 | + StringBuffer notificationBuffer = new StringBuffer(); | |
161 | + | |
162 | + // Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
163 | + // a mensagem enviada em "notificationBuffer" | |
164 | + NotificationListener listener = new TestNotificationListener(notificationBuffer); | |
165 | + | |
166 | + try { | |
167 | + // Anexa o listener no servidor MBean | |
168 | + server.addNotificationListener(instance.getObjectName(), listener, null, null); | |
169 | + } catch (InstanceNotFoundException e) { | |
170 | + Assert.fail(); | |
171 | + } | |
172 | + | |
173 | + // Manda a notificação pelo Demoiselle | |
174 | + AttributeChangeNotification notification = new AttributeChangeNotification("Attribute Changed", "name", | |
175 | + String.class, "Demoiselle 1", "Demoiselle 2"); | |
176 | + notificationManager.sendNotification(notification); | |
177 | + | |
178 | + // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
179 | + // o StringBuffer com nossa mensagem. | |
180 | + Assert.assertEquals("Attribute Changed: name = Demoiselle 2", notificationBuffer.toString()); | |
181 | + | |
182 | + } | |
183 | + | |
184 | + /** | |
185 | + * Implementação do {@link NotificationListener} do Java que vai por qualquer notificação recebida em um | |
186 | + * StringBuffer. | |
187 | + * | |
188 | + * @author serpro | |
189 | + */ | |
190 | + class TestNotificationListener implements NotificationListener { | |
191 | + | |
192 | + StringBuffer message; | |
193 | + | |
194 | + public TestNotificationListener(StringBuffer testMessage) { | |
195 | + this.message = testMessage; | |
196 | + } | |
197 | + | |
198 | + @Override | |
199 | + public void handleNotification(javax.management.Notification notification, Object handback) { | |
200 | + if (message != null) { | |
201 | + message.append(notification.getMessage()); | |
202 | + | |
203 | + if (notification instanceof javax.management.AttributeChangeNotification) { | |
204 | + message.append(": ") | |
205 | + .append(((javax.management.AttributeChangeNotification) notification).getAttributeName()) | |
206 | + .append(" = ") | |
207 | + .append(((javax.management.AttributeChangeNotification) notification).getNewValue()); | |
208 | + } | |
209 | + } | |
210 | + } | |
211 | + | |
212 | + } | |
213 | + | |
214 | +} | ... | ... |
impl/extension/jmx/src/test/resources/META-INF/beans.xml
... | ... | @@ -1,11 +0,0 @@ |
1 | -<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
3 | - | |
4 | - <interceptors> | |
5 | - <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | |
6 | - <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | |
7 | - <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | |
8 | - <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | |
9 | - </interceptors> | |
10 | - | |
11 | -</beans> |
... | ... | @@ -0,0 +1,11 @@ |
1 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
3 | + | |
4 | + <interceptors> | |
5 | + <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | |
6 | + <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | |
7 | + <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | |
8 | + <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | |
9 | + </interceptors> | |
10 | + | |
11 | +</beans> | ... | ... |
impl/extension/jmx/src/test/resources/javax.enterprise.inject.spi.Extension
0 → 100644
... | ... | @@ -0,0 +1,5 @@ |
1 | +br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap | |
2 | +br.gov.frameworkdemoiselle.internal.bootstrap.ConfigurationBootstrap | |
3 | +br.gov.frameworkdemoiselle.internal.bootstrap.ManagementBootstrap | |
4 | +br.gov.frameworkdemoiselle.internal.bootstrap.StartupBootstrap | |
5 | +br.gov.frameworkdemoiselle.internal.bootstrap.ShutdownBootstrap | ... | ... |
impl/extension/jpa/pom.xml
... | ... | @@ -170,6 +170,41 @@ |
170 | 170 | <version>2.16</version> |
171 | 171 | </plugin> |
172 | 172 | </plugins> |
173 | + <pluginManagement> | |
174 | + <plugins> | |
175 | + <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> | |
176 | + <plugin> | |
177 | + <groupId>org.eclipse.m2e</groupId> | |
178 | + <artifactId>lifecycle-mapping</artifactId> | |
179 | + <version>1.0.0</version> | |
180 | + <configuration> | |
181 | + <lifecycleMappingMetadata> | |
182 | + <pluginExecutions> | |
183 | + <pluginExecution> | |
184 | + <pluginExecutionFilter> | |
185 | + <groupId> | |
186 | + org.apache.maven.plugins | |
187 | + </groupId> | |
188 | + <artifactId> | |
189 | + maven-dependency-plugin | |
190 | + </artifactId> | |
191 | + <versionRange> | |
192 | + [2.1,) | |
193 | + </versionRange> | |
194 | + <goals> | |
195 | + <goal>unpack</goal> | |
196 | + </goals> | |
197 | + </pluginExecutionFilter> | |
198 | + <action> | |
199 | + <ignore></ignore> | |
200 | + </action> | |
201 | + </pluginExecution> | |
202 | + </pluginExecutions> | |
203 | + </lifecycleMappingMetadata> | |
204 | + </configuration> | |
205 | + </plugin> | |
206 | + </plugins> | |
207 | + </pluginManagement> | |
173 | 208 | </build> |
174 | 209 | |
175 | 210 | <dependencies> | ... | ... |