hammant 2002/12/04 05:48:22 Modified: src/documentation/content guide-punit.xml src/java/org/apache/avalon/phoenix/tools/punit PUnitTestCase.java Added: src/java/org/apache/avalon/phoenix/tools/punit PUnit.java PUnitHelper.java Log: typo, junit credits, plus refactor for Punit. Revision Changes Path 1.2 +3 -2 jakarta-avalon-phoenix/src/documentation/content/guide-punit.xml Index: guide-punit.xml =================================================================== RCS file: /home/cvs/jakarta-avalon-phoenix/src/documentation/content/guide-punit.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- guide-punit.xml 30 Nov 2002 08:43:42 -0000 1.1 +++ guide-punit.xml 4 Dec 2002 13:48:21 -0000 1.2 @@ -11,7 +11,8 @@ Phoenix has a component/lifecycle aware unit test framework called PUnit. It has no requirements on external meta information. As such it could be used for unit testing for a wide range of Avalon-Framework enabled components. Having said that, usage requires some knowledge of multi component applications and - the order of component lifecycling. + the order of component lifecycling. PUnit builds on JUnit. You should have testing experience of + <link href="http://www.junit.org">JUnit<link> before using PUnit. </p> </section> <section><title>Example Usage</title> @@ -101,7 +102,7 @@ } </source> <p> - What is shown here is a sinle block being manually instantiated, and registered with PUnit + What is shown here is a single block being manually instantiated, and registered with PUnit (addBlock). Configuration rather than being from a file, is handed in from this source via DefaultConfigurationBuilder (see its other methods for more flexibility). The method startup() is causing the components (one only in this case) to be started. After the normal 1.7 +21 -37 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitTestCase.java Index: PUnitTestCase.java =================================================================== RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitTestCase.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PUnitTestCase.java 12 Nov 2002 20:40:25 -0000 1.6 +++ PUnitTestCase.java 4 Dec 2002 13:48:21 -0000 1.7 @@ -19,13 +19,17 @@ * PUnitTestCase * @author Paul Hammant */ -public abstract class PUnitTestCase - extends TestCase +public abstract class PUnitTestCase extends TestCase implements PUnit { - private LifecycleHelper m_lifecycleHelper; - private ArrayList m_blocks; - private DefaultServiceManager m_serviceManager; - private PUnitLogger m_logger = new PUnitLogger(); + private PUnitHelper m_pUnitHelper = new PUnitHelper(); + + + /** + * PUnitTestCase + */ + public PUnitTestCase() + { + } /** * PUnitTestCase @@ -43,7 +47,7 @@ */ public final String lookupInLog( String startsWith ) { - return m_logger.get( startsWith ); + return m_pUnitHelper.lookupInLog( startsWith ); } /** @@ -51,9 +55,9 @@ * @param startsWith For an expression that starts with this * @return true or not */ - public final boolean logHasEntry( String startsWith ) + public boolean logHasEntry( String startsWith ) { - return m_logger.contains( startsWith ); + return m_pUnitHelper.logHasEntry( startsWith ); } /** @@ -62,10 +66,8 @@ */ protected void setUp() throws Exception { - m_lifecycleHelper = new LifecycleHelper(); - m_lifecycleHelper.enableLogging( new ConsoleLogger() ); - m_serviceManager = new DefaultServiceManager(); - m_blocks = new ArrayList(); + m_pUnitHelper.initialize(); + super.setUp(); } /** @@ -75,48 +77,30 @@ * @param serviceName The service name (for lookup) * @param configuration The configuration */ - protected void addBlock( final String blockName, + public void addBlock( final String blockName, final String serviceName, final Object block, final Configuration configuration ) { - final PUnitResourceProvider resourceProvider = - new PUnitResourceProvider( m_serviceManager, configuration, m_logger ); - final PUnitBlockEntry pBlock = new PUnitBlockEntry( blockName, block, resourceProvider ); - m_blocks.add( pBlock ); - if( serviceName != null ) - { - m_serviceManager.put( serviceName, block ); - } + m_pUnitHelper.addBlock(blockName, serviceName, block, configuration); } /** * Run blocks thru startup. * @throws LifecycleException If a problem */ - protected final void startup() throws LifecycleException + public void startup() throws LifecycleException { - for( int i = 0; i < m_blocks.size(); i++ ) - { - final PUnitBlockEntry block = (PUnitBlockEntry)m_blocks.get( i ); - m_lifecycleHelper.startup( block.getBlockName(), - block.getBlock(), - block.getResourceProvider() ); - } + m_pUnitHelper.startup(); } /** * Run blocks thru shutdown * @throws LifecycleException If a problem */ - protected final void shutdown() throws LifecycleException + public void shutdown() throws LifecycleException { - final int size = m_blocks.size(); - for( int i = 0; i < size; i++ ) - { - final PUnitBlockEntry block = (PUnitBlockEntry)m_blocks.get( i ); - m_lifecycleHelper.shutdown( block.getBlockName(), block.getBlock() ); - } + m_pUnitHelper.shutdown(); } } 1.4 +44 -43 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnit.java 1.1 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitHelper.java Index: PUnitHelper.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.avalon.phoenix.tools.punit; import org.apache.excalibur.containerkit.lifecycle.LifecycleHelper; import org.apache.excalibur.containerkit.lifecycle.LifecycleException; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.service.DefaultServiceManager; import java.util.ArrayList; /** * PUnit helper * @author Paul Hammant */ public final class PUnitHelper implements PUnit, Initializable { private LifecycleHelper m_lifecycleHelper; private ArrayList m_blocks; private DefaultServiceManager m_serviceManager; private PUnitLogger m_logger; /** * Query the log * @param startsWith For an expression that starts with this * @return The logged entry. */ public final String lookupInLog( String startsWith ) { return m_logger.get( startsWith ); } /** * Query the log * @param startsWith For an expression that starts with this * @return true or not */ public boolean logHasEntry( String startsWith ) { return m_logger.contains( startsWith ); } /** * Initialize * @throws Exception If a problem */ public void initialize() throws Exception { m_logger = new PUnitLogger(); m_lifecycleHelper = new LifecycleHelper(); m_lifecycleHelper.enableLogging( new ConsoleLogger() ); m_serviceManager = new DefaultServiceManager(); m_blocks = new ArrayList(); } /** * Add a block * @param blockName The block name * @param block The block * @param serviceName The service name (for lookup) * @param configuration The configuration */ public void addBlock( final String blockName, final String serviceName, final Object block, final Configuration configuration ) { final PUnitResourceProvider resourceProvider = new PUnitResourceProvider( m_serviceManager, configuration, m_logger ); final PUnitBlockEntry pBlock = new PUnitBlockEntry( blockName, block, resourceProvider ); m_blocks.add( pBlock ); if( serviceName != null ) { m_serviceManager.put( serviceName, block ); } } /** * Run blocks thru startup. * @throws LifecycleException If a problem */ public void startup() throws LifecycleException { for( int i = 0; i < m_blocks.size(); i++ ) { final PUnitBlockEntry block = (PUnitBlockEntry)m_blocks.get( i ); m_lifecycleHelper.startup( block.getBlockName(), block.getBlock(), block.getResourceProvider() ); } } /** * Run blocks thru shutdown * @throws LifecycleException If a problem */ public void shutdown() throws LifecycleException { final int size = m_blocks.size(); for( int i = 0; i < size; i++ ) { final PUnitBlockEntry block = (PUnitBlockEntry)m_blocks.get( i ); m_lifecycleHelper.shutdown( block.getBlockName(), block.getBlock() ); } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>