[jboss-cvs] JBossAS SVN: r95315 - in projects/kernel/trunk: weld-int/src/main/java/org/jboss/kernel/weld/plugins/annotated and 17 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 21 12:58:13 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-10-21 12:58:11 -0400 (Wed, 21 Oct 2009)
New Revision: 95315

Added:
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/UnsatisfiedDependencyRegistry.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstallAction.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceHolder.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/First.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Last.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Middle.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/test/
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/test/BidirectionalWeldAndMcTestCase.java
   projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/bidirectional/
   projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/bidirectional/test/
   projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/bidirectional/test/javax.enterprise.inject.spi.Extension
   projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/test/
Removed:
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/TestMcAfterBeanDiscoveryObserver.java
Modified:
   projects/kernel/trunk/pom.xml
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/annotated/MDRAnnotatedType.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerContextActions.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerInitializer.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldDescribeAction.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/metadata/WeldDependencyMetaData.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceFieldProducer.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceMethodProducer.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceProducer.java
   projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/McBeanRegistryObserver.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/AbstractWeldMcTest.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldMcTestDelegate.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldTestSuite.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/annotated/test/AnnotatedTypeTestCase.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java
   projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/wbtomc/test/InjectWeldInMcBeansTestCase.java
   projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/support/wb/javax.enterprise.inject.spi.Extension
   projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/test/javax.enterprise.inject.spi.Extension
Log:
[JBKERNEL-51] Test bidirectional injection between MC and Weld.
Rework the testsuite to always deploy things manually, and enable initialization of weld (so we can get the correct bean manager) before the weld classes are actually
 deployed. Disable weld-int from the main build until a snapshot containing WELD-220 has been deployed



Modified: projects/kernel/trunk/pom.xml
===================================================================
--- projects/kernel/trunk/pom.xml	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/pom.xml	2009-10-21 16:58:11 UTC (rev 95315)
@@ -29,7 +29,7 @@
     <module>jmx-aop-mc-int</module>
     <module>spring-int</module>
     <module>guice-int</module>
-    <module>weld-int</module>
+    <!--module>weld-int</module-->
     <module>build</module>
   </modules>
 

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/annotated/MDRAnnotatedType.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/annotated/MDRAnnotatedType.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/annotated/MDRAnnotatedType.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -50,7 +50,7 @@
    
    /** The decorated methods */
    private final Set<AnnotatedMethod<? super X>> annotatedMethods;
