You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2004/12/08 05:46:58 UTC

svn commit: r111211 - in incubator/beehive/trunk/netui: src/util/org/apache/beehive/netui/util/config test/src/junitTests/org/apache/beehive/netui/test/databinding/expression test/src/junitTests/org/apache/beehive/netui/test/script test/src/junitTests/org/apache/beehive/netui/test/util/config test/src/junitTests/org/apache/beehive/netui/test/util/type test/src/junitTests/org/apache/beehive/netui/util/config

Author: ekoneil
Date: Tue Dec  7 20:46:56 2004
New Revision: 111211

URL: http://svn.apache.org/viewcvs?view=rev&rev=111211
Log:
Fixup the duplication of the ConfigUtil class in the netui/test/src/junitTests package.

This was duplicated because the tests need to be able to re-load the test file.  This is significantly cleaner now.

BB: self
DRT: NetUI server pass


Added:
   incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java   (contents, props changed)
Removed:
   incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/util/config/ConfigUtil.java
Modified:
   incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java
   incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java
   incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java
   incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java

Modified: incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java?view=diff&rev=111211&p1=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java&r1=111210&p2=incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java&r2=111211
==============================================================================
--- incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java	(original)
+++ incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/ConfigUtil.java	Tue Dec  7 20:46:56 2004
@@ -17,18 +17,14 @@
  */
 package org.apache.beehive.netui.util.config;
 
-// java imports
 import java.io.InputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 
-// internal imports
-import org.apache.beehive.netui.util.Bundle;
 import org.apache.beehive.netui.util.config.bean.NetuiConfigDocument;
 import org.apache.beehive.netui.util.config.bean.NetuiConfigDocument.NetuiConfig;
 import org.apache.beehive.netui.util.logging.Logger;
 
-// external imports
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
 import org.apache.xmlbeans.XmlError;
@@ -48,18 +44,20 @@
  * <br/> 
  * </p>
  */
-public final class ConfigUtil
+public class ConfigUtil
 {
     // @todo: need to change NetuiConfigDocument.NetuiConfig to NetUIConfig
-    // @todo: need to provide a read-only implementation so that users can't edit
-    // the config file on the fly
+    // @todo: need to provide a read-only implementation so that users can't edit the config file on the fly
 
-    private static final Logger _logger = Logger.getInstance(ConfigUtil.class);
+    private static final Logger LOGGER = Logger.getInstance(ConfigUtil.class);
 
     private static final String DEFAULT_CONFIG = "org/apache/beehive/netui/util/config/netui-config-default.xml";
     
     private static NetuiConfigDocument _config = null;
 
+    /* do not construct */
+    protected ConfigUtil() {}
+
     /**
      * <p>
      * Initialize the NetUI configuration data.
@@ -78,6 +76,25 @@
     public static final void init(InputStream is)
         throws ConfigInitializationException
     {
+        if(_config != null)
+            throw new ConfigInitializationException("Config initialization already completed; unable to reload the NetUI config file.");
+
+        internalInit(is);
+    }
+
+    /**
+     * Internal method used to re-initialize the static class member that holds the
+     * ConfigDocument.  Note, this method does <b>no</b> checks to ensure that an
+     * existing document is being overwritten.  The behavior of ConfigUtil clients
+     * is undefined if their initial configuration is re-loaded.
+     *
+     * @param is The {@link java.io.InputStream} that contains the config document to load
+     * @throws ConfigInitializationException thrown when an error occurs loading the
+     * configuration file.
+     */
+    protected static final void internalInit(InputStream is)
+        throws ConfigInitializationException {
+
         // when initialized with a null InputStream, revert to using a default, barebones config file
         if(is == null) 
         {
@@ -88,8 +105,9 @@
                 throw new ConfigInitializationException("The NetUI runtime could not find the default config file.  " + 
                                                         "The webapp may not function properly.");
 
-            if(_logger.isInfoEnabled()) _logger.info("Loading the default NetUI config file.  The runtime will be configured " + 
-                                                     "with a set of minimum parameters.");
+            if(LOGGER.isInfoEnabled())
+                    LOGGER.info("Loading the default NetUI config file.  The runtime will be configured " +
+                                "with a set of minimum parameters.");
         }
 
         if(_config == null)
@@ -108,8 +126,7 @@
                 throw new ConfigInitializationException("Unable load the NetUI config file.  Cause: " + ex, ex);
             }
         }
