[jboss-cvs] JBossAS SVN: r95184 - in projects/kernel/trunk/weld-int/src: test/java/org/jboss/test/kernel/weld/mctowb/support/mc and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 20 11:35:30 EDT 2009
Author: kabir.khan at jboss.com
Date: 2009-10-20 11:35:29 -0400 (Tue, 20 Oct 2009)
New Revision: 95184
Added:
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/BeanWithSimpleWeldDependency.java
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/DependsOnBeanWithSimpleWeldDependency.java
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/Simple.java
Modified:
projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java
Log:
[JBKERNEL-51] Make sure MC beans pushed to weld are only injected from Weld as part of the MC install
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-20 15:27:54 UTC (rev 95183)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java 2009-10-20 15:35:29 UTC (rev 95184)
@@ -46,7 +46,7 @@
public void inject(T instance, CreationalContext<T> ctx)
{
- injectionTarget.inject(instance, ctx);
+ //No op, handled during the installation of the WeldKernelControllerContext
}
public void postConstruct(T instance)
Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/BeanWithSimpleWeldDependency.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/BeanWithSimpleWeldDependency.java (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/BeanWithSimpleWeldDependency.java 2009-10-20 15:35:29 UTC (rev 95184)
@@ -0,0 +1,47 @@
+/*
+* 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.mc;
+
+import javax.inject.Inject;
+
+import org.jboss.test.kernel.weld.mctowb.support.wb.Simple;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanWithSimpleWeldDependency
+{
+ @Inject
+ Simple simple = new Simple();
+
+ public Simple getSimple()
+ {
+ return simple;
+ }
+
+ public void setSimple(Simple simple)
+ {
+ this.simple = simple;
+ }
+}
Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/DependsOnBeanWithSimpleWeldDependency.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/DependsOnBeanWithSimpleWeldDependency.java (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/DependsOnBeanWithSimpleWeldDependency.java 2009-10-20 15:35:29 UTC (rev 95184)
@@ -0,0 +1,48 @@
+/*
+* 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.inject.Inject;
+
+import org.jboss.test.kernel.weld.mctowb.support.mc.BeanWithSimpleWeldDependency;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DependsOnBeanWithSimpleWeldDependency
+{
+ @Inject BeanWithSimpleWeldDependency bean;
+
+ public BeanWithSimpleWeldDependency getBean()
+ {
+ return bean;
+ }
+
+ public void setBean(BeanWithSimpleWeldDependency bean)
+ {
+ this.bean = bean;
+ }
+
+
+}
Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/Simple.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/Simple.java (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/Simple.java 2009-10-20 15:35:29 UTC (rev 95184)
@@ -0,0 +1,32 @@
+/*
+* 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;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Simple
+{
+
+}
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-20 15:27:54 UTC (rev 95183)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java 2009-10-20 15:35:29 UTC (rev 95184)
@@ -22,11 +22,8 @@
package org.jboss.test.kernel.weld.mctowb.test;
import java.util.Collection;
-import java.util.Set;
-import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -35,13 +32,16 @@
import org.jboss.kernel.weld.plugins.weld.AnnotatedTypeWrapper;
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;
import org.jboss.test.kernel.weld.mctowb.support.mc.LifecycleBean;
import org.jboss.test.kernel.weld.mctowb.support.mc.ThingBean;
import org.jboss.test.kernel.weld.mctowb.support.mc.ThingFieldProducer;
import org.jboss.test.kernel.weld.mctowb.support.mc.ThingMethodProducer;
import org.jboss.test.kernel.weld.mctowb.support.validateobserver.TestObserver;
+import org.jboss.test.kernel.weld.mctowb.support.wb.DependsOnBeanWithSimpleWeldDependency;
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;
@@ -118,14 +118,7 @@
ThingBean thing = assertBean("thing", ThingBean.class);
deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingField.class);
-// ThingField thingField = getWeldBean(ThingField.class);
- Set<Bean<?>> beans = getCurrentManager().getBeans(ThingField.class);
- assertEquals(1, beans.size());
- Bean<ThingField> bean = (Bean<ThingField>)beans.iterator().next();
- CreationalContext<ThingField> createCtx = getCurrentManager().createCreationalContext(null);
- ThingField thingField = bean.create(createCtx);
-
-
+ ThingField thingField = getWeldBean(ThingField.class);
assertEquals(thing, thingField.thing);
}
finally
@@ -226,7 +219,7 @@
}
}
- public void testPostConstructAndPreDestroyForExistingInstance() throws Exception
+ public void testPostConstructAndPreDestroyOnlyHappensOnceForExistingInstance() throws Exception
{
LifecycleBean.postConstruct = 0;
LifecycleBean.preDestroy = 0;
@@ -257,4 +250,30 @@
assertEquals(1, LifecycleBean.postConstruct);
}
}
+
+ public void testInjectionOnlyHappensOnceForExistingInstance() throws Exception
+ {
+ BeanWithSimpleWeldDependency bean = new BeanWithSimpleWeldDependency();
+ Simple simple = bean.getSimple();
+
+ WeldKernelControllerContext context = new WeldKernelControllerContext(null, createBeanMetaData("NotReallyDeployed :-)", BeanWithSimpleWeldDependency.class), bean, getCurrentManager());
+ context.setAnnotatedType(getCurrentManager().createAnnotatedType(BeanWithSimpleWeldDependency.class));
+ WeldFromMcRegistry.registerBean(context);
+ try
+ {
+ deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, DependsOnBeanWithSimpleWeldDependency.class, Simple.class);
+
+ DependsOnBeanWithSimpleWeldDependency wb = getWeldBean(DependsOnBeanWithSimpleWeldDependency.class);
+ BeanWithSimpleWeldDependency currentBean = wb.getBean();
+ assertSame(bean, currentBean);
+
+ assertSame(simple, bean.getSimple());
+ }
+ finally
+ {
+ undeployWeld();
+ WeldFromMcRegistry.unregisterBean(context);
+ }
+ }
+
}
More information about the jboss-cvs-commits
mailing list