-   
+
    /**
     * Constructor
     * 
@@ -172,4 +172,10 @@
    {
       return getDelegate().getJavaClass();
    }
+
+   @Override
+   public String toString()
+   {
+      return "MDRAnnotatedType{annotations=" + getAnnotations() + "; class " + getJavaClass().getName() + "}";
+   }
 }

Added: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/UnsatisfiedDependencyRegistry.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/UnsatisfiedDependencyRegistry.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/UnsatisfiedDependencyRegistry.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,74 @@
+/*
+* 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.kernel.weld.plugins.dependency;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnsatisfiedDependencyRegistry
+{
+   private static UnsatisfiedDependencyRegistry INSTANCE = new UnsatisfiedDependencyRegistry();
+   
+   Object IGNORE = new Object();
+
+   ConcurrentMap<WeldKernelControllerContext, Object> hungContexts = new ConcurrentHashMap<WeldKernelControllerContext, Object>();
+   
+   private UnsatisfiedDependencyRegistry()
+   {
+   }
+   
+   public static UnsatisfiedDependencyRegistry getInstance()
+   {
+      return INSTANCE;
+   }
+   
+   public void addHungContext(WeldKernelControllerContext context)
+   {
+      hungContexts.putIfAbsent(context, IGNORE);
+   }
+   
+   public void removeHungContext(WeldKernelControllerContext context)
+   {
+      hungContexts.remove(context);
+   }
+   
+   public void incrementContexts() throws Throwable
+   {
+      int size = hungContexts.size();
+      while (size > 0)
+      {
+         for (WeldKernelControllerContext context : hungContexts.keySet())
+         {
+            context.getController().change(context, context.getRequiredState());
+         }
+         
+         if (hungContexts.size() == 0 || hungContexts.size() == size)
+            break;
+         size = hungContexts.size();
+      }
+   }
+}

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerContextActions.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerContextActions.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerContextActions.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -27,7 +27,6 @@
 import org.jboss.dependency.plugins.action.ControllerContextAction;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.plugins.dependency.CreateDestroyLifecycleAction;
-import org.jboss.kernel.plugins.dependency.InstallAction;
 import org.jboss.kernel.plugins.dependency.KernelControllerContextActions;
 import org.jboss.kernel.plugins.dependency.PreInstallAction;
 import org.jboss.kernel.plugins.dependency.StartStopLifecycleAction;
@@ -47,14 +46,14 @@
       
       actions.put(ControllerState.PRE_INSTALL, new PreInstallAction());
       actions.put(ControllerState.DESCRIBED, new WeldDescribeAction());
+      actions.put(WeldRegisterWebBeanAction.STATE, new WeldRegisterWebBeanAction());
       actions.put(ControllerState.INSTANTIATED, new WeldInstantiateAction());
       actions.put(WeldPostConstructAction.STATE, new WeldPostConstructAction());
       actions.put(ControllerState.CONFIGURED, new WeldConfigureAction());
       actions.put(ControllerState.CREATE, new CreateDestroyLifecycleAction());
       actions.put(WeldPreDestroyAction.STATE, new WeldPreDestroyAction());
       actions.put(ControllerState.START, new StartStopLifecycleAction());
-      actions.put(WeldRegisterWebBeanAction.STATE, new WeldRegisterWebBeanAction());
-      actions.put(ControllerState.INSTALLED, new InstallAction());
+      actions.put(ControllerState.INSTALLED, new WeldInstallAction());
       INSTANCE = new WeldControllerContextActions(actions);
    }
    

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerInitializer.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerInitializer.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldControllerInitializer.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -34,8 +34,8 @@
 {
    static void initializeController(Controller controller)
    {
+      controller.addState(WeldRegisterWebBeanAction.STATE, ControllerState.INSTANTIATED);
       controller.addState(WeldPostConstructAction.STATE, ControllerState.CONFIGURED);
       controller.addState(WeldPreDestroyAction.STATE, ControllerState.START);
-      controller.addState(WeldRegisterWebBeanAction.STATE, ControllerState.INSTALLED);
    }
 }

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldDescribeAction.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldDescribeAction.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldDescribeAction.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -53,4 +53,10 @@
       super.cleanAnnotations(context);
    }
 
+   @Override
+   protected void uninstallActionInternal(KernelControllerContext context)
+   {
+      if (context instanceof WeldKernelControllerContext)
+         UnsatisfiedDependencyRegistry.getInstance().removeHungContext((WeldKernelControllerContext)context);
+   }
 }

Added: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstallAction.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstallAction.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstallAction.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,46 @@
+/*
+* 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.kernel.weld.plugins.dependency;
+
+import org.jboss.kernel.plugins.dependency.InstallAction;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class WeldInstallAction extends InstallAction
+{
+
+   @Override
+   protected void installActionInternal(KernelControllerContext context) throws Throwable
+   {
+      if (context instanceof WeldKernelControllerContext == false)
+         throw new IllegalArgumentException("context is not a WabBeansKernelControllerContext");
+      
+      super.installActionInternal(context);
+      
+      UnsatisfiedDependencyRegistry.getInstance().removeHungContext((WeldKernelControllerContext)context);
+   }
+
+}

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/metadata/WeldDependencyMetaData.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/metadata/WeldDependencyMetaData.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/metadata/WeldDependencyMetaData.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -34,6 +34,7 @@
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+import org.jboss.kernel.weld.plugins.dependency.UnsatisfiedDependencyRegistry;
 
 /**
  * DependencyMetaData representing a dependency on a web bean
@@ -121,10 +122,11 @@
          {
             context.getManager().validate(injectionPoint);
             setIDependOn(injectionPoint);
-          setResolved(true);
+            setResolved(true);
          }
          catch(InjectionException e)
          {
+            UnsatisfiedDependencyRegistry.getInstance().addHungContext(context);
             setResolved(false);
          }
 

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceFieldProducer.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceFieldProducer.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceFieldProducer.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -27,6 +27,8 @@
 import javax.enterprise.inject.CreationException;
 import javax.enterprise.inject.spi.Producer;
 
+import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
@@ -36,9 +38,9 @@
 {
    private final Field field;
    
-   ExisitingInstanceFieldProducer(Field field, Producer<T> delegate, T instance)
+   ExisitingInstanceFieldProducer(Field field, Producer<T> delegate, WeldKernelControllerContext context)
    {
-      super(delegate, instance);
+      super(delegate, context);
       this.field = field;
       SecurityActions.setAccessible(field);
    }
@@ -47,7 +49,7 @@
    {
       try
       {
-         return (T)field.get(getInstance());
+         return (T)field.get(getInstanceFromContext());
       }
       catch (Exception e)
       {

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceMethodProducer.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceMethodProducer.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExisitingInstanceMethodProducer.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -27,6 +27,8 @@
 import javax.enterprise.inject.CreationException;
 import javax.enterprise.inject.spi.Producer;
 
+import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
@@ -36,9 +38,9 @@
 {
    private final Method method;
    
-   ExisitingInstanceMethodProducer(Method method, Producer<T> delegate, T instance)
+   ExisitingInstanceMethodProducer(Method method, Producer<T> delegate, WeldKernelControllerContext context)
    {
-      super(delegate, instance);
+      super(delegate, context);
       this.method = method;
       SecurityActions.setAccessible(method);
    }
@@ -47,7 +49,7 @@
    {
       try
       {
-         return (T)method.invoke(getInstance());
+         return (T)method.invoke(getInstanceFromContext());
       }
       catch (Exception e)
       {

Added: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceHolder.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceHolder.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceHolder.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,67 @@
+/*
+* 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.kernel.weld.plugins.weld;
+
+import javax.enterprise.inject.ResolutionException;
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
+import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ExistingInstanceHolder<T>
+{
+   final WeldKernelControllerContext context;
+
+   public ExistingInstanceHolder(WeldKernelControllerContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      
+      this.context = context;
+   }
+   
+   T getInstanceFromContext()
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      
+      if (context.getState() != ControllerState.INSTALLED)
+      {
+         ControllerStateModel states = context.getController().getStates();
+         if (states.isBeforeState(context.getState(), ControllerState.INSTALLED))
+         {
+            throw new ResolutionException(context + " for " + context.getAnnotatedType() + " has not reached the INSTALLED state");
+         }
+      }
+      
+      T target = (T)context.getTarget();
+      if (target == null)
+         throw new ResolutionException("Context for " + context.getAnnotatedType() + " has an empty instance");
+      
+      return target;
+   }
+}

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -27,21 +27,25 @@
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
 
+import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class ExistingInstanceInjectionTarget<T> implements InjectionTarget<T>
+public class ExistingInstanceInjectionTarget<T> extends ExistingInstanceHolder<T> implements InjectionTarget<T>
 {
    final InjectionTarget<T> injectionTarget;
    
-   final T instance;
-   
-   ExistingInstanceInjectionTarget(InjectionTarget<T> injectionTarget, T instance)
+   ExistingInstanceInjectionTarget(InjectionTarget<T> injectionTarget, WeldKernelControllerContext context)
    {
+      super(context);
+      
+      if (injectionTarget == null)
+         throw new IllegalArgumentException("Null injection target");
+      
       this.injectionTarget = injectionTarget;
-      this.instance = instance;
    }
    
    public void inject(T instance, CreationalContext<T> ctx)
@@ -71,7 +75,7 @@
 
    public T produce(CreationalContext<T> ctx)
    {
-      return instance;
+      return getInstanceFromContext();
    }
 
 }

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceProducer.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceProducer.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceProducer.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -26,21 +26,21 @@
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Producer;
 
+import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public abstract class ExistingInstanceProducer<T> implements Producer<T>
+public abstract class ExistingInstanceProducer<T> extends ExistingInstanceHolder<T> implements Producer<T>
 {
    private final Producer<T> delegate;
    
-   private final T instance;
-   
-   ExistingInstanceProducer(Producer<T> delegate, T instance)
+   ExistingInstanceProducer(Producer<T> delegate, WeldKernelControllerContext context)
    {
+      super(context);
       this.delegate = delegate;
-      this.instance = instance;
    }
    
    public void dispose(T instance)
@@ -52,9 +52,4 @@
    {
       return delegate.getInjectionPoints();
    }
-
-   protected final T getInstance()
-   {
-      return instance;
-   }
 }

Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/McBeanRegistryObserver.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/McBeanRegistryObserver.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/McBeanRegistryObserver.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -26,6 +26,8 @@
 import java.lang.reflect.Method;
 
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.InjectionException;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
@@ -35,6 +37,7 @@
 import javax.enterprise.inject.spi.Producer;
 
 import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+import org.jboss.kernel.weld.plugins.dependency.UnsatisfiedDependencyRegistry;
 
 /**
  * Web Beans extension bean to register MC beans that should be accessible from web beans 
@@ -60,7 +63,7 @@
       {
          InjectionTarget<?> target = event.getInjectionTarget();
          @SuppressWarnings("unchecked")
-         ExistingInstanceInjectionTarget tgt = new ExistingInstanceInjectionTarget(target, context.getTarget());
+         ExistingInstanceInjectionTarget tgt = new ExistingInstanceInjectionTarget(target, context);
          event.setInjectionTarget(tgt);
       }
    }
@@ -82,13 +85,13 @@
          if (member instanceof Field)
          {
             @SuppressWarnings("unchecked")
-            Producer wrapped = new ExisitingInstanceFieldProducer((Field)member, producer, context.getTarget());
+            Producer wrapped = new ExisitingInstanceFieldProducer((Field)member, producer, context);
             event.setProducer(wrapped);
          }
          else if (member instanceof Method)
          {
             @SuppressWarnings("unchecked")
-            Producer wrapped = new ExisitingInstanceMethodProducer((Method)member, producer, context.getTarget());
+            Producer wrapped = new ExisitingInstanceMethodProducer((Method)member, producer, context);
             event.setProducer(wrapped);
          }
          else
@@ -97,4 +100,16 @@
          }
       }
    }
+   
+   public void processAfterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery)
+   {
+      try
+      {
+         UnsatisfiedDependencyRegistry.getInstance().incrementContexts();
+      }
+      catch(Throwable t)
+      {
+         throw new InjectionException("Error happened installing hung MC contexts following install of web beans", t);
+      }
+   }
 }

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/AbstractWeldMcTest.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/AbstractWeldMcTest.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/AbstractWeldMcTest.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -44,17 +44,6 @@
  */
 public class AbstractWeldMcTest extends MicrocontainerTest
 {
-   /**
-    * Whether or not, and when, to deploy mc beans on test setup
-    */
-   protected static AutoDeployMcBeans autodeployMcBeans = AutoDeployMcBeans.NONE;
-   
-   /**
-    * Classes that should be deployed as web beans on startup
-    */
-   protected static Class<?>[] autodeployWbClasses;
-   
-   
    public AbstractWeldMcTest(String name)
    {
       super(name);
@@ -69,7 +58,7 @@
     */
    public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
    {
-      return new WeldMcTestDelegate(clazz, autodeployMcBeans, autodeployWbClasses);
+      return new WeldMcTestDelegate(clazz);
    }
    
    /**
@@ -86,37 +75,75 @@
     * Gets the bean manager
     *
     * @return the bean manager
-    * @throws Exception if the manager could not be determined
+    * @throws IllegalStateException if deployWeld() or initializeWeld() was not called first 
     */
-   protected BeanManager getCurrentManager() throws Exception
+   protected BeanManager getCurrentManager()
    {
       return getDelegate().getCurrentManager();
    }
 
    /**
-    * Deploys the web beans classes
+    * Initialises the classes to be deployed in weld, and deploys them.
+    * After this calls to {@link #getCurrentManager()} are valid.
     * 
-    * @param webBeansClasses The classes that should be deployed as web beans
-    * @throws Exception if an error happened during deployment
+    * @param classes the classes to be deployed as web beans
+    * @throws IllegalStateException if weld was already initialized
     */
-   protected void deployWeld(Class<?>...webBeansClasses) throws Exception
+   protected void deployWeld(Class<?>...classes)
    {
-      getDelegate().deployWeld(webBeansClasses);
+      getDelegate().deployWeld(classes);
+   }      
+
+   /**
+    * Initialises the classes to be deployed in weld, without deploying them.
+    * After this calls to {@link #getCurrentManager()} are valid. To deploy
+    * classes call {@link #deployInitializedWeld()}
+    * 
+    * @param classes the classes to be deployed as web beans
+    * @throws IllegalStateException if weld was already initialized
+    */
+   protected void initializeWeld(Class<?>...classes)
+   {
+      getDelegate().initializeWeld(classes);
+   }      
+
+   /**
+    * Initialises weld with the classes to be deployed in weld, and deploys them.
+    * After this calls to {@link #getCurrentManager()} are valid.
+    *
+    * @param extension the package containing the {@link #EXTENSION_FILE} if you want to deploy extensions
+    * @param classes the classes to be deployed as web beans
+    * @throws IllegalStateException if weld was already initialized
+    */
+   protected void deployWeld(Package extension, Class<?>...classes)
+   {
+      getDelegate().deployWeld(extension, classes);
    }
    
    /**
-    * Deploys the web beans classes
+    * Initialises weld with the classes to be deployed in weld, without deploying them.
+    * After this calls to {@link #getCurrentManager()} are valid. To deploy
+    * classes call {@link #deployInitializedWeld()}
     *
-    * @param extension package in which to search for a file named {@link WeldMcTestDelegate#EXTENSION_FILE} for extensions.
-    * @param webBeansClasses The classes that should be deployed as web beans
-    * @throws Exception if an error happened during deployment
+    * @param extension the package containing the {@link #EXTENSION_FILE} if you want to deploy extensions
+    * @param classes the classes to be deployed as web beans
+    * @throws IllegalStateException if weld was already initialized
     */
-   protected void deployWeld(Package extension, Class<?>...webBeansClasses) throws Exception
+   protected void initializeWeld(Package extension, Class<?>...classes)
    {
-      getDelegate().deployWeld(extension, webBeansClasses);
+      getDelegate().initializeWeld(extension, classes);
    }
    
    /**
+    * Deploys the initialized classes to weld
+    * @throws IllegalStateException if weld was not initialized with the classes
+    */
+   protected void deployInitializedWeld()
+   {
+      getDelegate().deployInitializedWeld();
+   }
+   
+   /**
     * Undeploys the web beans classes if some were deployed
     * 
     * @throws Exception if an error happened during deployment

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldMcTestDelegate.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldMcTestDelegate.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldMcTestDelegate.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -53,28 +53,10 @@
     * The name of the file used to define extensions to be deployed
     */
    public static final String EXTENSION_FILE = "javax.enterprise.inject.spi.Extension";
-   
+      
    /**
-    * If and when beans should be deployed to MC 
+    * Contains the web beans deployment and bean manager
     */
-   protected AutoDeployMcBeans autoDeployMcBeans;
-
-   /**
-    * Classes that should be automatically deployed as web beans
-    */
-   protected Class<?>[] autodeployWbClasses;
-   
-   /**
-    * Here in case somebody needs to call {@link #getCurrentManager()} before any web beans are deployed. This will be 
-    * a different bean manager from the bean manager to which web beans are deployed, but is good enough to call
-    * {@link BeanManager#createAnnotatedType(Class)}, {@link BeanManager#createCreationalContext(javax.enterprise.context.spi.Contextual)},
-    * {@link BeanManager#createInjectionTarget(javax.enterprise.inject.spi.AnnotatedType)} etc. on
-    */
-   TestContainer bootstrapContainer;
-   
-   /**
-    * Contains the web beans deployment (either done automatically if autodeployWbClasses is set, or by calling deployWeld() manually)
-    */
    TestContainer testContainer;
    
    /**
@@ -86,14 +68,10 @@
     * Constructor
     * 
     * @param clazz the test class
-    * @param autoDeployMcBeans if and when mc beans should be deployed automatically
-    * @param autodeployWbClasses classes that should be automatically deployed as web beans
     */
-   protected WeldMcTestDelegate(Class<?> clazz, AutoDeployMcBeans autoDeployMcBeans, Class<?>...autodeployWbClasses) throws Exception
+   protected WeldMcTestDelegate(Class<?> clazz) throws Exception
    {
       super(clazz);
-      this.autoDeployMcBeans = autoDeployMcBeans;
-      this.autodeployWbClasses = autodeployWbClasses;
    }
 
    @Override
@@ -108,86 +86,110 @@
       // Create the deployer
       deployer = createDeployer();
 
-      if (autoDeployMcBeans == AutoDeployMcBeans.BEFORE)
-         deploy();
-      
-      if (autodeployWbClasses != null && autodeployWbClasses.length > 0)
-         deployWeld(autodeployWbClasses);
-      
-      if (autoDeployMcBeans == AutoDeployMcBeans.AFTER)
-         deploy();
    }
 
-   @Override
-   public void tearDown() throws Exception
+   /**
+    * Initialises the classes to be deployed in weld, and deploys them.
+    * After this calls to {@link #getCurrentManager()} are valid.
+    * 
+    * @param classes the classes to be deployed as web beans
+    * @throws IllegalStateException if weld was already initialized
+    */
+   protected void deployWeld(Class<?>...classes)
    {
-      if (autoDeployMcBeans == AutoDeployMcBeans.AFTER)
-         undeploy();
+      initializeWeld(true, null, classes);
+   }      
 
-      undeployWeld();
-      
-      if (autoDeployMcBeans == AutoDeployMcBeans.BEFORE)
-         undeploy();
-      
-      super.tearDown();
-   }
-   
    /**
-    * Deploys classes as web beans and sets {@link #lifecycle} to point to the created lifecycle
+    * Initialises the classes to be deployed in weld, without deploying them.
+    * After this calls to {@link #getCurrentManager()} are valid. To deploy
+    * classes call {@link #deployInitializedWeld()}
     * 
     * @param classes the classes to be deployed as web beans
-    * @throws Exception if an error occured
+    * @throws IllegalStateException if weld was already initialized
     */
