You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2006/03/09 03:03:19 UTC
svn commit: r384401 - in
/jakarta/commons/proper/logging/contrib/simon/jcl2/core: ./
test/org/apache/commons/logging/ test/resources/ test/resources/META-INF/
test/resources/META-INF/services/
Author: skitching
Date: Wed Mar 8 18:03:18 2006
New Revision: 384401
URL: http://svn.apache.org/viewcvs?rev=384401&view=rev
Log:
Add unit tests for Utils class
Added:
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java (with props)
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service1
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service2
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service3
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service4
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service5
jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service6
Modified:
jakarta/commons/proper/logging/contrib/simon/jcl2/core/pom.xml
Modified: jakarta/commons/proper/logging/contrib/simon/jcl2/core/pom.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/pom.xml?rev=384401&r1=384400&r2=384401&view=diff
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/pom.xml (original)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/pom.xml Wed Mar 8 18:03:18 2006
@@ -35,13 +35,13 @@
<directory>conf</directory>
</resource>
</resources>
-<!--
+
<testResources>
<testResource>
- <directory>src/test/resources</directory>
+ <directory>test/resources</directory>
</testResource>
</testResources>
--->
+
</build>
</project>
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java?rev=384401&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java (added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java Wed Mar 8 18:03:18 2006
@@ -0,0 +1,112 @@
+/*
+ * 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;
+
+import org.apache.commons.logging.PathableClassLoader;
+import org.apache.commons.logging.PathableTestSuite;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+/**
+ * Tests the Utils class.
+ */
+public class UtilsTestCase extends TestCase
+{
+ public interface Service0 {}
+ public interface Service1 {}
+ public interface Service2 {}
+ public interface Service3 {}
+ public interface Service4 {}
+ public interface Service5 {}
+ public interface Service6 {}
+
+ // service implementation cannot be instantiated
+ public static abstract class Service4Impl implements Service4 {}
+
+ // service implementation doesn't implement service
+ public static class Service5Impl {}
+
+ // service implementation valid
+ public static class Service6Impl implements Service6 {}
+
+ public void testCreateServiceInstance()
+ {
+ ClassLoader classLoader = null;
+
+ // service file cannot be found
+ try {
+ Object o = Utils.createServiceInstance(Service0.class, classLoader);
+ fail("Unexpectedly retrieved service for Service0");
+ } catch(LogConfigurationException ex) {
+ boolean msgOk = ex.getMessage().contains("has no service file");
+ assertTrue("Service0 service file does not exist", msgOk);
+ }
+
+ // service file is empty
+ try {
+ Object o = Utils.createServiceInstance(Service1.class, classLoader);
+ fail("Unexpectedly retrieved service for Service1");
+ } catch(LogConfigurationException ex) {
+ boolean msgOk = ex.getMessage().contains("contains no classname");
+ assertTrue("Service1 service file empty", msgOk);
+ }
+
+ // service file has only comments and blank lines
+ try {
+ Object o = Utils.createServiceInstance(Service2.class, classLoader);
+ fail("Unexpectedly retrieved service for Service2");
+ } catch(LogConfigurationException ex) {
+ boolean msgOk = ex.getMessage().contains("contains no classname");
+ assertTrue("Service2 service file has no class", msgOk);
+ }
+
+ // service file references nonexistent implementation
+ try {
+ Object o = Utils.createServiceInstance(Service3.class, classLoader);
+ fail("Unexpectedly retrieved service for Service3");
+ } catch(LogConfigurationException ex) {
+ boolean msgOk = ex.getMessage().contains("provider not found");
+ assertTrue("Service3 service file refers to nonexistent class", msgOk);
+ }
+
+ // service file references implementation that can't be instantiated
+ try {
+ Object o = Utils.createServiceInstance(Service4.class, classLoader);
+ fail("Unexpectedly retrieved service for Service4");
+ } catch(LogConfigurationException ex) {
+ boolean msgOk = ex.getMessage().contains("could not be instantiated");
+ assertTrue("Service4 service file refers to abstract class", msgOk);
+ }
+
+ // service file references implementation that isn't of valid type
+ try {
+ Object o = Utils.createServiceInstance(Service5.class, classLoader);
+ fail("Unexpectedly retrieved service for Service5");
+ } catch(LogConfigurationException ex) {
+ boolean msgOk = ex.getMessage().contains("does not implement");
+ assertTrue("Service5 service file refers to abstract class", msgOk);
+ }
+
+ // valid service file
+ Service6 s6 = (Service6) Utils.createServiceInstance(Service6.class, classLoader);
+
+ // test when loader is not null
+ Service6 s6a = (Service6) Utils.createServiceInstance(Service6.class,
+ Service6.class.getClassLoader());
+ }
+}
Propchange: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/org/apache/commons/logging/UtilsTestCase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service1
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase%24Service1?rev=384401&view=auto
==============================================================================
(empty)
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service2
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase%24Service2?rev=384401&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service2 (added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service2 Wed Mar 8 18:03:18 2006
@@ -0,0 +1,4 @@
+# this is a test service file
+# that contains just blank lines
+
+# and comments, and nothing else.
\ No newline at end of file
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service3
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase%24Service3?rev=384401&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service3 (added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service3 Wed Mar 8 18:03:18 2006
@@ -0,0 +1,3 @@
+# this service file refers to a class that doesn't exist
+
+org.apache.commons.logging.NoSuchServiceImplementation
\ No newline at end of file
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service4
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase%24Service4?rev=384401&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service4 (added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service4 Wed Mar 8 18:03:18 2006
@@ -0,0 +1,3 @@
+# this service file refers to a class that can't be instantiated
+
+org.apache.commons.logging.UtilsTestCase$Service4Impl
\ No newline at end of file
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service5
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase%24Service5?rev=384401&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service5 (added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service5 Wed Mar 8 18:03:18 2006
@@ -0,0 +1,4 @@
+# this service file refers to a class that can be instantiated but
+# doesn't implement the expected interface
+
+org.apache.commons.logging.UtilsTestCase$Service6Impl
\ No newline at end of file
Added: jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service6
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase%24Service6?rev=384401&view=auto
==============================================================================
--- jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service6 (added)
+++ jakarta/commons/proper/logging/contrib/simon/jcl2/core/test/resources/META-INF/services/org.apache.commons.logging.UtilsTestCase$Service6 Wed Mar 8 18:03:18 2006
@@ -0,0 +1,4 @@
+# this service file refers to a class that can be instantiated but
+# doesn't implement the expected interface
+
+org.apache.commons.logging.UtilsTestCase$Service6Impl
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org