Commit 6c692bd5843eb2d5f873b7ae5bbf7aa76b5e8f35
1 parent
eedd4c0d
Exists in
master
-Reparado problema onde o módulo de gerenciamento não conseguia injetar
classes ManagementController que fossem anotadas com qualifiers. -Ajuste nos testes do demoiselle-jmx -Alteração de mensagens de erro
Showing
10 changed files
with
89 additions
and
140 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
| 1 | package br.gov.frameworkdemoiselle.internal.bootstrap; | 1 | package br.gov.frameworkdemoiselle.internal.bootstrap; |
| 2 | 2 | ||
| 3 | +import java.lang.reflect.Modifier; | ||
| 3 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
| 4 | import java.util.Collections; | 5 | import java.util.Collections; |
| 5 | import java.util.List; | 6 | import java.util.List; |
| 7 | +import java.util.Locale; | ||
| 6 | import java.util.Set; | 8 | import java.util.Set; |
| 7 | 9 | ||
| 8 | import javax.enterprise.event.Observes; | 10 | import javax.enterprise.event.Observes; |
| @@ -15,13 +17,16 @@ import javax.enterprise.inject.spi.BeforeShutdown; | @@ -15,13 +17,16 @@ import javax.enterprise.inject.spi.BeforeShutdown; | ||
| 15 | import javax.enterprise.inject.spi.Extension; | 17 | import javax.enterprise.inject.spi.Extension; |
| 16 | import javax.enterprise.inject.spi.ProcessAnnotatedType; | 18 | import javax.enterprise.inject.spi.ProcessAnnotatedType; |
| 17 | 19 | ||
| 20 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
| 18 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; | 21 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
| 19 | import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | 22 | import br.gov.frameworkdemoiselle.internal.context.ManagedContext; |
| 20 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; | 23 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; |
| 21 | import br.gov.frameworkdemoiselle.internal.management.Management; | 24 | import br.gov.frameworkdemoiselle.internal.management.Management; |
| 25 | +import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | ||
| 22 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; | 26 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; |
| 23 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; | 27 | import br.gov.frameworkdemoiselle.stereotype.ManagementController; |
| 24 | import br.gov.frameworkdemoiselle.util.Beans; | 28 | import br.gov.frameworkdemoiselle.util.Beans; |
| 29 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 25 | 30 | ||
| 26 | public class ManagementBootstrap implements Extension { | 31 | public class ManagementBootstrap implements Extension { |
| 27 | 32 | ||
| @@ -43,8 +48,14 @@ public class ManagementBootstrap implements Extension { | @@ -43,8 +48,14 @@ public class ManagementBootstrap implements Extension { | ||
| 43 | 48 | ||
| 44 | @SuppressWarnings("unchecked") | 49 | @SuppressWarnings("unchecked") |
| 45 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event,BeanManager beanManager) { | 50 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event,BeanManager beanManager) { |
| 51 | + ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | ||
| 52 | + | ||
| 46 | Management monitoringManager = Beans.getReference(Management.class); | 53 | Management monitoringManager = Beans.getReference(Management.class); |
| 47 | for (AnnotatedType<?> type : types) { | 54 | for (AnnotatedType<?> type : types) { |
| 55 | + if (type.getJavaClass().isInterface() || Modifier.isAbstract(type.getJavaClass().getModifiers()) ){ | ||
| 56 | + throw new DemoiselleException(bundle.getString("management-abstract-class-defined" , type.getJavaClass().getCanonicalName())); | ||
| 57 | + } | ||
| 58 | + | ||
| 48 | ManagedType managedType = new ManagedType(type.getJavaClass()); | 59 | ManagedType managedType = new ManagedType(type.getJavaClass()); |
| 49 | monitoringManager.addManagedType(managedType); | 60 | monitoringManager.addManagedType(managedType); |
| 50 | } | 61 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagedType.java
| @@ -39,8 +39,11 @@ package br.gov.frameworkdemoiselle.internal.management; | @@ -39,8 +39,11 @@ package br.gov.frameworkdemoiselle.internal.management; | ||
| 39 | import java.lang.annotation.Annotation; | 39 | import java.lang.annotation.Annotation; |
| 40 | import java.lang.reflect.Field; | 40 | import java.lang.reflect.Field; |
| 41 | import java.lang.reflect.Method; | 41 | import java.lang.reflect.Method; |
| 42 | +import java.util.ArrayList; | ||
| 42 | import java.util.TreeMap; | 43 | import java.util.TreeMap; |
| 43 | 44 | ||
| 45 | +import javax.inject.Qualifier; | ||
| 46 | + | ||
| 44 | import br.gov.frameworkdemoiselle.DemoiselleException; | 47 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 45 | import br.gov.frameworkdemoiselle.annotation.ManagedOperation; | 48 | import br.gov.frameworkdemoiselle.annotation.ManagedOperation; |
| 46 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; | 49 | import br.gov.frameworkdemoiselle.annotation.ManagedProperty; |
| @@ -60,6 +63,8 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | @@ -60,6 +63,8 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
| 60 | public class ManagedType { | 63 | public class ManagedType { |
| 61 | 64 | ||
| 62 | private Class<?> type; | 65 | private Class<?> type; |
| 66 | + | ||
| 67 | + private Annotation[] qualifiers; | ||
| 63 | 68 | ||
| 64 | private TreeMap<String, FieldDetail> fields; | 69 | private TreeMap<String, FieldDetail> fields; |
| 65 | 70 | ||
| @@ -83,6 +88,7 @@ public class ManagedType { | @@ -83,6 +88,7 @@ public class ManagedType { | ||
| 83 | fields = new TreeMap<String, FieldDetail>(); | 88 | fields = new TreeMap<String, FieldDetail>(); |
| 84 | operationMethods = new TreeMap<String, MethodDetail>(); | 89 | operationMethods = new TreeMap<String, MethodDetail>(); |
| 85 | this.description = type.getAnnotation(ManagementController.class).description(); | 90 | this.description = type.getAnnotation(ManagementController.class).description(); |
| 91 | + this.qualifiers = getQualifierAnnotations(type); | ||
| 86 | 92 | ||
| 87 | initialize(); | 93 | initialize(); |
| 88 | } | 94 | } |
| @@ -102,6 +108,18 @@ public class ManagedType { | @@ -102,6 +108,18 @@ public class ManagedType { | ||
| 102 | public TreeMap<String, MethodDetail> getOperationMethods() { | 108 | public TreeMap<String, MethodDetail> getOperationMethods() { |
| 103 | return operationMethods; | 109 | return operationMethods; |
| 104 | } | 110 | } |
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * <p>Return a (possibly empty) list of all qualifiers this type have. Qualifiers | ||
| 114 | + * are any annotations marked as {@link Qualifier}.</p> | ||
| 115 | + * | ||
| 116 | + * <p>This method returns the true list of qualifiers. If implementators change this list, it will | ||
| 117 | + * affect future calls of this method. This is so that resources can be spared by not creating many instances of this list.</p> | ||
| 118 | + * | ||
| 119 | + */ | ||
| 120 | + public Annotation[] getQualifiers(){ | ||
| 121 | + return this.qualifiers; | ||
| 122 | + } | ||
| 105 | 123 | ||
| 106 | private void initialize() { | 124 | private void initialize() { |
| 107 | // Para cada atributo verifica se ele está anotado com ManagedProperty e extrai as informações dele (método get, set e | 125 | // Para cada atributo verifica se ele está anotado com ManagedProperty e extrai as informações dele (método get, set e |
| @@ -224,6 +242,33 @@ public class ManagedType { | @@ -224,6 +242,33 @@ public class ManagedType { | ||
| 224 | 242 | ||
| 225 | return setterMethod; | 243 | return setterMethod; |
| 226 | } | 244 | } |
| 245 | + | ||
| 246 | + /** | ||
| 247 | + * Indicates another {@link ManagedType} represents the same {@link Class} as this one. This method also supports a | ||
| 248 | + * {@link Class} as a parameter, in this case it will return <code>true</code> if the passed class is exactly the | ||
| 249 | + * same Java class represented by this {@link ManagedType}. | ||
| 250 | + */ | ||
| 251 | + @Override | ||
| 252 | + public boolean equals(Object other) { | ||
| 253 | + if (other == null) { | ||
| 254 | + return false; | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName()); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + private synchronized Annotation[] getQualifierAnnotations(Class<?> beanClass){ | ||
| 261 | + Annotation[] annotations = beanClass.getAnnotations(); | ||
| 262 | + ArrayList<Annotation> qualifiers = new ArrayList<Annotation>(annotations.length); | ||
| 263 | + | ||
| 264 | + for (int i=0; i<annotations.length; i++){ | ||
| 265 | + if (annotations[i].annotationType().getAnnotation(Qualifier.class) != null){ | ||
| 266 | + qualifiers.add(annotations[i]); | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + return qualifiers.toArray(new Annotation[0]); | ||
| 271 | + } | ||
| 227 | 272 | ||
| 228 | public final class FieldDetail { | 273 | public final class FieldDetail { |
| 229 | 274 | ||
| @@ -317,18 +362,4 @@ public class ManagedType { | @@ -317,18 +362,4 @@ public class ManagedType { | ||
| 317 | return parameterDescription; | 362 | return parameterDescription; |
| 318 | } | 363 | } |
| 319 | } | 364 | } |
| 320 | - | ||
| 321 | - /** | ||
| 322 | - * Indicates another {@link ManagedType} represents the same {@link Class} as this one. This method also supports a | ||
| 323 | - * {@link Class} as a parameter, in this case it will return <code>true</code> if the passed class is exactly the | ||
| 324 | - * same Java class represented by this {@link ManagedType}. | ||
| 325 | - */ | ||
| 326 | - @Override | ||
| 327 | - public boolean equals(Object other) { | ||
| 328 | - if (other == null) { | ||
| 329 | - return false; | ||
| 330 | - } | ||
| 331 | - | ||
| 332 | - return ((ManagedType) other).getType().getCanonicalName().equals(this.getType().getCanonicalName()); | ||
| 333 | - } | ||
| 334 | } | 365 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
| @@ -129,7 +129,7 @@ public class Management { | @@ -129,7 +129,7 @@ public class Management { | ||
| 129 | activateContexts(managedType.getType()); | 129 | activateContexts(managedType.getType()); |
| 130 | 130 | ||
| 131 | try { | 131 | try { |
| 132 | - Object delegate = Beans.getReference(managedType.getType()); | 132 | + Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers()); |
| 133 | MethodDetail method = managedType.getOperationMethods().get(actionName); | 133 | MethodDetail method = managedType.getOperationMethods().get(actionName); |
| 134 | 134 | ||
| 135 | if (method != null) { | 135 | if (method != null) { |
| @@ -179,7 +179,7 @@ public class Management { | @@ -179,7 +179,7 @@ public class Management { | ||
| 179 | activateContexts(managedType.getType()); | 179 | activateContexts(managedType.getType()); |
| 180 | 180 | ||
| 181 | try { | 181 | try { |
| 182 | - Object delegate = Beans.getReference(managedType.getType()); | 182 | + Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers()); |
| 183 | 183 | ||
| 184 | return getterMethod.invoke(delegate, (Object[]) null); | 184 | return getterMethod.invoke(delegate, (Object[]) null); |
| 185 | } catch (Exception e) { | 185 | } catch (Exception e) { |
| @@ -227,7 +227,7 @@ public class Management { | @@ -227,7 +227,7 @@ public class Management { | ||
| 227 | // Obtém uma instância da classe gerenciada, lembrando que | 227 | // Obtém uma instância da classe gerenciada, lembrando que |
| 228 | // classes | 228 | // classes |
| 229 | // anotadas com @ManagementController são sempre singletons. | 229 | // anotadas com @ManagementController são sempre singletons. |
| 230 | - Object delegate = Beans.getReference(managedType.getType()); | 230 | + Object delegate = Beans.getReference(managedType.getType() , managedType.getQualifiers() ); |
| 231 | 231 | ||
| 232 | // Se houver um validador anexado à propriedade alterada, executa o validador sobre | 232 | // Se houver um validador anexado à propriedade alterada, executa o validador sobre |
| 233 | // o novo valor. | 233 | // o novo valor. |
| @@ -343,5 +343,6 @@ public class Management { | @@ -343,5 +343,6 @@ public class Management { | ||
| 343 | 343 | ||
| 344 | return this.validator; | 344 | return this.validator; |
| 345 | } | 345 | } |
| 346 | + | ||
| 346 | 347 | ||
| 347 | } | 348 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/stereotype/ManagementController.java
| @@ -49,12 +49,14 @@ import javax.enterprise.inject.Stereotype; | @@ -49,12 +49,14 @@ import javax.enterprise.inject.Stereotype; | ||
| 49 | import javax.enterprise.util.Nonbinding; | 49 | import javax.enterprise.util.Nonbinding; |
| 50 | 50 | ||
| 51 | /** | 51 | /** |
| 52 | - * <p>Identifies a <b>management controller</b> class. What it means is that an external client can manage the application | 52 | + * <p>Identifies a <b>management controller</b> bean. What it means is that an external client can manage the application |
| 53 | * this class is in by reading or writing it's attributes and calling it's operations.</p> | 53 | * this class is in by reading or writing it's attributes and calling it's operations.</p> |
| 54 | * <p> | 54 | * <p> |
| 55 | * Only fields annotated with {@link br.gov.frameworkdemoiselle.annotation.ManagedProperty} or | 55 | * Only fields annotated with {@link br.gov.frameworkdemoiselle.annotation.ManagedProperty} or |
| 56 | * methods annotated with {@link br.gov.frameworkdemoiselle.annotation.ManagedOperation} will be exposed | 56 | * methods annotated with {@link br.gov.frameworkdemoiselle.annotation.ManagedOperation} will be exposed |
| 57 | * to clients.</p> | 57 | * to clients.</p> |
| 58 | + * <p>Only bean implementations (concrete classes) can be management controllers. It's a runtime error to mark an interface | ||
| 59 | + * or abstract class with this annotation.</p> | ||
| 58 | * <p>This stereotype only defines a class as managed, you need to choose an extension that will expose this managed class | 60 | * <p>This stereotype only defines a class as managed, you need to choose an extension that will expose this managed class |
| 59 | * to external clients using any technology available. One example is the Demoiselle JMX extension, that will expose | 61 | * to external clients using any technology available. One example is the Demoiselle JMX extension, that will expose |
| 60 | * managed classes as MBeans.</p> | 62 | * managed classes as MBeans.</p> |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| @@ -102,8 +102,9 @@ user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1} | @@ -102,8 +102,9 @@ user-has-role=Usu\u00E1rio {0} possui a(s) role(s)\: {1} | ||
| 102 | authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties. | 102 | authenticator-not-defined=Nenhum mecanismo de autentica\u00E7\u00E3o foi definido. Para utilizar {0} \u00E9 preciso definir a propriedade frameworkdemoiselle.security.authenticator.class como mecanismo de autentica\u00E7\u00E3o desejado no arquivo demoiselle.properties. |
| 103 | 103 | ||
| 104 | management-notification-attribute-changed=O atributo [{0}] da classe gerenciada [{1}] foi alterado | 104 | management-notification-attribute-changed=O atributo [{0}] da classe gerenciada [{1}] foi alterado |
| 105 | -management-null-class-defined=A classe gerenciada informada n\u00E3o pode ser nula | ||
| 106 | -management-no-annotation-found=Classe {0} precisa ser anotada com @Managed | 105 | +management-null-class-defined=O controlador de gerenciamento informado n\u00E3o pode ser [null] |
| 106 | +management-abstract-class-defined=O controlador de gerenciamento [{0}] precisa ser uma classe concreta | ||
| 107 | +management-no-annotation-found=Classe {0} precisa ser anotada com @ManagementController | ||
| 107 | management-invalid-property-no-getter-setter=Falha ao inicializar classe gerenciada {0}, n\u00E3o foi encontrado um m\u00E9todo get ou m\u00E9todo set para a propriedade {1} | 108 | management-invalid-property-no-getter-setter=Falha ao inicializar classe gerenciada {0}, n\u00E3o foi encontrado um m\u00E9todo get ou m\u00E9todo set para a propriedade {1} |
| 108 | management-invalid-property-as-operation=Falha ao inicializar classe gerenciada {0}, n\u00E3o \u00E9 poss\u00EDvel declarar uma propriedade cujo m\u00E9todo get ou set \u00E9 uma opera\u00E7\u00E3o | 109 | management-invalid-property-as-operation=Falha ao inicializar classe gerenciada {0}, n\u00E3o \u00E9 poss\u00EDvel declarar uma propriedade cujo m\u00E9todo get ou set \u00E9 uma opera\u00E7\u00E3o |
| 109 | management-introspection-error=Erro ao ler atributos da classe gerenciada {0} | 110 | management-introspection-error=Erro ao ler atributos da classe gerenciada {0} |
impl/extension/jmx/src/test/java/management/tests/internal/DynamicMBeanProxyTestCase.java
| @@ -52,6 +52,7 @@ import org.jboss.arquillian.container.test.api.Deployment; | @@ -52,6 +52,7 @@ import org.jboss.arquillian.container.test.api.Deployment; | ||
| 52 | import org.jboss.arquillian.junit.Arquillian; | 52 | import org.jboss.arquillian.junit.Arquillian; |
| 53 | import org.jboss.shrinkwrap.api.ShrinkWrap; | 53 | import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 54 | import org.jboss.shrinkwrap.api.asset.FileAsset; | 54 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| 55 | +import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
| 55 | import org.jboss.shrinkwrap.api.spec.JavaArchive; | 56 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 56 | import org.junit.Test; | 57 | import org.junit.Test; |
| 57 | import org.junit.runner.RunWith; | 58 | import org.junit.runner.RunWith; |
| @@ -68,13 +69,16 @@ public class DynamicMBeanProxyTestCase { | @@ -68,13 +69,16 @@ public class DynamicMBeanProxyTestCase { | ||
| 68 | mainDeployment | 69 | mainDeployment |
| 69 | .addPackages(true, "br") | 70 | .addPackages(true, "br") |
| 70 | .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | 71 | .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") |
| 71 | - .addAsResource(new FileAsset(new File("src/test/resources/configuration/demoiselle.properties")), | ||
| 72 | - "demoiselle.properties").addPackages(false, DynamicMBeanProxyTestCase.class.getPackage()) | 72 | + .addAsResource(new FileAsset(new File("src/test/resources/configuration/demoiselle.properties")),"demoiselle.properties") |
| 73 | + .addPackages(false, DynamicMBeanProxyTestCase.class.getPackage()) | ||
| 73 | .addClasses(LocaleProducer.class, ManagedTestClass.class); | 74 | .addClasses(LocaleProducer.class, ManagedTestClass.class); |
| 74 | - | 75 | + |
| 76 | + mainDeployment.as(ZipExporter.class).exportTo( | ||
| 77 | + new File("/home/81986912515/myPackage.jar"), true); | ||
| 78 | + | ||
| 75 | return mainDeployment; | 79 | return mainDeployment; |
| 76 | } | 80 | } |
| 77 | - | 81 | + |
| 78 | /** | 82 | /** |
| 79 | * Testa se o bootstrap está corretamente carregando e registrando classes anotadas com {@link Managed} como MBeans. | 83 | * Testa se o bootstrap está corretamente carregando e registrando classes anotadas com {@link Managed} como MBeans. |
| 80 | */ | 84 | */ |
| @@ -89,10 +93,12 @@ public class DynamicMBeanProxyTestCase { | @@ -89,10 +93,12 @@ public class DynamicMBeanProxyTestCase { | ||
| 89 | // o NotificationBroadcaster. Qualquer classe gerenciada criada pelo usuário | 93 | // o NotificationBroadcaster. Qualquer classe gerenciada criada pelo usuário |
| 90 | // será adicionada a ela, então esperamos 2 MBeans aqui. | 94 | // será adicionada a ela, então esperamos 2 MBeans aqui. |
| 91 | Assert.assertEquals(2, manager.listRegisteredMBeans().size()); | 95 | Assert.assertEquals(2, manager.listRegisteredMBeans().size()); |
| 96 | + | ||
| 92 | } | 97 | } |
| 93 | 98 | ||
| 94 | @Test | 99 | @Test |
| 95 | public void testAttributeWrite() { | 100 | public void testAttributeWrite() { |
| 101 | + | ||
| 96 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | 102 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 97 | 103 | ||
| 98 | ObjectName name = null; | 104 | ObjectName name = null; |
| @@ -107,10 +113,12 @@ public class DynamicMBeanProxyTestCase { | @@ -107,10 +113,12 @@ public class DynamicMBeanProxyTestCase { | ||
| 107 | } catch (Exception e) { | 113 | } catch (Exception e) { |
| 108 | Assert.fail(e.getMessage()); | 114 | Assert.fail(e.getMessage()); |
| 109 | } | 115 | } |
| 116 | + | ||
| 110 | } | 117 | } |
| 111 | 118 | ||
| 112 | @Test | 119 | @Test |
| 113 | public void testAttributeRead() { | 120 | public void testAttributeRead() { |
| 121 | + | ||
| 114 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | 122 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 115 | 123 | ||
| 116 | ObjectName name = null; | 124 | ObjectName name = null; |
| @@ -129,6 +137,7 @@ public class DynamicMBeanProxyTestCase { | @@ -129,6 +137,7 @@ public class DynamicMBeanProxyTestCase { | ||
| 129 | } catch (Exception e) { | 137 | } catch (Exception e) { |
| 130 | Assert.fail(); | 138 | Assert.fail(); |
| 131 | } | 139 | } |
| 140 | + | ||
| 132 | } | 141 | } |
| 133 | 142 | ||
| 134 | @Test | 143 | @Test |
| @@ -156,6 +165,7 @@ public class DynamicMBeanProxyTestCase { | @@ -156,6 +165,7 @@ public class DynamicMBeanProxyTestCase { | ||
| 156 | 165 | ||
| 157 | @Test | 166 | @Test |
| 158 | public void testTryWriteOverReadOnly() { | 167 | public void testTryWriteOverReadOnly() { |
| 168 | + | ||
| 159 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | 169 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 160 | 170 | ||
| 161 | ObjectName name = null; | 171 | ObjectName name = null; |
| @@ -170,6 +180,6 @@ public class DynamicMBeanProxyTestCase { | @@ -170,6 +180,6 @@ public class DynamicMBeanProxyTestCase { | ||
| 170 | } catch (Exception e) { | 180 | } catch (Exception e) { |
| 171 | Assert.fail(e.getMessage()); | 181 | Assert.fail(e.getMessage()); |
| 172 | } | 182 | } |
| 183 | + | ||
| 173 | } | 184 | } |
| 174 | - | ||
| 175 | } | 185 | } |
impl/extension/jmx/src/test/java/management/tests/internal/NotificationBroadcasterTestCase.java
| @@ -88,11 +88,12 @@ public class NotificationBroadcasterTestCase { | @@ -88,11 +88,12 @@ public class NotificationBroadcasterTestCase { | ||
| 88 | public void sendMessageTest(){ | 88 | public void sendMessageTest(){ |
| 89 | JMXConfig config = Beans.getReference(JMXConfig.class); | 89 | JMXConfig config = Beans.getReference(JMXConfig.class); |
| 90 | 90 | ||
| 91 | + //Este será o lado cliente. Este manager é usado para enviar notificações a partir do código da aplicação | ||
| 92 | + NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | ||
| 93 | + | ||
| 91 | //Obtém o servidor MBean onde anexaremos um listener para a notificação | 94 | //Obtém o servidor MBean onde anexaremos um listener para a notificação |
| 92 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); | 95 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 93 | 96 | ||
| 94 | - NotificationManager notificationManager = Beans.getReference(NotificationManager.class); | ||
| 95 | - | ||
| 96 | //Aqui obtemos o MBean de notificações já registrado pelo bootstrap | 97 | //Aqui obtemos o MBean de notificações já registrado pelo bootstrap |
| 97 | StringBuffer notificationMBeanName = new StringBuffer() | 98 | StringBuffer notificationMBeanName = new StringBuffer() |
| 98 | .append( config.getNotificationDomain()!=null ? config.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) | 99 | .append( config.getNotificationDomain()!=null ? config.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) |
impl/extension/jmx/src/test/java/management/tests/internal/RemoteManagementTestCase.java
| @@ -1,90 +0,0 @@ | @@ -1,90 +0,0 @@ | ||
| 1 | -package management.tests.internal; | ||
| 2 | - | ||
| 3 | -import java.io.File; | ||
| 4 | - | ||
| 5 | -import javax.management.Attribute; | ||
| 6 | -import javax.management.MBeanServerConnection; | ||
| 7 | -import javax.management.MalformedObjectNameException; | ||
| 8 | -import javax.management.ObjectName; | ||
| 9 | -import javax.management.remote.JMXConnector; | ||
| 10 | -import javax.management.remote.JMXConnectorFactory; | ||
| 11 | -import javax.management.remote.JMXServiceURL; | ||
| 12 | - | ||
| 13 | -import management.LocaleProducer; | ||
| 14 | -import management.domain.ManagedTestClass; | ||
| 15 | - | ||
| 16 | -import org.jboss.arquillian.container.test.api.Deployment; | ||
| 17 | -import org.jboss.arquillian.container.test.api.RunAsClient; | ||
| 18 | -import org.jboss.arquillian.junit.Arquillian; | ||
| 19 | -import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
| 20 | -import org.jboss.shrinkwrap.api.asset.FileAsset; | ||
| 21 | -import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
| 22 | -import org.junit.Assert; | ||
| 23 | -import org.junit.Ignore; | ||
| 24 | -import org.junit.Test; | ||
| 25 | -import org.junit.runner.RunWith; | ||
| 26 | - | ||
| 27 | -/** | ||
| 28 | - * | ||
| 29 | - * Tests remote management using JMX. | ||
| 30 | - * | ||
| 31 | - * <p> | ||
| 32 | - * TODO Currently you need to configure Eclipse Run configuration to pass | ||
| 33 | - * system properties enabling remote management to the Java VM. Arquillian's | ||
| 34 | - * current version doesn't support this. | ||
| 35 | - * </p> | ||
| 36 | - * | ||
| 37 | - * <p> | ||
| 38 | - * On a SUN virtual machine these properties need to be set to enable remote management: | ||
| 39 | - * <ul> | ||
| 40 | - * <li>com.sun.management.jmxremote.port=9999</li> | ||
| 41 | - * <li>com.sun.management.jmxremote.authenticate=false</li> | ||
| 42 | - * <li>com.sun.management.jmxremote.ssl=false</li> | ||
| 43 | - * </ul> | ||
| 44 | - * </p> | ||
| 45 | - * | ||
| 46 | - * @author serpro | ||
| 47 | - * | ||
| 48 | - */ | ||
| 49 | -@RunWith(Arquillian.class) | ||
| 50 | -@Ignore | ||
| 51 | -public class RemoteManagementTestCase { | ||
| 52 | - | ||
| 53 | - @Deployment(testable=false) | ||
| 54 | - public static JavaArchive createDeployment() { | ||
| 55 | - JavaArchive mainDeployment = ShrinkWrap.create(JavaArchive.class); | ||
| 56 | - mainDeployment | ||
| 57 | - .addPackages(true, "br") | ||
| 58 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | ||
| 59 | - .addAsResource(new FileAsset(new File("src/test/resources/configuration/demoiselle.properties")), | ||
| 60 | - "demoiselle.properties").addPackages(false, DynamicMBeanProxyTestCase.class.getPackage()) | ||
| 61 | - .addClasses(LocaleProducer.class, ManagedTestClass.class); | ||
| 62 | - | ||
| 63 | - return mainDeployment; | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - @Test | ||
| 67 | - @RunAsClient | ||
| 68 | - public void testRemotePropertyReading() { | ||
| 69 | - try { | ||
| 70 | - JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi"); | ||
| 71 | - JMXConnector jmxc = JMXConnectorFactory.connect(url, null); | ||
| 72 | - MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); | ||
| 73 | - | ||
| 74 | - ObjectName name = null; | ||
| 75 | - try { | ||
| 76 | - name = new ObjectName("br.gov.frameworkdemoiselle.jmx.domain:name=ManagedTest"); | ||
| 77 | - } catch (MalformedObjectNameException e) { | ||
| 78 | - Assert.fail(); | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - mbsc.setAttribute(name, new Attribute("attribute", "New Value")); | ||
| 82 | - Object info = mbsc.getAttribute(name, "attribute"); | ||
| 83 | - | ||
| 84 | - Assert.assertEquals("New Value", info); | ||
| 85 | - } catch (Exception e) { | ||
| 86 | - Assert.fail(e.getMessage()); | ||
| 87 | - } | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | -} |
impl/extension/jmx/src/test/resources/META-INF/beans.xml
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 1 | <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 3 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | 2 | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> |
| 3 | + | ||
| 4 | <interceptors> | 4 | <interceptors> |
| 5 | <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | 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> | ||
| 6 | </interceptors> | 9 | </interceptors> |
| 10 | + | ||
| 7 | </beans> | 11 | </beans> |
impl/extension/jmx/src/test/resources/META-INF/persistence.xml
| @@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
| 1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | -<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 3 | - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> | ||
| 4 | - | ||
| 5 | - <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> | ||
| 6 | - | ||
| 7 | - <class>br.gov.frameworkdemoiselle.jmx.domain.PersistedTestClass</class> | ||
| 8 | - | ||
| 9 | - <properties> | ||
| 10 | - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> | ||
| 11 | - <property name="javax.persistence.jdbc.user" value="sa" /> | ||
| 12 | - <property name="javax.persistence.jdbc.password" value="" /> | ||
| 13 | - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:hsql:." /> | ||
| 14 | - | ||
| 15 | - <property name="eclipselink.logging.level" value="FINE" /> | ||
| 16 | - <property name="eclipselink.ddl-generation" value="create-tables" /> | ||
| 17 | - <property name="eclipselink.ddl-generation.output-mode" value="database" /> | ||
| 18 | - </properties> | ||
| 19 | - </persistence-unit> | ||
| 20 | - | ||
| 21 | - | ||
| 22 | -</persistence> | ||
| 23 | \ No newline at end of file | 0 | \ No newline at end of file |