cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: rev 55857 - in cocoon/branches/BRANCH_2_1_X: . src/test/org/apache/cocoon/core/container src/test/org/apache/cocoon/environment/commandline/test tools/src tools/targets
Date Thu, 28 Oct 2004 14:32:34 GMT
Author: vgritsenko
Date: Thu Oct 28 07:32:34 2004
New Revision: 55857

Modified:
   cocoon/branches/BRANCH_2_1_X/build.properties
   cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
   cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
   cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl
   cocoon/branches/BRANCH_2_1_X/tools/targets/test-build.xml
Log:
Fix junit-tests-report target.
Output junit test report into separate directory.
Add junit.test.loglevel property to specify log level for junit tests logger.
Sync blocks junit target with core junit target (record results, do not halt on failure).


Modified: cocoon/branches/BRANCH_2_1_X/build.properties
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/build.properties	(original)
+++ cocoon/branches/BRANCH_2_1_X/build.properties	Thu Oct 28 07:32:34 2004
@@ -69,6 +69,7 @@
 
 junit.test.debugport=8000
 #junit.testcase=org.apache.cocoon.util.test.NetUtilsTestCase
+junit.test.loglevel=0
 
 # ---- Build -------------------------------------------------------------------
 
@@ -78,6 +79,7 @@
 build.mocks=${build}/mocks
 build.test=${build}/test
 build.test.output=${build.test}/output
+build.test.report=${build.test}/report
 build.docs=${build}/docs
 build.docs.printer=${build}/printer-docs
 build.site=${build}/site

Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/core/container/ContainerTestCase.java
Thu Oct 28 07:32:34 2004
@@ -1,16 +1,16 @@
-/* 
+/*
  * Copyright 2002-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 
- * 
+ * 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.
  */
@@ -58,7 +58,7 @@
  * <p>
  *   The following test case configuration can be used as a basis for new tests.
  *   Detailed explanations of the configuration elements can be found after
- *   the example. 
+ *   the example.
  * </p>
  * <pre>
  *   &lt;testcase&gt;
@@ -104,11 +104,11 @@
  *
  * <dt>roles</dt>
  * <dd>Roles configuration for the components configured in the
- *  <code>components</code> element.  
+ *  <code>components</code> element.
  * </dd>
  *
  * <dt>components</dt>
- * <dd>Used to configure any Components used by the test cases.  
+ * <dd>Used to configure any Components used by the test cases.
  * </dd>
  *
  * </dl>
