[jboss-cvs] JBossAS SVN: r63294 - in branches/Branch_4_2/ejb3/src: test/org/jboss/ejb3/test/ejbthree959 and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 1 05:46:25 EDT 2007


Author: wolfc
Date: 2007-06-01 05:46:24 -0400 (Fri, 01 Jun 2007)
New Revision: 63294

Added:
   branches/Branch_4_2/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java
Modified:
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java
Log:
EJBTHREE-959: expanded unit test

Added: branches/Branch_4_2/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml	2007-06-01 09:46:24 UTC (rev 63294)
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<jboss
+        xmlns="http://java.sun.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                            http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
+        version="3.0">
+   <enterprise-beans>
+      <session>
+         <ejb-name>MyStateful</ejb-name>
+         <cache-config>
+            <idle-timeout-seconds>5</idle-timeout-seconds>
+         </cache-config>
+      </session>
+   </enterprise-beans>
+</jboss>


Property changes on: branches/Branch_4_2/ejb3/src/resources/test/ejbthree959/META-INF/jboss.xml
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java	2007-06-01 07:27:07 UTC (rev 63293)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStateful.java	2007-06-01 09:46:24 UTC (rev 63294)
@@ -31,6 +31,7 @@
  */
 public interface MyStateful extends EJBObject
 {
+   void checkCtx();
    String sayHi();
    void setName(String name);
 }

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java	2007-06-01 07:27:07 UTC (rev 63293)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/MyStatefulBean.java	2007-06-01 09:46:24 UTC (rev 63294)
@@ -28,6 +28,8 @@
 import javax.ejb.SessionBean;
 import javax.ejb.SessionContext;
 
+import org.jboss.logging.Logger;
+
 /**
  * A 2.1 stateful bean.
  *
@@ -38,6 +40,8 @@
 {
    private static final long serialVersionUID = 1L;
    
+   private static final Logger log = Logger.getLogger(MyStatefulBean.class);
+   
    @SuppressWarnings("unused")
    private SessionContext ctx;
    
@@ -47,18 +51,29 @@
    
    public void ejbActivate() throws EJBException, RemoteException
    {
+      log.info("activate");
+      
+      StatusBean.activateCalls++;
    }
 
    public void ejbPassivate() throws EJBException, RemoteException
    {
+      log.info("passivate");
+      
+      StatusBean.passivateCalls++;
    }
 
    public void ejbRemove() throws EJBException, RemoteException
    {
+      log.info("remove");
+      
+      StatusBean.removeCalls++;
    }
 
    public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException
    {
+      log.info("set session context");
+      
       this.ctx = ctx;
    }
 
@@ -66,22 +81,36 @@
    
    public void ejbCreate() throws CreateException, RemoteException
    {
+      log.info("create");
+      
+      checkCtx();
+      
+      StatusBean.createCalls++;
    }
    
-   public void ejbPostCreate() throws CreateException, RemoteException
-   {   
-   }
-   
    public void ejbCreate(String name) throws CreateException, RemoteException
    {
+      log.info("create '" + name + "'");
+      
       setName(name);
+      
+      checkCtx();
+      
+      StatusBean.createCalls++;
    }
    
-   public void ejbPostCreate(String name) throws CreateException, RemoteException
-   {   
+   /* actual stuff */
+   
+   private void assertTrue(String msg, boolean condition)
+   {
+      if(!condition)
+         throw new RuntimeException(msg);
    }
    
