geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java ContextBuilderTest.java
Date Sat, 21 Feb 2004 17:41:08 GMT
jboynes     2004/02/21 09:41:08

  Modified:    modules/naming/src/java/org/apache/geronimo/naming/java
                        ReadOnlyContext.java
  Added:       modules/naming/src/java/org/apache/geronimo/naming/java
                        ComponentContextBuilder.java
               modules/naming/src/test/org/apache/geronimo/naming/java
                        ContextBuilderTest.java
  Removed:     modules/naming/src/java/org/apache/geronimo/naming/deployment
                        ComponentContextBuilder.java
               modules/naming/src/test/org/apache/geronimo/naming/deployment
                        ContextBuilderTest.java
  Log:
  Refactor ComponentContextBuilder to remove dependency on xmlbeans
  Did not include ref entries - waiting for new proxy code
  
  Revision  Changes    Path
  1.4       +8 -10     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReadOnlyContext.java	21 Feb 2004 17:01:24 -0000	1.3
  +++ ReadOnlyContext.java	21 Feb 2004 17:41:07 -0000	1.4
  @@ -101,7 +101,7 @@
       protected final Map bindings;         // bindings at my level
       protected final Map treeBindings;     // all bindings under me
   
  -    private boolean fixed = false;
  +    private boolean frozen = false;
   
       public ReadOnlyContext() {
           env = new Hashtable();
  @@ -126,14 +126,11 @@
       }
   
       public void freeze() {
  -        fixed = true;
  +        frozen = true;
       }
   
  -    public void externalBind(String name, Object value) throws NamingException {
  -        if (fixed) {
  -            throw new NamingException("ReadOnlyContext has been frozen");
  -        }
  -        internalBind(name, value);
  +    boolean isFrozen() {
  +        return frozen;
       }
   
       /**
  @@ -149,8 +146,9 @@
        * @throws javax.naming.NamingException
        */
       protected Map internalBind(String name, Object value) throws NamingException {
  -        assert name != null;
  -        assert !name.equals("");
  +        assert name != null && name.length() > 0;
  +        assert !frozen;
  +
           Map newBindings = new HashMap();
           int pos = name.indexOf('/');
           if (pos == -1) {
  
  
  
  1.4       +39 -148   incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
  
  
  
  
  1.1                  incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java/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.java;
  
  import java.util.Set;
  import java.util.HashSet;
  import java.util.Arrays;
  import javax.naming.NamingException;
  import javax.naming.NamingEnumeration;
  import javax.naming.NameClassPair;
  
  import junit.framework.TestCase;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/21 17:41:07 $
   */
  public class ContextBuilderTest extends TestCase {
      private ComponentContextBuilder builder;
  
      public void testFreeze() {
          ReadOnlyContext context = builder.getContext();
          assertTrue(context.isFrozen());
          try {
              builder.addEnvEntry(null, null, null);
              fail();
          } catch (IllegalStateException e) {
              // ok
          } catch (NamingException e) {
              fail();
          }
          try {
              builder.addUserTransaction(null);
              fail();
          } catch (IllegalStateException e) {
              // ok
          } catch (NamingException e) {
              fail();
          }
      }
  
      public void testEnvEntries() throws Exception {
          String stringVal = "Hello World";
          Character charVal = new Character('H');
          Byte byteVal = new Byte((byte)12);
          Short shortVal = new Short((short)12345);
          Integer intVal = new Integer(12345678);
          Long longVal = new Long(1234567890123456L);
          Float floatVal = new Float(123.456);
          Double doubleVal = new Double(12345.6789);
          Boolean booleanVal = Boolean.TRUE;
          builder.addEnvEntry("string", String.class.getName(), stringVal);
          builder.addEnvEntry("char", Character.class.getName(), charVal.toString());
          builder.addEnvEntry("byte", Byte.class.getName(), byteVal.toString());
          builder.addEnvEntry("short", Short.class.getName(), shortVal.toString());
          builder.addEnvEntry("int", Integer.class.getName(), intVal.toString());
          builder.addEnvEntry("long", Long.class.getName(), longVal.toString());
          builder.addEnvEntry("float", Float.class.getName(), floatVal.toString());
          builder.addEnvEntry("double", Double.class.getName(), doubleVal.toString());
          builder.addEnvEntry("boolean", Boolean.class.getName(), booleanVal.toString());
  
          ReadOnlyContext context = builder.getContext();
          Set actual = new HashSet();
          for (NamingEnumeration e = context.listBindings("env");e.hasMore();) {
              NameClassPair pair = (NameClassPair) e.next();
              actual.add(pair.getName());
          }
          Set expected = new HashSet(Arrays.asList(new String[] {"string", "char", "byte",
"short", "int", "long", "float", "double", "boolean"}));
          assertEquals(expected, actual);
          assertEquals(stringVal, context.lookup("env/string"));
          assertEquals(charVal, context.lookup("env/char"));
          assertEquals(byteVal, context.lookup("env/byte"));
          assertEquals(shortVal, context.lookup("env/short"));
          assertEquals(intVal, context.lookup("env/int"));
          assertEquals(longVal, context.lookup("env/long"));
          assertEquals(floatVal, context.lookup("env/float"));
          assertEquals(doubleVal, context.lookup("env/double"));
          assertEquals(booleanVal, context.lookup("env/boolean"));
      }
  
      protected void setUp() throws Exception {
          super.setUp();
          builder = new ComponentContextBuilder();
      }
  }
  
  
  

Mime
View raw message