geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/jmx ContextTest.java TestObject.java
Date Sun, 16 Nov 2003 05:24:38 GMT
djencks     2003/11/15 21:24:38

  Modified:    modules/core/src/java/org/apache/geronimo/naming/java
                        ComponentContextBuilder.java ReadOnlyContext.java
                        ReferenceFactory.java
               modules/core/src/java/org/apache/geronimo/naming/jmx
                        JMXReferenceFactory.java
               modules/core/src/test/org/apache/geronimo/naming/java
                        ContextBuilderTest.java
               modules/core/src/test/org/apache/geronimo/naming/jmx
                        ContextTest.java TestObject.java
  Log:
  Improve ReadOnlyContext bindings and tests thereon.
  
  Revision  Changes    Path
  1.10      +23 -5     incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
  
  Index: ComponentContextBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ComponentContextBuilder.java	13 Nov 2003 04:30:56 -0000	1.9
  +++ ComponentContextBuilder.java	16 Nov 2003 05:24:38 -0000	1.10
  @@ -68,6 +68,7 @@
   import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDIEnvironmentRefs;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDILocator;
  +import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbLocalRef;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
   import org.apache.geronimo.kernel.deployment.DeploymentException;
   
  @@ -96,6 +97,7 @@
           Map envMap = new HashMap();
           buildEnvEntries(envMap, refs.getEnvEntry());
           buildEJBRefs(envMap, refs.getGeronimoEJBRef());
  +        buildEJBLocalRefs(envMap, refs.getGeronimoEJBLocalRef());
           buildResourceRefs(envMap, refs.getGeronimoResourceRef());
   
           Map compMap = new HashMap();
  @@ -152,12 +154,28 @@
               String name = ejbRef.getEJBRefName();
               Reference ref = null;
               try {
  -                ref = referenceFactory.getReference(ejbRef, ejbRef.getEJBRefType());
  +                ref = referenceFactory.getReference(ejbRef.getEJBLink(), ejbRef);
               } catch (NamingException e) {
  -                throw new DeploymentException("Could not construct reference to " + ejbRef.getJndiName());
  +                throw new DeploymentException("Could not construct reference to " + ejbRef.getJndiName()
+ ", " + e.getMessage());
               }
               if (envMap.put(name, ref) != null) {
  -                throw new AssertionError("Duplicate entry for env-entry " + name);
  +                throw new DeploymentException("Duplicate entry for env-entry " + name);
  +            }
  +        }
  +    }
  +
  +    private void buildEJBLocalRefs(Map envMap, EjbLocalRef[] ejbLocalRefs) throws DeploymentException
{
  +        for (int i = 0; i < ejbLocalRefs.length; i++) {
  +            EjbLocalRef ejbLocalRef = ejbLocalRefs[i];
  +            String name = ejbLocalRef.getEJBRefName();
  +            Reference ref = null;
  +            try {
  +                ref = referenceFactory.getReference(ejbLocalRef.getEJBLink(), ejbLocalRef);
  +            } catch (NamingException e) {
  +                throw new DeploymentException("Could not construct reference to " + ejbLocalRef.getJndiName()
+ ", " + e.getMessage());
  +            }
  +            if (envMap.put(name, ref) != null) {
  +                throw new DeploymentException("Duplicate entry for env-entry " + name);
               }
           }
       }
  @@ -176,7 +194,7 @@
                   }
               } else {
                   try {
  -                    ref = referenceFactory.getReference(resRef, "ConnectionFactory");
  +                    ref = referenceFactory.getReference(null, resRef);
                   } catch (NamingException e) {
                       throw new DeploymentException("Could not construct reference to " +
resRef.getJndiName());
                   }
  
  
  
  1.6       +3 -3      incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
  
  Index: ReadOnlyContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ReadOnlyContext.java	13 Nov 2003 04:30:56 -0000	1.5
  +++ ReadOnlyContext.java	16 Nov 2003 05:24:38 -0000	1.6
  @@ -156,11 +156,11 @@
                   String scheme = name.substring(0, pos);
                   Context ctx = NamingManager.getURLContext(scheme, env);
                   if (ctx == null) {
  -                    throw new NamingException();
  +                    throw new NamingException("scheme " + scheme + " not recognized");
                   }
                   return ctx.lookup(name);
               }
  -            throw new NameNotFoundException();
  +            throw new NameNotFoundException(name);
           }
           if (result instanceof LinkRef) {
               LinkRef ref = (LinkRef) result;
  
  
  
  1.3       +4 -4      incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReferenceFactory.java
  
  Index: ReferenceFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ReferenceFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReferenceFactory.java	13 Nov 2003 22:22:30 -0000	1.2
  +++ ReferenceFactory.java	16 Nov 2003 05:24:38 -0000	1.3
  @@ -6,12 +6,12 @@
   import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDILocator;
   
   /**
  - * 
  + *
    *
    * @version $Revision$ $Date$
  - * 
  + *
    * */
   public interface ReferenceFactory {
   
  -    Reference getReference(JNDILocator locator, String type) throws NamingException;
  +    Reference getReference(String link, JNDILocator locator) throws NamingException;
   }
  
  
  
  1.3       +12 -9     incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/jmx/JMXReferenceFactory.java
  
  Index: JMXReferenceFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/jmx/JMXReferenceFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JMXReferenceFactory.java	13 Nov 2003 22:22:31 -0000	1.2
  +++ JMXReferenceFactory.java	16 Nov 2003 05:24:38 -0000	1.3
  @@ -62,6 +62,9 @@
   
   import org.apache.geronimo.naming.java.ReferenceFactory;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDILocator;
  +import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
  +import org.apache.geronimo.deployment.model.j2ee.EJBRef;
  +import org.apache.geronimo.deployment.model.j2ee.EJBLocalRef;
   
   /**
    * This is a preliminary implementation that makes several unwarranted and redundant assumptions
such as:
  @@ -75,8 +78,8 @@
    * */
   public class JMXReferenceFactory implements ReferenceFactory {
   
  -    private final static String EJB_HOME = "Home";
  -    private final static String EJB_LOCAL_HOME = "LocalHome";
  +    private final static String SESSION = "Session";
  +    private final static String ENTITY = "Entity";
       private final static String CONNECTION_FACTORY = "ConnectionFactory";
   
       private final String mbeanServerId;
  @@ -85,20 +88,20 @@
           this.mbeanServerId = mbeanServerId;
       }
   
  -    public Reference getReference(JNDILocator locator, String type) throws NamingException
{
  +    public Reference getReference(String link, JNDILocator locator) throws NamingException
{
           String methodName;
  -        if (EJB_HOME.equals(type)) {
  +        if (locator instanceof EJBRef) {
               methodName = "getEJBHome";
  -        } else if (EJB_LOCAL_HOME.equals(type)) {
  +        } else if (locator instanceof EJBLocalRef) {
               methodName = "getEJBLocalHome";
  -        } else if (CONNECTION_FACTORY.equals(type)) {
  +        } else if (locator instanceof ResourceRef) {
               methodName = "getConnectionFactory";
           } else {
  -            throw new NamingException("Invalid type: " + type);
  +            throw new NamingException("Invalid type: " + locator);
           }
   
           return new LinkRef(JMXContext.encode(mbeanServerId,
  -                locator.getJndiName(),
  +                (link == null)? locator.getJndiName(): link,
                   methodName));
       }
   }
  
  
  
  1.9       +57 -21    incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java
  
  Index: ContextBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ContextBuilderTest.java	16 Nov 2003 02:09:36 -0000	1.8
  +++ ContextBuilderTest.java	16 Nov 2003 05:24:38 -0000	1.9
  @@ -69,6 +69,7 @@
   import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbLocalRef;
  +import org.apache.geronimo.deployment.model.geronimo.ejb.Session;
   import org.apache.geronimo.transaction.manager.UserTransactionImpl;
   import org.apache.geronimo.kernel.jmx.JMXKernel;
   import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
  @@ -80,24 +81,28 @@
    * @version $Revision$ $Date$
    */
   public class ContextBuilderTest extends TestCase {
  -    private static final String objectName1 = "geronimo.test:name=test1";
  -    private static final String objectName2 = "geronimo.test:name=test2";
  -
  -    private ApplicationClient client;
  -
  -    private Context compCtx;
  -    private JMXKernel kernel;
  -    private ReferenceFactory referenceFactory;
  -    private TestObject testObject1 = new TestObject(new Object());
  -    private TestObject testObject2 = new TestObject(new Object());
  +    protected static final String objectName1 = "geronimo.test:name=test1";
  +    protected static final String objectName2 = "geronimo.test:name=test2";
  +    protected static final String objectName3 = "geronimo.test:name=test3";
  +
  +    protected ApplicationClient client;
  +    protected Session session;
  +    protected Context compCtx;
  +    protected JMXKernel kernel;
  +    protected ReferenceFactory referenceFactory;
  +    protected TestObject testObject1 = new TestObject();
  +    protected TestObject testObject2 = new TestObject();
  +    protected TestObject testObject3 = new TestObject();
   
       protected void setUp() throws Exception {
           kernel = new JMXKernel("geronimo.test");
           kernel.getMBeanServer().registerMBean(testObject1, ObjectName.getInstance(objectName1));
           kernel.getMBeanServer().registerMBean(testObject2, ObjectName.getInstance(objectName2));
  +        kernel.getMBeanServer().registerMBean(testObject3, ObjectName.getInstance(objectName3));
   
           referenceFactory = new JMXReferenceFactory(kernel.getMBeanServerId());
           client = new ApplicationClient();
  +        session = new Session();
           EnvEntry stringEntry = new EnvEntry();
           stringEntry.setEnvEntryName("string");
           stringEntry.setEnvEntryType("java.lang.String");
  @@ -109,15 +114,24 @@
   
           EjbRef ejbRef = new EjbRef();
           ejbRef.setEJBRefName("here/there/EJB1");
  -        ejbRef.setEJBRefType("Home");
  +        ejbRef.setEJBRefType("Session");
           ejbRef.setJndiName(objectName1);
   
  -        //EjbLocalRef ejbLocalRef = new EjbLocalRef();
  -        EjbRef ejbLocalRef = new EjbRef();
  +        EjbRef ejbLinkRef = new EjbRef();
  +        ejbLinkRef.setEJBRefName("here/LinkEjb");
  +        ejbLinkRef.setEJBRefType("Session");
  +        ejbLinkRef.setEJBLink(objectName3);
  +
  +        EjbLocalRef ejbLocalRef = new EjbLocalRef();
           ejbLocalRef.setEJBRefName("local/here/LocalEJB2");
  -        ejbLocalRef.setEJBRefType("LocalHome");
  +        ejbLocalRef.setEJBRefType("Entity");
           ejbLocalRef.setJndiName(objectName2);
   
  +        EjbLocalRef ejbLocalLinkRef = new EjbLocalRef();
  +        ejbLocalLinkRef.setEJBRefName("local/here/LinkLocalEjb");
  +        ejbLocalLinkRef.setEJBRefType("Entity");
  +        ejbLocalLinkRef.setEJBLink(objectName3);
  +
           ResourceRef urlRef = new ResourceRef();
           urlRef.setResRefName("url/testURL");
           urlRef.setResType(URL.class.getName());
  @@ -128,12 +142,13 @@
           cfRef.setJndiName(objectName1);
   
           client.setEnvEntry(new EnvEntry[] { stringEntry, intEntry });
  -        //client.setEJBRef(new EjbRef[] {ejbRef});
  -        client.setEJBRef(new EjbRef[] {ejbRef, ejbLocalRef});
  -        //client.setEJBLocalRef(new EjbLocalRef[] {ejbLocalRef});
  -
  +        session.setEnvEntry(client.getEnvEntry());
  +        client.setEJBRef(new EjbRef[] {ejbRef, ejbLinkRef});
  +        session.setEJBRef(client.getEJBRef());
  +        session.setEJBLocalRef(new EjbLocalRef[] {ejbLocalRef, ejbLocalLinkRef});
   
           client.setResourceRef(new ResourceRef[] { urlRef, cfRef });
  +        session.setResourceRef(client.getResourceRef());
       }
   
       public void testEnvEntries() throws Exception {
  @@ -157,15 +172,36 @@
           assertEquals(userTransaction, compCtx.lookup("UserTransaction"));
       }
   
  -    public void testEJBRefs() throws Exception {
  +    public void testClientEJBRefs() throws Exception {
           ReadOnlyContext compContext = new ComponentContextBuilder(referenceFactory, null).buildContext(client);
           RootContext.setComponentContext(compContext);
           InitialContext initialContext = new InitialContext();
           assertEquals("Expected object from testObject1", testObject1.getEJBHome(),
                   initialContext.lookup("java:comp/env/here/there/EJB1"));
  -        assertEquals("Expected object from testObject2", testObject2.getEJBLocalHome(),
  +        assertEquals("Expected object from testObject3", testObject3.getEJBHome(),
  +                initialContext.lookup("java:comp/env/here/LinkEjb"));
  +        assertEquals("Expected object from testObject1", testObject1.getConnectionFactory(),
  +                initialContext.lookup("java:comp/env/DefaultCF"));
  +    }
  +
  +    public void testLocalEJBRefs() throws Exception {
  +        ReadOnlyContext compContext = new ComponentContextBuilder(referenceFactory, null).buildContext(session);
  +        RootContext.setComponentContext(compContext);
  +        InitialContext initialContext = new InitialContext();
  +        assertEquals("Expected object from testObject1", testObject1.getEJBHome(),
  +                initialContext.lookup("java:comp/env/here/there/EJB1"));
  +
  +        assertEquals("Expected object from testObject3", testObject3.getEJBHome(),
  +                initialContext.lookup("java:comp/env/here/LinkEjb"));
  +
  +        assertEquals("Expected object from testObject1", testObject2.getEJBLocalHome(),
                   initialContext.lookup("java:comp/env/local/here/LocalEJB2"));
  +
  +        assertEquals("Expected object from testObject3", testObject3.getEJBLocalHome(),
  +                initialContext.lookup("java:comp/env/local/here/LinkLocalEjb"));
  +
           assertEquals("Expected object from testObject1", testObject1.getConnectionFactory(),
                   initialContext.lookup("java:comp/env/DefaultCF"));
       }
  +
   }
  
  
  
  1.3       +11 -11    incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/jmx/ContextTest.java
  
  Index: ContextTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/jmx/ContextTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ContextTest.java	13 Nov 2003 22:22:31 -0000	1.2
  +++ ContextTest.java	16 Nov 2003 05:24:38 -0000	1.3
  @@ -79,10 +79,10 @@
   import org.apache.geronimo.naming.java.RootContext;
   
   /**
  - * 
  + *
    *
    * @version $Revision$ $Date$
  - * 
  + *
    * */
   public class ContextTest extends TestCase {
   
  @@ -91,16 +91,16 @@
   
       private MBeanServer server;
       private String agentId;
  -    private Object payload = new Object();
       private ObjectName objectName;
       private JMXKernel kernel;
  +    private TestObject mbean;
   
       protected void setUp() throws Exception {
           kernel = new JMXKernel("geronimo.test");
           server = kernel.getMBeanServer();
           agentId = kernel.getMBeanServerId();
           objectName = new ObjectName(on1);
  -        Object mbean = new TestObject(payload);
  +        mbean = new TestObject();
           server.registerMBean(mbean, objectName);
       }
   
  @@ -111,13 +111,13 @@
       public void testLookupString() throws Exception {
           JMXContext context = new JMXContext(new Hashtable());
           Object result = context.lookup(JMXContext.encode(agentId, on1, mn1));
  -        assertTrue("Expected the supplied object back", result == payload);
  +        assertTrue("Expected the ", result == mbean.getEJBHome());
       }
   
       public void testLookupName() throws Exception {
           JMXContext context = new JMXContext(new Hashtable());
           Object result = context.lookup(new CompositeName(JMXContext.encode(agentId, on1,
mn1)));
  -        assertTrue("Expected the supplied object back", result == payload);
  +        assertTrue("Expected the supplied object back", result == mbean.getEJBHome());
       }
   
       public void testWrongObjectName() throws Exception {
  @@ -144,7 +144,7 @@
           jmxURLContextFactory contextFactory = new jmxURLContextFactory();
           Context context = (Context)contextFactory.getObjectInstance(null, null, null, new
Hashtable());
           Object result = context.lookup(JMXContext.encode(agentId, on1, mn1));
  -        assertTrue("Expected the supplied object back", result == payload);
  +        assertTrue("Expected the supplied object back", result == mbean.getEJBHome());
       }
   
   
  @@ -162,11 +162,11 @@
           Context envContext = (Context) initialContext.lookup("java:comp/env");
   
           Object result = initialContext.lookup("java:comp/env/link");
  -        assertTrue("Expected the supplied object back", result == payload);
  +        assertTrue("Expected the supplied object back", result == mbean.getEJBHome());
           result = compContext.lookup("env/link");
  -        assertTrue("Expected the supplied object back", result == payload);
  +        assertTrue("Expected the supplied object back", result == mbean.getEJBHome());
           result = envContext.lookup("link");
  -        assertTrue("Expected the supplied object back", result == payload);
  +        assertTrue("Expected the supplied object back", result == mbean.getEJBHome());
       }
   
   
  
  
  
  1.3       +10 -9     incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/jmx/TestObject.java
  
  Index: TestObject.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/jmx/TestObject.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestObject.java	13 Nov 2003 22:22:31 -0000	1.2
  +++ TestObject.java	16 Nov 2003 05:24:38 -0000	1.3
  @@ -59,29 +59,30 @@
   import javax.ejb.EJBHome;
   
   /**
  - * 
  + *
    *
    * @version $Revision$ $Date$
  - * 
  + *
    * */
   public class TestObject implements TestObjectMBean {
   
  -    private Object payload;
  +    private Object home = new Object();
  +    private Object local = new Object();
  +    private Object cf = new Object();
   
  -    public TestObject(Object payload) {
  -        this.payload = payload;
  +    public TestObject() {
       }
   
       public Object getEJBHome() {
  -        return payload;
  +        return home;
       }
   
       public Object getEJBLocalHome() {
  -        return payload;
  +        return local;
       }
   
       public Object getConnectionFactory() {
  -        return payload;
  +        return cf;
       }
   
   
  
  
  

Mime
View raw message