diff options
Diffstat (limited to 'tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader')
14 files changed, 0 insertions, 1433 deletions
diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java deleted file mode 100644 index c17d96a145..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader; - -import static javax.naming.Context.INITIAL_CONTEXT_FACTORY; -import java.io.StringReader; -import java.util.Hashtable; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.Name; -import javax.naming.NameClassPair; -import javax.naming.NamingEnumeration; -import javax.naming.Binding; -import javax.naming.NameParser; -import javax.naming.spi.InitialContextFactory; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.loader.impl.JNDIPropertyFactory; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; - -/** - * @version $Rev$ $Date$ - */ -@SuppressWarnings({"AccessOfSystemProperties"}) -public class JNDIPropertyFactoryTestCase extends TestCase { - private JNDIPropertyFactory factory; - private XMLInputFactory xmlFactory; - private Property property; - private String oldICF; - - public void testLookup() throws XMLStreamException, ConfigurationLoadException { - String instance = getInstance(String.class, "<foo>foo:/hello</foo>"); - assertEquals("Hello World", instance); - } - - private <T> T getInstance(Class<T> type, String xml) throws XMLStreamException, ConfigurationLoadException { - property.setType(type); - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - ObjectFactory<T> objectFactory = (ObjectFactory<T>) factory.createObjectFactory(reader, property); - return objectFactory.getInstance(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new JNDIPropertyFactory(); - xmlFactory = XMLInputFactory.newInstance(); - AssemblyFactory assemblyFactory = new AssemblyFactoryImpl(); - property = assemblyFactory.createProperty(); - - oldICF = System.getProperty(INITIAL_CONTEXT_FACTORY); - System.setProperty(INITIAL_CONTEXT_FACTORY, MockContextFactory.class.getName()); - } - - protected void tearDown() throws Exception { - if (oldICF != null) { - System.getProperty(INITIAL_CONTEXT_FACTORY, oldICF); - } - super.tearDown(); - } - - public static class MockContextFactory implements InitialContextFactory { - public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { - return new MockContext(); - } - } - - public static class MockContext implements Context { - public Object lookup(String name) throws NamingException { - if ("foo:/hello".equals(name)) { - return "Hello World"; - } - throw new AssertionError(); - } - - public Object lookup(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void bind(Name name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void bind(String name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rebind(Name name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rebind(String name, Object obj) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void unbind(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void unbind(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rename(Name oldName, Name newName) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void rename(String oldName, String newName) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<NameClassPair> list(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NamingEnumeration<Binding> listBindings(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void destroySubcontext(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public void destroySubcontext(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Context createSubcontext(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Context createSubcontext(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object lookupLink(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object lookupLink(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NameParser getNameParser(Name name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public NameParser getNameParser(String name) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Name composeName(Name name, Name prefix) throws NamingException { - throw new UnsupportedOperationException(); - } - - public String composeName(String name, String prefix) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object addToEnvironment(String propName, Object propVal) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Object removeFromEnvironment(String propName) throws NamingException { - throw new UnsupportedOperationException(); - } - - public Hashtable<?, ?> getEnvironment() throws NamingException { - throw new UnsupportedOperationException(); - } - - public void close() throws NamingException { - throw new UnsupportedOperationException(); - } - - public String getNameInNamespace() throws NamingException { - throw new UnsupportedOperationException(); - } - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/MockReaderSupport.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/MockReaderSupport.java deleted file mode 100644 index 542a4d7b2b..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/MockReaderSupport.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.Location; -import javax.xml.namespace.QName; -import javax.xml.namespace.NamespaceContext; - -/** - * Base class for a mock XMLStreamReader. - * - * @version $Rev$ $Date$ - */ -public class MockReaderSupport implements XMLStreamReader { - public QName getName() { - throw new UnsupportedOperationException(); - } - - public Object getProperty(String name) throws IllegalArgumentException { - throw new UnsupportedOperationException(); - } - - public int next() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public void require(int i, String name, String name1) throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public String getElementText() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public int nextTag() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public void close() throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public String getNamespaceURI(String name) { - throw new UnsupportedOperationException(); - } - - public boolean isStartElement() { - throw new UnsupportedOperationException(); - } - - public boolean isEndElement() { - throw new UnsupportedOperationException(); - } - - public boolean isCharacters() { - throw new UnsupportedOperationException(); - } - - public boolean isWhiteSpace() { - throw new UnsupportedOperationException(); - } - - public String getAttributeValue(String name, String name1) { - throw new UnsupportedOperationException(); - } - - public int getAttributeCount() { - throw new UnsupportedOperationException(); - } - - public QName getAttributeName(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeNamespace(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeLocalName(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributePrefix(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeType(int i) { - throw new UnsupportedOperationException(); - } - - public String getAttributeValue(int i) { - throw new UnsupportedOperationException(); - } - - public boolean isAttributeSpecified(int i) { - throw new UnsupportedOperationException(); - } - - public int getNamespaceCount() { - throw new UnsupportedOperationException(); - } - - public String getNamespacePrefix(int i) { - throw new UnsupportedOperationException(); - } - - public String getNamespaceURI(int i) { - throw new UnsupportedOperationException(); - } - - public NamespaceContext getNamespaceContext() { - throw new UnsupportedOperationException(); - } - - public int getEventType() { - throw new UnsupportedOperationException(); - } - - public String getText() { - throw new UnsupportedOperationException(); - } - - public char[] getTextCharacters() { - throw new UnsupportedOperationException(); - } - - public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException { - throw new UnsupportedOperationException(); - } - - public int getTextStart() { - throw new UnsupportedOperationException(); - } - - public int getTextLength() { - throw new UnsupportedOperationException(); - } - - public String getEncoding() { - throw new UnsupportedOperationException(); - } - - public boolean hasText() { - throw new UnsupportedOperationException(); - } - - public Location getLocation() { - throw new UnsupportedOperationException(); - } - - public String getLocalName() { - throw new UnsupportedOperationException(); - } - - public boolean hasName() { - throw new UnsupportedOperationException(); - } - - public String getNamespaceURI() { - throw new UnsupportedOperationException(); - } - - public String getPrefix() { - throw new UnsupportedOperationException(); - } - - public String getVersion() { - throw new UnsupportedOperationException(); - } - - public boolean isStandalone() { - throw new UnsupportedOperationException(); - } - - public boolean standaloneSet() { - throw new UnsupportedOperationException(); - } - - public String getCharacterEncodingScheme() { - throw new UnsupportedOperationException(); - } - - public String getPITarget() { - throw new UnsupportedOperationException(); - } - - public String getPIData() { - throw new UnsupportedOperationException(); - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryTestCase.java deleted file mode 100644 index 177e4e5005..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryTestCase.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader; - -import java.util.List; -import java.util.ArrayList; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.loader.impl.StAXLoaderRegistryImpl; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.AssemblyObject; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.AssemblyInitializationException; -import org.apache.tuscany.model.assembly.AssemblyVisitor; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; - -/** - * @version $Rev$ $Date$ - */ -public class StAXLoaderRegistryTestCase extends TestCase { - private StAXLoaderRegistryImpl registry; - private MockElementLoader loader; - private MockObject mockObject; - private MockReader reader; - private MockMonitor monitor; - private QName qname; - private ResourceLoaderImpl rl; - private LoaderContext loaderContext; - - public void testRegistrationEvents() throws XMLStreamException, ConfigurationLoadException { - reader.name = qname; - registry.registerLoader(qname, loader); - assertTrue(monitor.registered.contains(qname)); - assertEquals(1, monitor.registered.size()); - assertTrue(monitor.unregistered.isEmpty()); - assertTrue(monitor.loading.isEmpty()); - - registry.unregisterLoader(qname, loader); - assertTrue(monitor.registered.contains(qname)); - assertEquals(1, monitor.registered.size()); - assertTrue(monitor.unregistered.contains(qname)); - assertEquals(1, monitor.unregistered.size()); - assertTrue(monitor.loading.isEmpty()); - } - - public void testSuccessfulLoad() throws XMLStreamException, ConfigurationLoadException { - reader.name = qname; - registry.registerLoader(qname, loader); - assertSame(mockObject, registry.load(reader, loaderContext)); - assertEquals(1, monitor.loading.size()); - assertTrue(monitor.loading.contains(qname)); - } - - public void testFailedLoad() throws XMLStreamException, ConfigurationLoadException { - registry.registerLoader(qname, loader); - reader.name = new QName("foo"); - try { - registry.load(reader, loaderContext); - fail(); - } catch (ConfigurationLoadException e) { - assertEquals(1, monitor.loading.size()); - assertTrue(monitor.loading.contains(reader.name)); - } - } - - protected void setUp() throws Exception { - super.setUp(); - qname = new QName("test"); - monitor = new MockMonitor(); - registry = new StAXLoaderRegistryImpl(); - registry.setMonitor(monitor); - mockObject = new MockObject(); - loader = new MockElementLoader(); - reader = new MockReader(); - rl = new ResourceLoaderImpl(getClass().getClassLoader()); - loaderContext = new LoaderContext(rl); - } - - public static class MockMonitor implements StAXLoaderRegistryImpl.Monitor { - private List<QName> registered = new ArrayList<QName>(); - private List<QName> unregistered = new ArrayList<QName>(); - private List<QName> loading = new ArrayList<QName>(); - - public void registeringLoader(QName xmlType) { - registered.add(xmlType); - } - - public void unregisteringLoader(QName xmlType) { - unregistered.add(xmlType); - } - - public void elementLoad(QName xmlType) { - loading.add(xmlType); - } - } - - @SuppressWarnings({"NonStaticInnerClassInSecureContext"}) - public class MockElementLoader<MockObject> implements StAXElementLoader { - public AssemblyObject load(XMLStreamReader reader, LoaderContext loaderContext) throws XMLStreamException, ConfigurationLoadException { - assertEquals(qname, reader.getName()); - assertSame(rl, loaderContext.getResourceLoader()); - return mockObject; - } - } - - public static class MockObject implements AssemblyObject { - public void initialize(AssemblyContext modelContext) throws AssemblyInitializationException { - throw new UnsupportedOperationException(); - } - - public void freeze() { - throw new UnsupportedOperationException(); - } - - public boolean accept(AssemblyVisitor visitor) { - throw new UnsupportedOperationException(); - } - } - - private static class MockReader extends MockReaderSupport { - private QName name; - - public QName getName() { - return name; - } - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java deleted file mode 100644 index 0efe1ae82a..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.loader.impl.StringParserPropertyFactory; -import org.apache.tuscany.model.assembly.AssemblyFactory; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import java.beans.PropertyEditorManager; -import java.beans.PropertyEditorSupport; -import java.io.StringReader; -import java.net.URI; -import java.util.Arrays; - -/** - * @version $Rev$ $Date$ - */ -public class StringParserPropertyFactoryTestCase extends TestCase { - private StringParserPropertyFactory factory; - private XMLInputFactory xmlFactory; - private Property property; - - public void testSimpleString() throws XMLStreamException, ConfigurationLoadException { - String instance = getInstance(String.class, "<foo>Hello World</foo>"); - assertEquals("Hello World", instance); - } - - public void testByteArray() throws XMLStreamException, ConfigurationLoadException { - byte[] instance = getInstance(byte[].class, "<foo>01020304</foo>"); - assertTrue(Arrays.equals(new byte[]{1, 2, 3, 4}, instance)); - } - - public void testInteger() throws XMLStreamException, ConfigurationLoadException { - Integer instance = getInstance(Integer.class, "<foo>1234</foo>"); - assertEquals(Integer.valueOf(1234), instance); - } - - public void testInt() throws XMLStreamException, ConfigurationLoadException { - int instance = getInstance(Integer.TYPE, "<foo>1234</foo>"); - assertEquals(1234, instance); - } - - public void testBoolean() throws XMLStreamException, ConfigurationLoadException { - Boolean instance = getInstance(Boolean.class, "<foo>true</foo>"); - assertSame(Boolean.TRUE, instance); - } - - public void testConstructor() throws XMLStreamException, ConfigurationLoadException { - // java.net.URI has a ctr that takes a String - URI instance = getInstance(URI.class, "<foo>http://www.apache.org</foo>"); - assertEquals(URI.create("http://www.apache.org"), instance); - } - - public void testPropertyEditor() throws XMLStreamException, ConfigurationLoadException { - // register a property editor for java.lang.Class - PropertyEditorManager.registerEditor(Class.class, ClassEditor.class); - try { - Class<?> instance = getInstance(Class.class, "<foo>java.lang.Integer</foo>"); - assertEquals(Integer.class, instance); - } finally{ - PropertyEditorManager.registerEditor(Class.class, null); - } - } - - private <T> T getInstance(Class<T> type, String xml) throws XMLStreamException, ConfigurationLoadException { - property.setType(type); - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - ObjectFactory<T> objectFactory = (ObjectFactory<T>) factory.createObjectFactory(reader, property); - return objectFactory.getInstance(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new StringParserPropertyFactory(); - xmlFactory = XMLInputFactory.newInstance(); - AssemblyFactory assemblyFactory = new AssemblyFactoryImpl(); - property = assemblyFactory.createProperty(); - } - - public static class ClassEditor extends PropertyEditorSupport { - public void setAsText(String text) throws IllegalArgumentException { - try { - setValue(Class.forName(text)); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(text); - } - } - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java deleted file mode 100644 index 37056b3283..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentLoaderTestCase.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import java.util.List; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.config.ComponentTypeIntrospector; -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.core.extension.config.ImplementationProcessor; -import org.apache.tuscany.core.config.impl.Java5ComponentTypeIntrospector; -import org.apache.tuscany.core.config.processor.ProcessorUtils; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.core.loader.StAXPropertyFactory; -import org.apache.tuscany.core.loader.impl.StringParserPropertyFactory; -import org.apache.tuscany.core.system.assembly.SystemImplementation; -import org.apache.tuscany.model.assembly.Component; -import org.apache.tuscany.model.assembly.ConfiguredProperty; -import org.apache.tuscany.model.assembly.Property; -import org.apache.tuscany.model.assembly.AtomicComponent; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderTestCase extends LoaderTestSupport { - private ComponentLoader loader; - private ComponentTypeIntrospector introspector; - - public void testStringProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propString>HelloWorld</propString></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propString"); - assertEquals("HelloWorld", prop.getValue()); - } - - public void testIntProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propInt>1234</propInt></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propInt"); - assertEquals(1234, prop.getValue()); - } - - public void testIntegerProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propInteger>1234</propInteger></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propInteger"); - assertEquals(Integer.valueOf(1234), prop.getValue()); - } - - public void testCustomProperty() throws XMLStreamException, ConfigurationLoadException { - String xml = "<properties><propFoo factory='" + FooFactory.class.getName() + "'><name>Hello</name></propFoo></properties>"; - Component component = createFooComponent(); - loadProperties(xml, component); - ConfiguredProperty prop = component.getConfiguredProperty("propFoo"); - Foo instance = (Foo) prop.getValue(); - assertEquals("Hello", instance.name); - } - - private void loadProperties(String xml, Component component) throws XMLStreamException, ConfigurationLoadException { - XMLStreamReader reader = getReader(xml); - loader.loadProperties(reader, resourceLoader, component); - component.initialize(modelContext); - } - - private Component createFooComponent() { - SystemImplementation impl = assemblyFactory.createSystemImplementation(); - impl.setImplementationClass(ServiceImpl.class); - try { - impl.setComponentType(introspector.introspect(ServiceImpl.class)); - } catch (ConfigurationException e) { - throw new AssertionError(); - } - impl.initialize(null); - AtomicComponent component = assemblyFactory.createSimpleComponent(); - component.setImplementation(impl); - return component; - } - - protected void setUp() throws Exception { - super.setUp(); - loader = new ComponentLoader(); - loader.setFactory(assemblyFactory); - loader.setDefaultPropertyFactory(new StringParserPropertyFactory()); - introspector = ProcessorUtils.createCoreIntrospector(assemblyFactory); - } - - public static interface Service { - } - - public static class ServiceImpl implements Service { - public String propString; - public int propInt; - public Integer propInteger; - public Foo propFoo; - } - - public static class Foo { - public Foo() { - } - - private String name; - private Foo foo; - - public void setName(String val) { - name = val; - } - - public void setFoo(Foo val) { - foo = val; - } -/* - - private MyJaxBThing jaxBThing; - - public void setMyJaxBThing(MyJaxBThing thing) { - jaxBthing = thing; - } -*/ - } - - public static class FooFactory implements StAXPropertyFactory<Foo> { - public ObjectFactory<Foo> createObjectFactory(XMLStreamReader reader, Property property) throws XMLStreamException, ConfigurationLoadException { - reader.nextTag(); - String name = reader.getElementText(); - reader.next(); - Foo foo = new Foo(); - foo.setName(name); - return new SingletonObjectFactory<Foo>(foo); - } - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentTypeLoaderTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentTypeLoaderTestCase.java deleted file mode 100644 index 43b5bec143..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ComponentTypeLoaderTestCase.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.ComponentType; -import org.apache.tuscany.model.assembly.Service; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentTypeLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - XMLStreamReader reader = getReader("<componentType xmlns='http://www.osoa.org/xmlns/sca/0.9'><service name='service1'/></componentType>"); - ComponentType type = (ComponentType) registry.load(reader, loaderContext); - type.initialize(null); - assertNotNull(type); - assertEquals(1, type.getServices().size()); - Service service = type.getService("service1"); - assertEquals("service1", service.getName()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new ComponentTypeLoader()); - registerLoader(new ServiceLoader()); - } - -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/EntryPointLoaderTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/EntryPointLoaderTestCase.java deleted file mode 100644 index 8f207261fb..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/EntryPointLoaderTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.ENTRY_POINT; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.EntryPoint; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * @version $Rev$ $Date$ - */ -public class EntryPointLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<entryPoint xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'></entryPoint>"; - XMLStreamReader reader = getReader(xml); - EntryPoint ep = (EntryPoint) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, ENTRY_POINT.getNamespaceURI(), ENTRY_POINT.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(ep); - assertEquals("test", ep.getName()); - } - - public void testInterface() throws XMLStreamException, ConfigurationLoadException { - String interfaceName = MockService.class.getName(); - String xml = "<entryPoint xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'><interface.java interface='" + interfaceName + "'/></entryPoint>"; - XMLStreamReader reader = getReader(xml); - EntryPoint ep = (EntryPoint) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, ENTRY_POINT.getNamespaceURI(), ENTRY_POINT.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(ep); - assertEquals("test", ep.getName()); - ConfiguredService configuredService = ep.getConfiguredService(); - JavaServiceContract serviceContract = (JavaServiceContract) configuredService.getPort().getServiceContract(); - assertEquals(interfaceName, serviceContract.getInterfaceName()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new EntryPointLoader()); - registerLoader(new InterfaceJavaLoader()); - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ExternalServiceLoaderTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ExternalServiceLoaderTestCase.java deleted file mode 100644 index 1fc5b367d5..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/ExternalServiceLoaderTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.EXTERNAL_SERVICE; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamConstants; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.ConfiguredService; -import org.apache.tuscany.model.assembly.ExternalService; -import org.apache.tuscany.model.types.java.JavaServiceContract; - -/** - * @version $Rev$ $Date$ - */ -public class ExternalServiceLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<externalService xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'></externalService>"; - XMLStreamReader reader = getReader(xml); - ExternalService es = (ExternalService) registry.load(reader, loaderContext); - assertNotNull(es); - assertEquals("test", es.getName()); - reader.require(XMLStreamConstants.END_ELEMENT, EXTERNAL_SERVICE.getNamespaceURI(), EXTERNAL_SERVICE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - } - - public void testInterface() throws XMLStreamException, ConfigurationLoadException { - String interfaceName = MockService.class.getName(); - String xml = "<externalService xmlns='http://www.osoa.org/xmlns/sca/0.9' name='test'><interface.java interface='" + interfaceName + "'/></externalService>"; - XMLStreamReader reader = getReader(xml); - ExternalService es = (ExternalService) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, EXTERNAL_SERVICE.getNamespaceURI(), EXTERNAL_SERVICE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(es); - assertEquals("test", es.getName()); - ConfiguredService configuredService = es.getConfiguredService(); - JavaServiceContract serviceContract = (JavaServiceContract) configuredService.getPort().getServiceContract(); - assertEquals(interfaceName, serviceContract.getInterfaceName()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new ExternalServiceLoader()); - registerLoader(new InterfaceJavaLoader()); - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderInterfaceStylesTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderInterfaceStylesTestCase.java deleted file mode 100644 index 8b4f840f71..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderInterfaceStylesTestCase.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.INTERFACE_WSDL; - -import java.io.InputStream; -import java.net.URL; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; -import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl; -import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.helper.XSDHelper; - -/** - * @version $Rev$ $Date$ - */ -public class InterfaceWSDLLoaderInterfaceStylesTestCase extends LoaderTestSupport { - private WSDLDefinitionRegistryImpl wsdlRegistry; - private ResourceLoader resourceLoader; - private ClassLoader oldCL; - - public void testInterface() throws Exception { - wsdlRegistry.loadDefinition("http://www.interfacestyles.org", getClass().getResource("interfacestyles.wsdl"), resourceLoader); - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9' interface='http://www.interfacestyles.org#TestInterfaceStylesService'></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - - sc.initialize(modelContext); - - Class scInterface = sc.getInterface(); - assertNotNull(scInterface); - - assertNotNull(scInterface.getMethod("getAccountReportWrapped0", new Class[0])); - assertNotNull(scInterface.getMethod("getAccountReportWrapped1", new Class[] {String.class})); - assertNotNull(scInterface.getMethod("getAccountReportWrappedN", new Class[] {String.class, int.class})); - assertNotNull(scInterface.getMethod("getAccountReportBare0", new Class[0])); - assertNotNull(scInterface.getMethod("getAccountReportBare1Simple", new Class[]{String.class})); - assertNotNull(scInterface.getMethod("getAccountReportBare1Complex", new Class[]{Object.class})); - - } - - protected void setUp() throws Exception { - oldCL = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - resourceLoader = new ResourceLoaderImpl(getClass().getClassLoader()); - super.setUp(); - - wsdlRegistry = new WSDLDefinitionRegistryImpl(); - wsdlRegistry.setMonitor(NULL_MONITOR); - URL wsdlURL = getClass().getResource("interfacestyles.wsdl"); - wsdlRegistry.loadDefinition("http://www.interfacestyles.org", wsdlURL, resourceLoader); - InterfaceWSDLLoader loader = new InterfaceWSDLLoader(); - loader.setWsdlRegistry(wsdlRegistry); - registerLoader(loader); - - InputStream xsdInputStream = wsdlURL.openStream(); - try { - XSDHelper xsdHelper = SDOUtil.createXSDHelper(modelContext.getTypeHelper()); - xsdHelper.define(xsdInputStream, null); - } finally { - xsdInputStream.close(); - } - } - - protected void tearDown() throws Exception { - Thread.currentThread().setContextClassLoader(oldCL); - super.tearDown(); - } - - private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { - public void readingWSDL(String namespace, URL location) { - } - - public void cachingDefinition(String namespace, URL location) { - } - }; -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java deleted file mode 100644 index f97f13a1f7..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/InterfaceWSDLLoaderTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import java.net.URL; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; -import org.apache.tuscany.core.config.ConfigurationLoadException; -import static org.apache.tuscany.core.loader.assembly.AssemblyConstants.INTERFACE_WSDL; -import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl; -import org.apache.tuscany.model.types.wsdl.WSDLServiceContract; - -/** - * @version $Rev$ $Date$ - */ -public class InterfaceWSDLLoaderTestCase extends LoaderTestSupport { - private WSDLDefinitionRegistryImpl wsdlRegistry; - private ResourceLoader resourceLoader; - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9'></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - } - - public void testInterface() throws Exception { - wsdlRegistry.loadDefinition("http://www.example.org", getClass().getResource("example.wsdl"), resourceLoader); - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9' interface='http://www.example.org#HelloWorld'></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - } - - public void testInterfaceWithLocation() throws Exception { - wsdlRegistry.loadDefinition("http://www.example.org", getClass().getResource("example.wsdl"), resourceLoader); - String xml = "<interface.wsdl xmlns='http://www.osoa.org/xmlns/sca/0.9' xmlns:wsdli='http://www.w3.org/2006/01/wsdl-instance' " + - "wsdli:wsdlLocation='http://www.example.org " + getClass().getResource("example.wsdl") + "' "+ - "interface='http://www.example.org#HelloWorld'"+ - "></interface.wsdl>"; - XMLStreamReader reader = getReader(xml); - WSDLServiceContract sc = (WSDLServiceContract) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, INTERFACE_WSDL.getNamespaceURI(), INTERFACE_WSDL.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(sc); - } - - protected void setUp() throws Exception { - super.setUp(); - wsdlRegistry = new WSDLDefinitionRegistryImpl(); - wsdlRegistry.setMonitor(NULL_MONITOR); - resourceLoader = new ResourceLoaderImpl(getClass().getClassLoader()); - wsdlRegistry.loadDefinition("http://www.example.org", getClass().getResource("example.wsdl"), resourceLoader); - InterfaceWSDLLoader loader = new InterfaceWSDLLoader(); - loader.setWsdlRegistry(wsdlRegistry); - registerLoader(loader); - } - - private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { - public void readingWSDL(String namespace, URL location) { - } - - public void cachingDefinition(String namespace, URL location) { - } - }; -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/LoaderTestSupport.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/LoaderTestSupport.java deleted file mode 100644 index 4e2aea5e83..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/LoaderTestSupport.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import java.io.StringReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; -import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory; -import org.apache.tuscany.core.system.assembly.impl.SystemAssemblyFactoryImpl; -import org.apache.tuscany.core.loader.impl.StAXLoaderRegistryImpl; -import org.apache.tuscany.core.loader.LoaderContext; -import org.apache.tuscany.model.assembly.AssemblyContext; -import org.apache.tuscany.model.assembly.impl.AssemblyContextImpl; - -/** - * Base class for loader tests with common fixture elements. - * - * @version $Rev$ $Date$ - */ -public abstract class LoaderTestSupport extends TestCase { - protected SystemAssemblyFactory assemblyFactory; - protected ResourceLoader resourceLoader; - protected LoaderContext loaderContext; - protected AssemblyContext modelContext; - protected XMLInputFactory xmlFactory; - protected StAXLoaderRegistryImpl registry; - - protected static final StAXLoaderRegistryImpl.Monitor NULL_MONITOR = new StAXLoaderRegistryImpl.Monitor() { - public void registeringLoader(QName xmlType) { - } - - public void unregisteringLoader(QName xmlType) { - } - - public void elementLoad(QName xmlType) { - } - }; - - protected void setUp() throws Exception { - super.setUp(); - assemblyFactory = new SystemAssemblyFactoryImpl(); - resourceLoader = new ResourceLoaderImpl(getClass().getClassLoader()); - loaderContext = new LoaderContext(resourceLoader); - modelContext = new AssemblyContextImpl(assemblyFactory, null, resourceLoader); - xmlFactory = XMLInputFactory.newInstance(); - registry = new StAXLoaderRegistryImpl(); - registry.setMonitor(NULL_MONITOR); - } - - protected XMLStreamReader getReader(String xml) throws XMLStreamException { - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - return reader; - } - - protected void registerLoader(AbstractLoader<?> loader) { - loader.setFactory(assemblyFactory); - loader.setRegistry(registry); - loader.start(); - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/MockService.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/MockService.java deleted file mode 100644 index c1ea3dbc1e..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/MockService.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -/** - * @version $Rev$ $Date$ - */ -public interface MockService { -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java deleted file mode 100644 index 5543a41f91..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WSDLDefinitionRegistryTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - * Copyright 2006 The Apache Software Foundation or its licensors as applicable - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import java.net.URL; -import java.io.IOException; - -import javax.wsdl.Definition; -import javax.wsdl.WSDLException; -import javax.xml.namespace.QName; - -import junit.framework.TestCase; -import org.apache.tuscany.core.loader.impl.WSDLDefinitionRegistryImpl; -import org.apache.tuscany.common.resource.ResourceLoader; -import org.apache.tuscany.common.resource.impl.ResourceLoaderImpl; - -/** - * @version $Rev$ $Date$ - */ -public class WSDLDefinitionRegistryTestCase extends TestCase { - private static final String NS = "http://www.example.org"; - private WSDLDefinitionRegistryImpl wsdlRegistry; - private ResourceLoader rl; - - - public void testLoadFromAbsoluteWSDLLocation() { - try { - Definition def = wsdlRegistry.loadDefinition(NS + ' ' + rl.getResource("org/apache/tuscany/core/loader/assembly/example.wsdl"), rl); - assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); - } catch (IOException e) { - fail(e.getMessage()); - } catch (WSDLException e) { - fail(e.getMessage()); - } - } - - public void testLoadFromRelativeWSDLLocation() { - try { - Definition def = wsdlRegistry.loadDefinition(NS + " org/apache/tuscany/core/loader/assembly/example.wsdl", rl); - assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); - } catch (IOException e) { - fail(e.getMessage()); - } catch (WSDLException e) { - fail(e.getMessage()); - } - } - - protected void setUp() throws Exception { - super.setUp(); - wsdlRegistry = new WSDLDefinitionRegistryImpl(); - wsdlRegistry.setMonitor(NULL_MONITOR); - rl = new ResourceLoaderImpl(getClass().getClassLoader()); - } - - private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { - public void readingWSDL(String namespace, URL location) { - } - - public void cachingDefinition(String namespace, URL location) { - } - }; -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WireLoaderTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WireLoaderTestCase.java deleted file mode 100644 index 3a0331150d..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/loader/assembly/WireLoaderTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.tuscany.core.loader.assembly; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.core.config.ConfigurationLoadException; -import org.apache.tuscany.model.assembly.Wire; - -/** - * @version $Rev$ $Date$ - */ -public class WireLoaderTestCase extends LoaderTestSupport { - - public void testMinimal() throws XMLStreamException, ConfigurationLoadException { - String xml = "<wire xmlns='http://www.osoa.org/xmlns/sca/0.9'><source.uri>foo/fooService</source.uri><target.uri>bar</target.uri></wire>"; - XMLStreamReader reader = getReader(xml); - Wire wire = (Wire) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, AssemblyConstants.WIRE.getNamespaceURI(), AssemblyConstants.WIRE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(wire); - assertEquals("foo", wire.getSource().getPartName()); - assertEquals("fooService", wire.getSource().getServiceName()); - assertEquals("bar", wire.getTarget().getPartName()); - } - - public void testCompound() throws XMLStreamException, ConfigurationLoadException { - String xml = "<wire xmlns='http://www.osoa.org/xmlns/sca/0.9'><source.uri>foo/fooService</source.uri><target.uri>bar/bazService</target.uri></wire>"; - XMLStreamReader reader = getReader(xml); - Wire wire = (Wire) registry.load(reader, loaderContext); - reader.require(XMLStreamConstants.END_ELEMENT, AssemblyConstants.WIRE.getNamespaceURI(), AssemblyConstants.WIRE.getLocalPart()); - assertEquals(XMLStreamConstants.END_DOCUMENT, reader.next()); - assertNotNull(wire); - assertEquals("foo", wire.getSource().getPartName()); - assertEquals("fooService", wire.getSource().getServiceName()); - assertEquals("bar", wire.getTarget().getPartName()); - assertEquals("bazService", wire.getTarget().getServiceName()); - } - - protected void setUp() throws Exception { - super.setUp(); - registerLoader(new WireLoader()); - } -} |