[jboss-cvs] JBossAS SVN: r72754 - in trunk: testsuite/src/main/org/jboss/test/client/test and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 27 10:01:29 EDT 2008


Author: scott.stark at jboss.org
Date: 2008-04-27 10:01:28 -0400 (Sun, 27 Apr 2008)
New Revision: 72754

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/client/URLInjectorFactory.java
   trunk/testsuite/src/main/org/jboss/test/client/test/main/
   trunk/testsuite/src/main/org/jboss/test/client/test/main/Client.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
   trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java
   trunk/ejb3/src/main/org/jboss/ejb3/client/ClientResourceHandler.java
   trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java
   trunk/testsuite/src/main/org/jboss/test/client/test/AppClientUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/ee5client/unit/AppClientUnitTestCase.java
Log:
Update to rely on injection target metadata

Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2008-04-27 09:36:09 UTC (rev 72753)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientContainer.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -34,7 +34,6 @@
 import java.util.Map;
 import java.util.Properties;
 
-import javax.annotation.PostConstruct;
 import javax.naming.Context;
 import javax.naming.NameClassPair;
 import javax.naming.NameNotFoundException;
@@ -43,18 +42,14 @@
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.DependencyPolicy;
 import org.jboss.ejb3.InitialContextFactory;
-import org.jboss.ejb3.clientmodule.EJBRemoteHandler;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
 import org.jboss.injection.DependsHandler;
-import org.jboss.injection.EJBInjectionHandler;
 import org.jboss.injection.EncInjector;
 import org.jboss.injection.InjectionContainer;
 import org.jboss.injection.InjectionHandler;
-import org.jboss.injection.InjectionUtil;
 import org.jboss.injection.Injector;
 import org.jboss.injection.JndiInjectHandler;
 import org.jboss.injection.PersistenceUnitHandler;
-import org.jboss.injection.ResourceHandler;
 import org.jboss.injection.WebServiceRefHandler;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.client.jboss.JBossClientMetaData;
@@ -74,7 +69,9 @@
 public class ClientContainer implements InjectionContainer
 {
    private static final Logger log = Logger.getLogger(ClientContainer.class);
-   
+   private static final String VERSION = "$Revision:";
+   private static ThreadLocal<Properties> clientJndiEnv = new ThreadLocal<Properties>();
+
    private Class<?> mainClass;
    private JBossClientMetaData xml;
    private String applicationClientName;
@@ -82,14 +79,16 @@
    // for performance there is an array.
    private List<Injector> injectors = new ArrayList<Injector>();
    private Map<String, Map<AccessibleObject, Injector>> encInjections = new HashMap<String, Map<AccessibleObject, Injector>>();
-//   private Map<String, EncInjector> encInjectors = new HashMap<String, EncInjector>();
-   
    private Context enc;
-   private Context encEnv;
    private DependencyPolicy dependsPolicy;
-   
+
    private List<Method> postConstructs = new ArrayList<Method>();
 
+   public static Properties getJndiEnv()
+   {
+      return clientJndiEnv.get();
+   }
+
    public ClientContainer(JBossClientMetaData xml, Class<?> mainClass, String applicationClientName)
       throws Exception
    {
@@ -98,13 +97,15 @@
    public ClientContainer(JBossClientMetaData xml, Class<?> mainClass, String applicationClientName, Properties jndiEnv)
       throws Exception
    {
+      log.info("ClientContainer(version="+VERSION+")");
+      log.info("DependencyPolicy.CS: "+DependencyPolicy.class.getProtectionDomain().getCodeSource());
+      clientJndiEnv.set(jndiEnv);
       this.xml = xml;
       this.mainClass = mainClass;
       this.applicationClientName = applicationClientName;
       ClientJavaEEComponent client = new ClientJavaEEComponent(applicationClientName);
       this.dependsPolicy = new NoopDependencyPolicy(client);
 
-      //Context ctx = getInitialContext();
       Context ctx = InitialContextFactory.getInitialContext(jndiEnv);
       enc = (Context) ctx.lookup(applicationClientName);
       log.debug("Client ENC("+applicationClientName+"):");
@@ -349,14 +350,17 @@
    }
    
    /**
-    * Create dummy dd for PostConstruct annotations.
+    * Get the post construct methods
     * @throws ClassNotFoundException 
     * @throws NoSuchMethodException 
     * @throws SecurityException 
     *
     */
-   private void processPostConstructs() throws ClassNotFoundException, SecurityException, NoSuchMethodException
+   private void processPostConstructs()
+      throws ClassNotFoundException, SecurityException, NoSuchMethodException
    {
+      // First build a set of the callbacks by class
+      HashMap<Class<?>, Method> pcByClass = new HashMap<Class<?>, Method>();
       LifecycleCallbacksMetaData callbacks = xml.getPostConstructs();
       if(callbacks != null)
       {
@@ -371,11 +375,13 @@
                lifecycleClass = Thread.currentThread().getContextClassLoader().loadClass(className);
             Class<?> parameterTypes[] = new Class[0];
             Method method = lifecycleClass.getDeclaredMethod(methodName, parameterTypes);
-            postConstructs.add(method);
+            pcByClass.put(lifecycleClass, method);
          }
       }
+      // Use the unique callback methods
+      postConstructs.addAll(pcByClass.values());
    }
-   
+
    /* (non-Javadoc)
     * @see org.jboss.injection.InjectionContainer#resolveEjbContainer(java.lang.String, java.lang.Class)
     */

Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java	2008-04-27 09:36:09 UTC (rev 72753)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientLauncher.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -44,6 +44,7 @@
  * It must also contain an application client deployment descriptor file (META-INF/application-client.xml).
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
  * @version $Revision: $
  */
 public class ClientLauncher
@@ -81,11 +82,7 @@
       }
       ClientContainer container = new ClientContainer(xml, mainClass, applicationClientName, jndiEnv);
       