-   protected void deployWeld(Class<?>...classes) throws Exception
+   protected void initializeWeld(Class<?>...classes)
    {
-      deployWeld(null, classes);
+      initializeWeld(false, null, classes);
    }      
 
    /**
-    * Deploys classes as web beans and sets {@link #lifecycle} to point to the created lifecycle
+    * Initialises weld with the classes to be deployed in weld, and deploys them.
+    * After this calls to {@link #getCurrentManager()} are valid.
     *
     * @param extension the package containing the {@link #EXTENSION_FILE} if you want to deploy extensions
     * @param classes the classes to be deployed as web beans
-    * @throws Exception if an error occured
+    * @throws IllegalStateException if weld was already initialized
     */
-   protected void deployWeld(Package extension, Class<?>...classes) throws Exception
+   protected void deployWeld(Package extension, Class<?>...classes)
    {
-      deployWeld(false, extension, classes);
+      initializeWeld(true, extension, classes);
    }
    
    /**
-    * Deploys classes as web beans
+    * Initialises weld with the classes to be deployed in weld, without deploying them.
+    * After this calls to {@link #getCurrentManager()} are valid. To deploy
+    * classes call {@link #deployInitializedWeld()}
     *
-    * @param isForBootstrap if false, sets {@link #lifecycle} to point to the created lifecycle 
     * @param extension the package containing the {@link #EXTENSION_FILE} if you want to deploy extensions
     * @param classes the classes to be deployed as web beans
-    * @throws Exception if an error occured
+    * @throws IllegalStateException if weld was already initialized
     */
