[jboss-cvs] JBossAS SVN: r82747 - projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 10 00:04:17 EST 2009


Author: ALRubinger
Date: 2009-01-10 00:04:17 -0500 (Sat, 10 Jan 2009)
New Revision: 82747

Added:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/SessionTestCaseSupport.java
Modified:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSession2xOnlyTestCase.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSession2xOnlyTestCase.java
Log:
[EJBTHREE-1668] Added Tests that default business interface is not bound in JNDI if there is no business view

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSession2xOnlyTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSession2xOnlyTestCase.java	2009-01-10 02:36:05 UTC (rev 82746)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSession2xOnlyTestCase.java	2009-01-10 05:04:17 UTC (rev 82747)
@@ -46,7 +46,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public class ProxyStatefulSession2xOnlyTestCase extends SessionTestCaseBase
+public class ProxyStatefulSession2xOnlyTestCase extends SessionTestCaseSupport
 {
 
    // --------------------------------------------------------------------------------||
@@ -86,7 +86,48 @@
       assertTrue(bean instanceof MyStatefulRemoteHome);
    }
 
+   /**
+    * Test that there is NO binding for default business remote at beanname/remote
+    * 
+    * EJBTHREE-1668
+    * 
+    * @throws Exception
+    * @author Jaikiran Pai
+    */
+   @Test
+   public void testNoBindingForDefaultBusinessRemote() throws Exception
+   {
+      this.checkNoDefaultBusinessInterfaceBound(MyStateful2xOnlyBean.class, false);
+   }
+
+   /**
+    * Test that there is NO binding for default business local at beanname/local
+    *
+    * EJBTHREE-1668
+    * 
+    * @throws Exception
+    * @author Jaikiran Pai
+    */
+   @Test
+   public void testNoBindingForDefaultBusinessLocal() throws Exception
+   {
+      this.checkNoDefaultBusinessInterfaceBound(MyStateful2xOnlyBean.class, true);
+   }
+
    // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the Context to be used for JNDI Operations 
+    */
+   @Override
+   protected Context getNamingContext()
+   {
+      return context;
+   }
+
+   // --------------------------------------------------------------------------------||
    // Lifecycle Methods --------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSession2xOnlyTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSession2xOnlyTestCase.java	2009-01-10 02:36:05 UTC (rev 82746)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSession2xOnlyTestCase.java	2009-01-10 05:04:17 UTC (rev 82747)
@@ -23,6 +23,7 @@
 
 import static org.junit.Assert.assertTrue;
 
+import javax.naming.Context;
 import javax.naming.InitialContext;
 
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
@@ -38,34 +39,81 @@
 
 /**
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public class ProxyStatelessSession2xOnlyTestCase extends SessionTestCaseBase
+public class ProxyStatelessSession2xOnlyTestCase extends SessionTestCaseSupport
 {
 
    // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * JNDI Context
+    */
+   private static Context context;
+
+   // --------------------------------------------------------------------------------||
    // Tests --------------------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
    @Test
    public void testLocalHome() throws Exception
    {
-      InitialContext ctx = new InitialContext();
-
-      Object bean = ctx.lookup("MyStateless2xOnlyBean/localHome");
+      Object bean = this.getNamingContext().lookup("MyStateless2xOnlyBean/localHome");
       assertTrue(bean instanceof MyStatelessLocalHome);
    }
 
    @Test
    public void testRemoteHome() throws Exception
    {
-      InitialContext ctx = new InitialContext();
-
-      Object bean = ctx.lookup("MyStateless2xOnlyBean/home");
+      Object bean = this.getNamingContext().lookup("MyStateless2xOnlyBean/home");
       assertTrue(bean instanceof MyStatelessRemoteHome);
    }
 
+   /**
+    * Test that there is NO binding for default business remote at beanname/remote
+    * 
+    * EJBTHREE-1668
+    * 
+    * @throws Exception
+    * @author Jaikiran Pai
+    */
+   @Test
+   public void testNoBindingForDefaultBusinessRemote() throws Exception
+   {
+      this.checkNoDefaultBusinessInterfaceBound(MyStateless2xOnlyBean.class, false);
+   }
+
+   /**
+    * Test that there is NO binding for default business local at beanname/local
+    * 
+    * EJBTHREE-1668
+    * 
+    * @throws Exception
+    * @author Jaikiran Pai
+    */
+   @Test
+   public void testNoBindingForDefaultBusinessLocal() throws Exception
+   {
+      this.checkNoDefaultBusinessInterfaceBound(MyStateless2xOnlyBean.class, true);
+   }
+
    // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the Context to be used for JNDI Operations 
+    */
+   @Override
+   protected Context getNamingContext()
+   {
+      return context;
+   }
+
+   // --------------------------------------------------------------------------------||
    // Lifecycle Methods --------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
@@ -89,6 +137,9 @@
       // Install
       Ejb3RegistrarLocator.locateRegistrar().bind(container.getName(), container);
 
+      // Create JNDI Context
+      context = new InitialContext(); // Props from CP jndi.properties
+
    }
 
    @AfterClass

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/SessionTestCaseSupport.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/SessionTestCaseSupport.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/SessionTestCaseSupport.java	2009-01-10 05:04:17 UTC (rev 82747)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.proxy.session.unit;
+
+import static org.junit.Assert.fail;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+
+import org.jboss.ejb3.test.proxy.common.SessionTestCaseBase;
+
+/**
+ * SessionTestCaseSupport
+ * 
+ * Extends SessionTestCaseBase to add support for
+ * similarly-executed tests
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class SessionTestCaseSupport extends SessionTestCaseBase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Contracts ----------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the Context to be used for JNDI Operations 
+    */
+   protected abstract Context getNamingContext();
+
+   // --------------------------------------------------------------------------------||
+   // Test Support -------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Checks that a default business interface is not bound for the EJB w/ the
+    * specified implementation class
+    * 
+    * EJBTHREE-1668
+    * 
+    * @param beanImplClass
+    * @param isLocal
+    * @throws Exception
+    * @author Jaikiran Pai
+    * @author ALR (Revised Jaikiran's patch)
+    */
+   protected void checkNoDefaultBusinessInterfaceBound(Class<?> beanImplClass, boolean isLocal) throws Exception
+   {
+      // A simple context.lookup("beanName/[jndiSuffix]"), should have been enough
+      // to illustrate the issue. But a context.lookup throws a NullPointerException
+      //
+      // javax.naming.NamingException: Could not dereference object [Root exception is java.lang.NullPointerException]
+      // at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1337)
+      //
+      // and "errors" out the testcase. Not exactly what i wanted. So instead to get the
+      // test case failing, let's just check whether the jndi-name is present
+      NamingEnumeration<Binding> namingEnumeration = getNamingContext().listBindings(beanImplClass.getSimpleName());
+      while (namingEnumeration.hasMore())
+      {
+         Binding binding = namingEnumeration.next();
+         String suffix = isLocal ? "local" : "remote";
+         if (binding.getName().equals(suffix))
+         {
+            // This jndi-name should not have been present, since we do not have a default local business interface
+            // and assuming that no one intentionally bound something to this jndi-name
+            fail("JNDI name " + beanImplClass.getSimpleName() + "/" + suffix
+                  + " exists. Expected nothing to be bound with this jndi-name");
+         }
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list