You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2002/11/06 00:50:51 UTC
cvs commit: jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/tools/punit/test PUnitTestCaseTestCase.java TestBlock.java
hammant 2002/11/05 15:50:50
Modified: src/java/org/apache/avalon/phoenix/tools/punit
PUnitBlock.java PUnitResourceProvider.java
PUnitServiceManager.java
Added: src/java/org/apache/avalon/phoenix/tools/punit
PUnitComponentManager.java PUnitTestCase.java
src/test/org/apache/avalon/phoenix/tools/punit/test
PUnitTestCaseTestCase.java TestBlock.java
Removed: src/java/org/apache/avalon/phoenix/tools/punit PUnit.java
Log:
Punit working to a point
Revision Changes Path
1.3 +6 -7 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitBlock.java
Index: PUnitBlock.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitBlock.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PUnitBlock.java 1 Nov 2002 08:21:14 -0000 1.2
+++ PUnitBlock.java 5 Nov 2002 23:50:50 -0000 1.3
@@ -8,20 +8,19 @@
package org.apache.avalon.phoenix.tools.punit;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
public class PUnitBlock
{
private String m_blockName;
private Object m_block;
- private Configuration m_configuration;
+ private ResourceProvider m_resourceProvider;
- public PUnitBlock( String blockName, Object block, Configuration configuration )
+ public PUnitBlock( String blockName, Object block, ResourceProvider resourceProvider )
{
this.m_blockName = blockName;
this.m_block = block;
- this.m_configuration = configuration;
- // logger ?
- // context ?
+ this.m_resourceProvider = resourceProvider;
}
public String getBlockName()
@@ -34,8 +33,8 @@
return m_block;
}
- public Configuration getConfiguration()
+ public ResourceProvider getResourceProvider()
{
- return m_configuration;
+ return m_resourceProvider;
}
}
1.3 +28 -6 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitResourceProvider.java
Index: PUnitResourceProvider.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitResourceProvider.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PUnitResourceProvider.java 1 Nov 2002 08:22:37 -0000 1.2
+++ PUnitResourceProvider.java 5 Nov 2002 23:50:50 -0000 1.3
@@ -1,8 +1,17 @@
+/*
+ * 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.ResourceProvider;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.configuration.Configuration;
@@ -11,34 +20,47 @@
public class PUnitResourceProvider
implements ResourceProvider
{
+
+ private PUnitServiceManager m_pUnitServiceManager;
+ private PUnitComponentManager m_pUnitComponentManager;
+ private Configuration m_configuration;
+
+ public PUnitResourceProvider(PUnitServiceManager pUnitServiceManager, Configuration configuration)
+ {
+ m_pUnitServiceManager = pUnitServiceManager;
+ m_pUnitComponentManager = new PUnitComponentManager(pUnitServiceManager);
+ m_configuration = configuration;
+ }
+
public Object createObject(Object o) throws Exception
{
- return null;
+ return o;
}
public Logger createLogger(Object o) throws Exception
{
- return null;
+ // should be queryable mock logger ?
+ return new ConsoleLogger();
}
public Context createContext(Object o) throws Exception
{
- return null;
+ return new DefaultContext();
}
public ComponentManager createComponentManager(Object o) throws Exception
{
- return null;
+ return m_pUnitComponentManager;
}
public ServiceManager createServiceManager(Object o) throws Exception
{
- return new PUnitServiceManager();
+ return m_pUnitServiceManager;
}
public Configuration createConfiguration(Object o) throws Exception
{
- return null;
+ return m_configuration;
}
public Parameters createParameters(Object o) throws Exception
1.3 +19 -2 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitServiceManager.java
Index: PUnitServiceManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitServiceManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PUnitServiceManager.java 1 Nov 2002 08:21:14 -0000 1.2
+++ PUnitServiceManager.java 5 Nov 2002 23:50:50 -0000 1.3
@@ -1,23 +1,40 @@
+/*
+ * 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.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
+import java.util.HashMap;
+
public class PUnitServiceManager
implements ServiceManager
{
+ private HashMap m_serviceMap = new HashMap();
+
+ void addService( String name, Object object )
+ {
+ m_serviceMap.put(name, object);
+ }
+
public Object lookup( String key )
throws ServiceException
{
- return null;
+ return m_serviceMap.get(key);
}
public boolean hasService( String key )
{
- return false;
+ return m_serviceMap.containsKey(key);
}
public void release( Object service )
{
+
}
}
1.1 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitComponentManager.java
Index: PUnitComponentManager.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.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
public class PUnitComponentManager
implements ComponentManager
{
private ServiceManager m_serviceManager;
public PUnitComponentManager(ServiceManager serviceManager)
{
this.m_serviceManager = serviceManager;
}
public Component lookup( String key )
throws ComponentException
{
try
{
return (Component) m_serviceManager.lookup(key);
}
catch (ServiceException e)
{
throw new ComponentException(e.getMessage(), e.getCause());
}
}
public boolean hasComponent( String key )
{
return m_serviceManager.hasService(key);
}
public void release( Component Component )
{
}
}
1.1 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/punit/PUnitTestCase.java
Index: PUnitTestCase.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.logger.ConsoleLogger;
import org.apache.avalon.framework.configuration.Configuration;
import junit.framework.TestCase;
import java.util.ArrayList;
public abstract class PUnitTestCase extends TestCase
{
private LifecycleHelper m_lifecycleHelper;
private ArrayList m_blocks;
private PUnitServiceManager m_pUnitServiceManager;
protected void setUp() throws Exception
{
m_lifecycleHelper = new LifecycleHelper();
m_lifecycleHelper.enableLogging( new ConsoleLogger() );
m_pUnitServiceManager = new PUnitServiceManager();
m_blocks = new ArrayList();
}
public PUnitTestCase( String name )
{
super( name );
}
protected void addBlock( String blockName, String serviceName, Object block , Configuration configuration)
{
PUnitBlock pBlock = new PUnitBlock( blockName, block,
new PUnitResourceProvider(m_pUnitServiceManager, configuration) );
m_blocks.add( pBlock );
if (serviceName != null)
{
m_pUnitServiceManager.addService(serviceName, block);
}
}
protected final void startup() throws LifecycleException
{
System.out.println("--> a? ");
for( int i = 0; i < m_blocks.size(); i++ )
{
System.out.println("--> a " + i);
final PUnitBlock block = (PUnitBlock) m_blocks.get( i );
m_lifecycleHelper.startup( block.getBlockName(),
block.getBlock(),
block.getResourceProvider() );
}
}
protected final void shutdown() throws LifecycleException
{
for( int i = 0; i < m_blocks.size(); i++ )
{
PUnitBlock block = (PUnitBlock) m_blocks.get( i );
m_lifecycleHelper.shutdown( block.getBlockName(), block.getBlock() );
}
}
}
1.1 jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/tools/punit/test/PUnitTestCaseTestCase.java
Index: PUnitTestCaseTestCase.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 file.
*/
package org.apache.avalon.phoenix.tools.punit.test;
import org.apache.avalon.phoenix.tools.punit.PUnitTestCase;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.configuration.Configuration;
import org.xml.sax.InputSource;
import java.io.StringReader;
public class PUnitTestCaseTestCase extends PUnitTestCase
{
DefaultConfigurationBuilder m_defaultConfigurationBuilder = new DefaultConfigurationBuilder();
public PUnitTestCaseTestCase(String name)
{
super(name);
}
public void testBasicBlock() throws Exception
{
TestBlock block = new TestBlock();
Configuration configuration = m_defaultConfigurationBuilder.build(
new InputSource(new StringReader("<hi>Hi</hi>")));
addBlock("bl","block", block, configuration);
startup();
assertNotNull("Configuration null", block.m_configuration);
assertNotNull("Context null", block.m_context);
assertNotNull("Logger null", block.m_logger);
assertNotNull("ServiceManager null", block.m_serviceManager);
assertTrue("Not Initialized", block.m_initialized);
shutdown();
}
}
1.1 jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/tools/punit/test/TestBlock.java
Index: TestBlock.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.test;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
public class TestBlock
implements Serviceable, Configurable, Initializable, Contextualizable, LogEnabled
{
public ServiceManager m_serviceManager;
public boolean m_initialized;
public Context m_context;
public Logger m_logger;
public Configuration m_configuration;
public void service( final ServiceManager serviceManager ) throws ServiceException
{
System.out.println("-->1");
m_serviceManager = serviceManager;
}
public void initialize() throws Exception
{
System.out.println("-->2");
m_initialized = true;
}
public void contextualize(Context context) throws ContextException
{
System.out.println("-->3");
m_context = context;
}
public void enableLogging(Logger logger)
{
System.out.println("-->4");
m_logger = logger;
}
public void configure(Configuration configuration) throws ConfigurationException
{
System.out.println("-->5");
m_configuration = configuration;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>