diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
index 2ee0d4c..d261904 100644
--- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
+++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
@@ -21,7 +21,6 @@ import br.gov.frameworkdemoiselle.internal.context.ContextManager;
import br.gov.frameworkdemoiselle.internal.context.ManagedContext;
import br.gov.frameworkdemoiselle.internal.management.ManagedType;
import br.gov.frameworkdemoiselle.internal.management.Management;
-import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer;
import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
import br.gov.frameworkdemoiselle.stereotype.ManagementController;
@@ -48,7 +47,7 @@ public class ManagementBootstrap implements Extension {
@SuppressWarnings("unchecked")
public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) {
- ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-core-bundle", Locale.getDefault());
+ ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault());
Management monitoringManager = Beans.getReference(Management.class);
for (AnnotatedType> type : types) {
diff --git a/impl/core/src/test/java/management/AnnotationTestCase.java b/impl/core/src/test/java/management/AnnotationTestCase.java
deleted file mode 100644
index 075af76..0000000
--- a/impl/core/src/test/java/management/AnnotationTestCase.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package management;
-
-import java.io.File;
-
-import management.testclasses.DummyManagementExtension;
-import management.testclasses.ManagedClassStore;
-
-import org.jboss.arquillian.container.test.api.Deployer;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.FileAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import test.Tests;
-
-//TODO O arquillian está com um problema onde, embora os testes rodem todos individualmente,
-//ao pedir para rodar todos este teste individual causa todos os testes executados após esse
-//falharem. Até este problema ser resolvido este teste será ignorado.
-@RunWith(Arquillian.class)
-@Ignore
-public class AnnotationTestCase {
-
- /**
- * Deployment containing a malformed managed class. Tests using this deployment will check if deployment fails (it
- * has to).
- */
- @Deployment(name = "wrong_annotation", managed = false)
- public static JavaArchive createWrongAnnotationDeployment() {
- return ShrinkWrap
- .create(JavaArchive.class)
- .addClass(Tests.class)
- .addPackages(true, "br")
- .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")
- .addAsManifestResource(
- new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),
- "services/javax.enterprise.inject.spi.Extension")
- .addPackages(false, ManagementBootstrapTestCase.class.getPackage())
- //.addClasses(DummyManagementExtension.class, DummyManagedClassPropertyError.class, ManagedClassStore.class);
- .addClasses(DummyManagementExtension.class, ManagedClassStore.class);
- }
-
- @Test
- public void testWrongAnnotation(@ArquillianResource Deployer deployer) {
-
- try {
- deployer.deploy("wrong_annotation");
-
- // O processo de deploy precisa falhar, pois temos uma classe anotada com falhas.
- Assert.fail();
- } catch (Exception e) {
- //SUCCESS
- } finally {
- deployer.undeploy("wrong_annotation");
- }
- }
-
-}
diff --git a/impl/core/src/test/java/management/ManagementBootstrapTestCase.java b/impl/core/src/test/java/management/ManagementBootstrapTestCase.java
deleted file mode 100644
index 1c9b021..0000000
--- a/impl/core/src/test/java/management/ManagementBootstrapTestCase.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package management;
-
-import java.io.File;
-import java.util.List;
-
-import javax.enterprise.inject.spi.BeforeShutdown;
-
-import management.testclasses.DummyManagedClass;
-import management.testclasses.DummyManagementExtension;
-import management.testclasses.ManagedClassStore;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.FileAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import test.Tests;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType;
-import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
-import br.gov.frameworkdemoiselle.util.Beans;
-
-@RunWith(Arquillian.class)
-@Ignore
-public class ManagementBootstrapTestCase {
-
- /**
- * Deployment to test normal deployment behaviour
- *
- */
- @Deployment
- public static JavaArchive createDeployment() {
- return ShrinkWrap
- .create(JavaArchive.class)
- .addClass(Tests.class)
- .addPackages(true, "br")
- .addAsResource(
- new FileAsset(new File(
- "src/test/resources/beans.xml")),
- "beans.xml")
- .addAsManifestResource(
- new File(
- "src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),
- "services/javax.enterprise.inject.spi.Extension")
- .addPackages(false,
- ManagementBootstrapTestCase.class.getPackage())
- .addClasses(DummyManagementExtension.class,
- DummyManagedClass.class, ManagedClassStore.class);
- }
-
- /**
- * Test if a a management extension (a library that implements
- * {@link ManagementExtension}) is correctly detected.
- */
- @Test
- public void testManagementExtensionRegistration() {
- // "store" é application scoped e é usado pelo DummyManagementExtension
- // para
- // armazenar todos os beans anotados com @ManagementController. Se o
- // bootstrap rodou corretamente,
- // ele chamou DummyManagementExtension.initialize e este store conterá o
- // bean de teste que anotamos.
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- Assert.assertEquals(1, store.getManagedTypes().size());
- }
-
- /**
- * Test if a a management extension's shutdown method is correctly called
- * upon application shutdown.
- */
- @Test
- public void testManagementExtensionShutdown() {
- // "store" é application scoped e é usado pelo DummyManagementExtension
- // para
- // armazenar todos os beans anotados com @ManagementController. Se o
- // bootstrap rodou corretamente,
- // ele chamou DummyManagementExtension.initialize e este store conterá o
- // bean de teste que anotamos.
- // Nós então disparamos o evento de shutdown onde ele deverá limpar o
- // store.
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- // Detecta se a classe anotada foi detectada
- List managedTypes = store.getManagedTypes();
- Assert.assertEquals(1, managedTypes.size());
-
- Beans.getBeanManager().fireEvent(new BeforeShutdown() {
- });
-
- // Após o "undeploy", o ciclo de vida precisa ter removido a classe
- // gerenciada da lista.
- Assert.assertEquals(0, managedTypes.size());
- }
-
-}
diff --git a/impl/core/src/test/java/management/ManagementTestCase.java b/impl/core/src/test/java/management/ManagementTestCase.java
deleted file mode 100644
index 1ee7f4c..0000000
--- a/impl/core/src/test/java/management/ManagementTestCase.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package management;
-
-import java.io.File;
-
-import junit.framework.Assert;
-import management.testclasses.DummyManagedClass;
-import management.testclasses.DummyManagementExtension;
-import management.testclasses.ManagedClassStore;
-import management.testclasses.RequestScopeBeanClient;
-import management.testclasses.RequestScopedClass;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.FileAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import test.Tests;
-import br.gov.frameworkdemoiselle.DemoiselleException;
-import br.gov.frameworkdemoiselle.util.Beans;
-
-/**
- * Test case that simulates a management extension and tests if properties and operations on a managed class can be
- * easily accessed and invoked.
- *
- * @author serpro
- */
-@RunWith(Arquillian.class)
-public class ManagementTestCase {
-
- @Deployment
- public static JavaArchive createMultithreadedDeployment() {
- return ShrinkWrap
- .create(JavaArchive.class)
- .addClass(Tests.class)
- .addPackages(true, "br")
- .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")
- .addAsManifestResource(
- new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),
- "services/javax.enterprise.inject.spi.Extension")
- .addPackages(false, ManagementTestCase.class.getPackage())
- .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class,
- RequestScopeBeanClient.class, RequestScopedClass.class);
- }
-
- @Test
- public void testReadProperty() {
- DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);
- managedClass.setName("Test Name");
-
- // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" acessando
- // nosso tipo gerenciado DummyManagedClass remotamente.
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
- Object name = store.getProperty(DummyManagedClass.class, "name");
- Assert.assertEquals("Test Name", name);
- }
-
- @Test
- public void testWriteProperty() {
- // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" definindo
- // um novo valor em uma propriedade de nosso tipo gerenciado DummyManagedClass remotamente.
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
- store.setProperty(DummyManagedClass.class, "name", "Test Name");
-
- DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);
- Assert.assertEquals("Test Name", managedClass.getName());
- }
-
- @Test
- public void testReadAWriteOnly() {
-
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- try {
- store.getProperty(DummyManagedClass.class, "writeOnlyProperty");
- Assert.fail();
- } catch (DemoiselleException de) {
- // SUCCESS
- }
-
- }
-
- @Test
- public void testWriteAReadOnly() {
-
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- try {
- store.setProperty(DummyManagedClass.class, "readOnlyProperty", "New Value");
- Assert.fail();
- } catch (DemoiselleException de) {
- // SUCCESS
- }
-
- }
-
- @Test
- public void testInvokeOperation() {
-
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- try {
- store.setProperty(DummyManagedClass.class, "firstFactor", new Integer(10));
- store.setProperty(DummyManagedClass.class, "secondFactor", new Integer(15));
- Integer response = (Integer) store.invoke(DummyManagedClass.class, "sumFactors");
- Assert.assertEquals(new Integer(25), response);
- } catch (DemoiselleException de) {
- Assert.fail(de.getMessage());
- }
-
- }
-
- @Test
- public void testInvokeNonAnnotatedOperation() {
-
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- try {
- // O método "nonOperationAnnotatedMethod" existe na classe DummyManagedClass, mas não está anotado como
- // "@ManagedOperation", então
- // ela não pode ser exposta para extensões.
- store.invoke(DummyManagedClass.class, "nonOperationAnnotatedMethod");
- Assert.fail();
- } catch (DemoiselleException de) {
- // SUCCESS
- }
-
- }
-
- @Test
- public void testAccessLevelControl() {
- // tentamos escrever em uma propriedade que, apesar de ter método setter, está marcada como read-only.
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- try {
- store.setProperty(DummyManagedClass.class, "readOnlyPropertyWithSetMethod", "A Value");
- Assert.fail();
- } catch (DemoiselleException de) {
- System.out.println(de.getMessage());
- // success
- }
- }
-
- @Test
- public void testRequestScopedOperation() {
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- // Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem
- // operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova
- Object info = store.invoke(DummyManagedClass.class, "requestScopedOperation");
- Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);
-
- // Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request.
- info = store.invoke(DummyManagedClass.class, "requestScopedOperation");
- Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);
- }
-}
diff --git a/impl/core/src/test/java/management/NotificationTestCase.java b/impl/core/src/test/java/management/NotificationTestCase.java
deleted file mode 100644
index e0f230f..0000000
--- a/impl/core/src/test/java/management/NotificationTestCase.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Demoiselle Framework
- * Copyright (C) 2010 SERPRO
- * ----------------------------------------------------------------------------
- * This file is part of Demoiselle Framework.
- *
- * Demoiselle Framework is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License version 3
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License version 3
- * along with this program; if not, see
- * or write to the Free Software Foundation, Inc., 51 Franklin Street,
- * Fifth Floor, Boston, MA 02110-1301, USA.
- * ----------------------------------------------------------------------------
- * Este arquivo é parte do Framework Demoiselle.
- *
- * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
- * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
- * do Software Livre (FSF).
- *
- * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
- * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
- * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
- * para maiores detalhes.
- *
- * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
- * "LICENCA.txt", junto com esse programa. Se não, acesse
- * ou escreva para a Fundação do Software Livre (FSF) Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-package management;
-
-import java.io.File;
-
-import javax.inject.Inject;
-
-import junit.framework.Assert;
-import management.testclasses.DummyManagedClass;
-import management.testclasses.DummyNotificationListener;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.FileAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import test.Tests;
-import br.gov.frameworkdemoiselle.annotation.Name;
-import br.gov.frameworkdemoiselle.internal.management.ManagedType;
-import br.gov.frameworkdemoiselle.internal.management.Management;
-import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
-import br.gov.frameworkdemoiselle.management.GenericNotification;
-import br.gov.frameworkdemoiselle.management.NotificationManager;
-import br.gov.frameworkdemoiselle.util.Beans;
-import br.gov.frameworkdemoiselle.util.ResourceBundle;
-
-/**
- * Test the {@link NotificationManager} with a dummy extension to check if notifications are correctly propagated
- *
- * @author serpro
- */
-@RunWith(Arquillian.class)
-public class NotificationTestCase {
-
- @Inject
- private NotificationManager manager;
-
- @Inject
- @Name("demoiselle-core-bundle")
- private ResourceBundle bundle;
-
- @Deployment
- public static JavaArchive createDeployment() {
- return ShrinkWrap
- .create(JavaArchive.class)
- .addClass(Tests.class)
- .addPackages(true, "br")
- .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")
- .addAsManifestResource(
- new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),
- "services/javax.enterprise.inject.spi.Extension")
- .addPackages(false, NotificationTestCase.class.getPackage())
- .addClasses(DummyNotificationListener.class, DummyManagedClass.class);
- }
-
- /**
- * Test sending a normal notification
- */
- @Test
- public void testSendGenericNotification() {
- manager.sendNotification(new GenericNotification("Test Message"));
- DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
- Assert.assertEquals("Test Message", listener.getMessage());
- }
-
- /**
- * Test sending a notification of change in attribute
- */
- @Test
- public void testSendAttributeChangeNotification() {
- manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old",
- "new"));
- DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
- Assert.assertEquals("Test Message - attribute", listener.getMessage());
- }
-
- /**
- * Test if notifications are automatically sent when an attribute from a managed class change values
- */
- @Test
- public void testNotifyChangeManagedClass() {
- Management manager = Beans.getReference(Management.class);
-
- for (ManagedType type : manager.getManagedTypes()) {
- if (type.getType().equals(DummyManagedClass.class)) {
- manager.setProperty(type, "id", new Integer(10));
- break;
- }
- }
-
- DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
- Assert.assertEquals(
- bundle.getString("management-notification-attribute-changed", "id",
- DummyManagedClass.class.getCanonicalName())
- + " - id", listener.getMessage());
- }
-
-}
diff --git a/impl/core/src/test/java/management/ValidationTestCase.java b/impl/core/src/test/java/management/ValidationTestCase.java
deleted file mode 100644
index 7ba8133..0000000
--- a/impl/core/src/test/java/management/ValidationTestCase.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package management;
-
-import java.io.File;
-
-import management.testclasses.DummyManagedClass;
-import management.testclasses.DummyManagementExtension;
-import management.testclasses.DummyValidator;
-import management.testclasses.DummyValidatorAnnotation;
-import management.testclasses.ManagedClassStore;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.FileAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import test.Tests;
-import br.gov.frameworkdemoiselle.DemoiselleException;
-import br.gov.frameworkdemoiselle.util.Beans;
-
-@RunWith(Arquillian.class)
-public class ValidationTestCase {
-
- @Deployment
- public static JavaArchive createDeployment() {
- return ShrinkWrap
- .create(JavaArchive.class)
- .addClass(Tests.class)
- .addPackages(true, "br")
- .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml")
- .addAsManifestResource(
- new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"),
- "services/javax.enterprise.inject.spi.Extension")
- .addPackages(false, NotificationTestCase.class.getPackage())
- .addClasses(DummyManagementExtension.class, ManagedClassStore.class, DummyManagedClass.class,
- DummyValidator.class, DummyValidatorAnnotation.class);
- }
-
- /**
- * Test if a management controller accepts a valid value annotated with a core validation (from javax.validation)
- * when a property is being set by a management client
- */
- @Test
- public void testSetValidValue() {
- // Testa se é possível definir um valor válido para uma propriedade.
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
- store.setProperty(DummyManagedClass.class, "id", new Integer(1));
- Assert.assertEquals(new Integer(1), store.getProperty(DummyManagedClass.class, "id"));
- }
-
- /**
- * Test if a management controller refuses a valid value annotated with a core validation (from javax.validation)
- * when a property is being set by a management client
- */
- @Test
- public void testSetInvalidValue() {
- // Testa se é possível definir um valor válido para uma propriedade.
- try {
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
- store.setProperty(DummyManagedClass.class, "id", (Integer) null);
-
- Assert.fail();
- } catch (DemoiselleException de) {
- // Classes de gerenciamento disparam Demoiselle Exception quando uma validação falha
- }
- }
-
- /**
- * Tests if custom validators (outside the javax.validation package) run as normal
- */
- @Test
- public void testCustomValidation() {
-
- try {
- ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
-
- // Atributo "gender" deve aceitar apenas "M" ou "F", tanto maiúsculo quanto minúsculo. A anotação
- // customizada DummyValidatorAnnotation é uma simples validação que testa se uma string passada está
- // na lista de strings aceitas.
- store.setProperty(DummyManagedClass.class, "gender", "J");
-
- Assert.fail();
- } catch (DemoiselleException e) {
- Assert.assertTrue(e.getMessage().contains("Test Message"));
- }
-
- }
-
-}
diff --git a/impl/core/src/test/java/management/annotation/AnnotationTest.java b/impl/core/src/test/java/management/annotation/AnnotationTest.java
new file mode 100644
index 0000000..61b388a
--- /dev/null
+++ b/impl/core/src/test/java/management/annotation/AnnotationTest.java
@@ -0,0 +1,83 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package management.annotation;
+
+import management.testclasses.DummyManagedClassPropertyError;
+import management.testclasses.DummyManagementExtension;
+import management.testclasses.ManagedClassStore;
+
+import org.jboss.arquillian.container.test.api.Deployer;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import test.Tests;
+
+@RunWith(Arquillian.class)
+public class AnnotationTest {
+
+ /**
+ * Deployment containing a malformed managed class. Tests using this deployment will check if deployment fails (it
+ * has to).
+ */
+ @Deployment(name = "wrong_annotation", managed = false)
+ public static JavaArchive createWrongAnnotationDeployment() {
+
+ return Tests.createDeployment(AnnotationTest.class)
+ .addClasses(DummyManagementExtension.class, ManagedClassStore.class,DummyManagedClassPropertyError.class);
+ }
+
+ @Test
+ public void wrongAnnotation(@ArquillianResource Deployer deployer) {
+
+ try {
+ deployer.deploy("wrong_annotation");
+
+ // O processo de deploy precisa falhar, pois temos uma classe anotada com falhas.
+ Assert.fail();
+ } catch (Exception e) {
+ //SUCCESS
+ } finally {
+ deployer.undeploy("wrong_annotation");
+ }
+ }
+
+}
diff --git a/impl/core/src/test/java/management/basic/ManagementTest.java b/impl/core/src/test/java/management/basic/ManagementTest.java
new file mode 100644
index 0000000..ad5946e
--- /dev/null
+++ b/impl/core/src/test/java/management/basic/ManagementTest.java
@@ -0,0 +1,183 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package management.basic;
+
+import junit.framework.Assert;
+import management.testclasses.DummyManagedClass;
+import management.testclasses.DummyManagementExtension;
+import management.testclasses.ManagedClassStore;
+import management.testclasses.RequestScopeBeanClient;
+import management.testclasses.RequestScopedClass;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import test.Tests;
+import br.gov.frameworkdemoiselle.DemoiselleException;
+import br.gov.frameworkdemoiselle.util.Beans;
+
+/**
+ * Test case that simulates a management extension and tests if properties and operations on a managed class can be
+ * easily accessed and invoked.
+ *
+ * @author serpro
+ */
+@RunWith(Arquillian.class)
+public class ManagementTest {
+
+ @Deployment
+ public static JavaArchive createMultithreadedDeployment() {
+
+ return Tests.createDeployment(ManagementTest.class)
+ .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class,RequestScopeBeanClient.class, RequestScopedClass.class);
+ }
+
+ @Test
+ public void readProperty() {
+ DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);
+ managedClass.setName("Test Name");
+
+ // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" acessando
+ // nosso tipo gerenciado DummyManagedClass remotamente.
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+ Object name = store.getProperty(DummyManagedClass.class, "name");
+ Assert.assertEquals("Test Name", name);
+ }
+
+ @Test
+ public void writeProperty() {
+ // store é nossa extensão de gerenciamento falsa, então estamos testando um "cliente" definindo
+ // um novo valor em uma propriedade de nosso tipo gerenciado DummyManagedClass remotamente.
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+ store.setProperty(DummyManagedClass.class, "name", "Test Name");
+
+ DummyManagedClass managedClass = Beans.getReference(DummyManagedClass.class);
+ Assert.assertEquals("Test Name", managedClass.getName());
+ }
+
+ @Test
+ public void readAWriteOnly() {
+
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ try {
+ store.getProperty(DummyManagedClass.class, "writeOnlyProperty");
+ Assert.fail();
+ } catch (DemoiselleException de) {
+ // SUCCESS
+ }
+
+ }
+
+ @Test
+ public void writeAReadOnly() {
+
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ try {
+ store.setProperty(DummyManagedClass.class, "readOnlyProperty", "New Value");
+ Assert.fail();
+ } catch (DemoiselleException de) {
+ // SUCCESS
+ }
+
+ }
+
+ @Test
+ public void invokeOperation() {
+
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ try {
+ store.setProperty(DummyManagedClass.class, "firstFactor", new Integer(10));
+ store.setProperty(DummyManagedClass.class, "secondFactor", new Integer(15));
+ Integer response = (Integer) store.invoke(DummyManagedClass.class, "sumFactors");
+ Assert.assertEquals(new Integer(25), response);
+ } catch (DemoiselleException de) {
+ Assert.fail(de.getMessage());
+ }
+
+ }
+
+ @Test
+ public void invokeNonAnnotatedOperation() {
+
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ try {
+ // O método "nonOperationAnnotatedMethod" existe na classe DummyManagedClass, mas não está anotado como
+ // "@ManagedOperation", então
+ // ela não pode ser exposta para extensões.
+ store.invoke(DummyManagedClass.class, "nonOperationAnnotatedMethod");
+ Assert.fail();
+ } catch (DemoiselleException de) {
+ // SUCCESS
+ }
+
+ }
+
+ @Test
+ public void accessLevelControl() {
+ // tentamos escrever em uma propriedade que, apesar de ter método setter, está marcada como read-only.
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ try {
+ store.setProperty(DummyManagedClass.class, "readOnlyPropertyWithSetMethod", "A Value");
+ Assert.fail();
+ } catch (DemoiselleException de) {
+ System.out.println(de.getMessage());
+ // success
+ }
+ }
+
+ @Test
+ public void requestScopedOperation() {
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ // Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem
+ // operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova
+ Object info = store.invoke(DummyManagedClass.class, "requestScopedOperation");
+ Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);
+
+ // Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request.
+ info = store.invoke(DummyManagedClass.class, "requestScopedOperation");
+ Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info);
+ }
+}
diff --git a/impl/core/src/test/java/management/bootstrap/ManagementBootstrapTest.java b/impl/core/src/test/java/management/bootstrap/ManagementBootstrapTest.java
new file mode 100644
index 0000000..f4e1065
--- /dev/null
+++ b/impl/core/src/test/java/management/bootstrap/ManagementBootstrapTest.java
@@ -0,0 +1,117 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package management.bootstrap;
+
+import java.util.List;
+
+import management.testclasses.DummyManagedClass;
+import management.testclasses.DummyManagementExtension;
+import management.testclasses.ManagedClassStore;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import test.Tests;
+import br.gov.frameworkdemoiselle.internal.management.ManagedType;
+import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess;
+import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension;
+import br.gov.frameworkdemoiselle.util.Beans;
+
+@RunWith(Arquillian.class)
+public class ManagementBootstrapTest {
+
+ /**
+ * Deployment to test normal deployment behaviour
+ *
+ */
+ @Deployment
+ public static JavaArchive createDeployment() {
+ return Tests.createDeployment(ManagementBootstrapTest.class)
+ .addClasses(DummyManagementExtension.class,
+ DummyManagedClass.class, ManagedClassStore.class);
+ }
+
+ /**
+ * Test if a a management extension (a library that implements
+ * {@link ManagementExtension}) is correctly detected.
+ */
+ @Test
+ public void managementExtensionRegistration() {
+ // "store" é application scoped e é usado pelo DummyManagementExtension
+ // para
+ // armazenar todos os beans anotados com @ManagementController. Se o
+ // bootstrap rodou corretamente,
+ // ele chamou DummyManagementExtension.initialize e este store conterá o
+ // bean de teste que anotamos.
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ Assert.assertEquals(1, store.getManagedTypes().size());
+ }
+
+ /**
+ * Test if a a management extension's shutdown method is correctly called
+ * upon application shutdown.
+ */
+ @Test
+ public void managementExtensionShutdown() {
+ // "store" é application scoped e é usado pelo DummyManagementExtension
+ // para
+ // armazenar todos os beans anotados com @ManagementController. Se o
+ // bootstrap rodou corretamente,
+ // ele chamou DummyManagementExtension.initialize e este store conterá o
+ // bean de teste que anotamos.
+ // Nós então disparamos o evento de shutdown onde ele deverá limpar o
+ // store.
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ // Detecta se a classe anotada foi detectada
+ List managedTypes = store.getManagedTypes();
+ Assert.assertEquals(1, managedTypes.size());
+
+ Beans.getBeanManager().fireEvent(new AfterShutdownProccess() {
+ });
+
+ // Após o "undeploy", o ciclo de vida precisa ter removido a classe
+ // gerenciada da lista.
+ Assert.assertEquals(0, managedTypes.size());
+ }
+
+}
diff --git a/impl/core/src/test/java/management/notification/NotificationTest.java b/impl/core/src/test/java/management/notification/NotificationTest.java
new file mode 100644
index 0000000..82dddca
--- /dev/null
+++ b/impl/core/src/test/java/management/notification/NotificationTest.java
@@ -0,0 +1,124 @@
+/*
+ * Demoiselle Framework
+ * Copyright (C) 2010 SERPRO
+ * ----------------------------------------------------------------------------
+ * This file is part of Demoiselle Framework.
+ *
+ * Demoiselle Framework is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License version 3
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License version 3
+ * along with this program; if not, see
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Fifth Floor, Boston, MA 02110-1301, USA.
+ * ----------------------------------------------------------------------------
+ * Este arquivo é parte do Framework Demoiselle.
+ *
+ * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou
+ * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
+ * do Software Livre (FSF).
+ *
+ * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
+ * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
+ * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
+ * para maiores detalhes.
+ *
+ * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
+ * "LICENCA.txt", junto com esse programa. Se não, acesse
+ * ou escreva para a Fundação do Software Livre (FSF) Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+package management.notification;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+import management.testclasses.DummyManagedClass;
+import management.testclasses.DummyNotificationListener;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import test.Tests;
+import br.gov.frameworkdemoiselle.annotation.Name;
+import br.gov.frameworkdemoiselle.internal.management.ManagedType;
+import br.gov.frameworkdemoiselle.internal.management.Management;
+import br.gov.frameworkdemoiselle.management.AttributeChangeNotification;
+import br.gov.frameworkdemoiselle.management.GenericNotification;
+import br.gov.frameworkdemoiselle.management.NotificationManager;
+import br.gov.frameworkdemoiselle.util.Beans;
+import br.gov.frameworkdemoiselle.util.ResourceBundle;
+
+/**
+ * Test the {@link NotificationManager} with a dummy extension to check if notifications are correctly propagated
+ *
+ * @author serpro
+ */
+@RunWith(Arquillian.class)
+public class NotificationTest {
+
+ @Inject
+ private NotificationManager manager;
+
+ @Inject
+ @Name("demoiselle-core-bundle")
+ private ResourceBundle bundle;
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+ return Tests.createDeployment(NotificationTest.class)
+ .addClasses(DummyNotificationListener.class, DummyManagedClass.class);
+ }
+
+ /**
+ * Test sending a normal notification
+ */
+ @Test
+ public void sendGenericNotification() {
+ manager.sendNotification(new GenericNotification("Test Message"));
+ DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
+ Assert.assertEquals("Test Message", listener.getMessage());
+ }
+
+ /**
+ * Test sending a notification of change in attribute
+ */
+ @Test
+ public void sendAttributeChangeNotification() {
+ manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old",
+ "new"));
+ DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
+ Assert.assertEquals("Test Message - attribute", listener.getMessage());
+ }
+
+ /**
+ * Test if notifications are automatically sent when an attribute from a managed class change values
+ */
+ @Test
+ public void notifyChangeManagedClass() {
+ Management manager = Beans.getReference(Management.class);
+
+ for (ManagedType type : manager.getManagedTypes()) {
+ if (type.getType().equals(DummyManagedClass.class)) {
+ manager.setProperty(type, "id", new Integer(10));
+ break;
+ }
+ }
+
+ DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class);
+ Assert.assertEquals(
+ bundle.getString("management-notification-attribute-changed", "id",
+ DummyManagedClass.class.getCanonicalName())
+ + " - id", listener.getMessage());
+ }
+
+}
diff --git a/impl/core/src/test/java/management/validation/ValidationTest.java b/impl/core/src/test/java/management/validation/ValidationTest.java
new file mode 100644
index 0000000..092ebf8
--- /dev/null
+++ b/impl/core/src/test/java/management/validation/ValidationTest.java
@@ -0,0 +1,81 @@
+package management.validation;
+
+import management.testclasses.DummyManagedClass;
+import management.testclasses.DummyManagementExtension;
+import management.testclasses.DummyValidator;
+import management.testclasses.DummyValidatorAnnotation;
+import management.testclasses.ManagedClassStore;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import test.Tests;
+import br.gov.frameworkdemoiselle.DemoiselleException;
+import br.gov.frameworkdemoiselle.util.Beans;
+
+@RunWith(Arquillian.class)
+public class ValidationTest {
+
+ @Deployment
+ public static JavaArchive createDeployment() {
+
+ return Tests.createDeployment(ValidationTest.class)
+ .addClasses(DummyManagementExtension.class, ManagedClassStore.class, DummyManagedClass.class,DummyValidator.class, DummyValidatorAnnotation.class);
+
+ }
+
+ /**
+ * Test if a management controller accepts a valid value annotated with a core validation (from javax.validation)
+ * when a property is being set by a management client
+ */
+ @Test
+ public void setValidValue() {
+ // Testa se é possível definir um valor válido para uma propriedade.
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+ store.setProperty(DummyManagedClass.class, "id", new Integer(1));
+ Assert.assertEquals(new Integer(1), store.getProperty(DummyManagedClass.class, "id"));
+ }
+
+ /**
+ * Test if a management controller refuses a valid value annotated with a core validation (from javax.validation)
+ * when a property is being set by a management client
+ */
+ @Test
+ public void setInvalidValue() {
+ // Testa se é possível definir um valor válido para uma propriedade.
+ try {
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+ store.setProperty(DummyManagedClass.class, "id", (Integer) null);
+
+ Assert.fail();
+ } catch (DemoiselleException de) {
+ // Classes de gerenciamento disparam Demoiselle Exception quando uma validação falha
+ }
+ }
+
+ /**
+ * Tests if custom validators (outside the javax.validation package) run as normal
+ */
+ @Test
+ public void customValidation() {
+
+ try {
+ ManagedClassStore store = Beans.getReference(ManagedClassStore.class);
+
+ // Atributo "gender" deve aceitar apenas "M" ou "F", tanto maiúsculo quanto minúsculo. A anotação
+ // customizada DummyValidatorAnnotation é uma simples validação que testa se uma string passada está
+ // na lista de strings aceitas.
+ store.setProperty(DummyManagedClass.class, "gender", "J");
+
+ Assert.fail();
+ } catch (DemoiselleException e) {
+ Assert.assertTrue(e.getMessage().contains("Test Message"));
+ }
+
+ }
+
+}
--
libgit2 0.21.2