[jboss-cvs] JBossAS SVN: r64905 - in trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 28 05:18:14 EDT 2007


Author: wolfc
Date: 2007-08-28 05:18:14 -0400 (Tue, 28 Aug 2007)
New Revision: 64905

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Keeper.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/KeeperBean.java
Modified:
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java
Log:
EJBTHREE-1026: test with keeping entity reference

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Keeper.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Keeper.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Keeper.java	2007-08-28 09:18:14 UTC (rev 64905)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ejb3.test.xpcalt;
+
+import javax.ejb.Remote;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface Keeper extends Master
+{
+   void updateKeep(String text);
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Keeper.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/KeeperBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/KeeperBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/KeeperBean.java	2007-08-28 09:18:14 UTC (rev 64905)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ejb3.test.xpcalt;
+
+import static javax.ejb.TransactionAttributeType.NEVER;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.EJB;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.persistence.EntityManager;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.annotation.JndiInject;
+import org.jboss.annotation.ejb.cache.simple.CacheConfig;
+import org.jboss.logging.Logger;
+
+/**
+ * A SFSB that keeps a reference to a managed entity over passivation.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at CacheConfig(idleTimeoutSeconds=5)
+public class KeeperBean implements Keeper
+{
+   private static Logger log = Logger.getLogger(KeeperBean.class);
+   
+   //@PersistenceContext(type=EXTENDED)
+   @EJB(beanName="XPCAltBean")
+   private EntityManager em;
+   
+   private Thingy keep;
+   
+   @JndiInject(jndiName="java:/TransactionManager")
+   private TransactionManager tm;
+   
+   @TransactionAttribute(NEVER)
+   public long createThingy(long id)
+   {
+      log.info("em = " + em);
+      
+      Thingy thingy = new Thingy(id);
+      this.keep = em.merge(thingy);
+      long realId = keep.getId();
+      
+      thingy = em.find(Thingy.class, realId);
+      if(thingy == null || thingy.getId() != realId)
+         throw new IllegalStateException("can't find thingy with id " + realId);
+      
+      return id;
+   }
+   
+   @TransactionAttribute(NEVER)
+   public void checkThingy(long id)
+   {
+      Thingy thingy = em.find(Thingy.class, id);
+      if(thingy == null || thingy.getId() != id)
+         throw new IllegalStateException("can't find thingy with id " + id);
+   }
+   
+   public void doSomething()
+   {
+      log.info("doing nothing");
+   }
+   
+   @PostConstruct
+   protected void postConstruct()
+   {
+      log.info("postConstruct");
+   }
+   
+   @PostActivate
+   protected void postActivate()
+   {
+      log.info("postActivate");   
+   }
+   
+   @PreDestroy
+   protected void preDestroy()
+   {
+      log.info("preDestroy");
+   }
+   
+   @PrePassivate
+   protected void prePassivate()
+   {
+      log.info("prePassivate");
+   }
+   
+   @Remove
+   public void remove()
+   {
+      em.close();
+   }
+   
+   public void save()
+   {
+      try
+      {
+         if(tm.getTransaction() == null)
+            throw new RuntimeException("where is my transaction?");
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      
+      em.flush();
+   }
+   
+   @TransactionAttribute(NEVER)
+   public void updateKeep(String text)
+   {
+      keep.setText(text);
+   }
+}


Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/KeeperBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java	2007-08-28 08:57:11 UTC (rev 64904)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/Thingy.java	2007-08-28 09:18:14 UTC (rev 64905)
@@ -30,7 +30,7 @@
  * A thingy
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 @Entity
 public class Thingy implements Serializable
@@ -38,15 +38,22 @@
    private static final long serialVersionUID = 1L;
    
    private Long id;
+   private String text;
    
    public Thingy()
    {
-      
+      this(null, null);
    }
    
-   public Thingy(long id)
+   public Thingy(Long id)
    {
+      this(id, null);
+   }
+   
+   public Thingy(Long id, String s)
+   {
       this.id = id;
+      this.text = s;
    }
    
    @Id
@@ -60,8 +67,18 @@
       this.id = id;
    }
    
+   public String getText()
+   {
+      return text;
+   }
+   
+   public void setText(String s)
+   {
+      this.text = s;
+   }
+   
    public String toString()
    {
-      return super.toString() + "{id=" + id + "}";
+      return super.toString() + "{id=" + id + ",text=" + text + "}";
    }
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java	2007-08-28 08:57:11 UTC (rev 64904)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/xpcalt/unit/XPCAltTestCase.java	2007-08-28 09:18:14 UTC (rev 64905)
@@ -24,6 +24,7 @@
 import junit.framework.Test;
 
 import org.jboss.ejb3.test.xpcalt.Inspector;
+import org.jboss.ejb3.test.xpcalt.Keeper;
 import org.jboss.ejb3.test.xpcalt.Master;
 import org.jboss.ejb3.test.xpcalt.Thingy;
 import org.jboss.logging.Logger;
@@ -33,7 +34,7 @@
  * Test the an alternative to extended persistence context.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class XPCAltTestCase extends JBossTestCase
 {
@@ -97,9 +98,30 @@
       master.remove();
    }
    
+   public void testKeeper() throws Exception
+   {
+      Keeper keeper = (Keeper) getInitialContext().lookup("KeeperBean/remote");
+      Inspector inspector = (Inspector) getInitialContext().lookup("InspectorBean/remote");
+      
+      long id = keeper.createThingy(4);
+      
+      Thingy thingy = inspector.find(Thingy.class, id);
+      assertNull("thingy should not have been committed", thingy);
+            
+      Thread.sleep(10000);
+      
+      keeper.checkThingy(4);
+      
+      keeper.updateKeep("Showdown");
+      
+      keeper.save();
+      
+      thingy = inspector.find(Thingy.class, id);
+      assertEquals("Showdown", thingy.getText());
+   }
+   
    public static Test suite() throws Exception
    {
       return getDeploySetup(XPCAltTestCase.class, "xpcalt.jar");
    }
-
-}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list