Author: dallen6
Date: 2009-04-02 17:29:06 -0400 (Thu, 02 Apr 2009)
New Revision: 2293
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Egg.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/EggProducer.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Goose.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/MyCreationalContext.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjb.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjbImpl.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleBeanEEInjectionsTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithEjb.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithResources.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Farm.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/SimpleBeanLifecycleTest.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/beans.xml
Log:
Few more bean lifecycle tests.
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Egg.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Egg.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Egg.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,24 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle;
+
+import javax.annotation.PreDestroy;
+
+public class Egg
+{
+ private static boolean eggDestroyed = false;
+
+ public Egg()
+ {
+ eggDestroyed = false;
+ }
+
+ @PreDestroy
+ public void destroy()
+ {
+ eggDestroyed = true;
+ }
+
+ public static boolean isEggDestroyed()
+ {
+ return eggDestroyed;
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Egg.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/EggProducer.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/EggProducer.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/EggProducer.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,26 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle;
+
+import javax.inject.Disposes;
+import javax.inject.Produces;
+
+public class EggProducer
+{
+ private static boolean eggDisposed = false;
+
+ @Produces @Synchronous
+ public Egg nextEgg()
+ {
+ eggDisposed = false;
+ return new Egg();
+ }
+
+ public void disposeEgg(@Disposes @Synchronous Egg egg)
+ {
+ eggDisposed = true;
+ }
+
+ public static boolean isEggDisposed()
+ {
+ return eggDisposed;
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/EggProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Farm.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Farm.java 2009-04-01
15:04:36 UTC (rev 2292)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Farm.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -12,19 +12,20 @@
public Date founded;
public Date closed;
public int initialStaff;
+ public String location;
@Current
FarmOffice farmOffice;
@PostConstruct
- private void postConstruct()
+ protected void postConstruct()
{
founded = new Date();
initialStaff = farmOffice.noOfStaff;
}
@PreDestroy
- private void preDestroy()
+ protected void preDestroy()
{
closed = new Date();
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Goose.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Goose.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Goose.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle;
+
+
+public class Goose
+{
+ @Synchronous
+ private Egg currentEgg;
+
+ public Egg getCurrentEgg()
+ {
+ return currentEgg;
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/Goose.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/MyCreationalContext.java
(from rev 2292,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/MyCreationalContext.java)
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/MyCreationalContext.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/MyCreationalContext.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,36 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle;
+
+import javax.context.CreationalContext;
+
+class MyCreationalContext<T> implements CreationalContext<T>
+{
+ private static Object lastBeanPushed = null;
+ private static boolean pushCalled = false;
+
+ public void push(T incompleteInstance)
+ {
+ pushCalled = true;
+ lastBeanPushed = incompleteInstance;
+ }
+
+ public static Object getLastBeanPushed()
+ {
+ return lastBeanPushed;
+ }
+
+ public static void setLastBeanPushed(Object lastBeanPushed)
+ {
+ MyCreationalContext.lastBeanPushed = lastBeanPushed;
+ }
+
+ public static boolean isPushCalled()
+ {
+ return pushCalled;
+ }
+
+ public static void setPushCalled(boolean pushCalled)
+ {
+ MyCreationalContext.pushCalled = pushCalled;
+ }
+
+}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/SimpleBeanLifecycleTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/SimpleBeanLifecycleTest.java 2009-04-01
15:04:36 UTC (rev 2292)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/SimpleBeanLifecycleTest.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -3,6 +3,9 @@
import java.lang.annotation.Annotation;
import javax.context.Context;
+import javax.context.Contextual;
+import javax.context.CreationalContext;
+import javax.context.Dependent;
import javax.context.RequestScoped;
import javax.inject.AnnotationLiteral;
import javax.inject.CreationException;
@@ -73,6 +76,54 @@
@Test(groups = "beanLifecycle")
@SpecAssertions({
+ @SpecAssertion(section = "6.1", id = "b"),
+ @SpecAssertion(section = "6.2", id = "d")
+ })
+ public void testCreateReturnsSameBeanPushed() throws Exception
+ {
+ final CreationalContext<Farm> farmCreationalContext = new
MyCreationalContext<Farm>();
+ final Contextual<Farm> farmBean =
getCurrentManager().resolveByType(Farm.class).iterator().next();
+ MyCreationalContext.setLastBeanPushed(null);
+ MyCreationalContext.setPushCalled(false);
+ new RunInDependentContext()
+ {
+
+ @Override
+ protected void execute() throws Exception
+ {
+ Farm farmInstance =
getCurrentManager().getContext(Dependent.class).get(farmBean, farmCreationalContext);
+ if (MyCreationalContext.isPushCalled())
+ {
+ assert farmInstance.equals(MyCreationalContext.getLastBeanPushed());
+ }
+ assert farmInstance.farmOffice != null : "FarmOffice should be injected
by Contextual.create()";
+ }
+
+ }.run();
+ }
+
+ @Test(groups = { "ri-broken", "beanLifecycle" })
+ @SpecAssertions({
+ @SpecAssertion(section = "6.2", id = "e")
+ })
+ public void testCreateSetsInitialValuesFromXml() throws Exception
+ {
+ new RunInDependentContext()
+ {
+
+ @Override
+ protected void execute() throws Exception
+ {
+ Farm farmInstance = getCurrentManager().getInstanceByType(Farm.class);
+ assert farmInstance.location != null;
+ assert farmInstance.location.equals("Indiana");
+ }
+
+ }.run();
+ }
+
+ @Test(groups = "beanLifecycle")
+ @SpecAssertions({
@SpecAssertion(section = "6.2", id = "a"),
@SpecAssertion(section="2", id="g"),
@SpecAssertion(section="2.2", id="f"),
@@ -99,27 +150,6 @@
assert false;
}
- @Test(groups = { "stub", "beanLifecycle",
"commonAnnotations", "integration" })
- @SpecAssertion(section = "6.4", id = "b")
- public void testCreateInjectsEjb()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "beanLifecycle",
"commonAnnotations", "integration" })
- @SpecAssertion(section = "6.4", id = "c")
- public void testCreateInjectsPersistenceContext()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "beanLifecycle",
"commonAnnotations", "integration" })
- @SpecAssertion(section = "6.4", id = "d")
- public void testCreateInjectsResource()
- {
- assert false;
- }
-
@Test(groups = "injection")
@SpecAssertions({
@SpecAssertion(section = "6.4", id = "e"),
@@ -164,6 +194,24 @@
assert farm.closed != null;
}
+ @Test(groups = { "ri-broken", "beanLifecycle",
"lifecycleCallbacks" })
+ @SpecAssertions({
+ @SpecAssertion(section = "6.3", id = "a"),
+ @SpecAssertion(section = "6.3", id = "c")
+ })
+ public void testContextualDestroyDisposesWhenNecessary() throws Exception
+ {
+ final Contextual<Goose> gooseBean =
getCurrentManager().resolveByType(Goose.class).iterator().next();
+ final Goose goose = getCurrentManager().getInstanceByType(Goose.class);
+
+ assert !EggProducer.isEggDisposed();
+ assert !Egg.isEggDestroyed();
+ gooseBean.destroy(goose);
+ assert EggProducer.isEggDisposed();
+ //TODO Apparently Dependent scoped injected objects do not have their PreDestroy
method called
+ assert Egg.isEggDestroyed();
+ }
+
@Test
@SpecAssertion(section = "4.2", id = "baa")
public void testSubClassInheritsPostConstructOnSuperclass() throws Exception
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjb.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjb.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjb.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,9 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.ic;
+
+import javax.ejb.Local;
+
+@Local
+public interface MyEjb
+{
+ public void hello();
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjb.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjbImpl.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjbImpl.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjbImpl.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,13 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.ic;
+
+import javax.ejb.Stateless;
+
+@Stateless
+public class MyEjbImpl implements MyEjb
+{
+
+ public void hello()
+ {
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/MyEjbImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleBeanEEInjectionsTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleBeanEEInjectionsTest.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleBeanEEInjectionsTest.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,40 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.ic;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.testng.annotations.Test;
+
+@Artifact
+(a)Packaging(PackagingType.EAR)
+@IntegrationTest
+public class SimpleBeanEEInjectionsTest extends AbstractJSR299Test
+{
+ @Test(groups = { "stub", "beanLifecycle",
"commonAnnotations", "integration" })
+ @SpecAssertion(section = "6.4", id = "b")
+ public void testCreateInjectsEjb()
+ {
+ SimpleWithEjb bean = getCurrentManager().getInstanceByType(SimpleWithEjb.class);
+ assert bean.isEjbInjected();
+ }
+
+ @Test(groups = { "stub", "beanLifecycle",
"commonAnnotations", "integration" })
+ @SpecAssertion(section = "6.4", id = "c")
+ public void testCreateInjectsPersistenceContext()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "broken", "beanLifecycle",
"commonAnnotations", "integration" })
+ @SpecAssertion(section = "6.4", id = "d")
+ public void testCreateInjectsResource()
+ {
+ //TODO Spec defines resources for EJBs, not simple beans
+ SimpleWithResources bean =
getCurrentManager().getInstanceByType(SimpleWithResources.class);
+ assert bean.getMyResourceId() == 42;
+ assert "SimpleResource".equals(bean.getMyResourceName());
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleBeanEEInjectionsTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithEjb.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithEjb.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithEjb.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.ic;
+
+import javax.ejb.EJB;
+
+public class SimpleWithEjb
+{
+ @EJB
+ private MyEjb myEjb;
+
+ public boolean isEjbInjected()
+ {
+ return myEjb != null;
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithEjb.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithResources.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithResources.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithResources.java 2009-04-02
21:29:06 UTC (rev 2293)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.lifecycle.ic;
+
+import javax.annotation.Resource;
+
+public class SimpleWithResources
+{
+ @Resource
+ private int myResourceId;
+
+ @Resource
+ private String myResourceName;
+
+ public int getMyResourceId()
+ {
+ return myResourceId;
+ }
+
+ public String getMyResourceName()
+ {
+ return myResourceName;
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/ic/SimpleWithResources.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/beans.xml
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/beans.xml 2009-04-01
15:04:36 UTC (rev 2292)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/lifecycle/beans.xml 2009-04-02
21:29:06 UTC (rev 2293)
@@ -5,4 +5,7 @@
<Production />
<test:AnotherDeploymentType />
</Deploy>
+ <test:Farm>
+ <test:location>Indiana</test:location>
+ </test:Farm>
</Beans>