[jboss-cvs] JBossAS SVN: r95172 - in projects/kernel/trunk/weld-int/src: main/java/org/jboss/kernel/weld/plugins/weld and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 20 10:37:25 EDT 2009
Author: kabir.khan at jboss.com
Date: 2009-10-20 10:37:24 -0400 (Tue, 20 Oct 2009)
New Revision: 95172
Added:
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/LifecycleBean.java
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerA.java
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerB.java
Modified:
projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldConfigureAction.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/dependency/WeldInjector.java
projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstantiateAction.java
projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPostConstructAction.java
projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPreDestroyAction.java
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/AbstractWeldMcTest.java
projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java
Log:
[JBKERNEL-51] Make sure postconstruct/predestroy are only called once
Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldConfigureAction.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldConfigureAction.java 2009-10-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldConfigureAction.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -41,8 +41,7 @@
throw new IllegalArgumentException("context is not a WeldKernelControllerContext");
WeldInjector<?> injector = ((WeldKernelControllerContext)context).getWeldInjector();
- if (injector != null)
- injector.inject();
+ injector.inject();
}
@Override
@@ -54,7 +53,6 @@
throw new IllegalArgumentException("context is not a WeldKernelControllerContext");
WeldInjector<?> injector = ((WeldKernelControllerContext)context).getWeldInjector();
- if (injector != null)
- injector.unconfigure();
+ injector.unconfigure();
}
}
\ No newline at end of file
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-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldDescribeAction.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -42,8 +42,9 @@
super.applyAnnotations(context);
@SuppressWarnings("unchecked")
- WeldInjector<?> webBeansInjector = new WeldInjector((WeldKernelControllerContext)context, context.getBeanInfo().getClassInfo().getType());
- webBeansInjector.describe();
+ WeldInjector<?> weldInjector = new WeldInjector((WeldKernelControllerContext)context, context.getBeanInfo().getClassInfo().getType());
+ ((WeldKernelControllerContext)context).setWeldInjector(weldInjector);
+ weldInjector.describe();
}
@Override
Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInjector.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInjector.java 2009-10-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInjector.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -85,9 +85,14 @@
private CreationalContext<T> creationalContext;
/**
- * True if web beans should constuct this object
+ * True if web beans should construct this object
*/
private boolean createInWeld;
+
+ /**
+ * True if web beans should construct this object
+ */
+ private boolean injectInWeld;
/**
* Constrcutor
@@ -182,7 +187,7 @@
{
if (it.getInjectionPoints().size() > 0)
{
- context.setWeldInjector(this);
+ injectInWeld = true;
BeanMetaData metaData = context.getBeanMetaData();
for (InjectionPoint injectionPoint : it.getInjectionPoints())
{
@@ -230,7 +235,8 @@
*/
void inject()
{
- it.inject((T)context.getTarget(), creationalContext);
+ if (injectInWeld)
+ it.inject((T)context.getTarget(), creationalContext);
}
/**
@@ -238,36 +244,39 @@
*/
void unconfigure()
{
- Object tgt = context.getTarget();
- for (InjectionPoint ip : it.getInjectionPoints())
+ if (injectInWeld)
{
- //TODO Any point in creating ClassInfo here?
- if (ip.getMember() instanceof Method)
+ Object tgt = context.getTarget();
+ for (InjectionPoint ip : it.getInjectionPoints())
{
- Method m = (Method)ip.getMember();
- Object[] params = new Object[m.getParameterTypes().length];
- try
+ //TODO Any point in creating ClassInfo here?
+ if (ip.getMember() instanceof Method)
{
- m.invoke(tgt, params);
+ Method m = (Method)ip.getMember();
+ Object[] params = new Object[m.getParameterTypes().length];
+ try
+ {
+ m.invoke(tgt, params);
+ }
+ catch(Exception e)
+ {
+ log.warn("Error unsetting values for method " + m.getName() + " in bean " + context.getName(), e);
+ }
}
- catch(Exception e)
+ else if (ip.getMember() instanceof Field)
{
- log.warn("Error unsetting values for method " + m.getName() + " in bean " + context.getName(), e);
+ Field f = (Field)ip.getMember();
+ try
+ {
+ f.set(tgt, null);
+ }
+ catch (Exception e)
+ {
+ log.warn("Error unsetting values for field " + f.getName() + " in bean " + context.getName(), e);
+ }
}
- }
- else if (ip.getMember() instanceof Field)
- {
- Field f = (Field)ip.getMember();
- try
- {
- f.set(tgt, null);
- }
- catch (Exception e)
- {
- log.warn("Error unsetting values for field " + f.getName() + " in bean " + context.getName(), e);
- }
- }
- }
+ }
+ }
}
/**
Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstantiateAction.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstantiateAction.java 2009-10-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldInstantiateAction.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -43,7 +43,7 @@
throw new IllegalArgumentException("context is not a WabBeansKernelControllerContext");
WeldInjector<?> injector = ((WeldKernelControllerContext)context).getWeldInjector();
- if (injector != null && injector.createInWeld())
+ if (injector.createInWeld())
context.setTarget(injector.instantiate());
else
super.installActionInternal(context);
Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPostConstructAction.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPostConstructAction.java 2009-10-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPostConstructAction.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -48,8 +48,7 @@
throw new IllegalArgumentException("context is not a WeldKernelControllerContext");
WeldInjector<?> injector = ((WeldKernelControllerContext)context).getWeldInjector();
- if (injector != null)
- injector.postConstruct(context.getTarget());
+ injector.postConstruct(context.getTarget());
}
}
Modified: projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPreDestroyAction.java
===================================================================
--- projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPreDestroyAction.java 2009-10-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/dependency/WeldPreDestroyAction.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -48,8 +48,7 @@
throw new IllegalArgumentException("context is not a WeldKernelControllerContext");
WeldInjector<?> injector = ((WeldKernelControllerContext)context).getWeldInjector();
- if (injector != null)
- injector.preDestroy(context.getTarget());
+ injector.preDestroy(context.getTarget());
}
}
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 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/main/java/org/jboss/kernel/weld/plugins/weld/ExistingInstanceInjectionTarget.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -51,12 +51,12 @@
public void postConstruct(T instance)
{
- injectionTarget.postConstruct(instance);
+ //No op, handled during the installation of the WeldKernelControllerContext
}
public void preDestroy(T instance)
{
- injectionTarget.preDestroy(instance);
+ //No op, handled during the uninstallation of the WeldKernelControllerContext
}
public void dispose(T instance)
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-20 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/AbstractWeldMcTest.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -22,7 +22,10 @@
package org.jboss.test.kernel.weld;
import java.util.Collection;
+import java.util.Set;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import org.jboss.beans.info.spi.BeanAccessMode;
@@ -31,6 +34,7 @@
import org.jboss.kernel.weld.plugins.dependency.WeldKernelControllerContext;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.test.kernel.weld.mctowb.support.wb.ThingConstructor;
/**
*
@@ -167,4 +171,14 @@
return builder.getBeanMetaData();
}
+ protected <T> T getWeldBean(Class<T> clazz) throws Exception
+ {
+ Set<Bean<?>> beans = getCurrentManager().getBeans(clazz);
+ assertEquals(1, beans.size());
+ Bean<T> bean = (Bean<T>)beans.iterator().next();
+ CreationalContext<T> createCtx = getCurrentManager().createCreationalContext(null);
+
+ return bean.create(createCtx);
+ }
+
}
Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/LifecycleBean.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/LifecycleBean.java (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/mc/LifecycleBean.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -0,0 +1,50 @@
+/*
+* 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.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.inject.Default;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Default
+public class LifecycleBean
+{
+ public static int postConstruct;
+ public static int preDestroy;
+
+ @PostConstruct
+ public void postConstruct()
+ {
+ postConstruct++;
+ }
+
+ @PreDestroy
+ public void preDestroy()
+ {
+ preDestroy++;
+ }
+}
Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerA.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerA.java (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerA.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -0,0 +1,37 @@
+/*
+* 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.LifecycleBean;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LifecycleBeanConsumerA
+{
+ @Inject
+ public LifecycleBean bean;
+}
Added: projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerB.java
===================================================================
--- projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerB.java (rev 0)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/support/wb/LifecycleBeanConsumerB.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -0,0 +1,37 @@
+/*
+* 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.LifecycleBean;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LifecycleBeanConsumerB
+{
+ @Inject
+ public LifecycleBean bean;
+}
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 14:37:18 UTC (rev 95171)
+++ projects/kernel/trunk/weld-int/src/test/java/org/jboss/test/kernel/weld/mctowb/test/InjectMcBeansInWeldTestCase.java 2009-10-20 14:37:24 UTC (rev 95172)
@@ -35,10 +35,13 @@
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.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.LifecycleBeanConsumerA;
+import org.jboss.test.kernel.weld.mctowb.support.wb.LifecycleBeanConsumerB;
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;
@@ -114,11 +117,15 @@
{
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);
+
+
assertEquals(thing, thingField.thing);
}
finally
@@ -136,11 +143,8 @@
{
ThingBean thing = assertBean("thing", ThingBean.class);
deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingConstructor.class);
- Set<Bean<?>> beans = getCurrentManager().getBeans(ThingConstructor.class);
- assertEquals(1, beans.size());
- Bean<ThingConstructor> bean = (Bean<ThingConstructor>)beans.iterator().next();
- CreationalContext<ThingConstructor> createCtx = getCurrentManager().createCreationalContext(null);
- ThingConstructor thingField = bean.create(createCtx);
+
+ ThingConstructor thingField = getWeldBean(ThingConstructor.class);
assertEquals(thing, thingField.thing);
}
finally
@@ -157,13 +161,8 @@
{
ThingMethodProducer thing = assertBean("thing", ThingMethodProducer.class);
deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, 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.getThing(), thingField.thing);
}
finally
@@ -180,13 +179,8 @@
{
ThingMethodProducer thing = assertBean("thing", ThingMethodProducer.class);
deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingConstructor.class);
- Set<Bean<?>> beans = getCurrentManager().getBeans(ThingConstructor.class);
- assertEquals(1, beans.size());
- Bean<ThingConstructor> bean = (Bean<ThingConstructor>)beans.iterator().next();
- CreationalContext<ThingConstructor> createCtx = getCurrentManager().createCreationalContext(null);
-
- ThingConstructor thingField = bean.create(createCtx);
+ ThingConstructor thingField = getWeldBean(ThingConstructor.class);
assertEquals(thing.getThing(), thingField.thing);
}
finally
@@ -203,13 +197,8 @@
{
ThingFieldProducer thing = assertBean("thing", ThingFieldProducer.class);
deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, 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.getThing(), thingField.thing);
}
finally
@@ -226,13 +215,8 @@
{
ThingFieldProducer thing = assertBean("thing", ThingFieldProducer.class);
deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, ThingConstructor.class);
- Set<Bean<?>> beans = getCurrentManager().getBeans(ThingConstructor.class);
- assertEquals(1, beans.size());
- Bean<ThingConstructor> bean = (Bean<ThingConstructor>)beans.iterator().next();
- CreationalContext<ThingConstructor> createCtx = getCurrentManager().createCreationalContext(null);
-
- ThingConstructor thingField = bean.create(createCtx);
+ ThingConstructor thingField = getWeldBean(ThingConstructor.class);
assertEquals(thing.getThing(), thingField.thing);
}
finally
@@ -242,4 +226,34 @@
}
}
+ public void testPostConstructAndPreDestroyForExistingInstance() throws Exception
+ {
+ LifecycleBean.postConstruct = 0;
+ LifecycleBean.preDestroy = 0;
+ WeldKernelControllerContext context = deploy(createBeanMetaData("bean", LifecycleBean.class));
+ try
+ {
+ LifecycleBean bean = assertBean("bean", LifecycleBean.class);
+ assertEquals(0, LifecycleBean.preDestroy);
+ assertEquals(1, LifecycleBean.postConstruct);
+
+ deployWeld(TestMcAfterBeanDiscoveryObserver.class.getPackage(), TestMcAfterBeanDiscoveryObserver.class, LifecycleBeanConsumerA.class, LifecycleBeanConsumerB.class);
+
+ LifecycleBeanConsumerA consumerA = getWeldBean(LifecycleBeanConsumerA.class);
+ LifecycleBeanConsumerB consumerB = getWeldBean(LifecycleBeanConsumerB.class);
+ assertSame(consumerA.bean, consumerB.bean);
+
+ assertEquals(0, LifecycleBean.preDestroy);
+ assertEquals(1, LifecycleBean.postConstruct);
+ }
+ finally
+ {
+ undeployWeld();
+ assertEquals(0, LifecycleBean.preDestroy);
+ assertEquals(1, LifecycleBean.postConstruct);
+ undeploy(context);
+ assertEquals(1, LifecycleBean.preDestroy);
+ assertEquals(1, LifecycleBean.postConstruct);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list