[weld-commits] Weld SVN: r6945 - cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Mon Aug 9 16:07:24 EDT 2010


Author: marius.bogoevici
Date: 2010-08-09 16:07:23 -0400 (Mon, 09 Aug 2010)
New Revision: 6945

Added:
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBean.java
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBeanImpl.java
Modified:
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ManagedBean.java
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java
Log:
CDITCK-169 fixed in the 1.0 branch

Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ManagedBean.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ManagedBean.java	2010-08-09 17:37:52 UTC (rev 6944)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ManagedBean.java	2010-08-09 20:07:23 UTC (rev 6945)
@@ -22,7 +22,7 @@
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 
-class ManagedBean implements Serializable
+public class ManagedBean implements Serializable
 {
    @Inject @Database 
    private EntityManager persistenceContext;

Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java	2010-08-09 17:37:52 UTC (rev 6944)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java	2010-08-09 20:07:23 UTC (rev 6945)
@@ -55,11 +55,10 @@
    })
    public void testInjectionOfPersistenceContext()
    {
-      Bean<ManagedBean> managedBeanBean = getBeans(ManagedBean.class).iterator().next();
-      CreationalContext<ManagedBean> managedBeanCc = getCurrentManager().createCreationalContext(managedBeanBean);
-      ManagedBean managedBean = managedBeanBean.create(managedBeanCc);
+      ServiceBean serviceBean = getInstanceByType(ServiceBean.class);
+      ManagedBean managedBean = serviceBean.getManagedBean();
       assert managedBean.getPersistenceContext() != null : "Persistence context was not injected into bean";
-      assert managedBean.getPersistenceContext().isOpen() : "Persistence context not open injected into bean";
+      assert serviceBean.validateEntityManager();
    }
    
    @Test(groups = { "beanLifecycle", "commonAnnotations", "integration" })
@@ -88,7 +87,7 @@
       ManagedBean managedBean = managedBeanBean.create(managedBeanCc);
       managedBean = (ManagedBean) deserialize(serialize(managedBean));
       assert managedBean.getPersistenceContext() != null : "Persistence context was not injected into bean";
-      assert managedBean.getPersistenceContext().isOpen() : "Persistence context not open injected into bean";
+      assert managedBean.getPersistenceContext().getDelegate() != null : "Persistence context not deserialized correctly";
    }
    
    @Test(groups = { "beanLifecycle", "commonAnnotations", "integration" })

Added: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBean.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBean.java	                        (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBean.java	2010-08-09 20:07:23 UTC (rev 6945)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.jsr299.tck.tests.implementation.simple.resource.persistenceContext;
+
+import javax.ejb.Local;
+
+/**
+ * @author Marius Bogoevici
+ */
+ at Local
+public interface ServiceBean
+{
+   public boolean validateEntityManager();
+
+   public ManagedBean getManagedBean();
+}

Added: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBeanImpl.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBeanImpl.java	                        (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ServiceBeanImpl.java	2010-08-09 20:07:23 UTC (rev 6945)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.jsr299.tck.tests.implementation.simple.resource.persistenceContext;
+
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+/**
+ * @author Marius Bogoevici
+ */
+ at Stateless
+public class ServiceBeanImpl implements ServiceBean
+{
+   @Inject
+   ManagedBean managedBean;
+
+   public ManagedBean getManagedBean()
+   {
+      return managedBean;
+   }
+
+   public boolean validateEntityManager()
+   {
+      boolean entityManagerValid = true;
+      EntityManager entityManager = managedBean.getPersistenceContext();
+      assert entityManager != null;
+      Object delegate = entityManager.getDelegate();
+      assert delegate != null;
+      try
+      {
+         entityManager.getTransaction();
+         entityManagerValid = false;
+      }
+      catch (IllegalStateException e)
+      {
+         // an IllegalStateException is the expected result if this is a JTA entityManager
+      }
+      try
+      {
+         entityManager.close();
+         entityManagerValid = false;
+      }
+      catch (IllegalStateException e)
+      {
+         // an IllegalStateException is the expected result if the entityManager is container-managed
+      }
+      return entityManagerValid;
+   }
+}



More information about the weld-commits mailing list