[jboss-cvs] JBossAS SVN: r65573 - in projects/microcontainer/trunk/deployers-vfs/src: resources/tests/managed and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Sep 23 21:59:01 EDT 2007
Author: scott.stark at jboss.org
Date: 2007-09-23 21:59:01 -0400 (Sun, 23 Sep 2007)
New Revision: 65573
Added:
projects/microcontainer/trunk/deployers-vfs/src/resources/tests/managed/
projects/microcontainer/trunk/deployers-vfs/src/resources/tests/managed/annotated-beans.xml
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/AnnotatedBean.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanManagedDeploymentUnitTestCase.java
Log:
Start a test of bean ManagedObjects
Added: projects/microcontainer/trunk/deployers-vfs/src/resources/tests/managed/annotated-beans.xml
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/resources/tests/managed/annotated-beans.xml (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/resources/tests/managed/annotated-beans.xml 2007-09-24 01:59:01 UTC (rev 65573)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="AnnotatedBean" class="org.jboss.test.deployers.vfs.deployer.bean.support.AnnotatedBean">
+ <annotation>@org.jboss.managed.api.annotation.ManagementComponent(type="MCBean",subtype="AnnotationTest")</annotation>
+ <!-- Test -->
+ <property name="propWithXmlOverride">
+ <annotation>@org.jboss.managed.api.annotation.ManagementProperty(name="prop3", mappedName="propWithXmlOverride", description="ManagedProperty defined via xml annotation")</annotation>10</property>
+ </bean>
+ <bean name="Simple" class="org.jboss.test.deployers.vfs.deployer.bean.support.Simple" />
+</deployment>
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/AnnotatedBean.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/AnnotatedBean.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/AnnotatedBean.java 2007-09-24 01:59:01 UTC (rev 65573)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.deployers.vfs.deployer.bean.support;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject
+public class AnnotatedBean
+{
+ /** Should not be a ManagedProperty */
+ private String ignored;
+ private String prop1;
+ private int prop2;
+ /** A ManagedProperty whose annotation should come from the deployment descriptor */
+ private int propWithXmlOverride;
+ private Simple bean;
+
+ @ManagementProperty(ignored=true)
+ public String getIgnored()
+ {
+ return ignored;
+ }
+ public void setIgnored(String ignored)
+ {
+ this.ignored = ignored;
+ }
+ public String getProp1()
+ {
+ return prop1;
+ }
+ public void setProp1(String prop1)
+ {
+ this.prop1 = prop1;
+ }
+ public int getProp2()
+ {
+ return prop2;
+ }
+ public void setProp2(int prop2)
+ {
+ this.prop2 = prop2;
+ }
+
+ public int getPropWithXmlOverride()
+ {
+ return propWithXmlOverride;
+ }
+ public void setPropWithXmlOverride(int propWithXmlOverride)
+ {
+ this.propWithXmlOverride = propWithXmlOverride;
+ }
+
+ @ManagementObjectRef(name="Simple", type="MCBean")
+ public Simple getBean()
+ {
+ return bean;
+ }
+ public void setBean(Simple bean)
+ {
+ this.bean = bean;
+ }
+}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanManagedDeploymentUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanManagedDeploymentUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanManagedDeploymentUnitTestCase.java 2007-09-24 01:59:01 UTC (rev 65573)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.deployers.vfs.deployer.bean.test;
+
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.vfs.deployer.kernel.BeanDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.KernelDeploymentDeployer;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.kernel.Kernel;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * Tests of bean deployment ManagedObject/ManagedDeployment creation.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BeanManagedDeploymentUnitTestCase extends AbstractDeployerUnitTestCase
+{
+ public static Test suite()
+ {
+ return new TestSuite(BeanManagedDeploymentUnitTestCase.class);
+ }
+
+ public BeanManagedDeploymentUnitTestCase(String name) throws Throwable
+ {
+ super(name);
+ }
+
+ /**
+ * Basic test of getting ManagedObject/ManagedProperty from a bean deployment.
+ * TODO: the root ManagedObject for a KernelDeployment should be coming from a
+ * custom {@linkplain org.jboss.managed.spi.factory.InstanceClassFactory}
+ * @throws Exception
+ */
+ public void testBeanManagedObject()
+ throws Exception
+ {
+ super.enableTrace("org.jboss.managed.plugins.factory");
+ VFSDeployment context = createDeployment("/managed", "annotated-beans.xml");
+ assertDeploy(context);
+
+ ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
+ Map<String, ManagedObject> mos = main.getManagedObjects(context.getName());
+ log.info("annotated-beans.xml ManagedObjects: "+mos);
+ assertEquals("annotated-beans.xml has 1 ManagedObject", 1, mos.size());
+ ManagedObject kdMO = mos.values().iterator().next();
+ log.info("KernelDeployment.ManagedProperties: "+kdMO.getProperties());
+ ManagedProperty beanFactories = kdMO.getProperty("beanFactories");
+ assertNotNull(beanFactories);
+ ArrayValue beanFactoriesAV = ArrayValue.class.cast(beanFactories.getValue());
+ ArrayMetaType valueType = beanFactoriesAV.getMetaType();
+ assertEquals("BeanFactories size", 2, beanFactoriesAV.getLength());
+ GenericValue beanFactoriesGV = (GenericValue) beanFactoriesAV.getValue(0);
+ log.info("BeanFactories[0].GV: "+beanFactoriesGV);
+ ManagedObject beanFactoriesMO = (ManagedObject) beanFactoriesGV.getValue();
+ assertNotNull(beanFactoriesMO);
+ log.info("beanFactories.ManagedProperties: "+beanFactoriesMO.getProperties());
+ ManagedProperty properties = beanFactoriesMO.getProperty("properties");
+ assertNotNull(properties);
+ ArrayValue<CompositeValue> propertiesArray = ArrayValue.class.cast(properties.getValue());
+ }
+
+ public void testBeanManagedDeployment()
+ throws Exception
+ {
+ VFSDeployment context = createDeployment("/bean", "toplevel/my-beans.xml");
+ assertDeploy(context);
+ assertNotNull(controller.getInstalledContext("Test"));
+
+ assertUndeploy(context);
+ assertNull(controller.getContext("Test", null));
+ }
+
+ protected void addDeployers(Kernel kernel)
+ {
+ BeanDeployer beanDeployer = new BeanDeployer();
+ KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
+ BeanMetaDataDeployer beanMetaDataDeployer = new BeanMetaDataDeployer(kernel);
+ addDeployer(main, beanDeployer);
+ addDeployer(main, kernelDeploymentDeployer);
+ addDeployer(main, beanMetaDataDeployer);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list