-   protected TestContainer deployWeld(boolean isForBootstrap, Package extension, Class<?>...classes) throws Exception
+   protected void initializeWeld(Package extension, Class<?>...classes)
    {
+      initializeWeld(false, extension, classes);
+   }
+   
+   /**
+    * Initialises weld with the classes to be deployed in weld.
+    * After this calls to {@link #getCurrentManager()} are valid. To deploy
+    * classes call {@link #deployInitializedWeld()}
+    *
+    * @param deploy if true, deploys the classes to weld. Otherwise you must explicitly call {@link #deployInitializedWeld()} 
+    * @param extension the package containing the {@link #EXTENSION_FILE} if you want to deploy extensions
+    * @param classes the classes to be deployed as web beans
+    * @throws IllegalStateException if weld was already initialized
+    */
+   private void initializeWeld(boolean deploy, Package extension, Class<?>...classes)
+   {
+      if (testContainer != null)
+         throw new IllegalStateException("Weld container was already intialized");
+      
       copyExtensions(extension);
     
-      TestContainer testContainer = new TestContainer(new MockEELifecycle(), Arrays.asList(classes), null);
-      testContainer.startContainer();
-      testContainer.ensureRequestActive();
-
+      testContainer = new TestContainer(new MockEELifecycle(), Arrays.asList(classes), null);
+      testContainer.startContainer(false);
       
-      if (!isForBootstrap)
+      if (deploy)
       {
-         this.testContainer = testContainer;
+         deployInitializedWeld();
       }
-      return testContainer;
    }
 
    /**
-    * Undeploys the weld deployed if {@link #lifecycle} is set
+    * Deploys the initialized classes to weld
+    * @throws IllegalStateException if weld was not initialized with the classes
     */
