Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/container-integration/src/test/org/jicarilla/container/test/integration/avalon
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19900/container-integration/src/test/org/jicarilla/container/test/integration/avalon
Added Files:
AbstractAvalonAllInTheFamilyTestCase.java
JicarillaBasedAvalonAllInTheFamilyTestCase.java
JicarillaBasedFortressContainerTestCase.java
Log Message:
split out integration code from the main container project
--- NEW FILE: AbstractAvalonAllInTheFamilyTestCase.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.test.integration.avalon;
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
import org.jicarilla.container.tck.AbstractAllInTheFamilyTestCase;
import org.jicarilla.container.tck.components.interfaces.Bart;
import org.jicarilla.container.tck.components.interfaces.Homer;
import org.jicarilla.container.tck.components.interfaces.Lisa;
import org.jicarilla.container.tck.components.interfaces.Maggie;
import org.jicarilla.container.tck.components.interfaces.Marge;
import org.jicarilla.container.tck.components.interfaces.Script;
import org.jicarilla.container.tck.components.type3.rich.AllInTheFamilyScript;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: AbstractAvalonAllInTheFamilyTestCase.java,v 1.1 2004/03/08 21:05:25 lsimons Exp $
*/
public abstract class AbstractAvalonAllInTheFamilyTestCase
extends AbstractAllInTheFamilyTestCase
{
protected Container c;
protected abstract Container getContainer();
public void setUp() throws Exception
{
c = getContainer();
super.setUp();
}
protected AllInTheFamilyScript getScript()
{
try
{
ComponentHandler handler =
(ComponentHandler)c.get( Script.class.getName(), null );
return (AllInTheFamilyScript)handler.get();
}
catch( Exception e )
{
fail(
"Can't comply with getScript() because of a " +
"Exception of type " + e.getClass().getName() + " which " +
"provides the message: " + e.getMessage() );
}
return null; // unreachable!
}
protected Homer getHomer()
{
try
{
ComponentHandler handler =
(ComponentHandler)c.get( Homer.class.getName(), null );
return (Homer)handler.get();
}
catch( Exception e )
{
fail(
"Can't comply with getHomer() because of a " +
"Exception of type " + e.getClass().getName() + " which " +
"provides the message: " + e.getMessage() );
}
return null; // unreachable!
}
protected Marge getMarge()
{
try
{
ComponentHandler handler =
(ComponentHandler)c.get( Marge.class.getName(), null );
return (Marge)handler.get();
}
catch( Exception e )
{
fail(
"Can't comply with getMarge() because of a " +
"Exception of type " + e.getClass().getName() + " which " +
"provides the message: " + e.getMessage() );
}
return null; // unreachable!
}
protected Bart getBart()
{
try
{
ComponentHandler handler =
(ComponentHandler)c.get( Bart.class.getName(), null );
return (Bart)handler.get();
}
catch( Exception e )
{
fail(
"Can't comply with getBart() because of a " +
"Exception of type " + e.getClass().getName() + " which " +
"provides the message: " + e.getMessage() );
}
return null; // unreachable!
}
protected Lisa getLisa()
{
try
{
ComponentHandler handler =
(ComponentHandler)c.get( Lisa.class.getName(), null );
return (Lisa)handler.get();
}
catch( Exception e )
{
fail(
"Can't comply with getLisa() because of a " +
"Exception of type " + e.getClass().getName() + " which " +
"provides the message: " + e.getMessage() );
}
return null; // unreachable!
}
protected Maggie getMaggie()
{
try
{
ComponentHandler handler =
(ComponentHandler)c.get( Maggie.class.getName(), null );
return (Maggie)handler.get();
}
catch( Exception e )
{
fail(
"Can't comply with getMaggie() because of a " +
"Exception of type " + e.getClass().getName() + " which " +
"provides the message: " + e.getMessage() );
}
return null; // unreachable!
}
}
--- NEW FILE: JicarillaBasedAvalonAllInTheFamilyTestCase.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.test.integration.avalon;
import org.apache.avalon.fortress.Container;
import org.jicarilla.container.Resolver;
import org.jicarilla.container.adapters.SingletonAdapter;
import org.jicarilla.container.factories.Type1ComponentFactory;
import org.jicarilla.container.factories.Type25ComponentFactory;
import org.jicarilla.container.factories.Type2ComponentFactory;
import org.jicarilla.container.factories.Type35ComponentFactory;
import org.jicarilla.container.integration.avalon.JicarillaBasedFortressContainer;
import org.jicarilla.container.selectors.HintedClassSelector;
import org.jicarilla.container.tck.components.interfaces.Bart;
import org.jicarilla.container.tck.components.interfaces.Homer;
import org.jicarilla.container.tck.components.interfaces.Lisa;
import org.jicarilla.container.tck.components.interfaces.Maggie;
import org.jicarilla.container.tck.components.interfaces.Marge;
import org.jicarilla.container.tck.components.interfaces.Script;
import org.jicarilla.container.tck.components.type1.avalon.AvalonBart;
import org.jicarilla.container.tck.components.type1.avalon.AvalonHomer;
import org.jicarilla.container.tck.components.type1.avalon.AvalonLisa;
import org.jicarilla.container.tck.components.type1.avalon.AvalonMaggie;
import org.jicarilla.container.tck.components.type1.avalon.AvalonMarge;
import org.jicarilla.container.tck.components.type3.rich.AllInTheFamilyScript;
/**
*
*
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: JicarillaBasedAvalonAllInTheFamilyTestCase.java,v 1.1 2004/03/08 21:05:25 lsimons Exp $
*/
public class JicarillaBasedAvalonAllInTheFamilyTestCase
extends AbstractAvalonAllInTheFamilyTestCase
{
protected Container getContainer()
{
JicarillaBasedFortressContainer jc = new JicarillaBasedFortressContainer();
doPopulate(jc);
return jc;
}
protected void doPopulate( JicarillaBasedFortressContainer jc )
{
Resolver r = jc.getResolver();
jc.registerAdapter(
new HintedClassSelector(Marge.class),
new SingletonAdapter(
new Type1ComponentFactory( r, AvalonMarge.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Homer.class),
new SingletonAdapter(
new Type25ComponentFactory( r, AvalonHomer.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Bart.class),
new SingletonAdapter(
new Type2ComponentFactory( r, AvalonBart.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Lisa.class),
new SingletonAdapter(
new Type1ComponentFactory( r, AvalonLisa.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Maggie.class),
new SingletonAdapter(
new Type2ComponentFactory( r, AvalonMaggie.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Script.class),
new SingletonAdapter(
new Type35ComponentFactory( r, AllInTheFamilyScript.class.getName() )
)
);
}
}
--- NEW FILE: JicarillaBasedFortressContainerTestCase.java ---
/* ====================================================================
The Jicarilla Software License
Copyright (c) 2003 Leo Simons.
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.container.test.integration.avalon;
import junit.framework.TestCase;
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
import org.apache.avalon.framework.service.ServiceException;
import org.jicarilla.container.Resolver;
import org.jicarilla.container.adapters.SingletonAdapter;
import org.jicarilla.container.factories.Type1ComponentFactory;
import org.jicarilla.container.factories.Type25ComponentFactory;
import org.jicarilla.container.factories.Type2ComponentFactory;
import org.jicarilla.container.factories.Type35ComponentFactory;
import org.jicarilla.container.integration.avalon.JicarillaBasedFortressContainer;
import org.jicarilla.container.selectors.HintedClassSelector;
import org.jicarilla.container.tck.components.interfaces.Apu;
import org.jicarilla.container.tck.components.interfaces.Bart;
import org.jicarilla.container.tck.components.interfaces.Homer;
import org.jicarilla.container.tck.components.interfaces.Lisa;
import org.jicarilla.container.tck.components.interfaces.Maggie;
import org.jicarilla.container.tck.components.interfaces.Marge;
import org.jicarilla.container.tck.components.interfaces.Script;
import org.jicarilla.container.tck.components.type1.avalon.AvalonApu;
import org.jicarilla.container.tck.components.type1.avalon.AvalonBart;
import org.jicarilla.container.tck.components.type1.avalon.AvalonHomer;
import org.jicarilla.container.tck.components.type1.avalon.AvalonLisa;
import org.jicarilla.container.tck.components.type1.avalon.AvalonMaggie;
import org.jicarilla.container.tck.components.type1.avalon.AvalonMarge;
import org.jicarilla.container.tck.components.type3.rich.AllInTheFamilyScript;
/**
* @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
* @version $Id: JicarillaBasedFortressContainerTestCase.java,v 1.1 2004/03/08 21:05:25 lsimons Exp $
*/
public class JicarillaBasedFortressContainerTestCase extends TestCase
{
Container container = getContainer();
protected Container getContainer()
{
JicarillaBasedFortressContainer jc =
new JicarillaBasedFortressContainer();
Resolver r = jc.getResolver();
jc.registerAdapter(
new HintedClassSelector(Apu.class),
new SingletonAdapter(
new Type1ComponentFactory( r, AvalonApu.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Marge.class),
new SingletonAdapter(
new Type1ComponentFactory( r, AvalonMarge.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Homer.class),
new SingletonAdapter(
new Type25ComponentFactory( r, AvalonHomer.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Bart.class),
new SingletonAdapter(
new Type2ComponentFactory( r, AvalonBart.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Lisa.class),
new SingletonAdapter(
new Type1ComponentFactory( r, AvalonLisa.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Maggie.class),
new SingletonAdapter(
new Type2ComponentFactory( r, AvalonMaggie.class.getName() )
)
);
jc.registerAdapter(
new HintedClassSelector(Script.class),
new SingletonAdapter(
new Type35ComponentFactory( r, AllInTheFamilyScript.class.getName() )
)
);
return jc;
}
public void testBasicGet() throws Throwable
{
ComponentHandler handler =
(ComponentHandler)container.get( Homer.class.getName(), null );
Object instance = handler.get();
assertTrue( instance instanceof Homer );
assertTrue(
Homer.class.isAssignableFrom( handler.getComponentClass() ));
handler.put( instance );
}
public void testGetDoesNotAcceptNullKey() throws Throwable
{
try
{
container.get( null, null );
fail();
}
catch( Throwable t )
{
assertNotNull( t );
assertTrue( t instanceof ServiceException );
}
}
public void testGetAllSimpsons() throws Throwable
{
ComponentHandler handler =
(ComponentHandler)container.get( Homer.class.getName(), null );
Object instance = handler.get();
assertTrue( instance instanceof Homer );
handler =
(ComponentHandler)container.get( Apu.class.getName(), null );
instance = handler.get();
assertTrue( instance instanceof Apu );
handler =
(ComponentHandler)container.get( Marge.class.getName(), null );
instance = handler.get();
assertTrue( instance instanceof Marge );
handler =
(ComponentHandler)container.get( Bart.class.getName(), null );
instance = handler.get();
assertTrue( instance instanceof Bart );
handler =
(ComponentHandler)container.get( Lisa.class.getName(), null );
instance = handler.get();
assertTrue( instance instanceof Lisa );
handler =
(ComponentHandler)container.get( Maggie.class.getName(), null );
instance = handler.get();
assertTrue( instance instanceof Maggie );
handler =
(ComponentHandler)container.get( Script.class.getName(), null );
instance = handler.get();
assertTrue( instance instanceof Script );
Script script = (Script)instance;
script.runEpisode();
}
}
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.