-        else throw new ConfigInitializationException("Config initialization already completed; unable to reload the NetUI config file.");
-        
+
         assert _config != null;
 
         // Validate the document.
@@ -117,7 +134,7 @@
         ArrayList errorList = new ArrayList();
         validateOptions.setErrorListener(errorList);
         boolean isValid = _config.validate(validateOptions);
-                
+
         // Throw an exception if the XML is invalid.
         if (!isValid)
         {
@@ -136,31 +153,32 @@
             }
 
             throw new ConfigInitializationException(msg.toString());
-        }        
+        }
     }
 
     /**
-     * <p>
-     * Get the NetUI configuration object.  
-     * <br/>
-     * <br/>
-     * </p>
+     * Get the NetUI configuration object.
      *
      * @return a configuration bean that contains data
      * parsed from the netui-config.xml file.
      */
     public static NetuiConfig getConfig()
     {
-        if(_config != null)
+        if(_config != null) {
             return _config.getNetuiConfig();
-        // If the config file wasn't initialized, attempt to initialize a configuration
-        // from the default config file contained in the utility JAR.
-        else 
+        }
+        /*
+          If the config file wasn't initialized, attempt to initialize a configuration
+          from the default config file contained in the utility JAR.
+         */
+        else
         {
-            // This hopefully never happens and would only occur if the default config file isn't
-            // found in the util JAR.
-            if(_logger.isErrorEnabled()) _logger.error("An error occurred parsing the default config file.  " + 
-                                                       "The NetUI runtime is not properly configured.");
+            /*
+              This hopefully never happens and would only occur if the default config file isn't found in the util JAR.
+             */
+            if(LOGGER.isErrorEnabled())
+                LOGGER.error("An error occurred parsing the default config file.  " +
+                             "The NetUI runtime is not properly configured.");
 
             throw new IllegalStateException("The NetUI runtime could not find the default config file.  The webapp may not function properly.");
         }

Modified: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java?view=diff&rev=111211&p1=incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java&r1=111210&p2=incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java&r2=111211
==============================================================================
--- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java	(original)
+++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java	Tue Dec  7 20:46:56 2004
@@ -18,6 +18,7 @@
 package org.apache.beehive.netui.test.databinding.expression;
 
 // java imports
+import java.io.InputStream;
 import javax.servlet.jsp.tagext.Tag;
 
 // internal imports
@@ -28,6 +29,8 @@
 import org.apache.beehive.netui.tags.naming.IndexedNameInterceptor;
 
 import org.apache.beehive.netui.util.logging.Logger;
+import org.apache.beehive.netui.util.config.ConfigInitializationException;
+import org.apache.beehive.netui.test.util.config.TestConfigUtil;
 
 // external imports
 import junit.framework.Test;
@@ -488,6 +491,9 @@
         junit.textui.TestRunner.run(suite());
     }
 
-    protected void setUp() {}
+    protected void setUp() {
+        TestConfigUtil.testInit();
+    }
+  
     protected void tearDown() {}
 }

Modified: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java?view=diff&rev=111211&p1=incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java&r1=111210&p2=incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java&r2=111211
==============================================================================
--- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java	(original)
+++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/script/AbstractExpressionTest.java	Tue Dec  7 20:46:56 2004
@@ -17,6 +17,7 @@
  */
 package org.apache.beehive.netui.test.script;
 
+import java.io.InputStream;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
@@ -29,6 +30,9 @@
 import org.apache.beehive.netui.test.beans.SimpleTypeActionForm;
 import org.apache.beehive.netui.test.beans.ComplexTypeActionForm;
 import org.apache.beehive.netui.test.servlet.ServletFactory;
