[jboss-cvs] JBossAS SVN: r73705 - in projects/ejb3/trunk/proxy/src/test: java/org/jboss/ejb3/test/proxy/remoteaccess/unit and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 27 07:21:33 EDT 2008


Author: ALRubinger
Date: 2008-05-27 07:21:33 -0400 (Tue, 27 May 2008)
New Revision: 73705

Added:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJndiRemotePropertiesHackCl.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJnpserverPropertiesHackCl.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/RedirectClassloader.java
   projects/ejb3/trunk/proxy/src/test/resources/jndi-remote.properties
Removed:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesRedirectClassloader.java
Modified:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/MockServer.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/unit/RemoteAccessTestCase.java
Log:
[EJBTHREE-1345] Testing CL Hacks to use correct JNDI Properties

Deleted: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesRedirectClassloader.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesRedirectClassloader.java	2008-05-27 11:18:07 UTC (rev 73704)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesRedirectClassloader.java	2008-05-27 11:21:33 UTC (rev 73705)
@@ -1,64 +0,0 @@
-/*
- * 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.remoteaccess;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-
-import org.jboss.logging.Logger;
-
-/**
- * JndiPropertiesRedirectClassloader
- * 
- * Hacky classloader to use to prevent the JNP Server from
- * loading jndi.properties (which should be used by clients 
- * only) and instead swapping for jnpserver.properties
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class JndiPropertiesRedirectClassloader extends ClassLoader
-{
-
-   private static final String TO_REPLACE = "jndi.properties";
-
-   private static final String REPLACE_WITH = "jnpserver.properties";
-
-   private static final Logger log = Logger.getLogger(JndiPropertiesRedirectClassloader.class);
-
-   /**
-    * Replaces a request to load "jndi.properties" with "jnpserver.properties"
-    */
-   @Override
-   public Enumeration<URL> getResources(String name) throws IOException
-   {
-      if (name.equals(JndiPropertiesRedirectClassloader.TO_REPLACE))
-      {
-         log.info("Replacing request for " + JndiPropertiesRedirectClassloader.TO_REPLACE + " with "
-               + JndiPropertiesRedirectClassloader.REPLACE_WITH);
-         name = JndiPropertiesRedirectClassloader.REPLACE_WITH;
-      }
-      return super.getResources(name);
-   }
-
-}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJndiRemotePropertiesHackCl.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJndiRemotePropertiesHackCl.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJndiRemotePropertiesHackCl.java	2008-05-27 11:21:33 UTC (rev 73705)
@@ -0,0 +1,52 @@
+/*
+ * 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.remoteaccess;
+
+/**
+ * JndiPropertiesToJnpserverPropertiesHackCl
+ * 
+ * Hacky classloader to use to switch requests for 
+ * "jndi.properties" to use "jndi-remote.properties"
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JndiPropertiesToJndiRemotePropertiesHackCl extends RedirectClassloader
+{
+
+   private static final String TO_REPLACE = "jndi.properties";
+
+   private static final String REPLACE_WITH = "jndi-remote.properties";
+
+   @Override
+   protected String getFrom()
+   {
+      return JndiPropertiesToJndiRemotePropertiesHackCl.TO_REPLACE;
+   }
+
+   @Override
+   protected String getTo()
+   {
+      return JndiPropertiesToJndiRemotePropertiesHackCl.REPLACE_WITH;
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJnpserverPropertiesHackCl.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJnpserverPropertiesHackCl.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesToJnpserverPropertiesHackCl.java	2008-05-27 11:21:33 UTC (rev 73705)
@@ -0,0 +1,53 @@
+/*
+ * 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.remoteaccess;
+
+/**
+ * JndiPropertiesToJnpserverPropertiesHackCl
+ * 
+ * Hacky classloader to use to prevent the JNP Server from
+ * loading jndi.properties (which should be used by clients 
+ * only) and instead swapping for jnpserver.properties
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class JndiPropertiesToJnpserverPropertiesHackCl extends RedirectClassloader
+{
+
+   private static final String TO_REPLACE = "jndi.properties";
+
+   private static final String REPLACE_WITH = "jnpserver.properties";
+
+   @Override
+   protected String getFrom()
+   {
+      return JndiPropertiesToJnpserverPropertiesHackCl.TO_REPLACE;
+   }
+
+   @Override
+   protected String getTo()
+   {
+      return JndiPropertiesToJnpserverPropertiesHackCl.REPLACE_WITH;
+   }
+
+}

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/MockServer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/MockServer.java	2008-05-27 11:18:07 UTC (rev 73704)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/MockServer.java	2008-05-27 11:21:33 UTC (rev 73705)
@@ -105,7 +105,7 @@
 
       // Switch up to the hacky CL so that "jndi.properties" is not loaded
       ClassLoader olderLoader = Thread.currentThread().getContextClassLoader();
-      Thread.currentThread().setContextClassLoader(new JndiPropertiesRedirectClassloader());
+      Thread.currentThread().setContextClassLoader(new JndiPropertiesToJnpserverPropertiesHackCl());
 
       // Create and set a new MC Bootstrap 
       this.setBootstrap(EmbeddedTestMcBootstrap.createEmbeddedMcBootstrap());

Copied: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/RedirectClassloader.java (from rev 73702, projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/JndiPropertiesRedirectClassloader.java)
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/RedirectClassloader.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/RedirectClassloader.java	2008-05-27 11:21:33 UTC (rev 73705)
@@ -0,0 +1,66 @@
+/*
+ * 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.remoteaccess;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+import org.jboss.logging.Logger;
+
+/**
+ * RedirectClassloader
+ * 
+ * Hacky Classloader that will replace a queried resource
+ * with another under the hood
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class RedirectClassloader extends ClassLoader
+{
+
+   private static final String TO_REPLACE = "jndi.properties";
+
+   private static final String REPLACE_WITH = "jnpserver.properties";
+
+   private static final Logger log = Logger.getLogger(RedirectClassloader.class);
+
+   /**
+    * Replaces a request to load "jndi.properties" with "jnpserver.properties"
+    */
+   @Override
+   public Enumeration<URL> getResources(String name) throws IOException
+   {
+      if (name.equals(this.getFrom()))
+      {
+         log.info("Replacing request for " + this.getFrom() + " with " + this.getTo());
+         name = this.getTo();
+      }
+      return super.getResources(name);
+   }
+
+   protected abstract String getFrom();
+
+   protected abstract String getTo();
+
+}

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/unit/RemoteAccessTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/unit/RemoteAccessTestCase.java	2008-05-27 11:18:07 UTC (rev 73704)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/remoteaccess/unit/RemoteAccessTestCase.java	2008-05-27 11:21:33 UTC (rev 73705)
@@ -33,6 +33,7 @@
 import org.jboss.ejb3.common.thread.RedirectProcessOutputToSystemOutThread;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocal;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemote;