-   protected void undeployWeld() throws Exception
+   protected void deployInitializedWeld()
    {
+      if (testContainer == null)
+         throw new IllegalStateException("You must call initalizeWeld() before calling deployInitializedWeld()");
+      
+      testContainer.beginApplication();
+      testContainer.ensureRequestActive();
+   }
+   
+   
+   /**
+    * Undeploys the weld classes deployed and cleans up 
+    */
+   protected void undeployWeld()
+   {
       if (testContainer != null)
       {
          testContainer.stopContainer();
       }
+      testContainer = null;
       if (extensionFile != null)
       {
          extensionFile.delete();
@@ -319,17 +321,14 @@
    }
 
    /**
-    * Gets the current bean manager used. This will either be the bean manager for the
-    * deployed web beans as set in {@link #testContainer}, or a 'bootstrap' bean manager as 
-    * described in {@link #bootstrapContainer}
+    * Gets the bean manager used. 
+    * @return the bean manager used
+    * @throws IllegalStateException if deployWeld() or initializeWeld() was not called first 
     */
-   protected BeanManager getCurrentManager() throws Exception
+   protected BeanManager getCurrentManager()
    {
-      if (testContainer != null)
-         return testContainer.getBeanManager();
-      else if (bootstrapContainer == null)
-         bootstrapContainer = deployWeld(true, null);
-
-      return bootstrapContainer.getBeanManager();
+      if (testContainer == null)
+         throw new IllegalStateException("You need to call deployWeld() before you can call getCurrentManager()");
+      return testContainer.getBeanManager();
    }
 }

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldTestSuite.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldTestSuite.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/WeldTestSuite.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -25,6 +25,7 @@
 import junit.framework.TestSuite;
 
 import org.jboss.test.kernel.weld.annotated.test.AnnotatedTypeTestCase;
