[jboss-cvs] JBossAS SVN: r70439 - in projects/microcontainer/trunk: aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 5 12:20:19 EST 2008
Author: kabir.khan at jboss.com
Date: 2008-03-05 12:20:19 -0500 (Wed, 05 Mar 2008)
New Revision: 70439
Added:
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic0.xml
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic1.xml
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic2.xml
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic0.xml
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml
projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic2.xml
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor1.java
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor2.java
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCase.java
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCase.java
Modified:
projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AspectDependencyBuilderListItem.java
projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/LifecycleAspectDependencyBuilderListItem.java
projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleLifecycleCallback.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/LifecycleCallbackItem.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DependencyBuilderListItem.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/BeanFactoryJaxbTestCase.java
Log:
[JBMICROCONT-249] Add removeDependency() to DependencyBuilderListItem
Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AspectDependencyBuilderListItem.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AspectDependencyBuilderListItem.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AspectDependencyBuilderListItem.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -21,12 +21,16 @@
*/
package org.jboss.aop.microcontainer.integration;
+import java.util.Set;
+
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.dependency.plugins.AbstractDependencyItem;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
import org.jboss.kernel.spi.dependency.DependencyBuilderListItem;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.logging.Logger;
/**
*
@@ -35,7 +39,13 @@
*/
class AspectDependencyBuilderListItem implements DependencyBuilderListItem
{
- String dependencyName;
+ protected static Logger log = Logger.getLogger(AspectDependencyBuilderListItem.class);
+
+ /**
+ * The name of our dependency
+ */
+ protected String dependencyName;
+
AspectDependencyBuilderListItem(String name)
{
this.dependencyName = name;
@@ -44,11 +54,35 @@
public void addDependency(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
- AbstractDependencyItem dependency = new AbstractDependencyItem(metaData.getName(), dependencyName, ControllerState.INSTANTIATED, ControllerState.INSTALLED);
+ DependencyItem dependencyItem = new AbstractDependencyItem(metaData.getName(), dependencyName, ControllerState.INSTANTIATED, ControllerState.INSTALLED);
DependencyInfo depends = context.getDependencyInfo();
- depends.addIDependOn(dependency);
+ depends.addIDependOn(dependencyItem);
}
+ public void removeDependency(KernelControllerContext context)
+ {
+ DependencyInfo depends = context.getDependencyInfo();
+
+ Set<DependencyItem> items = depends.getIDependOn(null);
+ if (items.size() > 0)
+ {
+ for (DependencyItem item : items)
+ {
+ try
+ {
+ if (item.getIDependOn().equals(dependencyName))
+ {
+ depends.removeIDependOn(item);
+ }
+ }
+ catch (RuntimeException e)
+ {
+ log.warn("Problem uninstalling dependency " + dependencyName + " for " + context, e);
+ }
+ }
+ }
+ }
+
public boolean equals(Object o)
{
if (o instanceof AspectDependencyBuilderListItem)
Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/LifecycleAspectDependencyBuilderListItem.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/LifecycleAspectDependencyBuilderListItem.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/LifecycleAspectDependencyBuilderListItem.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -21,9 +21,13 @@
*/
package org.jboss.aop.microcontainer.integration;
+import java.util.Iterator;
+import java.util.List;
+
import org.jboss.dependency.plugins.AbstractLifecycleCallbackItem;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.LifecycleCallbackItem;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
@@ -62,6 +66,7 @@
return dependencyName.hashCode();
}
+ @Override
public void addDependency(KernelControllerContext context)
{
AbstractLifecycleCallbackItem callback = new AbstractLifecycleCallbackItem(dependencyName, state, ControllerState.INSTALLED, installMethod, uninstallMethod);
@@ -70,4 +75,28 @@
super.addDependency(context);
}
+
+ @Override
+ public void removeDependency(KernelControllerContext context)
+ {
+ DependencyInfo di = context.getDependencyInfo();
+
+ List<LifecycleCallbackItem> items = di.getLifecycleCallbacks();
+ for (int i = 0 ; i < items.size(); i++)
+ {
+ try
+ {
+ if (items.get(i).getBean().equals(dependencyName))
+ {
+ items.remove(i);
+ }
+ }
+ catch (RuntimeException e)
+ {
+ log.warn("Problem uninstalling dependency " + dependencyName + " for " + context, e);
+ }
+ }
+
+ super.removeDependency(context);
+ }
}
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic0.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic0.xml (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic0.xml 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+ <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+ </bean>
+
+ <aop:interceptor xmlns:aop="urn:jboss:aop-beans:1.0" name="InterceptedAdvice1" class="org.jboss.test.microcontainer.support.SimpleInterceptor1"/>
+
+ <bind xmlns="urn:jboss:aop-beans:1.0" pointcut="execution(* @org.jboss.test.microcontainer.support.Test->*(..))">
+ <interceptor-ref name="InterceptedAdvice1"/>
+ </bind>
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic1.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic1.xml (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic1.xml 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <aop:interceptor xmlns:aop="urn:jboss:aop-beans:1.0" name="InterceptedAdvice2" class="org.jboss.test.microcontainer.support.SimpleInterceptor2"/>
+
+ <bind xmlns="urn:jboss:aop-beans:1.0" pointcut="execution(* @org.jboss.test.microcontainer.support.Test->*(..))">
+ <interceptor-ref name="InterceptedAdvice2"/>
+ </bind>
+
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic2.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic2.xml (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCaseNotAutomatic2.xml 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Intercepted" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+ <annotation>@org.jboss.test.microcontainer.support.Test</annotation>
+ </bean>
+
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic0.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic0.xml (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic0.xml 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+ <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+ </bean>
+
+ <aop:lifecycle-configure xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="LifecycleCallbackConfigure"
+ class="org.jboss.test.microcontainer.support.SimpleLifecycleCallback"
+ classes="@org.jboss.test.microcontainer.support.Test">
+ </aop:lifecycle-configure>
+
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <aop:interceptor xmlns:aop="urn:jboss:aop-beans:1.0" name="InterceptedAdvice2" class="org.jboss.test.microcontainer.support.SimpleInterceptor2"/>
+
+ <aop:lifecycle-start xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="LifecycleCallbackStart"
+ class="org.jboss.test.microcontainer.support.SimpleLifecycleCallback"
+ classes="@org.jboss.test.microcontainer.support.Test">
+ </aop:lifecycle-start>
+
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic2.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic2.xml (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCaseNotAutomatic2.xml 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Intercepted" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+ <annotation>@org.jboss.test.microcontainer.support.Test</annotation>
+ </bean>
+
+</deployment>
Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor1.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor1.java (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor1.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.microcontainer.support;
+
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleInterceptor1 extends AbstractInterceptor
+{
+ public static boolean invoked;
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ invoked = true;
+ return invocation.invokeNext();
+ }
+}
Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor2.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor2.java (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleInterceptor2.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.microcontainer.support;
+
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleInterceptor2 extends AbstractInterceptor
+{
+ public static boolean invoked;
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ invoked = true;
+ return invocation.invokeNext();
+ }
+}
Modified: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleLifecycleCallback.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleLifecycleCallback.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/SimpleLifecycleCallback.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -55,6 +55,11 @@
this.testProperty = testProperty;
}
+ public static void clear()
+ {
+ interceptions.clear();
+ }
+
public static class Handled
{
public String contextName;
Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCase.java (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployAspectDependencyTestCase.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,91 @@
+package org.jboss.test.microcontainer.test;
+
+
+import junit.framework.Test;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.test.aop.junit.AOPMicrocontainerTest;
+import org.jboss.test.microcontainer.support.SimpleBeanImpl;
+import org.jboss.test.microcontainer.support.SimpleInterceptor1;
+import org.jboss.test.microcontainer.support.SimpleInterceptor2;
+
+public class UndeployAspectDependencyTestCase extends AOPMicrocontainerTest
+{
+
+ public UndeployAspectDependencyTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(UndeployAspectDependencyTestCase.class);
+ }
+
+ /**
+ * Validate that the
+ * @throws Exception
+ */
+ public void testUndeployAndRedeploy() throws Throwable
+ {
+ //Deploy first aspect
+ deploy("UndeployAspectDependencyTestCaseNotAutomatic0.xml");
+ try
+ {
+ boolean deployedAspect = false;
+ //Deploy second aspect
+ deploy("UndeployAspectDependencyTestCaseNotAutomatic1.xml");
+ try
+ {
+ //Deploy bean intercepted by both aspects
+ deploy("UndeployAspectDependencyTestCaseNotAutomatic2.xml");
+ try
+ {
+ SimpleBeanImpl bean = (SimpleBeanImpl)getBean("Intercepted");
+ SimpleInterceptor1.invoked = false;
+ SimpleInterceptor2.invoked = false;
+ bean.someMethod();
+ assertTrue(SimpleInterceptor1.invoked);
+ assertTrue(SimpleInterceptor2.invoked);
+
+ ControllerContext ctx = getControllerContext("Intercepted");
+ Controller controller = ctx.getController();
+
+ //Move the bean intercepted to pre-install state
+ controller.change(ctx, ControllerState.PRE_INSTALL);
+
+ //Undeploy the second aspect
+ undeploy("UndeployAspectDependencyTestCaseNotAutomatic1.xml");
+
+ //Move the bean back to the installed state
+ controller.change(ctx, ControllerState.INSTALLED);
+
+ bean = (SimpleBeanImpl)getBean("Intercepted");
+ SimpleInterceptor1.invoked = false;
+ SimpleInterceptor2.invoked = false;
+ bean.someMethod();
+ assertTrue(SimpleInterceptor1.invoked);
+ assertFalse(SimpleInterceptor2.invoked);
+ }
+ finally
+ {
+ undeploy("UndeployAspectDependencyTestCaseNotAutomatic2.xml");
+ }
+ }
+ finally
+ {
+ if (deployedAspect)
+ {
+ undeploy("UndeployAspectDependencyTestCaseNotAutomatic1.xml");
+ }
+ }
+ }
+ finally
+ {
+ undeploy("UndeployAspectDependencyTestCaseNotAutomatic0.xml");
+ }
+
+ }
+}
Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCase.java (rev 0)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/UndeployLifecycleCallbackDependencyTestCase.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -0,0 +1,122 @@
+package org.jboss.test.microcontainer.test;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.test.aop.junit.AOPMicrocontainerTest;
+import org.jboss.test.microcontainer.support.SimpleBeanImpl;
+import org.jboss.test.microcontainer.support.SimpleInterceptor1;
+import org.jboss.test.microcontainer.support.SimpleInterceptor2;
+import org.jboss.test.microcontainer.support.SimpleLifecycleCallback;
+import org.jboss.test.microcontainer.support.SimpleLifecycleCallback.Handled;
+
+public class UndeployLifecycleCallbackDependencyTestCase extends AOPMicrocontainerTest
+{
+
+ public UndeployLifecycleCallbackDependencyTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(UndeployLifecycleCallbackDependencyTestCase.class);
+ }
+
+ /**
+ * Validate that the
+ * @throws Exception
+ */
+ public void testUndeployAndRedeploy() throws Throwable
+ {
+ //Deploy first aspect
+ deploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic0.xml");
+ try
+ {
+ boolean deployedAspect = false;
+ //Deploy second aspect
+ deploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml");
+ try
+ {
+ SimpleLifecycleCallback.clear();
+ assertEquals(0, SimpleLifecycleCallback.interceptions.size());
+ //Deploy bean intercepted by both aspects
+ deploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic2.xml");
+ try
+ {
+ SimpleBeanImpl bean = (SimpleBeanImpl)getBean("Intercepted");
+ assertNotNull(bean);
+ assertEquals(2, SimpleLifecycleCallback.interceptions.size());
+ List list = SimpleLifecycleCallback.interceptions;
+ assertTrue(hasExpectedInterception("Intercepted", ControllerState.CONFIGURED));
+ assertTrue(hasExpectedInterception("Intercepted", ControllerState.START));
+
+ SimpleLifecycleCallback.clear();
+
+ ControllerContext ctx = getControllerContext("Intercepted");
+ Controller controller = ctx.getController();
+
+ //Move the bean intercepted to pre-install state
+ controller.change(ctx, ControllerState.PRE_INSTALL);
+
+ assertEquals(2, SimpleLifecycleCallback.interceptions.size());
+ list = SimpleLifecycleCallback.interceptions;
+ assertTrue(hasExpectedInterception("Intercepted", ControllerState.CONFIGURED));
+ assertTrue(hasExpectedInterception("Intercepted", ControllerState.START));
+
+ //Undeploy the second aspect
+ undeploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml");
+
+ //Move the bean back to the installed state
+ controller.change(ctx, ControllerState.INSTALLED);
+
+ bean = (SimpleBeanImpl)getBean("Intercepted");
+// SimpleInterceptor1.invoked = false;
+// SimpleInterceptor2.invoked = false;
+// bean.someMethod();
+// assertTrue(SimpleInterceptor1.invoked);
+// assertFalse(SimpleInterceptor2.invoked);
+ }
+ finally
+ {
+ undeploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic2.xml");
+ }
+ }
+ finally
+ {
+ if (deployedAspect)
+ {
+ undeploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic1.xml");
+ }
+ }
+ }
+ finally
+ {
+ undeploy("UndeployLifecycleCallbackDependencyTestCaseNotAutomatic0.xml");
+ }
+ }
+
+ private boolean hasExpectedInterception(String tgt, ControllerState state)
+ {
+ for (Handled handled : SimpleLifecycleCallback.interceptions)
+ {
+ if (handled.contextName.equals(tgt) && handled.toState.equals(state))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+//
+// private void getAssertUninstalledLifecycleCallback(String callbackName)
+// {
+// InstallUninstallLifecycleCallback callback = (InstallUninstallLifecycleCallback)getBean(callbackName);
+// assertTrue(callback.isUninstalledContext());
+// }
+}
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractLifecycleCallbackItem.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -42,11 +42,11 @@
ControllerState whenRequired;
String installMethod;
String uninstallMethod;
- String bean;
+ Object bean;
boolean installed;
public AbstractLifecycleCallbackItem(
- String bean,
+ Object bean,
ControllerState whenRequired,
ControllerState dependentState,
String installMethod,
@@ -59,6 +59,11 @@
this.uninstallMethod = uninstallMethod;
}
+ public Object getBean()
+ {
+ return bean;
+ }
+
public ControllerState getDependentState()
{
return dependentState;
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/LifecycleCallbackItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/LifecycleCallbackItem.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/LifecycleCallbackItem.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -29,6 +29,12 @@
public interface LifecycleCallbackItem
{
/**
+ * Gets the target bean implementing this callback
+ * @return the target bean name
+ */
+ Object getBean();
+
+ /**
* Get the target state of the bean this callback applies to indicating when this callback should trigger
* @return the state
*/
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -95,6 +95,35 @@
{
annotationsVisitor.after();
}
+
+ BeanInfo info = context.getBeanInfo();
+ if (info != null)
+ {
+ KernelController controller = (KernelController)context.getController();
+ KernelConfig config = controller.getKernel().getConfig();
+ DependencyBuilder dependencyBuilder;
+ try
+ {
+ dependencyBuilder = config.getDependencyBuilder();
+ }
+ catch (Throwable e)
+ {
+ log.debug("Error while cleaning the annotations: " + e);
+ return;
+ }
+ KernelMetaDataRepository repository = controller.getKernel().getMetaDataRepository();
+ MetaData md = repository.getMetaData(context);
+ // add custom dependencies (e.g. AOP layer).
+ List<DependencyBuilderListItem> dependencies = dependencyBuilder.getDependencies(info, md);
+ log.trace("Unwind extra dependencies for " + context.getName() + " " + dependencies);
+ if (dependencies != null && dependencies.isEmpty() == false)
+ {
+ for (DependencyBuilderListItem dependencyItem : dependencies)
+ {
+ dependencyItem.removeDependency(context);
+ }
+ }
+ }
}
protected BeanAnnotationAdapter getBeanAnnotationAdapter()
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DependencyBuilderListItem.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DependencyBuilderListItem.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DependencyBuilderListItem.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -35,4 +35,11 @@
* @param ctx the kernel controller context
*/
void addDependency(KernelControllerContext ctx);
+
+ /**
+ * Remove the dependency
+ *
+ * @param ctx the kernel controller context
+ */
+ void removeDependency(KernelControllerContext ctx);
}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/BeanFactoryJaxbTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/BeanFactoryJaxbTestCase.java 2008-03-05 17:13:57 UTC (rev 70438)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/deployment/xml/test/BeanFactoryJaxbTestCase.java 2008-03-05 17:20:19 UTC (rev 70439)
@@ -141,6 +141,7 @@
assertNull(factory.getUninstalls());
assertNull(factory.getInstallCallbacks());
assertNull(factory.getUninstallCallbacks());
+ factory.getBeans();
}
public void testBeanFactoryWithProperty() throws Exception
More information about the jboss-cvs-commits
mailing list