djencks     2004/10/28 17:21:31

  Added:       modules/core/src/test/org/openejb/deployment/slsb
                        AppException.java BasicStatelessContainerTest.java
                        MockEJB.java MockHome.java MockLocal.java
                        MockLocalHome.java MockRemote.java
                        StatelessClientContainerTest.java
  Log:

  Move the deployment classes ***ContainerBuilder to deployment.  Drag most ofthe 
testsuite along with them. Don't you wish we were on svn?
  
  Revision  Changes    Path
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/AppException.java
  
  Index: AppException.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public class AppException extends Exception {
      public AppException(String message) {
          super(message);
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/BasicStatelessContainerTest.java
  
  Index: BasicStatelessContainerTest.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import java.util.Collections;
  import java.util.HashSet;
  import javax.management.ObjectName;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.gbean.jmx.GBeanMBean;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  import org.apache.geronimo.naming.java.ReadOnlyContext;
  import org.openejb.deployment.DeploymentHelper;
  import org.openejb.deployment.StatelessContainerBuilder;
  import org.openejb.dispatch.InterfaceMethodSignature;
  import org.openejb.security.SecurityConfiguration;
  import org.openejb.transaction.ContainerPolicy;
  import org.openejb.transaction.TransactionPolicy;
  import org.openejb.transaction.TransactionPolicySource;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public class BasicStatelessContainerTest extends TestCase {
      private static final ObjectName CONTAINER_NAME = 
JMXUtil.getObjectName("geronimo.test:ejb=Mock");
      private Kernel kernel;
      private GBeanMBean container;
  
      public void testRemoteInvocation() throws Throwable {
          MockHome home = (MockHome) kernel.getAttribute(CONTAINER_NAME, "ejbHome");
          MockRemote remote = home.create();
          assertEquals(2, remote.intMethod(1));
      }
  
      public void testLocalInvocation() throws Throwable {
          MockLocalHome home = (MockLocalHome) kernel.getAttribute(CONTAINER_NAME, 
"ejbLocalHome");
          MockLocal remote = home.create();
          assertEquals(2, remote.intMethod(1));
          assertEquals(2, remote.intMethod(1));
          remote.remove();
      }
  
      public void testTimeout() throws Exception {
          MockLocalHome localHome = (MockLocalHome) 
kernel.getAttribute(CONTAINER_NAME, "ejbLocalHome");
          MockLocal local = localHome.create();
          local.startTimer();
          Thread.currentThread().sleep(200L);
          int timeoutCount = local.getTimeoutCount();
          assertEquals(1, timeoutCount);
      }
  
      public void testRemoteSpeed() throws Throwable {
          MockHome home = (MockHome) kernel.getAttribute(CONTAINER_NAME, "ejbHome");
          MockRemote remote = home.create();
          remote.intMethod(1);
          for (int i = 0; i < 1000; i++) {
              remote.intMethod(1);
          }
      }
  
      public void testLocalSpeed() throws Throwable {
          MockLocalHome home = (MockLocalHome) kernel.getAttribute(CONTAINER_NAME, 
"ejbLocalHome");
  
          MockLocal local = home.create();
          Integer integer = new Integer(1);
          local.integerMethod(integer);
          int COUNT = 100000;
          for (int i = 0; i < COUNT; i++) {
              local.integerMethod(integer);
          }
  
          COUNT = 100000;
          long start = System.currentTimeMillis();
          for (int i = 0; i < COUNT; i++) {
              local.integerMethod(integer);
          }
          long end = System.currentTimeMillis();
          System.out.println("Per local call w/out security: " + ((end - start) * 
1000000.0 / COUNT) + "ns");
      }
  
  /*
      public void testLocalSpeed2() throws Throwable {
          int index = 0;
          EJBInvocationImpl invocation = new 
EJBInvocationImpl(EJBInterfaceType.REMOTE, index, new Object[]{new Integer(1)});
          InvocationResult result = container.invoke(invocation);
          assertEquals(new Integer(2), result.getResult());
  
          for (int i = 0; i < 1000000; i++) {
              container.invoke(invocation);
          }
  
          long start = System.currentTimeMillis();
          for (int i = 0; i < 1000000; i++) {
              container.invoke(invocation);
          }
          long end = System.currentTimeMillis();
          System.out.println("Local Direct: " + (end - start));
      }
  */
  
      protected void setUp() throws Exception {
          super.setUp();
  
          kernel = 
DeploymentHelper.setUpKernelWithTransactionManager("statelessSessionTest");
          DeploymentHelper.setUpTimer(kernel);
  
          StatelessContainerBuilder builder = new StatelessContainerBuilder();
          builder.setClassLoader(this.getClass().getClassLoader());
          builder.setContainerId(CONTAINER_NAME.getCanonicalName());
          builder.setEJBName("MockEJB");
          builder.setBeanClassName(MockEJB.class.getName());
          builder.setHomeInterfaceName(MockHome.class.getName());
          builder.setLocalHomeInterfaceName(MockLocalHome.class.getName());
          builder.setRemoteInterfaceName(MockRemote.class.getName());
          builder.setLocalInterfaceName(MockLocal.class.getName());
          builder.setJndiNames(new String[0]);
          builder.setLocalJndiNames(new String[0]);
          builder.setUnshareableResources(new HashSet());
          builder.setTransactionPolicySource(new TransactionPolicySource() {
              public TransactionPolicy getTransactionPolicy(String methodIntf, 
InterfaceMethodSignature signature) {
                  return ContainerPolicy.Required;
              }
          });
          builder.setSecurityConfiguration(new SecurityConfiguration());
          builder.setComponentContext(new ReadOnlyContext());
          container = builder.createConfiguration();
  
          //start the ejb container
          container.setReferencePatterns("TransactionContextManager", 
Collections.singleton(DeploymentHelper.TRANSACTIONCONTEXTMANAGER_NAME));
          container.setReferencePatterns("TrackedConnectionAssociator", 
Collections.singleton(DeploymentHelper.TRACKEDCONNECTIONASSOCIATOR_NAME));
          container.setReferencePattern("Timer", 
DeploymentHelper.TRANSACTIONALTIMER_NAME);
          start(CONTAINER_NAME, container);
      }
  
      protected void tearDown() throws Exception {
          stop(CONTAINER_NAME);
          kernel.shutdown();
      }
  
      private void start(ObjectName name, GBeanMBean instance) throws Exception {
          kernel.loadGBean(name, instance);
          kernel.startGBean(name);
      }
  
      private void stop(ObjectName name) throws Exception {
          kernel.stopGBean(name);
          kernel.unloadGBean(name);
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/MockEJB.java
  
  Index: MockEJB.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import javax.ejb.CreateException;
  import javax.ejb.SessionBean;
  import javax.ejb.SessionContext;
  import javax.ejb.TimedObject;
  import javax.ejb.Timer;
  import javax.ejb.TimerService;
  
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public class MockEJB implements SessionBean, TimedObject {
  
      private int timeoutCount = 0;
  
      private SessionContext sessionContext;
  
      public int intMethod(int i) {
          return i + 1;
      }
  
      public Integer integerMethod(Integer i) {
          return i;
      }
  
      public void appException() throws AppException {
          throw new AppException("App Message");
      }
  
      public void sysException() {
          throw new IllegalArgumentException("Sys Message");
      }
  
      public void startTimer() {
          TimerService timerService = sessionContext.getTimerService();
          timerService.createTimer(100L, null);
      }
  
      public int getTimeoutCount() {
          return timeoutCount;
      }
  
      public void setSessionContext(SessionContext sessionContext) {
          this.sessionContext = sessionContext;
      }
  
      public void ejbCreate() throws CreateException {
      }
  
      public void ejbActivate() {
      }
  
      public void ejbPassivate() {
      }
  
      public void ejbRemove() {
      }
  
      public void ejbTimeout(Timer timer) {
          timeoutCount++;
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/MockHome.java
  
  Index: MockHome.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import java.rmi.RemoteException;
  import javax.ejb.EJBHome;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public interface MockHome extends EJBHome {
      public MockRemote create() throws RemoteException;
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/MockLocal.java
  
  Index: MockLocal.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import javax.ejb.EJBLocalObject;
  
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public interface MockLocal extends EJBLocalObject {
      int intMethod(int i);
  
      Integer integerMethod(Integer i);
  
      void appException() throws AppException;
  
      void sysException();
  
      void startTimer();
  
      int getTimeoutCount();
  
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/MockLocalHome.java
  
  Index: MockLocalHome.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import javax.ejb.EJBLocalHome;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public interface MockLocalHome extends EJBLocalHome {
      public MockLocal create();
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/MockRemote.java
  
  Index: MockRemote.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import java.rmi.RemoteException;
  import javax.ejb.EJBObject;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public interface MockRemote extends EJBObject {
      int intMethod(int i) throws RemoteException;
  
      void appException() throws RemoteException, AppException;
  
      void sysException() throws RemoteException;
  }
  
  
  
  1.1                  
openejb/modules/core/src/test/org/openejb/deployment/slsb/StatelessClientContainerTest.java
  
  Index: StatelessClientContainerTest.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.deployment.slsb;
  
  import java.rmi.RemoteException;
  import java.util.HashSet;
  import javax.ejb.EJBException;
  import javax.ejb.EJBHome;
  import javax.ejb.EJBMetaData;
  import javax.ejb.EJBObject;
  import javax.ejb.Handle;
  import javax.ejb.RemoveException;
  import javax.rmi.PortableRemoteObject;
  
  import junit.framework.AssertionFailedError;
  import junit.framework.TestCase;
  import 
org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
  import org.apache.geronimo.naming.java.ReadOnlyContext;
  import org.apache.geronimo.transaction.context.TransactionContextManager;
  import org.openejb.EJBContainer;
  import org.openejb.deployment.MockTransactionManager;
  import org.openejb.deployment.StatelessContainerBuilder;
  import org.openejb.dispatch.InterfaceMethodSignature;
  import org.openejb.security.SecurityConfiguration;
  import org.openejb.slsb.AppException;
  import org.openejb.slsb.MockEJB;
  import org.openejb.slsb.MockHome;
  import org.openejb.slsb.MockLocal;
  import org.openejb.slsb.MockLocalHome;
  import org.openejb.slsb.MockRemote;
  import org.openejb.transaction.ContainerPolicy;
  import org.openejb.transaction.TransactionPolicy;
  import org.openejb.transaction.TransactionPolicySource;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/10/28 21:21:31 $
   */
  public class StatelessClientContainerTest extends TestCase {
      private EJBContainer container;
  
      public void testMetadata() throws Exception {
          EJBMetaData metaData = container.getEJBHome().getEJBMetaData();
          assertTrue(metaData.isSession());
          assertTrue(metaData.isStatelessSession());
          assertEquals(MockHome.class, metaData.getHomeInterfaceClass());
          assertEquals(MockRemote.class, metaData.getRemoteInterfaceClass());
          EJBHome home = metaData.getEJBHome();
          assertTrue(home instanceof MockHome);
          try {
              PortableRemoteObject.narrow(home, MockHome.class);
          } catch (ClassCastException e) {
              fail("Unable to narrow home interface");
          }
          try {
              metaData.getPrimaryKeyClass();
              fail("Expected EJBException, but no exception was thrown");
          } catch (EJBException e) {
              // OK
          } catch (AssertionFailedError e) {
              throw e;
          } catch (Throwable t) {
              fail("Expected EJBException, but got " + t.getClass().getName());
          }
      }
  
      public void testHomeInterface() throws Exception {
          MockHome home = (MockHome) container.getEJBHome();
          assertTrue(home.create() instanceof MockRemote);
          try {
              home.remove(new Integer(1));
              fail("Expected RemoveException, but no exception was thrown");
          } catch (RemoveException e) {
              // OK
          } catch (AssertionFailedError e) {
              throw e;
          } catch (Throwable t) {
              fail("Expected RemoveException, but got " + t.getClass().getName());
          }
          try {
              home.remove(new Handle() {
                  public EJBObject getEJBObject() throws RemoteException {
                      return null;
                  }
              });
              fail("Expected RemoteException, but no exception was thrown");
          } catch (RemoteException e) {
              // OK
          } catch (AssertionFailedError e) {
              throw e;
          } catch (Throwable t) {
              fail("Expected RemoteException, but got " + t.getClass().getName());
          }
      }
  
      public void testLocalHomeInterface() {
          MockLocalHome localHome = (MockLocalHome) container.getEJBLocalHome();
          try {
              localHome.remove(new Integer(1));
              fail("Expected RemoveException, but no exception was thrown");
          } catch (RemoveException e) {
              // OK
          } catch (AssertionFailedError e) {
              throw e;
          } catch (Throwable t) {
              fail("Expected RemoveExceptions, but got " + t.getClass().getName());
          }
      }
  
      public void testObjectInterface() throws Exception {
          MockHome home = (MockHome) container.getEJBHome();
          MockRemote remote = home.create();
          assertTrue(remote.isIdentical(remote));
          assertTrue(remote.isIdentical(home.create()));
          try {
              remote.getPrimaryKey();
              fail("Expected RemoteException, but no exception was thrown");
          } catch (RemoteException e) {
              // OK
          } catch (AssertionFailedError e) {
              throw e;
          } catch (Throwable t) {
              fail("Expected RemoteException, but got " + t.getClass().getName());
          }
          remote.remove();
      }
  
      public void testLocalInterface() throws Exception {
          MockLocalHome localHome = (MockLocalHome) container.getEJBLocalHome();
          MockLocal local = localHome.create();
          assertTrue(local.isIdentical(local));
          assertTrue(local.isIdentical(localHome.create()));
          try {
              local.getPrimaryKey();
              fail("Expected EJBException, but no exception was thrown");
          } catch (EJBException e) {
               //OK
          } catch (AssertionFailedError e) {
              throw e;
          } catch (Throwable t) {
              fail("Expected EJBException, but got " + t.getClass().getName());
          }
          local.remove();
      }
  
      public void testInvocation() throws Exception {
          MockHome home = (MockHome) container.getEJBHome();
          MockRemote remote = home.create();
          assertEquals(2, remote.intMethod(1));
          try {
              remote.appException();
              fail("Expected AppException, but no exception was thrown");
          } catch (AppException e) {
              // OK
          }
          try {
              remote.sysException();
              fail("Expected RemoteException, but no exception was thrown");
          } catch (RemoteException e) {
              // OK
          }
      }
  
      protected void setUp() throws Exception {
          super.setUp();
          StatelessContainerBuilder builder = new StatelessContainerBuilder();
          builder.setClassLoader(this.getClass().getClassLoader());
          builder.setContainerId("MockEJB");
          builder.setEJBName("MockEJB");
          builder.setBeanClassName(MockEJB.class.getName());
          builder.setHomeInterfaceName(MockHome.class.getName());
          builder.setLocalHomeInterfaceName(MockLocalHome.class.getName());
          builder.setRemoteInterfaceName(MockRemote.class.getName());
          builder.setLocalInterfaceName(MockLocal.class.getName());
          builder.setJndiNames(new String[0]);
          builder.setLocalJndiNames(new String[0]);
          builder.setUnshareableResources(new HashSet());
          builder.setTransactionPolicySource(new TransactionPolicySource() {
              public TransactionPolicy getTransactionPolicy(String methodIntf, 
InterfaceMethodSignature signature) {
                  return ContainerPolicy.Required;
              }
          });
          builder.setSecurityConfiguration(new SecurityConfiguration());
          builder.setComponentContext(new ReadOnlyContext());
          builder.setTransactionContextManager(new TransactionContextManager(new 
MockTransactionManager(), null, null));
          builder.setTrackedConnectionAssociator(new ConnectionTrackingCoordinator());
          container = builder.createContainer();
      }
  }
  
  
  

Reply via email to