[jboss-cvs] JBossAS SVN: r112695 - in branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite: src/main/org/jboss/test and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Feb 26 18:30:24 EST 2012


Author: pskopek at redhat.com
Date: 2012-02-26 18:30:23 -0500 (Sun, 26 Feb 2012)
New Revision: 112695

Added:
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulator.java
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulatorBean.java
Modified:
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/imports/sections/naming.xml
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/NamingUtil.java
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java
   branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/test/NamingServerSetup.java
Log:
Fixing clustering HAJNDI tests to reflect new changes in Naming. [JBPAPP-7791]

Modified: branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/imports/sections/naming.xml
===================================================================
--- branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/imports/sections/naming.xml	2012-02-24 20:13:12 UTC (rev 112694)
+++ branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/imports/sections/naming.xml	2012-02-26 23:30:23 UTC (rev 112695)
@@ -139,5 +139,12 @@
             <include name="org/jboss/test/naming/restart/*"/>
          </fileset>
       </jar>
+   	
+      <!-- naming tests helper -->
+   	  <jar destfile="${build.lib}/naming-helper.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/naming/util/*"/>
+         </fileset>
+      </jar>
    </target>
 </project>

Modified: branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/NamingUtil.java
===================================================================
--- branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/NamingUtil.java	2012-02-24 20:13:12 UTC (rev 112694)
+++ branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/NamingUtil.java	2012-02-26 23:30:23 UTC (rev 112695)
@@ -124,7 +124,24 @@
       return ctx;
    }
    
+   
    /**
+    * Extract hostname from jndiURL parameter and get InitialContext using @see getFullInitialContext
+    * @param jndiUrl
+    * @return
+    * @throws Exception
+    */
+   public static InitialContext getFullInitialContextFromUrl(String jndiUrl) 
+         throws Exception 
+   {
+      log.debug("jndiUrl = " + jndiUrl);
+      URL url = new URL(jndiUrl);
+      log.debug("host="+url.getHost());
+      return NamingUtil.getFullInitialContext(url.getHost());
+   }
+   
+   
+   /**
     * Returns URL string for given resource. 
     * 
     * @param resource

Modified: branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java
===================================================================
--- branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java	2012-02-24 20:13:12 UTC (rev 112694)
+++ branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/cluster/test/HAJndiTestCase.java	2012-02-26 23:30:23 UTC (rev 112695)
@@ -31,7 +31,9 @@
 
 import org.jboss.test.cluster.ejb.CalledHome;
 import org.jboss.test.cluster.ejb.CalledRemote;
+import org.jboss.test.naming.util.JndiManipulator;
 import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.NamingUtil;
 import org.jnp.interfaces.NamingContext;
 
 /**
@@ -66,7 +68,7 @@
    private static final String JNDI_VALUE1 = "JNDIValue1";
    private static final String JNDI_VALUE2 = "JNDIValue2";
    private static final String JNDI_VALUE3 = "JNDIValue3";
-	
+   
    public HAJndiTestCase(String name)
    {
       super(name);
@@ -74,7 +76,7 @@
 
    public static Test suite() throws Exception
    {
-      return getDeploySetup(HAJndiTestCase.class, "cross-server.jar");
+      return getDeploySetup(HAJndiTestCase.class, "cross-server.jar,naming-helper.jar");
    }
 
    /**
@@ -88,8 +90,8 @@
       getLog().debug("HAJndiTestCase.testLocalBinding()");
       validateUrls();
       
-      // bind to node0 locally
-      Context naming = getContext(NODE0_JNDI);
+      // bind to node0 locally using different JNDI connector because of disabling bind operation from non-local JVMs
+      Context naming = NamingUtil.getFullInitialContextFromUrl(NODE0_JNDI);
       naming.bind(LOCAL0_KEY, LOCAL0_VALUE);
       closeContext(naming);
       
@@ -129,10 +131,14 @@
       getLog().debug("HAJndiTestCase.testHAJndiBinding()");
       validateUrls();
       
+      Context naming = null;
+      
       // bind to node0 using HA-JNDI
-      Context naming = getContext(NODE0_HAJNDI);
-      naming.bind(GLOBAL0_KEY, GLOBAL0_VALUE);
-      closeContext(naming);
+      //Context naming = getContext(NODE0_HAJNDI);
+      //naming.bind(GLOBAL0_KEY, GLOBAL0_VALUE);
+      //closeContext(naming);
+      JndiManipulator m = getJndiManipulator(NODE0_HAJNDI);
+      m.bind(NODE0_HAJNDI, GLOBAL0_KEY, GLOBAL0_VALUE);
       
       // lookup binding locally on Node0 - should fail
       naming = getContext(NODE0_JNDI);
@@ -165,6 +171,7 @@
     *
     * @throws Exception
     */
