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/naming/src/test/org/apache/geronimo/naming/jmx TestObject.java
Date Fri, 13 Feb 2004 23:41:47 GMT
djencks     2004/02/13 15:41:47

  Modified:    modules/naming/src/java/org/apache/geronimo/naming/java
                        ReadOnlyContext.java
               modules/naming/src/test/org/apache/geronimo/naming/java
                        AbstractContextTest.java
  Added:       modules/naming/src/java/org/apache/geronimo/naming/deployment
                        ComponentContextBuilder.java
               modules/naming/src/schema geronimo-naming.xsd xmlconfig.xml
               modules/naming/src/test/org/apache/geronimo/naming/deployment
                        ContextBuilderTest.java
  Removed:     modules/naming/src/java/org/apache/geronimo/naming/java
                        ComponentContextBuilder.java
               modules/naming/src/test/org/apache/geronimo/naming/jmx
                        TestObject.java
  Log:
  Add a schema for geronimo naming stuff, fix the tests
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/deployment/ComponentContextBuilder.java
  
  Index: ComponentContextBuilder.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.naming.deployment;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import javax.naming.NamingException;
  import javax.transaction.UserTransaction;
  
  import org.apache.geronimo.deployment.DeploymentException;
  import org.apache.geronimo.xbeans.geronimo.GerEjbLocalRefType;
  import org.apache.geronimo.xbeans.geronimo.GerEjbRefType;
  import org.apache.geronimo.xbeans.geronimo.GerMessageDestinationRefType;
  import org.apache.geronimo.xbeans.geronimo.GerResourceEnvRefType;
  import org.apache.geronimo.xbeans.geronimo.GerResourceRefType;
  import org.apache.geronimo.xbeans.j2ee.EjbLocalRefType;
  import org.apache.geronimo.xbeans.j2ee.EjbRefType;
  import org.apache.geronimo.xbeans.j2ee.EnvEntryType;
  import org.apache.geronimo.xbeans.j2ee.MessageDestinationRefType;
  import org.apache.geronimo.xbeans.j2ee.ResourceEnvRefType;
  import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
  import org.apache.geronimo.xbeans.j2ee.EjbLinkType;
  import org.apache.geronimo.xbeans.j2ee.MessageDestinationLinkType;
  import org.apache.geronimo.naming.java.ProxyFactory;
  import org.apache.geronimo.naming.java.ReadOnlyContext;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/13 23:41:47 $
   */
  public class ComponentContextBuilder {
  
      private static final String ENV = "env/";
  
      private final ProxyFactory proxyFactory;
      private final ClassLoader cl;
  
      public ComponentContextBuilder(ProxyFactory proxyFactory, ClassLoader cl) {
          this.proxyFactory = proxyFactory;
          this.cl = cl;
      }
  
      /**
       * Build a component context from definitions contained in POJOs read from
       * a deployment descriptor.
       * @return a Context that can be bound to java:comp
       */
      public ReadOnlyContext buildContext(EjbRefType[] ejbRefs, GerEjbRefType[] gerEjbRefs,
                                          EjbLocalRefType[] ejbLocalRefs, GerEjbLocalRefType[]
gerEjbLocalRefs,
                                          EnvEntryType[] envEntries,
                                          MessageDestinationRefType[] messageDestinationRefs,
GerMessageDestinationRefType[] gerMessageDestinationRefs ,
                                          ResourceEnvRefType[] resourceEnvRefs, GerResourceEnvRefType[]
gerResourceEnvRefs,
                                          ResourceRefType[] resourceRefs, GerResourceRefType[]
gerResourceRefs,
                                          UserTransaction userTransaction) throws DeploymentException
{
          ReadOnlyContext readOnlyContext = new ReadOnlyContext();
          buildEnvEntries(readOnlyContext, envEntries);
          buildEJBRefs(readOnlyContext, ejbRefs, gerEjbRefs);
          buildEJBLocalRefs(readOnlyContext, ejbLocalRefs, gerEjbLocalRefs);
          buildMessageDestinationRefs(readOnlyContext, messageDestinationRefs, gerMessageDestinationRefs);
          buildResourceEnvRefs(readOnlyContext, resourceEnvRefs, gerResourceEnvRefs);
          buildResourceRefs(readOnlyContext, resourceRefs, gerResourceRefs);
  
          if (userTransaction != null) {
              try {
                  readOnlyContext.externalBind("UserTransaction", userTransaction);
              } catch (NamingException e) {
                  throw new DeploymentException("could not bind UserTransaction", e);
              }
          }
          readOnlyContext.freeze();
          return readOnlyContext;
      }
  
      private void buildEnvEntries(ReadOnlyContext readOnlyContext, EnvEntryType[] envEntries)
throws DeploymentException {
          if (envEntries == null) {
              return;
          }
          for (int i = 0; i < envEntries.length; i++) {
              EnvEntryType entry = envEntries[i];
              String name = entry.getEnvEntryName().getStringValue();
              String type = entry.getEnvEntryType().getStringValue();
              String value = entry.getEnvEntryValue().getStringValue();
              Object mapEntry;
              try {
                  if (value == null) {
                      mapEntry = null;
                  } else if ("java.lang.String".equals(type)) {
                      mapEntry = value;
                  } else if ("java.lang.Character".equals(type)) {
                      mapEntry = new Character(value.charAt(0));
                  } else if ("java.lang.Boolean".equals(type)) {
                      mapEntry = Boolean.valueOf(value);
                  } else if ("java.lang.Byte".equals(type)) {
                      mapEntry = Byte.valueOf(value);
                  } else if ("java.lang.Short".equals(type)) {
                      mapEntry = Short.valueOf(value);
                  } else if ("java.lang.Integer".equals(type)) {
                      mapEntry = Integer.valueOf(value);
                  } else if ("java.lang.Long".equals(type)) {
                      mapEntry = Long.valueOf(value);
                  } else if ("java.lang.Float".equals(type)) {
                      mapEntry = Float.valueOf(value);
                  } else if ("java.lang.Double".equals(type)) {
                      mapEntry = Double.valueOf(value);
                  } else {
                      throw new AssertionError("Invalid class for env-entry " + name + ",
" + type);
                  }
              } catch (NumberFormatException e) {
                  throw new DeploymentException("Invalid numeric value for env-entry " + name
+ ", value=" + value);
              }
              try {
                  readOnlyContext.externalBind(ENV + name, mapEntry);
              } catch (NamingException e) {
                  throw new DeploymentException("Could not bind", e);
              }
          }
      }
  
      private void buildEJBRefs(ReadOnlyContext readOnlyContext, EjbRefType[] ejbRefs, GerEjbRefType[]
gerEjbRefs) throws DeploymentException {
          if (ejbRefs == null) {
              return;
          }
          assert ejbRefs.length == gerEjbRefs.length;
          for (int i = 0; i < ejbRefs.length; i++) {
              EjbRefType ejbRef = ejbRefs[i];
              String name = ejbRef.getEjbRefName().getStringValue();
              assert name.equals(gerEjbRefs[i].getEjbRefName().getStringValue());
              Object proxy = null;
              try {
                  proxy = proxyFactory.getProxy(loadClass(ejbRef.getHome().getStringValue()),
loadClass(ejbRef.getRemote().getStringValue()), getLink(gerEjbRefs[i].getUri(), ejbRef.getEjbLink()));
              } catch (NamingException e) {
                  throw new DeploymentException("Could not construct proxy for " + ejbRef
+ ", " + e.getMessage());
              }
              try {
                  readOnlyContext.externalBind(ENV + name, proxy);
              } catch (NamingException e) {
                  throw new DeploymentException("could not bind", e);
              }
          }
      }
  
      private void buildEJBLocalRefs(ReadOnlyContext readOnlyContext, EjbLocalRefType[] ejbLocalRefs,
GerEjbLocalRefType[] gerEjbLocalRefs) throws DeploymentException {
          if (ejbLocalRefs == null) {
              return;
          }
          assert ejbLocalRefs.length == gerEjbLocalRefs.length;
          for (int i = 0; i < ejbLocalRefs.length; i++) {
              EjbLocalRefType ejbLocalRef = ejbLocalRefs[i];
              String name = ejbLocalRef.getEjbRefName().getStringValue();
              assert name.equals(gerEjbLocalRefs[i].getEjbRefName().getStringValue());
              Object proxy = null;
              try {
                  proxy = proxyFactory.getProxy(loadClass(ejbLocalRef.getLocalHome().getStringValue()),
loadClass(ejbLocalRef.getLocal().getStringValue()), getLink(gerEjbLocalRefs[i].getUri(), ejbLocalRef.getEjbLink()));
              } catch (NamingException e) {
                  throw new DeploymentException("Could not construct reference to " + ejbLocalRef
+ ", " + e.getMessage());
              }
              try {
                  readOnlyContext.externalBind(ENV + name, proxy);
              } catch (NamingException e) {
                  throw new DeploymentException("Could not bind", e);
              }
          }
      }
  
      private void buildMessageDestinationRefs(ReadOnlyContext readOnlyContext, MessageDestinationRefType[]
messageDestinationRefs, GerMessageDestinationRefType[] gerMessageDestinationRefs) throws DeploymentException
{
          if (messageDestinationRefs == null) {
              return;
          }
          assert messageDestinationRefs.length == gerMessageDestinationRefs.length;
          for (int i = 0; i < messageDestinationRefs.length; i++) {
              MessageDestinationRefType messageDestination = messageDestinationRefs[i];
              String name = messageDestination.getMessageDestinationRefName().getStringValue();
              assert name.equals(gerMessageDestinationRefs[i].getMessageDestinationRefName().getStringValue());
              Object proxy = null;
              try {
                  proxy = proxyFactory.getProxy(loadClass(messageDestination.getMessageDestinationType().getStringValue()),
getLink(gerMessageDestinationRefs[i].getUri(), messageDestination.getMessageDestinationLink()));
              } catch (NamingException e) {
                  throw new DeploymentException("Could not construct reference to " + messageDestination
+ ", " + e.getMessage());
              }
              try {
                  readOnlyContext.externalBind(ENV + name, proxy);
              } catch (NamingException e) {
                  throw new DeploymentException("Could not bind", e);
              }
          }
      }
  
      private void buildResourceEnvRefs(ReadOnlyContext readOnlyContext, ResourceEnvRefType[]
resourceEnvRefs, GerResourceEnvRefType[] gerResourceEnvRefs) throws DeploymentException {
          if (resourceEnvRefs == null) {
              return;
          }
          assert resourceEnvRefs.length == gerResourceEnvRefs.length;
          for (int i = 0; i < resourceEnvRefs.length; i++) {
              ResourceEnvRefType resEnvRef = resourceEnvRefs[i];
              String name = resEnvRef.getResourceEnvRefName().getStringValue();
              assert name.equals(gerResourceEnvRefs[i].getResourceEnvRefName().getStringValue());
              Object proxy = null;
              try {
                  proxy = proxyFactory.getProxy(loadClass(resEnvRef.getResourceEnvRefType().getStringValue()),
getLink(gerResourceEnvRefs[i].getUri()));
              } catch (NamingException e) {
                  throw new DeploymentException("Could not construct reference to " + resEnvRef
+ ", " + e.getMessage());
              }
              try {
                  readOnlyContext.externalBind(ENV + name, proxy);
              } catch (NamingException e) {
                  throw new DeploymentException("Could not bind", e);
              }
          }
      }
  
      private void buildResourceRefs(ReadOnlyContext readOnlyContext, ResourceRefType[] resRefs,
GerResourceRefType[] gerResRefs) throws DeploymentException {
          if (resRefs == null) {
              return;
          }
          assert resRefs.length == gerResRefs.length;
          for (int i=0; i < resRefs.length; i++) {
              ResourceRefType resRef = resRefs[i];
              String name = resRef.getResRefName().getStringValue();
              assert name.equals(gerResRefs[i].getResRefName().getStringValue());
              String type = resRef.getResType().getStringValue();
              Object proxy;
              if ("java.net.URL".equals(type)) {
                  //for some reason the spec regards URL as a connection factory...
                  try {
                      proxy = new URL(gerResRefs[i].getUri());
                  } catch (MalformedURLException e) {
                      throw new DeploymentException("Invalid URL for resource-proxy "+name,
e);
                  }
              } else {
                  try {
                      proxy = proxyFactory.getProxy(loadClass(resRef.getResType().getStringValue()),
getLink(gerResRefs[i].getUri()));
                  } catch (NamingException e) {
                      throw new DeploymentException("Could not construct reference to " +
resRef);
                  }
              }
              try {
                  readOnlyContext.externalBind(ENV + name, proxy);
              } catch (NamingException e) {
                  throw new DeploymentException("Could not bind", e);
              }
          }
      }
  
      //TODO figure out how to use the link properly.
      private Object getLink(String uri, EjbLinkType link) {
          if (link != null) {
              return link.getStringValue();
          }
          return uri;
      }
  
      private Object getLink(String uri, MessageDestinationLinkType link) {
          if (link != null) {
              return link.getStringValue();
          }
          return uri;
      }
  
      private Object getLink(String uri) {
          return uri;
      }
  
      private Class loadClass(String stringValue) throws DeploymentException {
          try {
              return cl.loadClass(stringValue);
          } catch (ClassNotFoundException e) {
              throw new DeploymentException("Could not load interface class: " + stringValue,
e);
          }
      }
  }
  
  
  
  1.2       +15 -2     incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
  
  Index: ReadOnlyContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReadOnlyContext.java	12 Feb 2004 20:38:18 -0000	1.1
  +++ ReadOnlyContext.java	13 Feb 2004 23:41:47 -0000	1.2
  @@ -100,7 +100,9 @@
       protected final Map bindings;         // bindings at my level
       protected final Map treeBindings;     // all bindings under me
   
  -    protected ReadOnlyContext() {
  +    private boolean fixed = false;
  +
  +    public ReadOnlyContext() {
           env = new Hashtable();
           bindings = new HashMap();
           treeBindings = new HashMap();
  @@ -120,6 +122,17 @@
           this.bindings = clone.bindings;
           this.treeBindings = clone.treeBindings;
           this.env = new Hashtable(env);
  +    }
  +
  +    public void freeze() {
  +        fixed = true;
  +    }
  +
  +    public void externalBind(String name, Object value) throws NamingException {
  +        if (fixed) {
  +            throw new NamingException("ReadOnlyContext has been frozen");
  +        }
  +        internalBind(name, value);
       }
   
       /**
  
  
  
  1.1                  incubator-geronimo/modules/naming/src/schema/geronimo-naming.xsd
  
  Index: geronimo-naming.xsd
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:ger="http://geronimo.apache.org/xml/ns/j2ee"
      targetNamespace="http://geronimo.apache.org/xml/ns/j2ee"
      xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified"
      attributeFormDefault="unqualified"
      version="1.0">
      <xsd:import namespace="http://java.sun.com/xml/ns/j2ee" schemaLocation="j2ee_1_4.xsd"/>
  
      <xsd:group name="jndiEnvironmentRefsGroup">
          <xsd:annotation>
              <xsd:documentation>
  
                  This group keeps the usage of the contained JNDI environment
                  reference elements consistent across J2EE deployment descriptors.
  
              </xsd:documentation>
          </xsd:annotation>
          <xsd:sequence>
              <xsd:element name="env-entry"
                  type="ger:env-entryType"
                  minOccurs="0" maxOccurs="unbounded"/>
              <xsd:element name="ejb-ref"
                  type="ger:ejb-refType"
                  minOccurs="0" maxOccurs="unbounded"/>
              <xsd:element name="ejb-local-ref"
                  type="ger:ejb-local-refType"
                  minOccurs="0" maxOccurs="unbounded"/>
              <!-- leave web services out until I know what they do -->
              <!--xsd:group ref="ger:service-refGroup"/-->
              <xsd:element name="resource-ref"
                  type="ger:resource-refType"
                  minOccurs="0" maxOccurs="unbounded"/>
              <xsd:element name="resource-env-ref"
                  type="ger:resource-env-refType"
                  minOccurs="0" maxOccurs="unbounded"/>
              <xsd:element name="message-destination-ref"
                  type="ger:message-destination-refType"
                  minOccurs="0" maxOccurs="unbounded"/>
          </xsd:sequence>
      </xsd:group>
  
      <xsd:complexType name="ejb-refType">
          <xsd:sequence>
              <xsd:element name="ejb-ref-name" type="j2ee:ejb-ref-nameType"/>
              <xsd:element name="uri" type="xsd:string"/>
          </xsd:sequence>
      </xsd:complexType>
  
      <!-- has exactly same content as ejb-refType, might not be needed -->
      <xsd:complexType name="ejb-local-refType">
          <xsd:sequence>
              <xsd:element name="ejb-ref-name" type="j2ee:ejb-ref-nameType"/>
              <xsd:element name="uri" type="xsd:string"/>
          </xsd:sequence>
      </xsd:complexType>
  
      <xsd:complexType name="message-destination-refType">
          <xsd:sequence>
              <xsd:element name="message-destination-ref-name"
                  type="j2ee:jndi-nameType"/>
              <xsd:element name="uri" type="xsd:string"/>
          </xsd:sequence>
      </xsd:complexType>
  
      <xsd:complexType name="resource-env-refType">
          <xsd:sequence>
              <xsd:element name="resource-env-ref-name"
                  type="j2ee:jndi-nameType"/>
              <xsd:element name="uri" type="xsd:string"/>
          </xsd:sequence>
      </xsd:complexType>
  
      <xsd:complexType name="resource-refType">
          <xsd:sequence>
              <xsd:element name="res-ref-name"
                  type="j2ee:jndi-nameType"/>
              <xsd:element name="uri" type="xsd:string"/>
          </xsd:sequence>
      </xsd:complexType>
  
  </xsd:schema>
  
  
  1.1                  incubator-geronimo/modules/naming/src/schema/xmlconfig.xml
  
  Index: xmlconfig.xml
  ===================================================================
  <xb:config xmlns:xb="http://www.bea.com/2002/09/xbean/config"
      >
  
      <xb:namespace uri="http://geronimo.apache.org/xml/ns/j2ee">
          <xb:package>org.apache.geronimo.xbeans.geronimo</xb:package>
          <xb:prefix>Ger</xb:prefix>
      </xb:namespace>
  
  
  </xb:config>
  
  
  1.1                  incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/deployment/ContextBuilderTest.java
  
  Index: ContextBuilderTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.naming.deployment;
  
  import java.net.URL;
  
  import javax.management.InstanceAlreadyExistsException;
  import javax.management.MBeanRegistrationException;
  import javax.management.MalformedObjectNameException;
  import javax.management.NotCompliantMBeanException;
  import javax.naming.Context;
  import javax.naming.NameNotFoundException;
  import javax.naming.NamingException;
  import javax.transaction.HeuristicMixedException;
  import javax.transaction.HeuristicRollbackException;
  import javax.transaction.NotSupportedException;
  import javax.transaction.RollbackException;
  import javax.transaction.SystemException;
  import javax.transaction.UserTransaction;
  
  import junit.framework.TestCase;
  import org.apache.geronimo.deployment.DeploymentException;
  import org.apache.geronimo.kernel.jmx.JMXKernel;
  import org.apache.geronimo.naming.java.ProxyFactory;
  import org.apache.geronimo.xbeans.geronimo.GerEjbLocalRefType;
  import org.apache.geronimo.xbeans.geronimo.GerEjbRefType;
  import org.apache.geronimo.xbeans.geronimo.GerMessageDestinationRefType;
  import org.apache.geronimo.xbeans.geronimo.GerResourceEnvRefType;
  import org.apache.geronimo.xbeans.geronimo.GerResourceRefType;
  import org.apache.geronimo.xbeans.j2ee.EjbLocalRefType;
  import org.apache.geronimo.xbeans.j2ee.EjbRefType;
  import org.apache.geronimo.xbeans.j2ee.EnvEntryType;
  import org.apache.geronimo.xbeans.j2ee.MessageDestinationRefType;
  import org.apache.geronimo.xbeans.j2ee.ResourceEnvRefType;
  import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
  
  /**
   * THIS IS A COPY OF org.apache.geronimo.naming.java.ContextBuilderTest.
   * Copied because maven doesn't share test classes.
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/13 23:41:47 $
   */
  public class ContextBuilderTest extends TestCase {
  
      protected EjbRefType[] ejbRefs;
      private GerEjbRefType[] gerEjbRefs;
      protected EjbLocalRefType[] ejbLocalRefs;
      private GerEjbLocalRefType[] gerEjbLocalRefs;
      protected EnvEntryType[] envEntries;
      private MessageDestinationRefType[] messageDestinationRefs;
      private GerMessageDestinationRefType[] gerMessageDestinationRefs;
      private ResourceEnvRefType[] resEnvRefs;
      private GerResourceEnvRefType[] gerResEnvRefs;
      protected ResourceRefType[] resRefs;
      private GerResourceRefType[] gerResRefs;
      protected Context compCtx;
      protected JMXKernel kernel;
      protected ProxyFactory proxyFactory;
  
      private static final String EJB1_NAME = "here/there/EJB1";
      private static final String EJB2_NAME = "here/LinkEjb";
      private static final String LOCAL_EJB1_NAME = "local/here/LocalEJB2";
      private static final String LOCAL_EJB2_NAME = "local/here/LinkLocalEjb";
      private static final String RESOURCE_REF1_NAME = "url/testURL";
      private static final String RESOURCE_REF2_NAME = "DefaultCF";
  
      protected void setUpContext(UserTransaction userTransaction) throws InstanceAlreadyExistsException,
MBeanRegistrationException, NotCompliantMBeanException, MalformedObjectNameException, DeploymentException
{
  
          proxyFactory = new ProxyFactory() {
              public Object getProxy(Class homeInterface, Class remoteInterface, Object targetId)
throws NamingException {
                  return targetId;
              }
  
              public Object getProxy(Class interfaced, Object targetId) throws NamingException
{
                  return targetId;
              }
  
          };
  
          //Ejb Refs
          EjbRefType ejbRef = EjbRefType.Factory.newInstance();
          ejbRef.addNewEjbRefName().setStringValue(EJB1_NAME);
          ejbRef.addNewEjbRefType().setStringValue("Session");
          ejbRef.addNewHome().setStringValue(Object.class.getName());
          ejbRef.addNewRemote().setStringValue(Object.class.getName());
          GerEjbRefType gerEjbRef = GerEjbRefType.Factory.newInstance();
          gerEjbRef.addNewEjbRefName().setStringValue(EJB1_NAME);
          gerEjbRef.setUri(EJB1_NAME);
  
          EjbRefType ejbLinkRef = EjbRefType.Factory.newInstance();
          ejbLinkRef.addNewEjbRefName().setStringValue(EJB2_NAME);
          ejbLinkRef.addNewEjbRefType().setStringValue("Session");
          ejbLinkRef.addNewHome().setStringValue(Object.class.getName());
          ejbLinkRef.addNewRemote().setStringValue(Object.class.getName());
          ejbLinkRef.addNewEjbLink().setStringValue(EJB2_NAME);
          GerEjbRefType gerEjbLinkRef = GerEjbRefType.Factory.newInstance();
          gerEjbLinkRef.addNewEjbRefName().setStringValue(EJB2_NAME);
          ejbRefs = new EjbRefType[]{ejbRef, ejbLinkRef};
          gerEjbRefs = new GerEjbRefType[] {gerEjbRef, gerEjbLinkRef};
  
  
          //ejb local refs
          EjbLocalRefType ejbLocalRef = EjbLocalRefType.Factory.newInstance();
          ejbLocalRef.addNewEjbRefName().setStringValue(LOCAL_EJB1_NAME);
          ejbLocalRef.addNewEjbRefType().setStringValue("Entity");
          ejbLocalRef.addNewLocalHome().setStringValue(Object.class.getName());
          ejbLocalRef.addNewLocal().setStringValue(Object.class.getName());
          GerEjbLocalRefType gerEjbLocalRef = GerEjbLocalRefType.Factory.newInstance();
          gerEjbLocalRef.addNewEjbRefName().setStringValue(LOCAL_EJB1_NAME);
          gerEjbLocalRef.setUri(LOCAL_EJB1_NAME);
  
          EjbLocalRefType ejbLocalLinkRef = EjbLocalRefType.Factory.newInstance();
          ejbLocalLinkRef.addNewEjbRefName().setStringValue(LOCAL_EJB2_NAME);
          ejbLocalLinkRef.addNewEjbRefType().setStringValue("Entity");
          ejbLocalLinkRef.addNewLocalHome().setStringValue(Object.class.getName());
          ejbLocalLinkRef.addNewLocal().setStringValue(Object.class.getName());
          ejbLocalLinkRef.addNewEjbLink().setStringValue(LOCAL_EJB2_NAME);
          GerEjbLocalRefType gerEjbLocalLinkRef = GerEjbLocalRefType.Factory.newInstance();
          gerEjbLocalLinkRef.addNewEjbRefName().setStringValue(LOCAL_EJB2_NAME);
          ejbLocalRefs = new EjbLocalRefType[]{ejbLocalRef, ejbLocalLinkRef};
          gerEjbLocalRefs = new GerEjbLocalRefType[] {gerEjbLocalRef, gerEjbLocalLinkRef};
  
  
          //env entries
          EnvEntryType stringEntry = EnvEntryType.Factory.newInstance();
          stringEntry.addNewEnvEntryName().setStringValue("hello/world");
          stringEntry.addNewEnvEntryType().setStringValue("java.lang.String");
          stringEntry.addNewEnvEntryValue().setStringValue("Hello World");
          EnvEntryType intEntry = EnvEntryType.Factory.newInstance();
          intEntry.addNewEnvEntryName().setStringValue("int");
          intEntry.addNewEnvEntryType().setStringValue("java.lang.Integer");
          intEntry.addNewEnvEntryValue().setStringValue("12345");
          envEntries = new EnvEntryType[]{stringEntry, intEntry};
  
          //message destinations
          messageDestinationRefs = new MessageDestinationRefType[] {};
          gerMessageDestinationRefs = new GerMessageDestinationRefType[] {};
  
          //resource env refs (admin objects)
          resEnvRefs = new ResourceEnvRefType[] {};
          gerResEnvRefs = new GerResourceEnvRefType[] {};
  
          //resource refs
          ResourceRefType urlRef = ResourceRefType.Factory.newInstance();
          urlRef.addNewResRefName().setStringValue(RESOURCE_REF1_NAME);
          urlRef.addNewResType().setStringValue(URL.class.getName());
          GerResourceRefType gerUrlRef = GerResourceRefType.Factory.newInstance();
          gerUrlRef.addNewResRefName().setStringValue(RESOURCE_REF1_NAME);
          gerUrlRef.setUri("http://localhost/path");
  
          ResourceRefType cfRef = ResourceRefType.Factory.newInstance();
          cfRef.addNewResRefName().setStringValue(RESOURCE_REF2_NAME);
          cfRef.addNewResType().setStringValue("javax.sql.DataSource");
          GerResourceRefType gerCfRef = GerResourceRefType.Factory.newInstance();
          gerCfRef.addNewResRefName().setStringValue(RESOURCE_REF2_NAME);
          gerCfRef.setUri(RESOURCE_REF2_NAME);
          resRefs = new ResourceRefType[]{urlRef, cfRef};
          gerResRefs = new GerResourceRefType[] {gerUrlRef, gerCfRef};
  
          //put it all together
          compCtx = new ComponentContextBuilder(proxyFactory, this.getClass().getClassLoader())
                  .buildContext(ejbRefs, gerEjbRefs,
                          ejbLocalRefs, gerEjbLocalRefs,
                          envEntries,
                          messageDestinationRefs, gerMessageDestinationRefs,
                          resEnvRefs, gerResEnvRefs,
                          resRefs, gerResRefs,
                          userTransaction);
      }
  
      public void testEnvEntries() throws Exception {
          setUpContext(null);
          assertEquals("Hello World", compCtx.lookup("env/hello/world"));
          assertEquals(new Integer(12345), compCtx.lookup("env/int"));
      }
  
      public void testNoUserTransaction() throws Exception {
          setUpContext(null);
          try {
              compCtx.lookup("UserTransaction");
              fail("Expected NameNotFoundException");
          } catch (NameNotFoundException e) {
              // OK
          }
      }
  
      public void testUserTransaction() throws Exception {
          UserTransaction userTransaction = new UserTransaction() {
              public void begin() throws NotSupportedException, SystemException {
              }
  
              public void commit() throws HeuristicMixedException, HeuristicRollbackException,
IllegalStateException, RollbackException, SecurityException, SystemException {
              }
  
              public int getStatus() throws SystemException {
                  return 0;
              }
  
              public void rollback() throws IllegalStateException, SecurityException, SystemException
{
              }
  
              public void setRollbackOnly() throws IllegalStateException, SystemException
{
              }
  
              public void setTransactionTimeout(int seconds) throws SystemException {
              }
  
          };
          setUpContext(userTransaction);
          assertEquals(userTransaction, compCtx.lookup("UserTransaction"));
      }
  
  
      public void testEJBRefs() throws Exception {
          setUpContext(null);
          assertEquals("Expected object from testObject1", EJB1_NAME,
                  compCtx.lookup("env/" + EJB1_NAME));
          assertEquals("Expected object from testObject3", EJB2_NAME,
                  compCtx.lookup("env/" + EJB2_NAME));
      }
  
      public void testLocalEJBRefs() throws Exception {
          setUpContext(null);
          assertEquals("Expected object from testObject1", LOCAL_EJB1_NAME,
                  compCtx.lookup("env/" + LOCAL_EJB1_NAME));
  
          assertEquals("Expected object from testObject3", LOCAL_EJB2_NAME,
                  compCtx.lookup("env/" + LOCAL_EJB2_NAME));
      }
  
      public void testResourceRefs() throws Exception {
          setUpContext(null);
          assertEquals(new URL("http://localhost/path"), compCtx.lookup("env/" + RESOURCE_REF1_NAME));
          assertEquals("Expected object from testObject1", RESOURCE_REF2_NAME,
                  compCtx.lookup("env/" + RESOURCE_REF2_NAME));
      }
  
  }
  
  
  
  1.2       +1 -12     incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java/AbstractContextTest.java
  
  Index: AbstractContextTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java/AbstractContextTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractContextTest.java	12 Feb 2004 20:38:19 -0000	1.1
  +++ AbstractContextTest.java	13 Feb 2004 23:41:47 -0000	1.2
  @@ -60,17 +60,12 @@
   import java.util.Map;
   import java.util.Properties;
   
  -import javax.management.MBeanServer;
  -import javax.management.ObjectName;
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import javax.naming.LinkRef;
   import javax.naming.NamingException;
   
   import junit.framework.TestCase;
  -import org.apache.geronimo.gbean.GBeanInfo;
  -import org.apache.geronimo.gbean.jmx.GBeanMBean;
  -import org.apache.geronimo.naming.jmx.TestObject;
   
   /**
    *
  @@ -116,10 +111,4 @@
           readOnlyContext.internalBind(name, value);
       }
   
  -    public static TestObject registerTestObject(MBeanServer server, ObjectName objectName)
throws Exception {
  -        GBeanInfo gbeanInfo = TestObject.getGBeanInfo();
  -        GBeanMBean gbean = new GBeanMBean(gbeanInfo);
  -        server.registerMBean(gbean, objectName);
  -        return (TestObject) gbean.getTarget();
  -    }
   }
  
  
  

Mime
View raw message