You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2008/06/28 20:48:33 UTC

svn commit: r672566 [3/9] - in /openejb/trunk/openejb3: ./ api/ api/ejb31-api-experimental/ api/ejb31-api-experimental/src/ api/ejb31-api-experimental/src/main/ api/ejb31-api-experimental/src/main/java/ api/ejb31-api-experimental/src/main/java/javax/ a...

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BasicSingletonPojoBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BasicSingletonPojoBean.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BasicSingletonPojoBean.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BasicSingletonPojoBean.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import org.apache.openejb.test.ApplicationException;
+import org.apache.openejb.test.object.OperationsPolicy;
+
+import javax.ejb.SessionContext;
+import javax.ejb.EJBException;
+import java.util.Properties;
+import java.rmi.RemoteException;
+
+public class BasicSingletonPojoBean implements BasicSingletonBusinessLocal, BasicSingletonBusinessRemote {
+
+    /**
+     * Maps to BasicSingletonObject.businessMethod
+     *
+     * @return
+     * @see org.apache.openejb.test.singleton.BasicSingletonObject#businessMethod
+     */
+    public String businessMethod(String text){
+        StringBuffer b = new StringBuffer(text);
+        return b.reverse().toString();
+    }
+
+    public void scheduleTimer(String name) {
+        // ejbContext.getTimerService().createTimer(1, name);
+    }
+
+    public Object echo(Object object) {
+        return object;
+    }
+
+    /**
+     * Throws an ApplicationException when invoked
+     *
+     */
+    public void throwApplicationException() throws ApplicationException {
+        throw new ApplicationException("Testing ability to throw Application Exceptions");
+    }
+
+    /**
+     * Throws a java.lang.NullPointerException when invoked
+     * This is a system exception and should result in the
+     * destruction of the instance and invalidation of the
+     * remote reference.
+     *
+     */
+    public void throwSystemException_NullPointer() {
+        throw new NullPointerException("Testing ability to throw System Exceptions");
+    }
+
+    /**
+     * Maps to BasicSingletonObject.getPermissionsReport
+     *
+     * Returns a report of the bean's
+     * runtime permissions
+     *
+     * @return
+     * @see org.apache.openejb.test.singleton.BasicSingletonObject#getPermissionsReport
+     */
+    public Properties getPermissionsReport(){
+        /* TO DO: */
+        return null;
+    }
+
+    /**
+     * Maps to BasicSingletonObject.getAllowedOperationsReport
+     *
+     * Returns a report of the allowed opperations
+     * for one of the bean's methods.
+     *
+     * @param methodName The method for which to get the allowed opperations report
+     * @return
+     * @see org.apache.openejb.test.singleton.BasicSingletonObject#getAllowedOperationsReport
+     */
+    public OperationsPolicy getAllowedOperationsReport(String methodName){
+        return null;
+    }
+
+    public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException {
+    }
+
+    public Object remove() {
+        return "Executed remove() Method";
+    }
+    
+    public String remove(String arg) {
+        return arg;
+    }
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonBean.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonBean.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonBean.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,212 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import java.rmi.RemoteException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBException;
+import javax.ejb.SessionContext;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.RollbackException;
+import javax.transaction.UserTransaction;
+
+import org.apache.openejb.test.object.Account;
+import org.apache.openejb.test.object.Transaction;
+
+/**
+ * 
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public class BeanTxSingletonBean implements javax.ejb.SessionBean{
+
+    
+    private String name;
+    private SessionContext ejbContext;
+    private InitialContext jndiContext;
+    public final String jndiDatabaseEntry = "jdbc/singleton/beanManagedTransaction/database";
+
+
+    
+    //=============================
+    // Home interface methods
+    //    
+    
+    //    
+    // Home interface methods
+    //=============================
+    
+
+    //=============================
+    // Remote interface methods
+    //    
+    
+    public Transaction getUserTransaction() throws RemoteException{
+        
+        UserTransaction ut = null;
+        try{
+            ut = ejbContext.getUserTransaction();
+        } catch (IllegalStateException ise){
+            throw new RemoteException(ise.getMessage());
+        }
+        if (ut == null) return null;
+        return new Transaction(ut);
+    }
+    
+    public Transaction jndiUserTransaction() throws RemoteException{
+        UserTransaction ut = null;
+        try{
+            ut = (UserTransaction)jndiContext.lookup("java:comp/UserTransaction");
+        } catch (Exception e){
+            throw new RemoteException(e.getMessage());
+        }
+        if (ut == null) return null;
+        return new Transaction(ut);
+    }
+
+    public void openAccount(Account acct, Boolean rollback) throws RemoteException, RollbackException{
+        
+        try{
+            DataSource ds = (DataSource)javax.rmi.PortableRemoteObject.narrow( jndiContext.lookup("java:comp/env/database"), DataSource.class);
+            Connection con = ds.getConnection();
+
+            try {
+                UserTransaction ut = ejbContext.getUserTransaction();
+                /*[1] Begin the transaction */
+                ut.begin();
+
+                /*[2] Update the table */
+                PreparedStatement stmt = con.prepareStatement("insert into Account (SSN, First_name, Last_name, Balance) values (?,?,?,?)");
+                try {
+                    stmt.setString(1, acct.getSsn());
+                    stmt.setString(2, acct.getFirstName());
+                    stmt.setString(3, acct.getLastName());
+                    stmt.setInt(4, acct.getBalance());
+                    stmt.executeUpdate();
+                } finally {
+                    stmt.close();
+                }
+
+                /*[3] Commit or Rollback the transaction */
+                if (rollback.booleanValue()) ut.setRollbackOnly();
+
+                /*[4] Commit or Rollback the transaction */
+                ut.commit();
+            } finally {
+                con.close();
+            }
+        } catch (RollbackException re){
+            throw re;
+        } catch (Exception e){
+            e.printStackTrace();
+            throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
+        }
+    }
+
+    public Account retreiveAccount(String ssn) throws RemoteException {
+        Account acct = new Account();
+        try{
+            DataSource ds = (DataSource)javax.rmi.PortableRemoteObject.narrow( jndiContext.lookup("java:comp/env/database"), DataSource.class);
+            Connection con = ds.getConnection();
+
+            try {
+                PreparedStatement stmt = con.prepareStatement("select * from Account where SSN = ?");
+                try {
+                    stmt.setString(1, ssn);
+                    ResultSet rs = stmt.executeQuery();
+                    if (!rs.next()) return null;
+
+                    acct.setSsn( rs.getString(1) );
+                    acct.setFirstName( rs.getString(2) );
+                    acct.setLastName( rs.getString(3) );
+                    acct.setBalance( rs.getInt(4) );
+                } finally {
+                    stmt.close();
+                }
+            } finally {
+                con.close();
+            }
+        } catch (Exception e){
+            e.printStackTrace();
+            throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
+        }
+        return acct;
+    }
+
+
+    //    
+    // Remote interface methods
+    //=============================
+
+
+    //=================================
+    // SessionBean interface methods
+    //    
+    /**
+     * 
+     * @param name
+     * @exception javax.ejb.CreateException
+     */
+    public void ejbCreate() throws javax.ejb.CreateException{
+        try {
+            jndiContext = new InitialContext(); 
+        } catch (Exception e){
+            throw new CreateException("Can not get the initial context: "+e.getMessage());
+        }
+    }
+    /**
+     * Set the associated session context. The container calls this method
+     * after the instance creation.
+     */
+    public void setSessionContext(SessionContext ctx) throws EJBException,RemoteException {
+        ejbContext = ctx;
+    }
+    /**
+     * A container invokes this method before it ends the life of the session
+     * object. This happens as a result of a client's invoking a remove
+     * operation, or when a container decides to terminate the session object
+     * after a timeout.
+     */
+    public void ejbRemove() throws EJBException,RemoteException {
+    }
+    /**
+     * The activate method is called when the instance is activated
+     * from its "passive" state. The instance should acquire any resource
+     * that it has released earlier in the ejbPassivate() method.
+     */
+    public void ejbActivate() throws EJBException,RemoteException {
+    }
+    /**
+     * The passivate method is called before the instance enters
+     * the "passive" state. The instance should release any resources that
+     * it can re-acquire later in the ejbActivate() method.
+     */
+    public void ejbPassivate() throws EJBException,RemoteException {
+    }
+    //    
+    // SessionBean interface methods
+    //==================================
+    
+    public String remove(String arg) {
+        return arg;
+    }
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonHome.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonHome.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonHome.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonHome.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+
+/**
+ * 
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public interface BeanTxSingletonHome extends javax.ejb.EJBHome {
+
+    public BeanTxSingletonObject create()
+    throws javax.ejb.CreateException, java.rmi.RemoteException;
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonObject.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonObject.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonObject.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/BeanTxSingletonObject.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import java.rmi.RemoteException;
+
+import org.apache.openejb.test.object.Account;
+import org.apache.openejb.test.object.Transaction;
+
+/**
+ * 
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public interface BeanTxSingletonObject extends javax.ejb.EJBObject{
+    
+    public Transaction getUserTransaction() throws RemoteException;
+    
+    public Transaction jndiUserTransaction() throws RemoteException;
+
+    public void openAccount(Account account, Boolean commit) throws RemoteException, javax.transaction.RollbackException;
+
+    public Account retreiveAccount(String ssn) throws RemoteException;
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonBean.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonBean.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonBean.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,196 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import java.rmi.RemoteException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBException;
+import javax.ejb.SessionContext;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.RollbackException;
+
+import org.apache.openejb.test.object.Account;
+
+/**
+ * 
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+public class ContainerTxSingletonBean implements javax.ejb.SessionBean{
+
+    
+    private String name;
+    private SessionContext ejbContext;
+    private InitialContext jndiContext;
+    public final String jndiDatabaseEntry = "jdbc/singleton/containerManagedTransaction/database";
+
+
+    
+    //=============================
+    // Home interface methods
+    //    
+    
+    //    
+    // Home interface methods
+    //=============================
+    
+
+    //=============================
+    // Remote interface methods
+    //    
+    
+    public String txMandatoryMethod(String message) {
+        return message;
+    }
+    
+    public String txNeverMethod(String message) {
+        return message;
+    }
+    
+    public String txNotSupportedMethod(String message) {
+        return message;
+    }
+    
+    public String txRequiredMethod(String message) {
+        return message;
+    }
+    
+    public String txRequiresNewMethod(String message) {
+        return message;
+    }
+    
+    public String txSupportsMethod(String message) {
+        return message;
+    }
+
+    public void openAccount(Account acct, Boolean rollback) throws RollbackException{
+        
+        try{
+            DataSource ds = (DataSource)jndiContext.lookup("java:comp/env/database");
+            Connection con = ds.getConnection();
+
+            try {
+                /*[2] Update the table */
+                PreparedStatement stmt = con.prepareStatement("insert into Account (SSN, First_name, Last_name, Balance) values (?,?,?,?)");
+                try {
+                    stmt.setString(1, acct.getSsn());
+                    stmt.setString(2, acct.getFirstName());
+                    stmt.setString(3, acct.getLastName());
+                    stmt.setInt(4, acct.getBalance());
+                    stmt.executeUpdate();
+                } finally {
+                    stmt.close();
+                }
+            } finally {
+                con.close();
+            }
+        } catch (Exception e){
+            //throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
+        }
+    }
+
+    public Account retreiveAccount(String ssn) {
+        Account acct = new Account();
+        try{
+            DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/database");
+            Connection con = ds.getConnection();
+
+            try {
+                PreparedStatement stmt = con.prepareStatement("select * from Account where SSN = ?");
+                try {
+                    stmt.setString(1, ssn);
+                    ResultSet rs = stmt.executeQuery();
+                    if (!rs.next()) return null;
+
+                    acct.setSsn( rs.getString(1) );
+                    acct.setFirstName( rs.getString(2) );
+                    acct.setLastName( rs.getString(3) );
+                    acct.setBalance( rs.getInt(4) );
+                } finally {
+                    stmt.close();
+                }
+            } finally {
+                con.close();
+            }
+        } catch (Exception e){
+            //throw new RemoteException("[Bean] "+e.getClass().getName()+" : "+e.getMessage());
+        }
+        return acct;
+    }
+
+
+    //    
+    // Remote interface methods
+    //=============================
+
+
+    //=================================
+    // SessionBean interface methods
+    //    
+    /**
+     * 
+     * @exception javax.ejb.CreateException
+     */
+    public void ejbCreate() throws javax.ejb.CreateException{
+        try {
+            jndiContext = new InitialContext(); 
+        } catch (Exception e){
+            throw new CreateException("Can not get the initial context: "+e.getMessage());
+        }
+    }
+    /**
+     * Set the associated session context. The container calls this method
+     * after the instance creation.
+     */
+    public void setSessionContext(SessionContext ctx) throws EJBException,RemoteException {
+        ejbContext = ctx;
+    }
+    /**
+     * A container invokes this method before it ends the life of the session
+     * object. This happens as a result of a client's invoking a remove
+     * operation, or when a container decides to terminate the session object
+     * after a timeout.
+     */
+    public void ejbRemove() throws EJBException,RemoteException {
+    }
+    /**
+     * The activate method is called when the instance is activated
+     * from its "passive" state. The instance should acquire any resource
+     * that it has released earlier in the ejbPassivate() method.
+     */
+    public void ejbActivate() throws EJBException,RemoteException {
+    }
+    /**
+     * The passivate method is called before the instance enters
+     * the "passive" state. The instance should release any resources that
+     * it can re-acquire later in the ejbActivate() method.
+     */
+    public void ejbPassivate() throws EJBException,RemoteException {
+    }
+    //    
+    // SessionBean interface methods
+    //==================================
+    public String remove(String arg) {
+        return arg;
+    }
+    
+    
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonHome.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonHome.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonHome.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonHome.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+
+
+/**
+ * 
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+public interface ContainerTxSingletonHome extends javax.ejb.EJBHome {
+
+    public ContainerTxSingletonObject create()
+    throws javax.ejb.CreateException, java.rmi.RemoteException;
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonObject.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonObject.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonObject.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContainerTxSingletonObject.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import java.rmi.RemoteException;
+
+import javax.transaction.RollbackException;
+
+import org.apache.openejb.test.object.Account;
+
+/**
+ * 
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+public interface ContainerTxSingletonObject extends javax.ejb.EJBObject{
+    
+    public String txMandatoryMethod(String message) throws RemoteException;
+    
+    public String txNeverMethod(String message) throws RemoteException;
+    
+    public String txNotSupportedMethod(String message) throws RemoteException;
+    
+    public String txRequiredMethod(String message) throws RemoteException;
+    
+    public String txRequiresNewMethod(String message) throws RemoteException;
+    
+    public String txSupportsMethod(String message) throws RemoteException;
+
+    public Account retreiveAccount(String ssn) throws RemoteException;
+    
+    public void openAccount(Account acct, Boolean rollback) throws RemoteException, RollbackException;
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonBean.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonBean.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonBean.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,485 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+import org.apache.openejb.test.TestFailureException;
+import org.apache.openejb.test.entity.bmp.BasicBmpHome;
+import org.apache.openejb.test.entity.bmp.BasicBmpObject;
+import org.apache.openejb.test.stateful.BasicStatefulHome;
+import org.apache.openejb.test.stateful.BasicStatefulObject;
+import org.apache.openejb.test.stateful.BasicStatefulBusinessLocal;
+import org.apache.openejb.test.stateful.BasicStatefulBusinessRemote;
+
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.ejb.SessionContext;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+import javax.sql.DataSource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.QueueConnectionFactory;
+import javax.naming.InitialContext;
+import java.rmi.RemoteException;
+
+/**
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public class ContextLookupSingletonBean implements javax.ejb.SessionBean {
+
+    private String name;
+    private SessionContext ejbContext;
+
+    //=============================
+    // Home interface methods
+    //
+    //
+    // Home interface methods
+    //=============================
+
+
+    //=============================
+    // Remote interface methods
+    //
+    public void lookupEntityBean() throws TestFailureException {
+        try {
+            try {
+                BasicBmpHome home = (BasicBmpHome) ejbContext.lookup("singleton/beanReferences/bmp_entity");
+                Assert.assertNotNull("The EJBHome looked up is null", home);
+
+                BasicBmpObject object = home.createObject("Enc Bean");
+                Assert.assertNotNull("The EJBObject is null", object);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBean() throws TestFailureException {
+        try {
+            try {
+                BasicStatefulHome home = (BasicStatefulHome) ejbContext.lookup("singleton/beanReferences/stateful");
+                Assert.assertNotNull("The EJBHome looked up is null", home);
+
+                BasicStatefulObject object = home.createObject("Enc Bean");
+                Assert.assertNotNull("The EJBObject is null", object);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBean() throws TestFailureException {
+        try {
+            try {
+                BasicSingletonHome home = (BasicSingletonHome) ejbContext.lookup("singleton/beanReferences/singleton");
+                Assert.assertNotNull("The EJBHome looked up is null", home);
+
+                BasicSingletonObject object = home.createObject();
+                Assert.assertNotNull("The EJBObject is null", object);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBusinessLocal() throws TestFailureException{
+        try{
+            try{
+            BasicSingletonBusinessLocal object = (BasicSingletonBusinessLocal) ejbContext.lookup("singleton/beanReferences/singleton-business-local");
+            Assert.assertNotNull("The EJB BusinessLocal is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBusinessRemote() throws TestFailureException{
+        try{
+            try{
+            BasicSingletonBusinessRemote object = (BasicSingletonBusinessRemote) ejbContext.lookup("singleton/beanReferences/singleton-business-remote");
+            Assert.assertNotNull("The EJB BusinessRemote is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBusinessLocal() throws TestFailureException{
+        try{
+            try{
+            BasicStatefulBusinessLocal object = (BasicStatefulBusinessLocal) ejbContext.lookup("singleton/beanReferences/stateful-business-local");
+            Assert.assertNotNull("The EJB BusinessLocal is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBusinessRemote() throws TestFailureException{
+        try{
+            try{
+            BasicStatefulBusinessRemote object = (BasicStatefulBusinessRemote) ejbContext.lookup("singleton/beanReferences/stateful-business-remote");
+            Assert.assertNotNull("The EJB BusinessRemote is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStringEntry() throws TestFailureException {
+        try {
+            try {
+                String expected = new String("1");
+                String actual = (String) ejbContext.lookup("singleton/references/String");
+
+                Assert.assertNotNull("The String looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupDoubleEntry() throws TestFailureException {
+        try {
+            try {
+                Double expected = new Double(1.0D);
+                Double actual = (Double) ejbContext.lookup("singleton/references/Double");
+
+                Assert.assertNotNull("The Double looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupLongEntry() throws TestFailureException {
+        try {
+            try {
+                Long expected = new Long(1L);
+                Long actual = (Long) ejbContext.lookup("singleton/references/Long");
+
+                Assert.assertNotNull("The Long looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupFloatEntry() throws TestFailureException {
+        try {
+            try {
+                Float expected = new Float(1.0F);
+                Float actual = (Float) ejbContext.lookup("singleton/references/Float");
+
+                Assert.assertNotNull("The Float looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupIntegerEntry() throws TestFailureException {
+        try {
+            try {
+                Integer expected = new Integer(1);
+                Integer actual = (Integer) ejbContext.lookup("singleton/references/Integer");
+
+                Assert.assertNotNull("The Integer looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupShortEntry() throws TestFailureException {
+        try {
+            try {
+                Short expected = new Short((short) 1);
+                Short actual = (Short) ejbContext.lookup("singleton/references/Short");
+
+                Assert.assertNotNull("The Short looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupBooleanEntry() throws TestFailureException {
+        try {
+            try {
+                Boolean expected = new Boolean(true);
+                Boolean actual = (Boolean) ejbContext.lookup("singleton/references/Boolean");
+
+                Assert.assertNotNull("The Boolean looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupByteEntry() throws TestFailureException {
+        try {
+            try {
+                Byte expected = new Byte((byte) 1);
+                Byte actual = (Byte) ejbContext.lookup("singleton/references/Byte");
+
+                Assert.assertNotNull("The Byte looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupCharacterEntry() throws TestFailureException {
+        try {
+            try {
+                Character expected = new Character('D');
+                Character actual = (Character) ejbContext.lookup("singleton/references/Character");
+
+                Assert.assertNotNull("The Character looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupResource() throws TestFailureException {
+        try {
+            try {
+                Object obj = ejbContext.lookup("datasource");
+                Assert.assertNotNull("The DataSource is null", obj);
+                Assert.assertTrue("Not an instance of DataSource", obj instanceof DataSource);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupJMSConnectionFactory() throws TestFailureException{
+        try{
+            try{
+                Object obj = ejbContext.lookup("jms");
+                Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+                Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+                ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+                testJmsConnection(connectionFactory.createConnection());
+
+                obj = ejbContext.lookup("TopicCF");
+                Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+                Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+                TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+                testJmsConnection(topicConnectionFactory.createConnection());
+
+                obj = ejbContext.lookup("QueueCF");
+                Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+                Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+                QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+                testJmsConnection(queueConnectionFactory.createConnection());
+            } catch (Exception e){
+                e.printStackTrace();
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    private void testJmsConnection(Connection connection) throws JMSException {
+        Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+        Topic topic = session.createTopic("test");
+        MessageProducer producer = session.createProducer(topic);
+        producer.send(session.createMessage());
+        producer.close();
+        session.close();
+        connection.close();
+    }
+
+    public void lookupPersistenceUnit() throws TestFailureException{
+        try{
+            try{
+                EntityManagerFactory emf = (EntityManagerFactory)ejbContext.lookup("persistence/TestUnit");
+                Assert.assertNotNull("The EntityManagerFactory is null", emf );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+    
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                EntityManager em = (EntityManager)ejbContext.lookup("persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSessionContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);                
+
+                // lookup in enc
+                SessionContext sctx = (SessionContext)ctx.lookup("java:comp/env/sessioncontext");
+                Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx );
+
+                // lookup using global name
+                EJBContext ejbCtx = (EJBContext)ctx.lookup("java:comp/EJBContext");
+                Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx );
+
+                // verify context was set via legacy set method
+                Assert.assertNotNull("The SessionContext is null from setter method", ejbContext );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+        
+    }
+    
+    
+    //
+    // Remote interface methods
+    //=============================
+
+    //================================
+    // SessionBean interface methods
+    //
+
+    /**
+     * Set the associated session context. The container calls this method
+     * after the instance creation.
+     */
+    public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException {
+        ejbContext = ctx;
+    }
+
+    /**
+     * @throws javax.ejb.CreateException
+     */
+    public void ejbCreate() throws javax.ejb.CreateException {
+        this.name = "nameless automaton";
+    }
+
+    /**
+     * A container invokes this method before it ends the life of the session
+     * object. This happens as a result of a client's invoking a remove
+     * operation, or when a container decides to terminate the session object
+     * after a timeout.
+     */
+    public void ejbRemove() throws EJBException, RemoteException {
+    }
+
+    /**
+     * The activate method is called when the instance is activated
+     * from its "passive" state. The instance should acquire any resource
+     * that it has released earlier in the ejbPassivate() method.
+     */
+    public void ejbActivate() throws EJBException, RemoteException {
+        // Should never called.
+    }
+
+    /**
+     * The passivate method is called before the instance enters
+     * the "passive" state. The instance should release any resources that
+     * it can re-acquire later in the ejbActivate() method.
+     */
+    public void ejbPassivate() throws EJBException, RemoteException {
+        // Should never called.
+    }
+
+    //
+    // SessionBean interface methods
+    //================================
+    
+    public String remove(String arg) {
+        return arg;
+    }
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonPojoBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonPojoBean.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonPojoBean.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/ContextLookupSingletonPojoBean.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,381 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import org.apache.openejb.test.TestFailureException;
+import org.apache.openejb.test.stateful.BasicStatefulHome;
+import org.apache.openejb.test.stateful.BasicStatefulObject;
+import org.apache.openejb.test.stateful.BasicStatefulBusinessLocal;
+import org.apache.openejb.test.stateful.BasicStatefulBusinessRemote;
+import org.apache.openejb.test.entity.bmp.BasicBmpHome;
+import org.apache.openejb.test.entity.bmp.BasicBmpObject;
+
+import javax.ejb.EJBContext;
+import javax.ejb.SessionContext;
+import javax.ejb.EJBException;
+import javax.sql.DataSource;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import java.rmi.RemoteException;
+
+public class ContextLookupSingletonPojoBean {
+
+    public void lookupEntityBean() throws TestFailureException {
+        try {
+            try {
+                BasicBmpHome home = (BasicBmpHome) getSessionContext().lookup("singleton/beanReferences/bmp_entity");
+                Assert.assertNotNull("The EJBHome looked up is null", home);
+
+                BasicBmpObject object = home.createObject("Enc Bean");
+                Assert.assertNotNull("The EJBObject is null", object);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBean() throws TestFailureException {
+        try {
+            try {
+                BasicStatefulHome home = (BasicStatefulHome) getSessionContext().lookup("singleton/beanReferences/stateful");
+                Assert.assertNotNull("The EJBHome looked up is null", home);
+
+                BasicStatefulObject object = home.createObject("Enc Bean");
+                Assert.assertNotNull("The EJBObject is null", object);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBean() throws TestFailureException {
+        try {
+            try {
+                BasicSingletonHome home = (BasicSingletonHome) getSessionContext().lookup("singleton/beanReferences/singleton");
+                Assert.assertNotNull("The EJBHome looked up is null", home);
+
+                BasicSingletonObject object = home.createObject();
+                Assert.assertNotNull("The EJBObject is null", object);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBusinessLocal() throws TestFailureException{
+        try{
+            try{
+            BasicSingletonBusinessLocal object = (BasicSingletonBusinessLocal) getSessionContext().lookup("singleton/beanReferences/singleton-business-local");
+            Assert.assertNotNull("The EJB BusinessLocal is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBusinessRemote() throws TestFailureException{
+        try{
+            try{
+            BasicSingletonBusinessRemote object = (BasicSingletonBusinessRemote) getSessionContext().lookup("singleton/beanReferences/singleton-business-remote");
+            Assert.assertNotNull("The EJB BusinessRemote is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBusinessLocal() throws TestFailureException{
+        try{
+            try{
+            BasicStatefulBusinessLocal object = (BasicStatefulBusinessLocal) getSessionContext().lookup("singleton/beanReferences/stateful-business-local");
+            Assert.assertNotNull("The EJB BusinessLocal is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBusinessRemote() throws TestFailureException{
+        try{
+            try{
+            BasicStatefulBusinessRemote object = (BasicStatefulBusinessRemote) getSessionContext().lookup("singleton/beanReferences/stateful-business-remote");
+            Assert.assertNotNull("The EJB BusinessRemote is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+
+    public void lookupStringEntry() throws TestFailureException {
+        try {
+            try {
+                String expected = new String("1");
+                String actual = (String) getSessionContext().lookup("singleton/references/String");
+
+                Assert.assertNotNull("The String looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupDoubleEntry() throws TestFailureException {
+        try {
+            try {
+                Double expected = new Double(1.0D);
+                Double actual = (Double) getSessionContext().lookup("singleton/references/Double");
+
+                Assert.assertNotNull("The Double looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupLongEntry() throws TestFailureException {
+        try {
+            try {
+                Long expected = new Long(1L);
+                Long actual = (Long) getSessionContext().lookup("singleton/references/Long");
+
+                Assert.assertNotNull("The Long looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupFloatEntry() throws TestFailureException {
+        try {
+            try {
+                Float expected = new Float(1.0F);
+                Float actual = (Float) getSessionContext().lookup("singleton/references/Float");
+
+                Assert.assertNotNull("The Float looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupIntegerEntry() throws TestFailureException {
+        try {
+            try {
+                Integer expected = new Integer(1);
+                Integer actual = (Integer) getSessionContext().lookup("singleton/references/Integer");
+
+                Assert.assertNotNull("The Integer looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupShortEntry() throws TestFailureException {
+        try {
+            try {
+                Short expected = new Short((short) 1);
+                Short actual = (Short) getSessionContext().lookup("singleton/references/Short");
+
+                Assert.assertNotNull("The Short looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupBooleanEntry() throws TestFailureException {
+        try {
+            try {
+                Boolean expected = new Boolean(true);
+                Boolean actual = (Boolean) getSessionContext().lookup("singleton/references/Boolean");
+
+                Assert.assertNotNull("The Boolean looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupByteEntry() throws TestFailureException {
+        try {
+            try {
+                Byte expected = new Byte((byte) 1);
+                Byte actual = (Byte) getSessionContext().lookup("singleton/references/Byte");
+
+                Assert.assertNotNull("The Byte looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupCharacterEntry() throws TestFailureException {
+        try {
+            try {
+                Character expected = new Character('D');
+                Character actual = (Character) getSessionContext().lookup("singleton/references/Character");
+
+                Assert.assertNotNull("The Character looked up is null", actual);
+                Assert.assertEquals(expected, actual);
+
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupResource() throws TestFailureException {
+        try {
+            try {
+                Object obj = getSessionContext().lookup("datasource");
+                Assert.assertNotNull("The DataSource is null", obj);
+                Assert.assertTrue("Not an instance of DataSource", obj instanceof DataSource);
+            } catch (Exception e) {
+                Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+            }
+        } catch (AssertionFailedError afe) {
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupPersistenceUnit() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
+                Assert.assertNotNull("The EntityManagerFactory is null", emf );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+    
+    public void lookupSessionContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);                
+
+                // lookup in enc
+                SessionContext sctx = (SessionContext)ctx.lookup("java:comp/env/sessioncontext");
+                Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx );
+
+                // lookup using global name
+                EJBContext ejbCtx = (EJBContext)ctx.lookup("java:comp/EJBContext");
+                Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+        
+    }    
+
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    /**
+     * Set the associated session context. The container calls this method
+     * after the instance creation.
+     */
+    public SessionContext getSessionContext() throws EJBException, RemoteException {
+        SessionContext ejbContext = null;
+        try {
+            ejbContext = (SessionContext) new InitialContext().lookup("java:comp/EJBContext");
+        } catch (NamingException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return ejbContext;
+    }
+}

Added: openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/EncSingletonBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/EncSingletonBean.java?rev=672566&view=auto
==============================================================================
--- openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/EncSingletonBean.java (added)
+++ openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/singleton/EncSingletonBean.java Sat Jun 28 11:48:28 2008
@@ -0,0 +1,544 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.test.singleton;
+
+import java.rmi.RemoteException;
+import java.sql.Connection;
+
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.ejb.SessionContext;
+import javax.naming.InitialContext;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityManager;
+import javax.sql.DataSource;
+import javax.jms.ConnectionFactory;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.MessageProducer;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.JMSException;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openejb.test.TestFailureException;
+import org.apache.openejb.test.entity.bmp.BasicBmpHome;
+import org.apache.openejb.test.entity.bmp.BasicBmpObject;
+import org.apache.openejb.test.stateful.BasicStatefulHome;
+import org.apache.openejb.test.stateful.BasicStatefulObject;
+import org.apache.openejb.test.stateful.BasicStatefulBusinessRemote;
+import org.apache.openejb.test.stateful.BasicStatefulBusinessLocal;
+
+/**
+ *
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public class EncSingletonBean implements javax.ejb.SessionBean{
+
+    private String name;
+    private SessionContext ejbContext;
+
+
+    //=============================
+    // Home interface methods
+    //
+    //
+    // Home interface methods
+    //=============================
+
+
+    //=============================
+    // Remote interface methods
+    //
+    public void lookupEntityBean() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            BasicBmpHome home = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/singleton/beanReferences/bmp_entity"), BasicBmpHome.class );
+            Assert.assertNotNull("The EJBHome looked up is null",home);
+
+            BasicBmpObject object = home.createObject("Enc Bean");
+            Assert.assertNotNull("The EJBObject is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBean() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            BasicStatefulHome home = (BasicStatefulHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/singleton/beanReferences/stateful"), BasicStatefulHome.class );
+            Assert.assertNotNull("The EJBHome looked up is null",home);
+
+            BasicStatefulObject object = home.createObject("Enc Bean");
+            Assert.assertNotNull("The EJBObject is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBean() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            BasicSingletonHome home = (BasicSingletonHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/singleton/beanReferences/singleton"), BasicSingletonHome.class );
+            Assert.assertNotNull("The EJBHome looked up is null",home);
+
+            BasicSingletonObject object = home.createObject();
+            Assert.assertNotNull("The EJBObject is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBusinessLocal() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+                Object o = ctx.lookup("java:comp/env/singleton/beanReferences/singleton-business-local");
+                BasicSingletonBusinessLocal object = (BasicSingletonBusinessLocal) o;
+            Assert.assertNotNull("The EJB BusinessLocal is null", object );
+            } catch (Exception e){
+                e.printStackTrace();
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSingletonBusinessRemote() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            BasicSingletonBusinessRemote object = (BasicSingletonBusinessRemote) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/singleton/beanReferences/singleton-business-remote"), BasicSingletonBusinessRemote.class );
+            Assert.assertNotNull("The EJB BusinessRemote is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBusinessLocal() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            BasicStatefulBusinessLocal object = (BasicStatefulBusinessLocal) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/singleton/beanReferences/stateful-business-local"), BasicStatefulBusinessLocal.class );
+            Assert.assertNotNull("The EJB BusinessLocal is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStatefulBusinessRemote() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            BasicStatefulBusinessRemote object = (BasicStatefulBusinessRemote) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/singleton/beanReferences/stateful-business-remote"), BasicStatefulBusinessRemote.class );
+            Assert.assertNotNull("The EJB BusinessRemote is null", object );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupStringEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            String expected = new String("1");
+            String actual   = (String)ctx.lookup("java:comp/env/singleton/references/String");
+
+            Assert.assertNotNull("The String looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupDoubleEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Double expected = new Double(1.0D);
+            Double actual   = (Double)ctx.lookup("java:comp/env/singleton/references/Double");
+
+            Assert.assertNotNull("The Double looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupLongEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Long expected = new Long(1L);
+            Long actual   = (Long)ctx.lookup("java:comp/env/singleton/references/Long");
+
+            Assert.assertNotNull("The Long looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupFloatEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Float expected = new Float(1.0F);
+            Float actual   = (Float)ctx.lookup("java:comp/env/singleton/references/Float");
+
+            Assert.assertNotNull("The Float looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupIntegerEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Integer expected = new Integer(1);
+            Integer actual   = (Integer)ctx.lookup("java:comp/env/singleton/references/Integer");
+
+            Assert.assertNotNull("The Integer looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupShortEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Short expected = new Short((short)1);
+            Short actual   = (Short)ctx.lookup("java:comp/env/singleton/references/Short");
+
+            Assert.assertNotNull("The Short looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupBooleanEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Boolean expected = new Boolean(true);
+            Boolean actual = (Boolean)ctx.lookup("java:comp/env/singleton/references/Boolean");
+
+            Assert.assertNotNull("The Boolean looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupByteEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Byte expected = new Byte((byte)1);
+            Byte actual   = (Byte)ctx.lookup("java:comp/env/singleton/references/Byte");
+
+            Assert.assertNotNull("The Byte looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupCharacterEntry() throws TestFailureException{
+        try{
+            try{
+            InitialContext ctx = new InitialContext();
+            Assert.assertNotNull("The InitialContext is null", ctx );
+
+            Character expected = new Character('D');
+            Character actual   = (Character)ctx.lookup("java:comp/env/singleton/references/Character");
+
+            Assert.assertNotNull("The Character looked up is null", actual );
+            Assert.assertEquals(expected, actual );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupResource() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                Object obj = ctx.lookup("java:comp/env/datasource");
+                Assert.assertNotNull("The DataSource is null", obj);
+                Assert.assertTrue("Not an instance of DataSource", obj instanceof DataSource);
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupJMSConnectionFactory() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                Object obj = ctx.lookup("java:comp/env/jms");
+                Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
+                Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
+                ConnectionFactory connectionFactory = (ConnectionFactory) obj;
+                testJmsConnection(connectionFactory.createConnection());
+
+                obj = ctx.lookup("java:comp/env/TopicCF");
+                Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
+                Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
+                TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
+                testJmsConnection(topicConnectionFactory.createConnection());
+
+                obj = ctx.lookup("java:comp/env/QueueCF");
+                Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
+                Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
+                QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
+                testJmsConnection(queueConnectionFactory.createConnection());
+            } catch (Exception e){
+                e.printStackTrace();
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    private void testJmsConnection(javax.jms.Connection connection) throws JMSException {
+        Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+        Topic topic = session.createTopic("test");
+        MessageProducer producer = session.createProducer(topic);
+        producer.send(session.createMessage());
+        producer.close();
+        session.close();
+        connection.close();
+    }
+
+    public void lookupPersistenceUnit() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManagerFactory emf = (EntityManagerFactory)ctx.lookup("java:comp/env/persistence/TestUnit");
+                Assert.assertNotNull("The EntityManagerFactory is null", emf );
+
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupPersistenceContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+                EntityManager em = (EntityManager)ctx.lookup("java:comp/env/persistence/TestContext");
+                Assert.assertNotNull("The EntityManager is null", em);
+
+                // call a do nothing method to assure entity manager actually exists
+                em.getFlushMode();
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+    }
+
+    public void lookupSessionContext() throws TestFailureException{
+        try{
+            try{
+                InitialContext ctx = new InitialContext();
+                Assert.assertNotNull("The InitialContext is null", ctx);
+
+                // lookup in enc
+                SessionContext sctx = (SessionContext)ctx.lookup("java:comp/env/sessioncontext");
+                Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx );
+
+                // lookup using global name
+                EJBContext ejbCtx = (EJBContext)ctx.lookup("java:comp/EJBContext");
+                Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx );
+
+                // verify context was set via legacy set method
+                Assert.assertNotNull("The SessionContext is null from setter method", ejbContext );
+            } catch (Exception e){
+                Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+            }
+        } catch (AssertionFailedError afe){
+            throw new TestFailureException(afe);
+        }
+
+    }
+
+
+    //    
+    // Remote interface methods
+    //=============================
+
+
+    //================================
+    // SessionBean interface methods
+    //    
+    /**
+     * Set the associated session context. The container calls this method
+     * after the instance creation.
+     */
+    public void setSessionContext(SessionContext ctx) throws EJBException,RemoteException {
+        ejbContext = ctx;
+    }
+    /**
+     * 
+     * @exception javax.ejb.CreateException
+     */
+    public void ejbCreate() throws javax.ejb.CreateException{
+        this.name = "nameless automaton";
+    }
+    /**
+     * A container invokes this method before it ends the life of the session
+     * object. This happens as a result of a client's invoking a remove
+     * operation, or when a container decides to terminate the session object
+     * after a timeout.
+     */
+    public void ejbRemove() throws EJBException,RemoteException {
+    }
+
+    /**
+     * The activate method is called when the instance is activated
+     * from its "passive" state. The instance should acquire any resource
+     * that it has released earlier in the ejbPassivate() method.
+     */
+    public void ejbActivate() throws EJBException,RemoteException {
+        // Should never called.
+    }
+    /**
+     * The passivate method is called before the instance enters
+     * the "passive" state. The instance should release any resources that
+     * it can re-acquire later in the ejbActivate() method.
+     */
+    public void ejbPassivate() throws EJBException,RemoteException {
+        // Should never called.
+    }
+
+    //    
+    // SessionBean interface methods
+    //================================
+    public String remove(String arg) {
+        return arg;
+    }
+}