You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/09/12 21:29:42 UTC
cvs commit: jakarta-avalon-excalibur/container/src/test/org/apache/excalibur/container/legacy/test LegacyComponentManagerTestCase.java
bloritsch 2002/09/12 12:29:42
Added: container/src/test/org/apache/excalibur/container/legacy/test
LegacyComponentManagerTestCase.java
Log:
add LegacyComponentManagerTestCase
Revision Changes Path
1.1 jakarta-avalon-excalibur/container/src/test/org/apache/excalibur/container/legacy/test/LegacyComponentManagerTestCase.java
Index: LegacyComponentManagerTestCase.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.excalibur.container.legacy.test;
import org.apache.avalon.framework.component.*;
import org.apache.avalon.framework.service.*;
import org.apache.excalibur.container.legacy.LegacyComponentManager;
import junit.framework.TestCase;
/**
* Test the LegacyComponentManager/Selector. Requires JDK 1.3+
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
*/
public final class LegacyComponentManagerTestCase extends junit.framework.TestCase
{
public LegacyComponentManagerTestCase()
{
this("Test the LegacyCompoenntManager");
}
public LegacyComponentManagerTestCase(String name)
{
super( name );
}
public static interface Test
{
String ROLE = Test.class.getName();
int getTestVal();
}
private final static String SELECTOR_ROLE = Test.ROLE + "Selector";
private static final class TestImpl implements Test
{
private final int m_val;
public TestImpl() { this( -1 ); }
public TestImpl( int val ) { m_val = val; }
public int getTestVal() { return m_val; }
}
public void setUp()
{
DefaultServiceSelector selector = new DefaultServiceSelector();
selector.put( "default", new TestImpl(0) );
selector.put( "other", new TestImpl(1) );
selector.makeReadOnly();
DefaultServiceManager manager = new DefaultServiceManager();
manager.put( SELECTOR_ROLE, selector );
manager.put( Test.ROLE, new TestImpl(7) );
manager.makeReadOnly();
m_manager = manager;
m_legacyManager = new LegacyComponentManager( m_manager );
}
private ComponentManager m_legacyManager;
private ServiceManager m_manager;
private void assertIsComponent( Object comp )
{
assertTrue( comp + " is not a component", comp instanceof Component );
}
private void assertNotComponent( Object comp )
{
assertTrue( comp + " is a component", ! ( comp instanceof Component ) );
}
public void testRegularLookup()
throws Exception
{
assertTrue( m_manager.hasService( Test.ROLE ) );
assertTrue( m_legacyManager.hasComponent( Test.ROLE ) );
Test service = (Test) m_manager.lookup( Test.ROLE );
Test component = (Test) m_legacyManager.lookup( Test.ROLE );
assertTrue( service != null );
assertTrue( component != null );
assertNotComponent( service );
assertIsComponent( component );
assertEquals( service.getTestVal(), component.getTestVal() );
assertEquals( 7, component.getTestVal() );
assertEquals( 7, service.getTestVal() );
}
public void testSelectorLookup()
throws Exception
{
assertTrue( m_manager.hasService( SELECTOR_ROLE ) );
assertTrue( m_legacyManager.hasComponent( SELECTOR_ROLE ) );
Object serviceTst = m_manager.lookup( SELECTOR_ROLE );
Object componentTst = m_legacyManager.lookup( SELECTOR_ROLE );
assertTrue( serviceTst != null );
assertTrue( componentTst != null );
assertNotComponent( serviceTst );
assertIsComponent( componentTst );
assertTrue( serviceTst instanceof ServiceSelector );
assertTrue( componentTst instanceof ComponentSelector );
}
public void testWIthinSelectorLookup()
throws Exception
{
assertTrue( m_manager.hasService( SELECTOR_ROLE ) );
assertTrue( m_legacyManager.hasComponent( SELECTOR_ROLE ) );
ServiceSelector svcSel = (ServiceSelector) m_manager.lookup( SELECTOR_ROLE );
ComponentSelector cmpSel = (ComponentSelector) m_legacyManager.lookup( SELECTOR_ROLE );
assertTrue( svcSel != null );
assertTrue( cmpSel != null );
assertNotComponent( svcSel );
assertIsComponent( cmpSel );
assertTrue( svcSel.isSelectable( "default" ) );
assertTrue( cmpSel.hasComponent( "default" ) );
Test service = (Test) svcSel.select( "default" );
Test component = (Test) cmpSel.select( "default" );
assertTrue( service != null );
assertTrue( component != null );
assertNotComponent( service );
assertIsComponent( component );
assertEquals( service.getTestVal(), component.getTestVal() );
assertEquals( 0, component.getTestVal() );
assertEquals( 0, service.getTestVal() );
assertTrue( svcSel.isSelectable( "other" ) );
assertTrue( cmpSel.hasComponent( "other" ) );
service = (Test) svcSel.select( "other" );
component = (Test) cmpSel.select( "other" );
assertTrue( service != null );
assertTrue( component != null );
assertNotComponent( service );
assertIsComponent( component );
assertEquals( service.getTestVal(), component.getTestVal() );
assertEquals( 1, component.getTestVal() );
assertEquals( 1, service.getTestVal() );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>