Commit dc145b4f66b3b5c33ed37c759202fce40afa01de
1 parent
08e1c3e9
Exists in
master
Ajustado padrão do nome das classes de teste
Showing
10 changed files
with
506 additions
and
483 deletions
Show diff stats
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/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 | ... | ... |