-      // TODO: postContruct
- 
       container.invokeMain(args);
-      
-      // TODO: preDestroy
    }
 
    /**

Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/ClientResourceHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/ClientResourceHandler.java	2008-04-27 09:36:09 UTC (rev 72753)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/ClientResourceHandler.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -36,10 +36,8 @@
 import org.jboss.injection.EJBContextPropertyInjector;
 import org.jboss.injection.InjectionContainer;
 import org.jboss.injection.InjectionHandler;
-import org.jboss.injection.InjectionUtil;
 import org.jboss.injection.Injector;
 import org.jboss.injection.InjectorFactory;
-import org.jboss.injection.JndiPropertyInjector;
 import org.jboss.injection.UserTransactionPropertyInjector;
 import org.jboss.injection.lang.reflect.BeanProperty;
 import org.jboss.injection.lang.reflect.BeanPropertyFactory;
@@ -81,31 +79,7 @@
             log.debug("ignoring env-entry " + envEntry);
             continue;
          }
-         /* Handle the injection targets
-         ClassLoader loader = container.getClassloader();
-         Set<ResourceInjectionTargetMetaData> targets = envEntry.getInjectionTargets();
-         if(targets != null)
-         {
-            for(ResourceInjectionTargetMetaData target : targets)
-            {
-               String className = target.getInjectionTargetClass();
-               String targetName = target.getInjectionTargetName();
-               Class<?> c = loader.loadClass(className);
-               AccessibleObject ao = Utils.getAccessibleObject(c, targetName);
-               BeanProperty prop = BeanPropertyFactory.create(ao);
-               JndiPropertyInjector propInjector = new JndiPropertyInjector(prop, encName, container.getEnc());
-               container.getInjectors().add(propInjector);
-            }
-         }
-         else
-         {
-            log.warn("No injection targets seen for: "+envEntry);
-         }
-         */
-         AccessibleObject ao = Utils.getAccessibleObject(clientClass, envEntry.getEnvEntryName());
-         BeanProperty prop = BeanPropertyFactory.create(ao);
-         JndiPropertyInjector propInjector = new JndiPropertyInjector(prop, encName, container.getEnc());
-         container.getInjectors().add(propInjector);         
+         Utils.injectionTarget(encName, envEntry, container);
       }
    }
 