+import org.jboss.ejb3.test.proxy.remoteaccess.JndiPropertiesToJndiRemotePropertiesHackCl;
 import org.jboss.ejb3.test.proxy.remoteaccess.MockServer;
 import org.jboss.logging.Logger;
 import org.junit.AfterClass;
@@ -85,8 +86,16 @@
    @Test
    public void testInvocation() throws Throwable
    {
+
+      // Switch up to the hacky CL so that "jndi.properties" is not loaded, and uses instead "jndi-remote.properties"
+      ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+      Thread.currentThread().setContextClassLoader(new JndiPropertiesToJndiRemotePropertiesHackCl());
+
       InitialContext ctx = new InitialContext();
 
+      // Replace the CL
+      Thread.currentThread().setContextClassLoader(oldLoader);
+
       Object bean = ctx.lookup("MyStatelessBean/remote");
       assertTrue(bean instanceof MyStatelessLocal);
 
@@ -126,6 +135,7 @@
       Process p = RemoteAccessTestCase.getRemoteProcess();
       p.getOutputStream().flush();
       p.destroy();
+
    }
 
    // --------------------------------------------------------------------------------||
@@ -217,4 +227,5 @@
    {
       RemoteAccessTestCase.remoteProcess = remoteProcess;
    }
+
 }

Added: projects/ejb3/trunk/proxy/src/test/resources/jndi-remote.properties
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/jndi-remote.properties	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/jndi-remote.properties	2008-05-27 11:21:33 UTC (rev 73705)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+java.naming.provider.url=jnp://localhost:1099
\ No newline at end of file




More information about the jboss-cvs-commits mailing list