+import org.apache.beehive.netui.test.util.config.TestConfigUtil;
+import org.apache.beehive.netui.util.config.ConfigUtil;
+import org.apache.beehive.netui.util.config.ConfigInitializationException;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -39,6 +43,7 @@
 
 public abstract class AbstractExpressionTest
     extends TestCase {
+
     protected static final int COMPLEX_FORM = 1;
     protected static final int SIMPLE_FORM = 2;
 
@@ -108,7 +113,7 @@
 
         useForm(SIMPLE_FORM);
 
-        org.apache.beehive.netui.util.config.ConfigUtil.loadDefault();
+        TestConfigUtil.testInit();
     }
 
     protected void tearDown() {

Added: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java?view=auto&rev=111211
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/config/TestConfigUtil.java	Tue Dec  7 20:46:56 2004
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.test.util.config;
+
+import java.io.InputStream;
+
+import org.apache.beehive.netui.util.config.ConfigUtil;
+import org.apache.beehive.netui.util.config.ConfigInitializationException;
+
+/**
+ *
+ */
+public class TestConfigUtil
+    extends ConfigUtil {
+
+    private static final String DEFAULT_CONFIG = "WEB-INF/netui-config.xml";
+
+    public static final void testInit(InputStream is)
+        throws ConfigInitializationException {
+        internalInit(is);
+    }
+
+    public static final void testInit() {
+
+        try {
+            InputStream is = TestConfigUtil.class.getClassLoader().getResourceAsStream(DEFAULT_CONFIG);
+            testInit(is);
+        }
+        catch(ConfigInitializationException cie) {
+            /*
+              sometimes bad form to do this, but in the default case for testing,
+              it's convenient to just bail with a runtime exception to just
+              fail the test
+             */
+
+            throw new IllegalStateException("Caught exception initializing the default config file \"" + DEFAULT_CONFIG + "\"", cie);
+        }
+    }
+}

Modified: incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java?view=diff&rev=111211&p1=incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java&r1=111210&p2=incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java&r2=111211
==============================================================================
--- incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java	(original)
+++ incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/type/TypeUtilsTest.java	Tue Dec  7 20:46:56 2004
@@ -24,10 +24,13 @@
 import java.sql.Timestamp;
 import java.util.Date;
 import java.util.Locale;
+import java.io.InputStream;
 
 // internal imports
 import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.beehive.netui.util.type.TypeUtils;
+import org.apache.beehive.netui.util.config.ConfigInitializationException;
+import org.apache.beehive.netui.test.util.config.TestConfigUtil;
 
 // external imports
 import junit.framework.Test;
@@ -135,7 +138,8 @@
                 Class type = (Class)_tests[i][1];
                 boolean valid = ((Boolean)_tests[i][2]).booleanValue();
                 
-                if(_logger.isDebugEnabled()) _logger.debug("tests[" + i + "]: convert \"" + value + "\" to type \"" + type + "\"");
+                if(_logger.isDebugEnabled())
+                    _logger.debug("tests[" + i + "]: convert \"" + value + "\" to type \"" + type + "\"");
                 
                 Object result = null;
                 try
@@ -148,7 +152,8 @@
                 }
                 catch(Exception e)
                 {
-                    if(!valid) continue;
+                    if(!valid)
+                        continue;
                     else if(valid)
                         throw new TestFailedException("The test case [" + i + "] failed because an illegal value \"" + 
                                                       value + "\" was accepted in converting to type \"" + type + "\"");
@@ -215,6 +220,9 @@
         junit.textui.TestRunner.run(suite());
     }
 
-    protected void setUp() {}
+    protected void setUp() {
+        TestConfigUtil.testInit();
+    }
+
     protected void tearDown() {}
 }

Deleted: /incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/util/config/ConfigUtil.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/util/config/ConfigUtil.java?view=auto&rev=111210
==============================================================================