-   /* actual stuff */
+   public void checkCtx()
+   {
+      assertTrue("ctx is not set", ctx != null);
+   }
    
    public String sayHi()
    {

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java	2007-06-01 09:46:24 UTC (rev 63294)
@@ -0,0 +1,44 @@
+/*
+ * 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.ejbthree959;
+
+import javax.ejb.Remote;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Remote
+public interface Status
+{
+   int getActivateCalls();
+
+   int getCreateCalls();
+
+   int getPassivateCalls();
+
+   int getRemoveCalls();
+
+   void reset();
+}


Property changes on: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/Status.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java	2007-06-01 09:46:24 UTC (rev 63294)
@@ -0,0 +1,67 @@
+/*
+ * 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.ejbthree959;
+
+import javax.ejb.Stateless;
+
+/**
+ * Dirty bean to check status of MyStatefulBean
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Stateless
+public class StatusBean implements Status
+{
+   static int activateCalls;
+   static int createCalls;
+   static int passivateCalls;
+   static int removeCalls;
+   
+   public int getActivateCalls()
+   {
+      return activateCalls;
+   }
+   
+   public int getCreateCalls()
+   {
+      return createCalls;
+   }
+   
+   public int getPassivateCalls()
+   {
+      return passivateCalls;
+   }
+   
+   public int getRemoveCalls()
+   {
+      return removeCalls;
+   }
+   
+   public void reset()
+   {
+      activateCalls = 0;
+      createCalls = 0;
+      removeCalls = 0;
+      passivateCalls = 0;
+   }
+}


Property changes on: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/StatusBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java	2007-06-01 07:27:07 UTC (rev 63293)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/ejbthree959/unit/EJB21TestCase.java	2007-06-01 09:46:24 UTC (rev 63294)
@@ -21,12 +21,15 @@
  */
 package org.jboss.ejb3.test.ejbthree959.unit;
 
+import javax.ejb.NoSuchEJBException;
+import javax.naming.NamingException;
 import javax.rmi.PortableRemoteObject;
 
 import junit.framework.Test;
 
 import org.jboss.ejb3.test.ejbthree959.MyStateful;
 import org.jboss.ejb3.test.ejbthree959.MyStatefulHome;
+import org.jboss.ejb3.test.ejbthree959.Status;
 import org.jboss.test.JBossTestCase;
 
 
@@ -44,25 +47,84 @@
       super(name);
    }
 
+   private MyStatefulHome getMyStatefulHome() throws Exception
+   {
+      return (MyStatefulHome) PortableRemoteObject.narrow(getInitialContext().lookup("MyStateful/home"), MyStatefulHome.class);
+   }
+   
+   private Status getStatus() throws Exception
+   {
+      return (Status) getInitialContext().lookup("StatusBean/remote");
+   }
+   
    public void testCreateNoArgs() throws Exception
    {
-      MyStatefulHome home = (MyStatefulHome) PortableRemoteObject.narrow(getInitialContext().lookup("MyStateful/home"), MyStatefulHome.class);
+      MyStatefulHome home = getMyStatefulHome();
       MyStateful bean = home.create();
       bean.setName("testCreateNoArgs");
       String expected = "Hi testCreateNoArgs";
       String actual = bean.sayHi();
       assertEquals(expected, actual);
+      bean.remove();
    }
    
    public void testCreateWithArgs() throws Exception
    {
-      MyStatefulHome home = (MyStatefulHome) PortableRemoteObject.narrow(getInitialContext().lookup("MyStateful/home"), MyStatefulHome.class);
+      MyStatefulHome home = getMyStatefulHome();
       MyStateful bean = home.create("testCreateWithArgs");
       String expected = "Hi testCreateWithArgs";
       String actual = bean.sayHi();
       assertEquals(expected, actual);
+      bean.remove();
    }
    
+   public void testCtx() throws Exception
+   {
+      MyStatefulHome home = getMyStatefulHome();
+      MyStateful bean = home.create();
+      bean.checkCtx();
+      bean.remove();
+   }
+   
+   public void testLifeCycle() throws Exception
+   {
+      Status status = getStatus();
+      status.reset();
+      
+      MyStatefulHome home = getMyStatefulHome();
+      MyStateful bean = home.create();
+      
+      assertEquals(1, status.getCreateCalls());
+      
+      bean.setName("testLifeCycle");
+      String expected = "Hi testLifeCycle";
+      String actual = bean.sayHi();
+      assertEquals(expected, actual);
+      
+      sleep(10000);
+      
+      assertEquals(1, status.getPassivateCalls());
+      
+      actual = bean.sayHi();
+      assertEquals(expected, actual);
+      
+      assertEquals(1, status.getActivateCalls());
+      
+      bean.remove();
+      
+      assertEquals(1, status.getRemoveCalls());
+      
+      try
+      {
+         bean.sayHi();
+         fail("expected no such ejb exception");
+      }
+      catch(NoSuchEJBException e)
+      {
+         // good
+      }
+   }
+   
    public static Test suite() throws Exception
    {
       return getDeploySetup(EJB21TestCase.class, "ejbthree959.jar");




More information about the jboss-cvs-commits mailing list