@@ -116,10 +116,10 @@
  * @version $Id: $
  */
 public class ContainerTestCase extends TestCase {
-    
+
     /** The default logger */
-    private Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
-    
+    private Logger logger;
+
     /** The service manager to use */
     private ServiceManager manager;
 
@@ -132,15 +132,19 @@
     protected ServiceManager getManager() {
         return this.manager;
     }
-    
+
     /* (non-Javadoc)
      * @see junit.framework.TestCase#setUp()
      */
     protected void setUp() throws Exception {
         super.setUp();
-        this.prepare();
+
+        String level = System.getProperty("junit.test.loglevel", "" + ConsoleLogger.LEVEL_DEBUG);
+        this.logger = new ConsoleLogger(Integer.parseInt(level));
+
+        prepare();
     }
-    
+
     /**
      * Initializes the ComponentLocator
      *
@@ -152,11 +156,11 @@
         final String resourceName = getClass().getName().replace( '.', '/' ) + ".xtest";
         URL resource = getClass().getClassLoader().getResource( resourceName );
 
-        if( resource != null ) {
-            getLogger().debug( "Loading resource " + resourceName );
-            prepare( resource.openStream() );
+        if (resource != null) {
+            getLogger().debug("Loading resource " + resourceName);
+            prepare(resource.openStream());
         } else {
-            getLogger().debug( "Resource not found " + resourceName );
+            getLogger().debug("Resource not found " + resourceName);
         }
     }
 
@@ -171,27 +175,27 @@
      * the mentioned initialize method is also the place to set a different logging priority
      * to the member variable m_logPriority.
      */
-    protected final void prepare( final InputStream testconf )
+    protected final void prepare(final InputStream testconf)
     throws Exception {
-        if ( getLogger().isDebugEnabled() ) {
-            getLogger().debug( "ContainerTestCase.initialize" );
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("ContainerTestCase.initialize");
         }
 
         final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
-        final Configuration conf = builder.build( testconf );
+        final Configuration conf = builder.build(testconf);
 
-        Context context = this.setupContext( conf.getChild( "context" ) );
+        Context context = this.setupContext(conf.getChild("context"));
 
-        setupManagers( conf.getChild( "components" ),
-                       conf.getChild( "roles" ),
-                       context );
+        setupManagers(conf.getChild("components"),
+                      conf.getChild("roles"),
+                      context);
     }
 
     /* (non-Javadoc)
      * @see junit.framework.TestCase#tearDown()
      */
     protected void tearDown() throws Exception {
-        this.done();
+        done();
         super.tearDown();
     }
 
@@ -199,7 +203,7 @@
      * Disposes the <code>ComponentLocator</code>
      */
     final private void done() {
-        if( manager != null ) {
+        if (manager != null) {
             ContainerUtil.dispose(manager);
             manager = null;
         }
@@ -216,24 +220,24 @@
     throws Exception {
         final DefaultContext context = new DefaultContext();
         final Configuration[] confs = conf.getChildren( "entry" );
-        for( int i = 0; i < confs.length; i++ ) {
-            final String key = confs[ i ].getAttribute( "name" );
-            final String value = confs[ i ].getAttribute( "value", null );
-            if( value == null ) {
-                String clazz = confs[ i ].getAttribute( "class" );
-                Object obj = getClass().getClassLoader().loadClass( clazz ).newInstance();
-                context.put( key, obj );
-                if( getLogger().isInfoEnabled() ) {
-                    getLogger().info( "ContainerTestCase: added an instance of class " +
clazz + " to context entry " + key );
+        for (int i = 0; i < confs.length; i++) {
+            final String key = confs[i].getAttribute("name");
+            final String value = confs[i].getAttribute("value", null);
+            if (value == null) {
+                String clazz = confs[i].getAttribute("class");
+                Object obj = getClass().getClassLoader().loadClass(clazz).newInstance();
+                context.put(key, obj);
+                if (getLogger().isInfoEnabled()) {
+                    getLogger().info("ContainerTestCase: added an instance of class " + clazz
+ " to context entry " + key);
                 }
             } else {
-                context.put( key, value );
-                if( getLogger().isInfoEnabled() ) {
-                    getLogger().info( "ContainerTestCase: added value \"" + value + "\" to
context entry " + key );
+                context.put(key, value);
+                if (getLogger().isInfoEnabled()) {
+                    getLogger().info("ContainerTestCase: added value \"" + value + "\" to
context entry " + key);
                 }
             }
         }
-        addContext( context );
+        addContext(context);
         return context ;
     }
 
@@ -241,42 +245,41 @@
      * This method may be overwritten by subclasses to put additional objects
      * into the context programmatically.
      */
-    protected void addContext( DefaultContext context ) {
+    protected void addContext(DefaultContext context) {
     }
 
-    final private void setupManagers( final Configuration confCM,
-                                      final Configuration confRM,
-                                      final Context context )
+    final private void setupManagers(final Configuration confCM,
+                                     final Configuration confRM,
+                                     final Context context)
     throws Exception {
         // Setup the RoleManager
         DefaultRoleManager roleManager = new DefaultRoleManager();
-        roleManager.enableLogging( this.getLogger() );
-        roleManager.configure( confRM );
+        roleManager.enableLogging(getLogger());
+        roleManager.configure(confRM);
 
         // Set up the ComponentLocator
         ExcaliburComponentManager ecManager = new ExcaliburComponentManager();
-        ecManager.enableLogging( this.getLogger() );
-        ecManager.contextualize( context );
-        ecManager.setRoleManager( roleManager );
-        ecManager.setLoggerManager( new DefaultLoggerManager(this.logger));
-        ecManager.configure( confCM );
+        ecManager.enableLogging(getLogger());
+        ecManager.contextualize(context);
+        ecManager.setRoleManager(roleManager);
+        ecManager.setLoggerManager(new DefaultLoggerManager(getLogger()));
+        ecManager.configure(confCM);
         ecManager.initialize();
         this.manager = new WrapperServiceManager(ecManager);
     }
 
-    protected final Object lookup( final String key )
+    protected final Object lookup(final String key)
     throws ServiceException {
-        return manager.lookup( key );
+        return manager.lookup(key);
     }
 
-    protected final void release( final Object object ) {
-        manager.release( object );
+    protected final void release(final Object object) {
+        manager.release(object);
     }
-    
+
     protected static class DefaultLoggerManager implements LoggerManager {
-        
         private Logger logger;
-        
+
         public DefaultLoggerManager(Logger logger) {
             this.logger = logger;
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/environment/commandline/test/CommandLineContextTestCase.java
Thu Oct 28 07:32:34 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-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.
@@ -14,72 +14,48 @@
  * limitations under the License.
  */
 package org.apache.cocoon.environment.commandline.test;
-import java.io.File;
-import java.net.URL;
+
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+
+import org.apache.cocoon.environment.commandline.CommandLineContext;
 
 import junit.framework.TestCase;
 import junit.swingui.TestRunner;
 
-import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.cocoon.environment.commandline.CommandLineContext;
-import org.apache.log.Priority;
+import java.io.File;
+import java.net.URL;
 
 /**
  * A simple test case for CommandLineContext.
  *
  * @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
- * @version CVS $Id: CommandLineContextTestCase.java,v 1.6 2004/03/05 13:03:03 bdelacretaz
Exp $
+ * @version CVS $Id$
  */
-public final class CommandLineContextTestCase
-         extends TestCase
-{
-    ///Format of default formatter
-    /**
-     *Description of the Field
-     *
-     * @since
-     */
-    protected final static String FORMAT =
-            "%7.7{priority} %{time}   [%8.8{category}] (%{context}): %{message}\\n%{throwable}";
-    /**
-     *Description of the Field
-     *
-     * @since
-     */
-    protected Priority m_logPriority = Priority.INFO;
+public final class CommandLineContextTestCase extends TestCase {
 
     private String commandLineContextDir;
     private CommandLineContext commandLineContext;
 
 
     /**
-     *Constructor for the CommandLineContextTestCase object
-     *
-     * @since
+     * Constructor for the CommandLineContextTestCase object
      */
     public CommandLineContextTestCase() {
         this("CommandLineContextTestCase");
     }
 
-
     /**
-     *Constructor for the CommandLineContextTestCase object
-     *
-     * @param  name  Description of Parameter
-     * @since
+     * Constructor for the CommandLineContextTestCase object
      */
     public CommandLineContextTestCase(String name) {
         super(name);
-
     }
 
-
     /**
-     *The main program for the CommandLineContextTestCase class
+     * The main program for the CommandLineContextTestCase class
      *
      * @param  args           The command line arguments
-     * @exception  Exception  Description of Exception
-     * @since
      */
     public static void main(final String[] args) throws Exception {
         final String[] testCaseName = {CommandLineContextTestCase.class.getName()};
@@ -88,39 +64,31 @@
 
 
     /**
-     *The JUnit setup method
-     *
-     * @exception  Exception  Description of Exception
-     * @since
+     * The JUnit setup method
      */
     public void setUp() throws Exception {
         commandLineContextDir = System.getProperty("java.io.tmpdir", "/tmp");
-        new File(commandLineContextDir, "foo"+File.separator+"bar").mkdirs();
+        new File(commandLineContextDir, "foo" + File.separator + "bar").mkdirs();
+
+        String level = System.getProperty("junit.test.loglevel", "" + ConsoleLogger.LEVEL_DEBUG);
+        Logger logger = new ConsoleLogger(Integer.parseInt(level));
+
         commandLineContext = new CommandLineContext(commandLineContextDir);
-        commandLineContext.enableLogging( new ConsoleLogger() );
+        commandLineContext.enableLogging(logger);
     }
 
-
     /**
-     *The teardown method for JUnit
-     *
-     * @exception  Exception  Description of Exception
-     * @since
+     * The teardown method for JUnit
      */
     public void tearDown() throws Exception {
-        new File(commandLineContextDir, "foo"+File.separator+"bar").delete();
+        new File(commandLineContextDir, "foo" + File.separator + "bar").delete();
         new File(commandLineContextDir, "foo").delete();
     }
 
-
     /**
      * A unit test for <code>getResource()</code>
-     *
-     * @exception  Exception  Description of Exception
-     * @since
      */
     public void testGetResource() throws Exception {
-
         Object[] test_values = {
                 new String[]{"", commandLineContextDir},
                 new String[]{"/", commandLineContextDir},
@@ -136,21 +104,15 @@
             if (result != null) {
                 expected = new File(tests[1]).toURL();
             }
-            String message = "Test " +
-                    "'" + test + "'";
+            String message = "Test " + "'" + test + "'";
             assertEquals(message, expected, result);
         }
     }
 
-
     /**
      * A unit test for <code>getRealPath()</code>
-     *
-     * @exception  Exception  Description of Exception
-     * @since
      */
     public void testGetRealPath() throws Exception {
-
         Object[] test_values = {
                 new String[]{"", ""},
                 new String[]{"/", "/"},
@@ -170,13 +132,9 @@
         }
     }
 
-
     /**
      * A unit test for <code>getAttribute</code>,
      * <code>setAttribute</code>, and <code>removeAttribute()</code>
-     *
-     * @exception  Exception  Description of Exception
-     * @since
      */
     public void testAttributes() throws Exception {
         Object[] test_values = {
@@ -189,11 +147,6 @@
             String name = tests[0];
             String expected = tests[1];
 
-            /* NEVER USED!
-            String message = "Test " +
-                    "'" + name + "'" + ", " + "'" + expected + "'";
-            */
-
             commandLineContext.setAttribute(name, expected);
 
             String result = (String) commandLineContext.getAttribute(name);
@@ -204,29 +157,4 @@
             assertEquals("Test " + "'" + "<null>" + "'", null, result);
         }
     }
-
-
-    /**
-     * Setup a <code>Logger</code>.
-     * <p>
-     *   Setup a logger needed by AbstractLogEnabled objects.
-     * </p>
-     *
-     * @return    Logger for logging
-     * @since
-    private final Logger setupLogger() {
-        //FIXME(GP): This method should setup a LogConfigurator and LogManager
-        //           according to the configuration spec. not yet completed/implemented
-        //           It will return a default logger for now.
-        final org.apache.log.Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor("Test");
-        logger.setPriority(m_logPriority);
-
-        final PatternFormatter formatter = new PatternFormatter(FORMAT);
-        final StreamTarget target = new StreamTarget(System.out, formatter);
-        logger.setLogTargets(new LogTarget[]{target});
-
-        return logger;
-    }
-     */
 }
-

Modified: cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl	(original)
+++ cocoon/branches/BRANCH_2_1_X/tools/src/blocks-build.xsl	Thu Oct 28 07:32:34 2004
@@ -622,8 +622,9 @@
             </classpath>
           </javac>
 
-          <junit printsummary="yes" haltonfailure="yes" fork="yes">
+          <junit printsummary="yes" fork="yes" failureproperty="junit.test.failed">
             <jvmarg value="-Djava.endorsed.dirs=lib/endorsed"/>
+            <jvmarg value="-Djunit.test.loglevel=${{junit.test.loglevel}}"/>
             <classpath>
               <path refid="{$block-name}.classpath"/>
               <path refid="test.classpath"/>
@@ -631,7 +632,8 @@
               <pathelement location="${{build.blocks}}/{$block-name}/test"/>
             </classpath>
             <formatter type="plain" usefile="no"/>
-            <batchtest>
+            <formatter type="xml"/>
+            <batchtest todir="${{build.test.output}}">
               <fileset dir="${{build.blocks}}/{$block-name}/test">
                 <include name="**/*TestCase.class"/>
                 <include name="**/*Test.class"/>

Modified: cocoon/branches/BRANCH_2_1_X/tools/targets/test-build.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/tools/targets/test-build.xml	(original)
+++ cocoon/branches/BRANCH_2_1_X/tools/targets/test-build.xml	Thu Oct 28 07:32:34 2004
@@ -32,16 +32,19 @@
 
   <target name="junit-tests-prepare">
     <delete dir="${build.test.output}"/>
+    <delete dir="${build.test.report}"/>
     <mkdir dir="${build.test.output}"/>
   </target>
 
   <!-- Runs JUnit tests -->
   <target name="core-junit-tests" depends="compile-tests, junit-tests-prepare">
     <junit printsummary="yes" fork="yes" failureproperty="junit.test.failed">
+      <jvmarg value="-Djava.endorsed.dirs=lib/endorsed"/>
+      <jvmarg value="-Djunit.test.loglevel=${junit.test.loglevel}"/>
       <classpath>
         <path refid="test.classpath"/>
       </classpath>
-      <formatter type="plain"/>
+      <formatter type="plain" usefile="no"/>
       <formatter type="xml"/>
       <batchtest todir="${build.test.output}">
         <fileset dir="${build.test}">
@@ -67,6 +70,7 @@
     <junit printsummary="yes" fork="yes" failureproperty="junit.test.failed">
       <jvmarg value="-Xdebug"/>
       <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${junit.test.debugport}"/>
+      <jvmarg value="-Djunit.test.loglevel=${junit.test.loglevel}"/>
       <classpath refid="test.classpath"/>
       <formatter type="plain"/>
       <formatter type="xml"/>
@@ -82,14 +86,15 @@
          target="tests"/>
   </target>      
   
-  <target name="junit-tests-report">
+  <target name="junit-tests-report" depends="init">
+    <mkdir dir="${build.test.report}"/>
     <junitreport todir="${build.test.output}">
       <fileset dir="${build.test.output}">
        <include name="TEST-*.xml"/>
       </fileset>
-      <report format="frames" todir="${build.test.output}"/>
+      <report format="frames" todir="${build.test.report}"/>
     </junitreport>
-    <echo message="Unit report is at ${build.test.output}/index.html"/>
+    <echo message="Unit report is at ${build.test.report}/index.html"/>
     <fail if="junit.test.failed"
           message="One or more JUnit tests failed or caused errors. Please have a look into
the report for details."/>
   </target>

Mime
View raw message