@@ -117,15 +91,15 @@
 
          if (envRef.getMappedName() == null || envRef.getMappedName().equals(""))
          {
+            // Handle known injection types
             if (envRef.getResUrl() != null)
             {
                try
                {
                   URL resURL = new URL(envRef.getResUrl().trim());
-                  AccessibleObject ao = Utils.getAccessibleObject(clientClass, envRef.getResourceRefName());
-                  BeanProperty prop = BeanPropertyFactory.create(ao);
-                  URLPropertyInjector propInjector = new URLPropertyInjector(prop, resURL);
-                  container.getInjectors().add(propInjector); 
+                  URLInjectorFactory factory = new URLInjectorFactory(resURL);
+                  Utils.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
+                  continue;
                }
                catch (MalformedURLException e)
                {
@@ -142,15 +116,8 @@
                      return new UserTransactionPropertyInjector(property, ic);
                   }
                };
-               if(envRef.getInjectionTargets() != null)
-               {
-                  InjectionUtil.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
-                  continue;
-               }
-               else
-               {
-                  encName = "java:comp/UserTransaction";
-               }
+               Utils.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
+               continue;
             }
             else if (ORB.class.getName().equals(envRef.getType()))
             {
@@ -177,20 +144,8 @@
             if(resTypeName != null)
             {
                Class<?> resType = Class.forName(resTypeName);
-               if(EJBContext.class.isAssignableFrom(resType))
+               if (resType.equals(UserTransaction.class))
                {
-                  InjectorFactory<?> factory = new InjectorFactory<EJBContextPropertyInjector>()
-                  {
-                     public EJBContextPropertyInjector create(BeanProperty property)
-                     {
-                        return new EJBContextPropertyInjector(property);
-                     }
-                  };
-                  InjectionUtil.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
-                  continue;
-               }
-               else if (resType.equals(UserTransaction.class))
-               {
                   final InjectionContainer ic = container;
                   InjectorFactory<?> factory = new InjectorFactory<UserTransactionPropertyInjector>()
                   {
@@ -201,7 +156,7 @@
                   };
                   if(envRef.getInjectionTargets() != null)
                   {
-                     InjectionUtil.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
+                     Utils.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
                      continue;
                   }
                   else
@@ -237,19 +192,8 @@
          String encName = "env/" + envRef.getMessageDestinationRefName();
          String jndiName = envRef.getMappedName();
          if (jndiName == null || jndiName.equals(""))
-         {
-            // Look for a message-destination-link
-            String link = envRef.getLink();
-            if( link != null )
-            {
-               jndiName = container.resolveMessageDestination(link);
-               if (jndiName == null)
-                  throw new RuntimeException("message-destination-link not found " + link + " of deployment " + container.getIdentifier());
-               // TODO: add dependency
-            }
-            else
-               throw new RuntimeException("mapped-name or message-destination-link is required for " + envRef.getMessageDestinationRefName() + " of deployment " + container.getIdentifier());
-         }
+            throw new RuntimeException("mapped-name or message-destination-link is required for " + envRef.getMessageDestinationRefName() + " of deployment " + container.getIdentifier());
+            
          Utils.injectionTarget(encName, envRef, container);
       }
    }
@@ -270,16 +214,14 @@
 
    public void handleClassAnnotations(Class<?> clazz, InjectionContainer container)
    {
-      throw new IllegalStateException("Annotations are not handled");
+      throw new IllegalStateException("Annotations are not handled in the client");
    }
-
    public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
    {
-      throw new IllegalStateException("Annotations are not handled");
+      throw new IllegalStateException("Annotations are not handled in the client");
    }
-   
    public void handleFieldAnnotations(Field field, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
    {
-      throw new IllegalStateException("Annotations are not handled");
+      throw new IllegalStateException("Annotations are not handled in the client");
    }
 }

Added: trunk/ejb3/src/main/org/jboss/ejb3/client/URLInjectorFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/URLInjectorFactory.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/URLInjectorFactory.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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.ejb3.client;
+
+import java.net.URL;
+
+import org.jboss.injection.Injector;
+import org.jboss.injection.InjectorFactory;
+import org.jboss.injection.lang.reflect.BeanProperty;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class URLInjectorFactory
+   implements InjectorFactory<URLPropertyInjector>
+{
+   private URL url;
+
+   URLInjectorFactory(URL url)
+   {
+      this.url = url;
+   }
+
+   public URLPropertyInjector create(BeanProperty property)
+   {
+      return new URLPropertyInjector(property, url);
+   }
+
+}

Modified: trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java	2008-04-27 09:36:09 UTC (rev 72753)
+++ trunk/ejb3/src/main/org/jboss/ejb3/client/Utils.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -24,36 +24,52 @@
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.jboss.injection.InjectionContainer;
 import org.jboss.injection.Injector;
+import org.jboss.injection.InjectorFactory;
 import org.jboss.injection.JndiFieldInjector;
 import org.jboss.injection.JndiMethodInjector;
+import org.jboss.injection.JndiPropertyInjector;
+import org.jboss.injection.lang.reflect.BeanProperty;
+import org.jboss.injection.lang.reflect.BeanPropertyFactory;
 import org.jboss.metadata.javaee.spec.ResourceInjectionMetaData;
 import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
 
 /**
+ * Injection utilities
+ * 
  * @author Scott.Stark at jboss.org
  * @version $Revision:$
  */
 public class Utils
 {
-   static AccessibleObject getAccessibleObject(Class<?> c, String name)
+   /**
+    * Create and add multiple injectors for injection targets.
+    * 
+    * @param injectors          the list on which to add injectors
+    * @param classLoader        the class loader to resolve an injection target
+    * @param factory            the injector factory
+    * @param injectionTargets   the injection targets
+    */
+   public static void createInjectors(List<Injector> injectors,
+         ClassLoader classLoader,
+         InjectorFactory<?> factory,
+         Collection<ResourceInjectionTargetMetaData> injectionTargets)
    {
-      AccessibleObject ao = null;
-      try
+      if(injectionTargets == null)
+         return;
+
+      for(ResourceInjectionTargetMetaData injectionTarget : injectionTargets)
       {
-         Field f = c.getDeclaredField(name);
-         ao = f;
+         AccessibleObject ao = findInjectionTarget(classLoader, injectionTarget);
+         BeanProperty property = BeanPropertyFactory.create(ao);
+         injectors.add(factory.create(property));
       }
-      catch (NoSuchFieldException e)
-      {
-         String setter = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
-         // TODO
-      }
-      return ao;
    }
 
    public static Class<?> injectionTarget(String encName,
@@ -64,21 +80,23 @@
       
       if(ref.getInjectionTargets() == null)
          return injectionType;
-      
+
+      ClassLoader loader = container.getClassloader();
       for(ResourceInjectionTargetMetaData injectionTarget : ref.getInjectionTargets())
       {
-         // todo, get injection target class
-         AccessibleObject ao = findInjectionTarget(container.getClassloader(), injectionTarget);
+         AccessibleObject ao = findInjectionTarget(loader, injectionTarget);
+         BeanProperty prop = BeanPropertyFactory.create(ao);
+         JndiPropertyInjector propInjector = new JndiPropertyInjector(prop, encName, container.getEnc());
+         container.getInjectors().add(propInjector);
+         // Validate all the injection types are consistent
          Class<?> type;
          if (ao instanceof Field)
          {
             type = ((Field) ao).getType();
-            container.getInjectors().add(new JndiFieldInjector((Field) ao, encName, container.getEnc()));
          }
          else
          {
             type = ((Method) ao).getParameterTypes()[0];
-            container.getInjectors().add(new JndiMethodInjector((Method) ao, encName, container.getEnc()));
          }
          if(injectionType == null)
             injectionType = type;
@@ -105,12 +123,14 @@
 
       for (Field field : clazz.getDeclaredFields())
       {
-         if (target.getInjectionTargetName().equals(field.getName())) return field;
+         if (target.getInjectionTargetName().equals(field.getName()))
+            return field;
       }
 
-      for (java.lang.reflect.Method method : clazz.getDeclaredMethods())
+      for (Method method : clazz.getDeclaredMethods())
       {
-         if (method.getName().equals(target.getInjectionTargetName())) return method;
+         if (method.getName().equals(target.getInjectionTargetName()))
+            return method;
       }
 
       throw new RuntimeException("<injection-target> could not be found: " + target.getInjectionTargetClass() + "." + target.getInjectionTargetName());

Modified: trunk/testsuite/src/main/org/jboss/test/client/test/AppClientUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/client/test/AppClientUnitTestCase.java	2008-04-27 09:36:09 UTC (rev 72753)
+++ trunk/testsuite/src/main/org/jboss/test/client/test/AppClientUnitTestCase.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -28,6 +28,8 @@
 import javax.naming.NamingException;
 import javax.jms.Queue;
 
+import org.jboss.ejb3.client.ClientLauncher;
+import org.jboss.test.client.test.main.Client;
 import org.jboss.test.cts.interfaces.StatelessSession;
 import org.jboss.test.cts.interfaces.StatelessSessionHome;
 import org.jboss.test.JBossTestCase;
@@ -48,13 +50,30 @@
       super(name);
    }
 
+   /**
+    * Validate the ClientLauncher for the test-client deployment/main class
+    * @throws Throwable
+    */
+   public void testClientLauncher()
+      throws Throwable
+   {
+      String mainClassName = Client.class.getName();
+      // must match JNDI name in jboss-client.xml or display-name in application-client.xml
+      String applicationClientName = "test-client";
+      String[] args = {};
+      
+      ClientLauncher launcher = new ClientLauncher();
+      Properties env = getENCProps(applicationClientName);
+      launcher.launch(mainClassName, applicationClientName, args, env);
+   }
+
    /** Test that the client java:comp/env context contains what is expected
     * @throws Exception
     */ 
    public void testENC() throws Exception
    {
       Context enc = getENC();
-      getLog().debug("ENC: "+enc);
+      log.debug("testENC, ENC.env:"+enc.getEnvironment());
 
       String str0 = (String) enc.lookup("String0");
       assertTrue("String0 == String0Value", str0.equals("String0Value"));
@@ -104,17 +123,21 @@
     */ 
    private Context getENC() throws NamingException
    {
+      Properties env = getENCProps("test-client");
+      InitialContext ctx = new InitialContext(env);
+      Context enc = (Context) ctx.lookup("java:comp/env");
+      return enc;
+   }
+   private Properties getENCProps(String applicationClientName)
+   {
       Properties env = new Properties();
       env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
          "org.jnp.interfaces.NamingContextFactory");
       env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
       env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
-      env.setProperty("j2ee.clientName", "test-client");
-      InitialContext ctx = new InitialContext(env);
-      Context enc = (Context) ctx.lookup("java:comp/env");
-      return enc;
+      env.setProperty("j2ee.clientName", applicationClientName);
+      return env;
    }
-
    public static Test suite() throws Exception
    {
       TestSuite suite = new TestSuite();

Added: trunk/testsuite/src/main/org/jboss/test/client/test/main/Client.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/client/test/main/Client.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/client/test/main/Client.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * 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.client.test.main;
+
+import java.net.URL;
+
+import javax.jms.Queue;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.cts.interfaces.StatelessSession;
+import org.jboss.test.cts.interfaces.StatelessSessionHome;
+
+/**
+ * A javaee application client
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class Client
+{
+   private static Logger log = Logger.getLogger(Client.class);
+
+   static void assertTrue(String msg, boolean exp)
+   {
+      if(exp == false)
+         throw new IllegalStateException(msg);
+   }
+   /** Test that the client java:comp/env context contains what is expected
+    * @throws Exception
+    */ 
+   public static void testENC() throws Exception
+   {
+      log.info("+++ testENC");
+      Context enc = getENC();
+
+      String str0 = (String) enc.lookup("String0");
+      assertTrue("String0 == String0Value", str0.equals("String0Value"));
+
+      Float flt0 = (Float) enc.lookup("Float0");
+      assertTrue("Float0 == 3.14", flt0.equals(new Float("3.14")));
+
+      Long long0 = (Long) enc.lookup("Long0");
+      assertTrue("Long0 == 123456789", long0.equals(new Long(123456789)));
+
+      StatelessSessionHome home = (StatelessSessionHome) enc.lookup("ejb/StatelessSessionBean");
+      assertTrue("ejb/StatelessSessionBean isa StatelessSessionHome", home != null);
+
+      URL jbossHome = (URL) enc.lookup("url/JBossHome");
+      assertTrue("url/JBossHome == http://www.jboss.org",
+         jbossHome.toString().equals("http://www.jboss.org"));
+
+      URL indirectURL = (URL) enc.lookup("url/IndirectURL");
+      assertTrue("url/IndirectURL == http://www.somesite.com",
+         indirectURL.toString().equals("http://www.somesite.com"));
+
+      Queue testQueue = (Queue) enc.lookup("jms/aQueue");
+      assertTrue("jms/aQueue isa Queue", testQueue != null);
+
+      Queue anotherQueue = (Queue) enc.lookup("jms/anotherQueue");
+      assertTrue("jms/anotherQueue isa Queue", anotherQueue != null);
+
+      Queue anotherQueue2 = (Queue) enc.lookup("jms/anotherQueue2");
+      assertTrue("jms/anotherQueue2 isa Queue", anotherQueue2 != null);
+   }
+   /** Test access to EJBs located through the java:comp/env context
+    * @throws Exception
+    */ 
+   static void testEjbs() throws Exception
+   {
+      log.info("+++ testEjbs");
+      Context enc = getENC();      
+      StatelessSessionHome home = (StatelessSessionHome) enc.lookup("ejb/StatelessSessionBean");
+      StatelessSession session = home.create();
+      session.method1("testEjbs");
+      session.remove();
+   }
+
+   static Context getENC()
+      throws NamingException
+   {
+      Context ic = new InitialContext();
+      log.debug("Client, ENC.env:"+ic.getEnvironment());
+      Context enc = (Context) ic.lookup("java:comp/env");
+      return enc;
+   }
+   public static void main(String[] args)
+      throws Exception
+   {
+      testENC();
+      testEjbs();
+   }
+}

Modified: trunk/testsuite/src/main/org/jboss/test/ee5client/unit/AppClientUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ee5client/unit/AppClientUnitTestCase.java	2008-04-27 09:36:09 UTC (rev 72753)
+++ trunk/testsuite/src/main/org/jboss/test/ee5client/unit/AppClientUnitTestCase.java	2008-04-27 14:01:28 UTC (rev 72754)
@@ -25,8 +25,6 @@
 import java.util.Properties;
 
 import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 
 import junit.framework.Test;
 
@@ -35,9 +33,10 @@
 import org.jboss.test.ee5client.client.HelloWorldClient;
 
 /**
- * Comment
+ * A basic EE5 application client test case
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author Scott.Stark at jboss.org
  * @version $Revision: $
  */
 public class AppClientUnitTestCase extends JBossTestCase
@@ -84,6 +83,5 @@
    public static Test suite() throws Exception
    {
       return getDeploySetup(AppClientUnitTestCase.class, "ee5client-jms-service.xml,ee5client-test.ear");
-      //return getDeploySetup(AppClientUnitTestCase.class, "appclient-test.jar,appclient-test-client.jar");
    }
 }


Property changes on: trunk/testsuite/src/main/org/jboss/test/ee5client/unit/AppClientUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Revision Id




More information about the jboss-cvs-commits mailing list