Hi Luciano,

I am just about sharing my experience in this without going too much into
what you are doing.  Hope this helps.  If you still have problems, let me
know and I will take a detailed look into this.

I assume you are trying to test an ImplementationLoader for its handling of
duplicate components.  If so, then you must simply have to focus on that
'unit'  i.e. the ImplementationLoader.  You need not test if the loader is
registered or picked up from the registry and invoked.  These things you
assume and just start with the phase when the loader is actually invoked.

Through the mock reader you only need to feed those inputs that the Loader
actually reads from the XMLReader argument.  Basically you provide mock
inputs just to the Loader and test how it handles these inputs.  So in your
case you might be feeding in duplicates to see if the loader is able to
detect this.

- Venkat



On 1/23/07, Luciano Resende <[EMAIL PROTECTED]> wrote:

I'm trying to use easyMock to create a unit testing to verify that
exception
is being thrown for duplicated Components...
Looks like the reader that is simulating the scdl is returning the right
values, but then, the registry does not find a loader to handle
implementation.java

Portion given by the reader so far :

        <composite xmlns="http://www.osoa.org/xmlns/sca/1.0";
                   name="composite_component-include2">

            <component name="component">
                <implementation.java class="
org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/>

It's failing as it's not finding the proper loader to handle
implementation.java... How do I tell get the registry properly loaded with
the proper loaders registred ? Or any other way I should handle this ?

Code:

    public void testLoadDuplicatedComponentTypeFromMock() throws
Exception{
        /*
        //main
        <composite xmlns="http://www.osoa.org/xmlns/sca/1.0";
name="CompositeComponent">
            <include name="composite_component-include1"
scdlLocation="composite_component-include1.scdl"/>
            <include name="composite_component-include2"
scdlLocation="composite_component-include2.scdl"/>
        </composite>
        //include 1
        <composite xmlns="http://www.osoa.org/xmlns/sca/1.0";
                   name="composite_component-include2">

            <component name="component">
                <implementation.java class="
org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/>
            </component>

            <service name="service" >
                <interface.java interface="
org.apache.tuscany.core.mock.component.BasicInterface"/>
                <reference>component</reference>
            </service>
        </composite>
         */


        EasyMock.expect(mockReader.getName()).andReturn(COMPOSITE);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.isA(String.class))).andReturn(COMPOSITE_NAME);
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.START_ELEMENT);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.isA(String.class))).andReturn(COMPOSITE_NAME);

        //first component
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.START_ELEMENT);
        EasyMock.expect(mockReader.getName()).andReturn(COMPONENT);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.isA(String.class))).andReturn(COMPONENT_NAME);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.eq("initLevel"))).andReturn(null);
        EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(
String.class), EasyMock.isA(String.class))).andReturn(null);
        EasyMock.expect(mockReader.nextTag()).andReturn(0);
        EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(
String.class), EasyMock.isA(String.class))).andReturn(null);
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.START_ELEMENT);
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.END_ELEMENT);
        EasyMock.expect(mockReader.getName()).andReturn(null
/*COMPONENT_IMPLEMENTATION_JAVA*/);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.isA(String.class))).andReturn(null
/*COMPONENT_IMPLEMENTATION_JAVA_CLASS*/);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.eq("initLevel"))).andReturn(null);
        EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(
String.class), EasyMock.isA(String.class))).andReturn(null);
        EasyMock.expect(mockReader.nextTag()).andReturn(0);
        EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(
String.class), EasyMock.isA(String.class))).andReturn(null);
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.END_ELEMENT);
        //second and duplicated component
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.START_ELEMENT);
        EasyMock.expect(mockReader.getName()).andReturn(COMPONENT);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.isA(String.class))).andReturn(COMPONENT_NAME);
        EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(
String.class), EasyMock.isA(String.class))).andReturn(null);
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.START_ELEMENT);
        EasyMock.expect(mockReader.getName
()).andReturn(COMPONENT_IMPLEMENTATION_JAVA);
        EasyMock.expect(mockReader.getAttributeValue((String)
EasyMock.isNull(), EasyMock.isA(String.class
))).andReturn(COMPONENT_IMPLEMENTATION_JAVA_CLASS);
        EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(
String.class), EasyMock.isA(String.class))).andReturn(null);
        EasyMock.expect(mockReader.next()).andReturn(
XMLStreamConstants.END_ELEMENT);

        //replay reader
        EasyMock.replay(mockReader);

        ModelObject modelObject = new ModelObject() {};

        CompositeComponentType composite = loader.load(
EasyMock.createNiceMock(CompositeComponent.class),
            modelObject,
            mockReader,
            EasyMock.createNiceMock(DeploymentContext.class));

        assertEquals(COMPOSITE_NAME, composite.getName());

    }

Exception:

java.lang.NullPointerException
    at org.apache.tuscany.spi.loader.UnrecognizedElementException.<init>(
UnrecognizedElementException.java:39)
    at org.apache.tuscany.core.loader.LoaderRegistryImpl.load(
LoaderRegistryImpl.java:82)
    at org.apache.tuscany.core.loader.ComponentLoader.loadImplementation(
ComponentLoader.java:199)
    at org.apache.tuscany.core.loader.ComponentLoader.load(
ComponentLoader.java:110)
    at org.apache.tuscany.core.loader.ComponentLoader.load(
ComponentLoader.java:79)
    at org.apache.tuscany.core.loader.LoaderRegistryImpl.load(
LoaderRegistryImpl.java:84)
    at
org.apache.tuscany.core.implementation.composite.CompositeLoader.load
(CompositeLoader.java:96)
    at
org.apache.tuscany.core.implementation.composite.CompositeLoader.load
(CompositeLoader.java:68)
    at org.apache.tuscany.core.loader.LoaderRegistryImpl.load(
LoaderRegistryImpl.java:84)
    at
org.apache.tuscany.core.implementation.composite.CompositeLoader.load
(CompositeLoader.java:96)
    at

org.apache.tuscany.core.implementation.composite.CompositeLoaderTestCase.testLoadDuplicatedComponentTypeFromMock
(CompositeLoaderTestCase.java:152)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(
JUnit3TestReference.java:128)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(
TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(
RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
RemoteTestRunner.java:196)




--
Luciano Resende
http://people.apache.org/~lresende


Reply via email to