+   /*  disabled, because testing Naming operations from client does not make sense anymore 
    public void testHAJndiOperations()
       throws Exception
    {
@@ -206,7 +213,8 @@
       
       closeContext(naming);  
    }
-
+   */
+   
    /**
     * Test EJB Bindings using local and HA-JNDI lookups
     *
@@ -420,4 +428,19 @@
 
    }
 
+   private JndiManipulator getJndiManipulator(String jndiUrl) throws Exception {
+      
+      Properties env = new Properties();        
+      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+      env.setProperty(Context.PROVIDER_URL, jndiUrl);
+      env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+      
+      Context ctx = new InitialContext (env);
+      JndiManipulator m = (JndiManipulator)ctx.lookup("JndiManipulatorBean/remote");
+      ctx.close();
+      
+      return m;
+      
+   }
+   
 }

Modified: branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/test/NamingServerSetup.java
===================================================================
--- branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/test/NamingServerSetup.java	2012-02-24 20:13:12 UTC (rev 112694)
+++ branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/test/NamingServerSetup.java	2012-02-26 23:30:23 UTC (rev 112695)
@@ -21,10 +21,13 @@
  */
 package org.jboss.test.naming.test;
 
+import java.rmi.RemoteException;
+import java.util.Collection;
 import java.util.Hashtable;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.Name;
 import javax.naming.NamingException;
 import javax.naming.RefAddr;
 import javax.naming.Reference;
@@ -37,8 +40,11 @@
 import junit.framework.Test;
 
 import org.jboss.naming.ENCFactory;
+import org.jboss.test.NamingUtil;
+import org.jnp.interfaces.Naming;
 import org.jnp.interfaces.NamingContext;
 import org.jnp.server.Main;
+import org.jnp.server.NamingBean;
 import org.jnp.server.NamingBeanImpl;
 
 /** 
@@ -75,9 +81,12 @@
       namingServer.setInstallGlobalService(true);
       namingBean.setUseGlobalService(false);
       namingBean.setInstallGlobalService(true);
-      namingServer.setNamingInfo(namingBean);
+      FakeNamingBean fnb = new FakeNamingBean();
+      namingServer.setNamingInfo(fnb);
+      //namingBean.start();
+      namingServer.start();
       namingBean.start();
-      namingServer.start();
+      fnb.setRealInstance(namingBean.getNamingInstance());
 
       NamingManager.setInitialContextFactoryBuilder(this);
       /* Bind an ObjectFactory to "java:comp" so that "java:comp/env" lookups
@@ -89,7 +98,10 @@
       ENCFactory.setTopClassLoader(topLoader);
       RefAddr refAddr = new StringRefAddr("nns", "ENC");
       Reference envRef = new Reference("javax.naming.Context", refAddr, ENCFactory.class.getName(), null);
-      Context ctx = (Context)iniCtx.lookup("java:");
+      //Context ctx = (Context)iniCtx.lookup("java:");
+      System.out.println("XX povider URL="+iniCtx.getEnvironment().get(Context.PROVIDER_URL));
+      
+      Context ctx = NamingUtil.getFullInitialContext("localhost");
       ctx.rebind("comp", envRef);
    }
 
@@ -111,3 +123,68 @@
       }
    }
 }
+
+class FakeNamingBean implements NamingBean, Naming {
+
+   Naming realInstance;
+   
+   public void setRealInstance(Naming realInstance) {
+      this.realInstance = realInstance;
+   }
+   
+   public FakeNamingBean() {
+   }
+   
+   
+   public Naming getNamingInstance()
+   {
+      return this;
+   }
+
+
+   public void bind(Name name, Object obj, String className)
+         throws NamingException, RemoteException
+   {
+      realInstance.bind(name, obj, className);
+   }
+
+
+   public void rebind(Name name, Object obj, String className)
+         throws NamingException, RemoteException
+   {  
+      realInstance.rebind(name, obj, className);
+   }
+
+
+   public void unbind(Name name) throws NamingException, RemoteException
+   {
+      realInstance.unbind(name);
+   }
+
+
+   public Object lookup(Name name) throws NamingException, RemoteException
+   {
+      return realInstance.lookup(name);
+   }
+
+
+   public Collection list(Name name) throws NamingException, RemoteException
+   {
+      return realInstance.list(name);
+   }
+
+
+   public Collection listBindings(Name name) throws NamingException,
+         RemoteException
+   {
+      return realInstance.listBindings(name);
+   }
+
+
+   public Context createSubcontext(Name name) throws NamingException,
+         RemoteException
+   {
+      return realInstance.createSubcontext(name);
+   }
+   
+}

Added: branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulator.java
===================================================================
--- branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulator.java	                        (rev 0)
+++ branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulator.java	2012-02-26 23:30:23 UTC (rev 112695)
@@ -0,0 +1,47 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.test.naming.util;
+
+import java.util.Collection;
+import javax.naming.Context;
+
+/**
+ * @author  <a href="mailto:pskopek at redhat.com">Peter Skopek</a>
+ *
+ */
+public interface JndiManipulator
+{
+   public void bind(String jndiUrl, String jndiName, Object data) throws Exception;
+
+   public void rebind(String jndiUrl, String jndiName, Object data) throws Exception;
+
+   public void unbind(String jndiUrl, String jndiName) throws Exception;
+
+   public Object lookup(String jndiUrl, String jndiName) throws Exception;
+
+   public Collection list(String jndiUrl, String jndiName) throws Exception;
+
+   public Collection listBindings(String jndiUrl, String jndiName) throws Exception;
+         
+   public void createSubcontext(String jndiUrl, String jndiName) throws Exception;
+}

