[Jboss-cvs] JBossAS SVN: r55365 - in branches/MC_VDF_WORK/system-jmx/src: resources/tests/org/jboss/test/system/controller resources/tests/org/jboss/test/system/controller/integration resources/tests/org/jboss/test/system/controller/integration/test tests/org/jboss/test/system/controller tests/org/jboss/test/system/controller/integration tests/org/jboss/test/system/controller/integration/support tests/org/jboss/test/system/controller/integration/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 7 09:37:32 EDT 2006
Author: adrian at jboss.org
Date: 2006-08-07 09:37:27 -0400 (Mon, 07 Aug 2006)
New Revision: 55365
Added:
branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/
branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/
branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase-mc.xml
branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.xml
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/support/
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/support/SimpleBean.java
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/AbstractIntegrationTest.java
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.java
branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/IntegrationTestDelegate.java
Log:
[JBAS-1841] - Basic test of injecting jmx objects into pojos.
Added: branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase-mc.xml
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase-mc.xml 2006-08-07 13:25:13 UTC (rev 55364)
+++ branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase-mc.xml 2006-08-07 13:37:27 UTC (rev 55365)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="Test" class="org.jboss.test.system.controller.integration.support.SimpleBean">
+ <property name="simple"><inject bean="jboss.test:type=test"/></property>
+ </bean>
+</deployment>
Added: branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.xml
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.xml 2006-08-07 13:25:13 UTC (rev 55364)
+++ branches/MC_VDF_WORK/system-jmx/src/resources/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.xml 2006-08-07 13:37:27 UTC (rev 55365)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+ <mbean name="jboss.test:type=test" code="org.jboss.test.system.controller.support.Simple"/>
+</server>
\ No newline at end of file
Added: branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/support/SimpleBean.java
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/support/SimpleBean.java 2006-08-07 13:25:13 UTC (rev 55364)
+++ branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/support/SimpleBean.java 2006-08-07 13:37:27 UTC (rev 55365)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.system.controller.integration.support;
+
+import org.jboss.test.system.controller.support.Simple;
+
+/**
+ * SimpleBean.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleBean
+{
+ /** Injection */
+ private Simple simple;
+
+ /**
+ * Get the simple.
+ *
+ * @return the simple.
+ */
+ public Simple getSimple()
+ {
+ return simple;
+ }
+
+ /**
+ * Set the simple.
+ *
+ * @param simple the simple.
+ */
+ public void setSimple(Simple simple)
+ {
+ this.simple = simple;
+ }
+}
Added: branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/AbstractIntegrationTest.java
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/AbstractIntegrationTest.java 2006-08-07 13:25:13 UTC (rev 55364)
+++ branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/AbstractIntegrationTest.java 2006-08-07 13:37:27 UTC (rev 55365)
@@ -0,0 +1,171 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* 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.system.controller.integration.test;
+
+import java.net.URL;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.system.controller.AbstractControllerTest;
+
+/**
+ * An integration Test.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.2 $
+ */
+public abstract class AbstractIntegrationTest extends AbstractControllerTest
+{
+ /**
+ * Create a new integration test.
+ *
+ * @param name the test name
+ */
+ public AbstractIntegrationTest(String name)
+ {
+ super(name);
+ }
+
+ public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+ {
+ IntegrationTestDelegate delegate = new IntegrationTestDelegate(clazz);
+ // @todo delegate.enableSecurity = true;
+ return delegate;
+ }
+
+ /**
+ * Get a bean
+ *
+ * @param name the bean name
+ * @return the bean
+ * @throws IllegalStateException when the bean does not exist
+ */
+ protected Object getBean(Object name)
+ {
+ return getBean(name, ControllerState.INSTALLED);
+ }
+
+ /**
+ * Get a bean
+ *
+ * @param name the name of the bean
+ * @param state the state of the bean
+ * @return the bean
+ * @throws IllegalStateException when the bean does not exist at that state
+ */
+ protected Object getBean(Object name, ControllerState state)
+ {
+ return getIntegrationDelegate().getBean(name, state);
+ }
+
+ /**
+ * Get a context
+ *
+ * @param name the bean name
+ * @return the context
+ * @throws IllegalStateException when the context does not exist
+ */
+ protected ControllerContext getControllerContext(Object name)
+ {
+ return getControllerContext(name, ControllerState.INSTALLED);
+ }
+
+ /**
+ * Get a context
+ *
+ * @param name the name of the bean
+ * @param state the state of the bean
+ * @return the context
+ * @throws IllegalStateException when the context does not exist at that state
+ */
+ protected ControllerContext getControllerContext(Object name, ControllerState state)
+ {
+ return getIntegrationDelegate().getControllerContext(name, state);
+ }
+
+ /**
+ * Deploy a url
+ *
+ * @param url the deployment url
+ * @return the deployment
+ * @throws Throwable for any error
+ */
+ protected KernelDeployment deployMC(URL url) throws Exception
+ {
+ return getIntegrationDelegate().deployMC(url);
+ }
+
+ /**
+ * Deploy a resource
+ *
+ * @param resource the deployment resource
+ * @return the deployment
+ * @throws Throwable for any error
+ */
+ protected KernelDeployment deployMC(String resource) throws Exception
+ {
+ URL url = getClass().getResource(resource);
+ if (url == null)
+ throw new IllegalArgumentException("Resource not found: " + resource);
+ return getIntegrationDelegate().deployMC(url);
+ }
+
+ /**
+ * Undeploy a deployment
+ *
+ * @param deployment the deployment
+ */
+ protected void undeployMC(KernelDeployment deployment)
+ {
+ getIntegrationDelegate().undeployMC(deployment);
+ }
+
+ /**
+ * Undeploy a deployment
+ *
+ * @param resource the url
+ */
+ protected void undeployMC(String resource)
+ {
+ URL url = getClass().getResource(resource);
+ if (url == null)
+ throw new IllegalArgumentException("Resource not found: " + resource);
+ getIntegrationDelegate().undeployMC(url);
+ }
+
+ /**
+ * Validate
+ *
+ * @throws Exception for any error
+ */
+ protected void validateMC() throws Exception
+ {
+ getIntegrationDelegate().validateMC();
+ }
+
+ protected IntegrationTestDelegate getIntegrationDelegate()
+ {
+ return (IntegrationTestDelegate) getDelegate();
+ }
+}
Added: branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.java
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.java 2006-08-07 13:25:13 UTC (rev 55364)
+++ branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/ConfigureMCFromJMXUnitTestCase.java 2006-08-07 13:37:27 UTC (rev 55365)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.system.controller.integration.test;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.test.system.controller.integration.support.SimpleBean;
+
+import junit.framework.Test;
+
+/**
+ * ConfigureMCFromJMXUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ConfigureMCFromJMXUnitTestCase extends AbstractIntegrationTest
+{
+ public static Test suite()
+ {
+ return suite(ConfigureMCFromJMXUnitTestCase.class);
+ }
+
+ public ConfigureMCFromJMXUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testConfigureMCFromJMX() throws Throwable
+ {
+ ControllerContext mbeanContext = getControllerContext("jboss.test:type=test");
+ assertNotNull(mbeanContext);
+ Object mbean = mbeanContext.getTarget();
+ assertNotNull(mbean);
+
+ ControllerContext beanContext = getControllerContext("Test");
+ assertNotNull(beanContext);
+ Object bean = beanContext.getTarget();
+ assertNotNull(bean);
+ assertTrue(bean instanceof SimpleBean);
+
+ SimpleBean simpleBean = (SimpleBean) bean;
+
+ Object injected = simpleBean.getSimple();
+
+ assertTrue("MBean was not injected: ", mbean == injected);
+ }
+}
Added: branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/IntegrationTestDelegate.java
===================================================================
--- branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/IntegrationTestDelegate.java 2006-08-07 13:25:13 UTC (rev 55364)
+++ branches/MC_VDF_WORK/system-jmx/src/tests/org/jboss/test/system/controller/integration/test/IntegrationTestDelegate.java 2006-08-07 13:37:27 UTC (rev 55365)
@@ -0,0 +1,292 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* 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.system.controller.integration.test;
+
+import java.net.URL;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.system.ServiceController;
+import org.jboss.system.ServiceControllerMBean;
+import org.jboss.test.system.controller.NewControllerTestDelegate;
+
+/**
+ * IntegrationTestDelegate.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class IntegrationTestDelegate extends NewControllerTestDelegate
+{
+ /** The kernel */
+ protected Kernel kernel;
+
+ /** The deployer */
+ protected BasicXMLDeployer beanDeployer;
+
+ public IntegrationTestDelegate(Class clazz)
+ {
+ super(clazz);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ try
+ {
+ // Create the deployer
+ beanDeployer = new BasicXMLDeployer(kernel);
+
+ // Deploy
+ deployMC();
+
+ validateMC();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ServiceControllerMBean createServiceController() throws Exception
+ {
+ try
+ {
+ // Bootstrap the kernel
+ AbstractBootstrap bootstrap = getBootstrap();
+ bootstrap.run();
+ kernel = bootstrap.getKernel();
+
+ // Create the service controller
+ ServiceController result = new ServiceController();
+ result.setKernel(kernel);
+ return result;
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void tearDown() throws Exception
+ {
+ undeployMC();
+ super.tearDown();
+ }
+
+ /**
+ * Get the kernel bootstrap
+ *
+ * @return the bootstrap
+ */
+ protected AbstractBootstrap getBootstrap() throws Exception
+ {
+ return new BasicBootstrap();
+ }
+
+ /**
+ * Get a bean
+ *
+ * @param name the name of the bean
+ * @param state the state of the bean
+ * @return the bean
+ * @throws IllegalStateException when the bean does not exist at that state
+ */
+ protected Object getBean(final Object name, final ControllerState state)
+ {
+ ControllerContext context = getControllerContext(name, state);
+ return context.getTarget();
+ }
+
+ /**
+ * Get a context
+ *
+ * @param name the name of the bean
+ * @param state the state of the bean
+ * @return the context
+ * @throws IllegalStateException when the context does not exist at that state
+ */
+ protected ControllerContext getControllerContext(final Object name, final ControllerState state)
+ {
+ KernelController controller = kernel.getController();
+ ControllerContext context = controller.getContext(name, state);
+ if (context == null)
+ throw new IllegalStateException("Bean not found " + name);
+ return context;
+ }
+
+ /**
+ * Validate
+ */
+ protected void validateMC() throws Exception
+ {
+ try
+ {
+ beanDeployer.validate();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException(t);
+ }
+ }
+
+ /**
+ * Deploy a url
+ *
+ * @param url the deployment url
+ * @return the deployment
+ * @throws Throwable for any error
+ */
+ protected KernelDeployment deployMC(URL url) throws Exception
+ {
+ try
+ {
+ log.debug("Deploying " + url);
+ KernelDeployment deployment = beanDeployer.deploy(url);
+ log.trace("Deployed " + url);
+ return deployment;
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException(t);
+ }
+ }
+
+ /**
+ * Undeploy a deployment
+ *
+ * @param url the url
+ */
+ protected void undeployMC(URL url)
+ {
+ log.debug("Undeploying " + url);
+ try
+ {
+ beanDeployer.undeploy(url);
+ log.trace("Undeployed " + url);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during undeployment: " + url, t);
+ }
+ }
+
+ /**
+ * Undeploy a deployment
+ *
+ * @param deployment the deployment
+ */
+ protected void undeployMC(KernelDeployment deployment)
+ {
+ log.debug("Undeploying " + deployment.getName());
+ try
+ {
+ beanDeployer.undeploy(deployment);
+ log.trace("Undeployed " + deployment.getName());
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error during undeployment: " + deployment.getName(), t);
+ }
+ }
+
+ /**
+ * Deploy the beans
+ *
+ * @throws Exception for any error
+ */
+ protected void deployMC() throws Exception
+ {
+ String testName = clazz.getName();
+ testName = testName.replace('.', '/') + "-mc.xml";
+ URL url = clazz.getClassLoader().getResource(testName);
+ if (url != null)
+ deployMC(url);
+ else
+ log.debug("No test specific deployment " + testName);
+ }
+
+ /**
+ * Undeploy all
+ */
+ protected void undeployMC()
+ {
+ log.debug("Undeploying " + beanDeployer.getDeploymentNames());
+ beanDeployer.shutdown();
+ }
+
+}
More information about the jboss-cvs-commits
mailing list