+import org.jboss.test.kernel.weld.bidirectional.test.BidirectionalWeldAndMcTestCase;
 //import org.jboss.test.kernel.weld.beanwrapper.test.BeanImplementationTestCase;
 import org.jboss.test.kernel.weld.mctowb.test.InjectMcBeansInWeldTestCase;
 import org.jboss.test.kernel.weld.wbtomc.test.InjectWeldInMcBeansTestCase;
@@ -43,6 +44,7 @@
       suite.addTest(AnnotatedTypeTestCase.suite());
       suite.addTest(InjectWeldInMcBeansTestCase.suite());
       suite.addTest(InjectMcBeansInWeldTestCase.suite());
+      suite.addTest(BidirectionalWeldAndMcTestCase.suite());
       
       return suite;
    }

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/annotated/test/AnnotatedTypeTestCase.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/annotated/test/AnnotatedTypeTestCase.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/annotated/test/AnnotatedTypeTestCase.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -73,6 +73,20 @@
       return new TestSuite(AnnotatedTypeTestCase.class);
    }
 
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      initializeWeld();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      undeployWeld();
+      super.tearDown();
+   }
+
    public void testNoAnnotationsOnClassNullMetaData() throws Exception
    {
       AnnotatedType<NotAnnotatedBean> type = createAnnotatedType(NotAnnotatedBean.class, null);

Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/First.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/First.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/First.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,41 @@
+/*
+* 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.kernel.weld.bidirectional.support;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Default
+public class First
+{
+   @Inject Middle middle;
+
+   public Middle getMiddle()
+   {
+      return middle;
+   }
+}

Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Last.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Last.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Last.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,35 @@
+/*
+* 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.kernel.weld.bidirectional.support;
+
+import javax.enterprise.inject.Default;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Default
+public class Last
+{
+
+}

Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Middle.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Middle.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/support/Middle.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,41 @@
+/*
+* 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.kernel.weld.bidirectional.support;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Default
+public class Middle
+{
+   @Inject Last last;
+
+   public Last getLast()
+   {
+      return last;
+   }
+}

Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/test/BidirectionalWeldAndMcTestCase.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/test/BidirectionalWeldAndMcTestCase.java	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/bidirectional/test/BidirectionalWeldAndMcTestCase.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1,102 @@
+/*
+* 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.kernel.weld.bidirectional.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
+import org.jboss.kernel.weld.plugins.weld.McBeanRegistryObserver;
+import org.jboss.test.kernel.weld.AbstractWeldMcTest;
+import org.jboss.test.kernel.weld.bidirectional.support.First;
+import org.jboss.test.kernel.weld.bidirectional.support.Last;
+import org.jboss.test.kernel.weld.bidirectional.support.Middle;
+import org.jboss.testharness.impl.packaging.Artifact;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Artifact
+public class BidirectionalWeldAndMcTestCase extends AbstractWeldMcTest
+{
+   public BidirectionalWeldAndMcTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return new TestSuite(BidirectionalWeldAndMcTestCase.class);
+   }
+
+   public void testMcDependsOnWeldDependsOnMc() throws Exception
+   {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, Middle.class);
+      
+      WeldKernelControllerContext firstContext = deploy(createBeanMetaData("First", First.class));
+      WeldKernelControllerContext lastContext = deploy(createBeanMetaData("Last", Last.class));
+      try
+      {
+         deployInitializedWeld();
+         
+         Last last = getWeldBean(Last.class);
+         Middle middle = getWeldBean(Middle.class);
+         First first = getWeldBean(First.class);
+
+         assertSame(last, middle.getLast());
+         
+         assertSame(first, assertBean("First", First.class));
+         assertSame(last, assertBean("Last", Last.class));
+      }
+      finally
+      {
+         undeployWeld();
+         undeploy(firstContext);
+         undeploy(lastContext);
+      }
+   }
+   
+   public void testWeldDependsOnMcDependsOnWeld() throws Exception
+   {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, First.class, Last.class);
+      
+      WeldKernelControllerContext middleContext = deploy(createBeanMetaData("Middle", Middle.class));
+      try
+      {
+         deployInitializedWeld();
+         
+         getWeldBean(Last.class);
+         Middle middle = getWeldBean(Middle.class);
+         First first = getWeldBean(First.class);
+
+         assertSame(middle, first.getMiddle());
+         assertSame(middle, assertBean("Middle", Middle.class));
+      }
+      finally
+      {
+         undeployWeld();
+         undeploy(middleContext);
+      }
+   }
+}

Deleted: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/TestMcAfterBeanDiscoveryObserver.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/TestMcAfterBeanDiscoveryObserver.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/TestMcAfterBeanDiscoveryObserver.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -1,57 +0,0 @@
-/*
-* 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.kernel.weld.mctowb.support.wb;
-
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.ProcessInjectionTarget;
-import javax.enterprise.inject.spi.ProcessProducer;
-
-import org.jboss.kernel.weld.plugins.weld.McBeanRegistryObserver;
-import org.jboss.testharness.impl.packaging.Artifact;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
- at Artifact
-public class TestMcAfterBeanDiscoveryObserver extends McBeanRegistryObserver
-{
-   @Override
-   public void addType(@Observes BeforeBeanDiscovery event)
-   {
-      super.addType(event);
-   }
-
-   @Override
-   public void processInjectionTarget(@Observes ProcessInjectionTarget<?> event)
-   {
-      super.processInjectionTarget(event);
-   }
-
-   @Override
-   public void processProducer(@Observes ProcessProducer<?, ?> event)
-   {
-      super.processProducer(event);
-   }
-}   
\ No newline at end of file

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -28,8 +28,10 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
 import org.jboss.kernel.weld.plugins.weld.AnnotatedTypeWrapper;
+import org.jboss.kernel.weld.plugins.weld.McBeanRegistryObserver;
 import org.jboss.kernel.weld.plugins.weld.WeldFromMcRegistry;
 import org.jboss.test.kernel.weld.AbstractWeldMcTest;
 import org.jboss.test.kernel.weld.mctowb.support.mc.BeanWithSimpleWeldDependency;
@@ -42,7 +44,6 @@
 import org.jboss.test.kernel.weld.mctowb.support.wb.LifecycleBeanConsumerA;
 import org.jboss.test.kernel.weld.mctowb.support.wb.LifecycleBeanConsumerB;
 import org.jboss.test.kernel.weld.mctowb.support.wb.Simple;
-import org.jboss.test.kernel.weld.mctowb.support.wb.TestMcAfterBeanDiscoveryObserver;
 import org.jboss.test.kernel.weld.mctowb.support.wb.ThingConstructor;
 import org.jboss.test.kernel.weld.mctowb.support.wb.ThingField;
 import org.jboss.testharness.impl.packaging.Artifact;
@@ -81,17 +82,26 @@
 
    public void testAnnotatedTypeWrapper() throws Exception
    {
-      AnnotatedTypeWrapper wrap1 = new AnnotatedTypeWrapper(getCurrentManager().createAnnotatedType(ThingBean.class));
-      AnnotatedTypeWrapper wrap2 = new AnnotatedTypeWrapper(getCurrentManager().createAnnotatedType(ThingBean.class));
-      
-      assertTrue(wrap1.hashCode() != 0);
-      assertEquals(wrap1.hashCode(), wrap2.hashCode());
-      assertTrue(wrap1.equals(wrap2));
-      assertTrue(wrap2.equals(wrap1));
+      try
+      {
+         initializeWeld();
+         AnnotatedTypeWrapper wrap1 = new AnnotatedTypeWrapper(getCurrentManager().createAnnotatedType(ThingBean.class));
+         AnnotatedTypeWrapper wrap2 = new AnnotatedTypeWrapper(getCurrentManager().createAnnotatedType(ThingBean.class));
+         
+         assertTrue(wrap1.hashCode() != 0);
+         assertEquals(wrap1.hashCode(), wrap2.hashCode());
+         assertTrue(wrap1.equals(wrap2));
+         assertTrue(wrap2.equals(wrap1));
+      }
+      finally
+      {
+         undeployWeld();
+      }
    }
    
    public void testWeldFromMcRegistry() throws Exception
    {
+      initializeWeld();
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingBean.class));
       try
       {
@@ -112,11 +122,12 @@
    
    public void testInjectMcBeanIntoField() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, ThingField.class);
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingBean.class));
       try
       {
          ThingBean thing = assertBean("thing", ThingBean.class);
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingField.class);
+         deployInitializedWeld();
 
          ThingField thingField = getWeldBean(ThingField.class);
          assertEquals(thing, thingField.thing);
@@ -131,11 +142,12 @@
    
    public void testInjectMcBeanIntoConstructor() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, ThingConstructor.class);
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingBean.class));
       try
       {
          ThingBean thing = assertBean("thing", ThingBean.class);
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingConstructor.class);
+         deployInitializedWeld();
          
          ThingConstructor thingField = getWeldBean(ThingConstructor.class);
          assertEquals(thing, thingField.thing);
@@ -149,11 +161,12 @@
    
    public void testInjectMcMethodProducedBeanIntoField() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, ThingField.class);
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingMethodProducer.class));
       try
       {
          ThingMethodProducer thing = assertBean("thing", ThingMethodProducer.class);
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingField.class);
+         deployInitializedWeld();
          
          ThingField thingField = getWeldBean(ThingField.class);
          assertEquals(thing.getThing(), thingField.thing);
@@ -167,11 +180,12 @@
    
    public void testInjectMcMethodProducedBeanIntoConstructor() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, ThingConstructor.class);
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingMethodProducer.class));
       try
       {
          ThingMethodProducer thing = assertBean("thing", ThingMethodProducer.class);
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingConstructor.class);
+         deployInitializedWeld();
          
          ThingConstructor thingField = getWeldBean(ThingConstructor.class);
          assertEquals(thing.getThing(), thingField.thing);
@@ -185,11 +199,12 @@
 
    public void testInjectMcFieldProducedBeanIntoField() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, ThingField.class);
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingFieldProducer.class));
       try
       {
          ThingFieldProducer thing = assertBean("thing", ThingFieldProducer.class);
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingField.class);
+         deployInitializedWeld();
          
          ThingField thingField = getWeldBean(ThingField.class);
          assertEquals(thing.getThing(), thingField.thing);
@@ -203,11 +218,12 @@
    
    public void testInjectMcFieldProducedBeanIntoConstructor() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, ThingConstructor.class);
       WeldKernelControllerContext context = deploy(createBeanMetaData("thing", ThingFieldProducer.class));
       try
       {
          ThingFieldProducer thing = assertBean("thing", ThingFieldProducer.class);
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingConstructor.class);
+         deployInitializedWeld();
          
          ThingConstructor thingField = getWeldBean(ThingConstructor.class);
          assertEquals(thing.getThing(), thingField.thing);
@@ -221,6 +237,7 @@
 
    public void testPostConstructAndPreDestroyOnlyHappensOnceForExistingInstance() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, LifecycleBeanConsumerA.class, LifecycleBeanConsumerB.class);
       LifecycleBean.postConstruct = 0;
       LifecycleBean.preDestroy = 0;
       WeldKernelControllerContext context = deploy(createBeanMetaData("bean", LifecycleBean.class));
@@ -230,7 +247,7 @@
          assertEquals(0, LifecycleBean.preDestroy);
          assertEquals(1, LifecycleBean.postConstruct);
          
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, LifecycleBeanConsumerA.class, LifecycleBeanConsumerB.class);
+         deployInitializedWeld();
          
          LifecycleBeanConsumerA consumerA = getWeldBean(LifecycleBeanConsumerA.class);      
          LifecycleBeanConsumerB consumerB = getWeldBean(LifecycleBeanConsumerB.class);
@@ -253,15 +270,17 @@
    
    public void testInjectionOnlyHappensOnceForExistingInstance() throws Exception
    {
+      initializeWeld(this.getClass().getPackage(), McBeanRegistryObserver.class, DependsOnBeanWithSimpleWeldDependency.class, Simple.class);
+      //Add a context manually so that it seems that it is installed as far as weld is concerned
       BeanWithSimpleWeldDependency bean = new BeanWithSimpleWeldDependency();
       Simple simple = bean.getSimple();
-      
       WeldKernelControllerContext context = new WeldKernelControllerContext(null, createBeanMetaData("NotReallyDeployed :-)", BeanWithSimpleWeldDependency.class), bean, getCurrentManager());
+      context.setState(ControllerState.INSTALLED);
       context.setAnnotatedType(getCurrentManager().createAnnotatedType(BeanWithSimpleWeldDependency.class));
       WeldFromMcRegistry.registerBean(context);
       try
       {
-         deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, DependsOnBeanWithSimpleWeldDependency.class, Simple.class);
+         deployInitializedWeld();
          
          DependsOnBeanWithSimpleWeldDependency wb = getWeldBean(DependsOnBeanWithSimpleWeldDependency.class);
          BeanWithSimpleWeldDependency currentBean = wb.getBean();

Modified: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/wbtomc/test/InjectWeldInMcBeansTestCase.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/wbtomc/test/InjectWeldInMcBeansTestCase.java	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/wbtomc/test/InjectWeldInMcBeansTestCase.java	2009-10-21 16:58:11 UTC (rev 95315)
@@ -72,11 +72,6 @@
 @Artifact
 public class InjectWeldInMcBeansTestCase extends AbstractWeldMcTest
 {
-   static
-   {
-      autodeployWbClasses = new Class[] {WebBean.class};
-   }
-   
    public InjectWeldInMcBeansTestCase(String name)
    {
       super(name);
@@ -87,6 +82,20 @@
       return new TestSuite(InjectWeldInMcBeansTestCase.class);
    }
    
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      deployWeld(WebBean.class);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      undeployWeld();
+      super.tearDown();
+   }
+   
    public void testInjectFromWeldToExternalFieldObject() throws Exception
    {
       NonContextual<ExternalBeanField> nonContextual = new NonContextual<ExternalBeanField>(getCurrentManager(), ExternalBeanField.class);

Added: projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/bidirectional/test/javax.enterprise.inject.spi.Extension
===================================================================
--- projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/bidirectional/test/javax.enterprise.inject.spi.Extension	                        (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/bidirectional/test/javax.enterprise.inject.spi.Extension	2009-10-21 16:58:11 UTC (rev 95315)
@@ -0,0 +1 @@
+org.jboss.kernel.weld.plugins.weld.McBeanRegistryObserver
\ No newline at end of file

Modified: projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/support/wb/javax.enterprise.inject.spi.Extension
===================================================================
--- projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/support/wb/javax.enterprise.inject.spi.Extension	2009-10-21 16:25:31 UTC (rev 95314)
+++ projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/support/wb/javax.enterprise.inject.spi.Extension	2009-10-21 16:58:11 UTC (rev 95315)
@@ -1 +1 @@
-org.jboss.test.kernel.weld.mctowb.support.wb.TestMcAfterBeanDiscoveryObserver
\ No newline at end of file
+org.jboss.kernel.weld.plugins.weld.McBeanRegistryObserver
\ No newline at end of file

Copied: projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/test (from rev 95117, projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/support/wb)

Modified: projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/test/javax.enterprise.inject.spi.Extension
===================================================================
--- projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/support/wb/javax.enterprise.inject.spi.Extension	2009-10-19 15:12:36 UTC (rev 95117)
+++ projects/kernel/trunk/weld-int/src/test/resources/org/jboss/test/kernel/weld/mctowb/test/javax.enterprise.inject.spi.Extension	2009-10-21 16:58:11 UTC (rev 95315)
@@ -1 +1 @@
-org.jboss.test.kernel.weld.mctowb.support.wb.TestMcAfterBeanDiscoveryObserver
\ No newline at end of file
+org.jboss.kernel.weld.plugins.weld.McBeanRegistryObserver
\ No newline at end of file




More information about the jboss-cvs-commits mailing list