Added: branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulatorBean.java
===================================================================
--- branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulatorBean.java	                        (rev 0)
+++ branches/JBPAPP_4_3_0_GA_CP10_JBPAPP-7791/testsuite/src/main/org/jboss/test/naming/util/JndiManipulatorBean.java	2012-02-26 23:30:23 UTC (rev 112695)
@@ -0,0 +1,116 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.test.naming.util;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Helper bean to manipulate JNDI object from server side.
+ * @author  <a href="mailto:pskopek at redhat.com">Peter Skopek</a>
+ *
+ */
+ at Stateless
+ at Remote(JndiManipulator.class)
+public class JndiManipulatorBean implements JndiManipulator 
+{
+   
+   /**
+    * Bind data to jndiUrl under given jndiName.
+    * @param jndiUrl
+    * @param jndiName
+    * @param data
+    */
+   public void bind(String jndiUrl, String jndiName, Object data) 
+         throws Exception 
+   {
+      Context ctx = getContext(jndiUrl);
+      ctx.bind(jndiName, data);
+      ctx.close();
+   }
+
+   public void rebind(String jndiUrl, String jndiName, Object data)
+         throws Exception
+   {
+      Context ctx = getContext(jndiUrl);
+      ctx.rebind(jndiName, data);
+      ctx.close();
+   }
+
+   public void unbind(String jndiUrl, String jndiName) throws Exception
+   {
+      Context ctx = getContext(jndiUrl);
+      ctx.unbind(jndiName);
+      ctx.close();
+   }
+
+   public Object lookup(String jndiUrl, String jndiName) throws Exception
+   {
+      Context ctx = getContext(jndiUrl);
+      Object data = ctx.lookup(jndiName);
+      ctx.close();
+      return data;
+   }
+
+   public Collection list(String jndiUrl, String jndiName) throws Exception
+   {
+      Context ctx = getContext(jndiUrl);
+      Collection list = (Collection)ctx.list(jndiName);
+      ctx.close();
+      return list;
+   }
+
+   public Collection listBindings(String jndiUrl, String jndiName)
+         throws Exception
+   {
+      Context ctx = getContext(jndiUrl);
+      Collection list = (Collection)ctx.listBindings(jndiName);
+      ctx.close();
+      return list;
+   }
+
+   public void createSubcontext(String jndiUrl, String jndiName)
+         throws Exception
+   {
+      Context ctx = getContext(jndiUrl);
+      ctx.createSubcontext(jndiName);
+      ctx.close();
+   }
+
+   private Context getContext(String jndiUrl) throws NamingException {
+      Properties env = new Properties();        
+      env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+      env.setProperty(Context.PROVIDER_URL, jndiUrl);
+      env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+      
+      Context ctx = new InitialContext (env);
+      return ctx;
+   }
+   
+}



More information about the jboss-cvs-commits mailing list