commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r369713 - in /jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config: ./ nopriority/ priority10/ priority20/ priority20a/
Date Tue, 17 Jan 2006 08:01:15 GMT
Author: skitching
Date: Tue Jan 17 00:01:08 2006
New Revision: 369713

URL: http://svn.apache.org/viewcvs?rev=369713&view=rev
Log:
Unit tests for the new LogFactory feature which loads the commons-logging.properties
file with the highest priority.

Added:
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java
  (with props)
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/nopriority/
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/nopriority/commons-logging.properties
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority10/
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority10/commons-logging.properties
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20/
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20/commons-logging.properties
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20a/
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20a/commons-logging.properties

Added: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java?rev=369713&view=auto
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java
(added)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java
Tue Jan 17 00:01:08 2006
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2006 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.
+ */ 
+
+package org.apache.commons.logging.config;
+
+
+import java.net.URL;
+import java.util.Enumeration;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.PathableClassLoader;
+import org.apache.commons.logging.PathableTestSuite;
+
+
+/**
+ * Tests that verify that the process of configuring logging on startup
+ * works correctly by selecting the file with the highest priority.
+ */
+
+public class PriorityConfigTestCase extends TestCase {
+
+    // ------------------------------------------- JUnit Infrastructure Methods
+
+
+    /**
+     * Return the tests included in this test suite.
+     */
+    public static Test suite() throws Exception {
+        Class thisClass = PriorityConfigTestCase.class;
+
+        // Determine the URL to this .class file, so that we can then
+        // append the priority dirs to it. For tidiness, load this
+        // class through a dummy loader though this is not absolutely
+        // necessary...
+        PathableClassLoader dummy = new PathableClassLoader(null);
+        dummy.useSystemLoader("junit.");
+        dummy.addLogicalLib("testclasses");
+        dummy.addLogicalLib("commons-logging");
+        
+        String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
+        URL baseUrl = dummy.findResource(thisClassPath);
+
+        // Now set up the desired classloader hierarchy. We'll put a config
+        // file of priority=10 in the container path, and ones of both
+        // "no priority" and priority=20 in the webapp path.
+        //
+        // A second properties file with priority=20 is also added,
+        // so we can check that the first one in the classpath is
+        // used.
+        PathableClassLoader containerLoader = new PathableClassLoader(null);
+        containerLoader.useSystemLoader("junit.");
+        containerLoader.addLogicalLib("commons-logging");
+        
+        URL pri10URL = new URL(baseUrl, "priority10/");
+        containerLoader.addURL(pri10URL);
+
+        PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
+        webappLoader.setParentFirst(true);
+        webappLoader.addLogicalLib("testclasses");
+
+        URL noPriorityURL = new URL(baseUrl, "nopriority/");
+        webappLoader.addURL(noPriorityURL);
+        
+        URL pri20URL = new URL(baseUrl, "priority20/");
+        webappLoader.addURL(pri20URL);
+        
+        URL pri20aURL = new URL(baseUrl, "priority20a/");
+        webappLoader.addURL(pri20aURL);
+        
+        // load the test class via webapp loader, and use the webapp loader
+        // as the tccl loader too.
+        Class testClass = webappLoader.loadClass(thisClass.getName());
+        return new PathableTestSuite(testClass, webappLoader);
+    }
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() throws Exception {
+        LogFactory.releaseAll();
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+        LogFactory.releaseAll();
+    }
+
+    // ----------------------------------------------------------- Test Methods
+
+    /**
+     * Verify that the config file being used is the one containing
+     * the desired configId value.
+     */
+    public void testPriority() throws Exception {
+        LogFactory instance = LogFactory.getFactory();
+        String id = (String) instance.getAttribute("configId");
+        assertEquals("Correct config file loaded", "priority20", id );
+    }
+}

Propchange: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/PriorityConfigTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/nopriority/commons-logging.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/nopriority/commons-logging.properties?rev=369713&view=auto
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/nopriority/commons-logging.properties
(added)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/nopriority/commons-logging.properties
Tue Jan 17 00:01:08 2006
@@ -0,0 +1 @@
+configId=nopriority

Added: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority10/commons-logging.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority10/commons-logging.properties?rev=369713&view=auto
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority10/commons-logging.properties
(added)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority10/commons-logging.properties
Tue Jan 17 00:01:08 2006
@@ -0,0 +1,2 @@
+priority=10.5
+configId=priority10

Added: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20/commons-logging.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20/commons-logging.properties?rev=369713&view=auto
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20/commons-logging.properties
(added)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20/commons-logging.properties
Tue Jan 17 00:01:08 2006
@@ -0,0 +1,2 @@
+priority=20.6
+configId=priority20

Added: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20a/commons-logging.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20a/commons-logging.properties?rev=369713&view=auto
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20a/commons-logging.properties
(added)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/config/priority20a/commons-logging.properties
Tue Jan 17 00:01:08 2006
@@ -0,0 +1,2 @@
+priority=20.6
+configId=priority20a



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message