diff options
Diffstat (limited to 'sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org')
35 files changed, 2637 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java new file mode 100644 index 0000000000..72739d56c4 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class AssertionTestCase extends TestCase { + /** + * test case that confirms that JRE assertions are enabled + */ + public void testAssertionsAreEnabled() { + try { + assert false; + fail("assertions are not enabled"); + } catch (AssertionError e) { + // ok + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java new file mode 100644 index 0000000000..1e7b2ab67c --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi; + +import junit.framework.TestCase; + +/** + * Tests parsing of naming patters + * + * @version $Rev$ $Date$ + */ +public class QualifiedNameTestCase extends TestCase { + + public void testSimpleName() throws Exception { + QualifiedName name = new QualifiedName("Foo"); + assertEquals("Foo", name.getPartName()); + assertEquals(null, name.getPortName()); + assertEquals("Foo", name.getQualifiedName()); + assertEquals("Foo", name.getFragment()); + assertEquals("Foo", name.toString()); + } + + public void testCompoundName() throws Exception { + QualifiedName name = new QualifiedName("Foo/Bar"); + assertEquals("Foo", name.getPartName()); + assertEquals("Bar", name.getPortName()); + assertEquals("Foo/Bar", name.getQualifiedName()); + assertEquals("Foo#Bar", name.getFragment()); + assertEquals("Foo/Bar", name.toString()); + } + + public void testCompoundMultiName() throws Exception { + try { + new QualifiedName("Foo/Bar/Baz"); + fail("Invalid name exception not thrown"); + } catch (InvalidNameException e) { + // ok; + } + } + + public void testInvalidName() throws Exception { + try { + new QualifiedName("/Foo/Bar"); + fail("Invalid name exception not thrown"); + } catch (InvalidNameException e) { + //expected + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java new file mode 100644 index 0000000000..593b5a992b --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi; + +import junit.framework.TestCase; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class TuscanyRuntimeExceptionTestCase extends TestCase { + + public void testIdentifier() throws Exception { + TuscanyRuntimeException e = new TestException("bar", "foo"); + assertEquals("foo", e.getIdentifier()); + } + + public void testEmptyGetMessage() throws Exception { + TuscanyRuntimeException e = new TestException(); + e.getMessage(); + } + + private class TestException extends TuscanyRuntimeException { + + public TestException() { + } + + public TestException(String message, String identifier) { + super(message, identifier); + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java new file mode 100644 index 0000000000..210997b8c8 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.component; + +import java.net.URI; + +import org.apache.tuscany.spi.event.Event; +import org.apache.tuscany.spi.event.EventFilter; +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.event.TrueFilter; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractSCAObjectTestCase extends TestCase { + + public void testFireListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + object.addListener(listener); + object.publish(event); + } + + public void testRemoveListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + object.addListener(listener); + object.removeListener(listener); + object.publish(event); + } + + public void testFalseFilterListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + object.addListener(new FalseFilter(), listener); + object.publish(event); + } + + public void testTrueFilterListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + object.addListener(new TrueFilter(), listener); + object.publish(event); + } + + public void testToString() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + assertNotNull(object.toString()); + } + + private class TestSCAObject extends AbstractSCAObject { + public TestSCAObject(URI name) { + super(name); + } + + } + + private class TestEvent implements Event { + public Object getSource() { + return null; + } + } + + private class FalseFilter implements EventFilter { + + public boolean match(Event event) { + return false; + } + } + + +} + + + diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java new file mode 100644 index 0000000000..510e6e4390 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.component; + +import java.io.Serializable; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings({"SerializableHasSerializationMethods"}) +public class MockSCAExternalizable implements Serializable, SCAExternalizable { + private static final long serialVersionUID = 5071815222959279772L; + + private WorkContext context; + private boolean activated; + + public void setWorkContext(WorkContext context) { + this.context = context; + } + + public WorkContext getContext() { + return context; + } + + public void reactivate() throws ReactivationException { + activated = true; + } + + public boolean isActivated() { + return activated; + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java new file mode 100644 index 0000000000..c853f427fb --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.component; + +import java.io.Serializable; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings({"SerializableHasSerializationMethods"}) +public class MockSerializable implements Serializable { + private static final long serialVersionUID = 4013396228070042469L; + + private MockSCAExternalizable externalizable; + + public MockSerializable() { + } + + public MockSCAExternalizable getExternalizable() { + return externalizable; + } + + public void setExternalizable(MockSCAExternalizable externalizable) { + this.externalizable = externalizable; + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java new file mode 100644 index 0000000000..ae316bc441 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.component; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class SCAObjectInputStreamTestCase extends TestCase { + + public void testSCAExternalizable() throws Exception { + WorkContext context = EasyMock.createMock(WorkContext.class); + MockSCAExternalizable ext = new MockSCAExternalizable(); + MockSerializable serializable = new MockSerializable(); + serializable.setExternalizable(ext); + ByteArrayOutputStream bas = new ByteArrayOutputStream(); + ObjectOutputStream o = new ObjectOutputStream(bas); + o.writeObject(serializable); + o.close(); + ByteArrayInputStream bytes = new ByteArrayInputStream(bas.toByteArray()); + SCAObjectInputStream stream = new SCAObjectInputStream(bytes, context); + MockSerializable deserialized = (MockSerializable) stream.readObject(); + MockSCAExternalizable deserializedExt = deserialized.getExternalizable(); + assertTrue(deserializedExt.isActivated()); + assertEquals(context, deserializedExt.getContext()); + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java new file mode 100644 index 0000000000..40843dea94 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.databinding.extension; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import junit.framework.TestCase; + +/** + * + */ +public class DOMHelperTestCase extends TestCase { + private static final QName FOO_NAME = new QName("http://foo", "foo"); + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testDOM() throws Exception { + DocumentBuilder builder = DOMHelper.newDocumentBuilder(); + assertNotNull(builder); + Document document = DOMHelper.newDocument(); + assertNotNull(document); + Element element = DOMHelper.createElement(document, FOO_NAME); + document.appendChild(element); + QName name = DOMHelper.getQName(element); + assertEquals(FOO_NAME, name); + + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java new file mode 100644 index 0000000000..b4b5f6a39a --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.databinding.extension; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.DataBindingRegistry; +import org.easymock.EasyMock; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * + */ +public class DataBindingExtensionTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testExtension() { + DataBinding1 binding1 = new DataBinding1(Node.class); + assertEquals(Node.class.getName(), binding1.getName()); + assertNotNull(binding1.introspect(Element.class)); + assertNull(binding1.introspect(String.class)); + assertNull(binding1.getWrapperHandler()); + + DataBindingRegistry registry = EasyMock.createMock(DataBindingRegistry.class); + registry.register(binding1); + EasyMock.expect(registry.getDataBinding(Node.class.getName())).andReturn(binding1); + EasyMock.replay(registry); + + binding1.setDataBindingRegistry(registry); + binding1.init(); + assertNotNull(registry.getDataBinding(Node.class.getName())); + + DataBinding1 binding2 = new DataBinding1("dom", Node.class); + assertEquals("dom", binding2.getName()); + } + + private static class DataBinding1 extends DataBindingExtension { + + /** + * @param baseType + */ + public DataBinding1(Class<?> baseType) { + super(baseType); + } + + /** + * @param name + * @param baseType + */ + public DataBinding1(String name, Class<?> baseType) { + super(name, baseType); + } + + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java new file mode 100644 index 0000000000..6ff7909fa3 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.databinding.extension; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.TypeInfo; + +import org.easymock.EasyMock; + +/** + * + */ +public class SimpleTypeMapperExtensionTestCase extends TestCase { + + private static final Map<String, Object> SAMPLE_VALUES = new HashMap<String, Object>(); + + static { + SAMPLE_VALUES.put("anyURI", "http://www.w3.com"); + SAMPLE_VALUES.put("boolean", new String[] {"true", "false", "1", "0"}); + SAMPLE_VALUES.put("byte", new String[] {"-128", "127"}); + SAMPLE_VALUES.put("date", new String[] {"2004-03-15", "2002-09-24-06:00"}); + SAMPLE_VALUES.put("dateTime", "2003-12-25T08:30:00"); + SAMPLE_VALUES.put("decimal", "3.1415292"); + SAMPLE_VALUES.put("double", new String[] {"3.1415292", "INF", "NaN"}); + SAMPLE_VALUES.put("duration", new String[] {"P8M3DT7H33M2S", "P5Y2M10DT15H"}); + SAMPLE_VALUES.put("float", new String[] {"3.1415292", "INF", "NaN"}); + SAMPLE_VALUES.put("gDay", "---11"); + /* + * The value space of xsd:gMonth is the period of one calendar month recurring + * each calendar year (such as the month of April). Its lexical space should + * follow the ISO 8601 syntax for such periods (i.e., -- MM) with an optional + * time zone. + * Tip: There's a typo in the W3C XML Schema Recommendation, in which the format + * is defined as -- MM -- --. Even though an erratum should be published to + * bring the W3C XML Schema inline with ISO 8601, most current schema processors + * expect the (bogus) -- MM -- -- format. + * + * The test might be broken in JDK 1.6 + */ + SAMPLE_VALUES.put("gMonth", "--02--"); + SAMPLE_VALUES.put("gMonthDay", "--02-14"); + SAMPLE_VALUES.put("gYear", "1999"); + SAMPLE_VALUES.put("gYearMonth", "1972-08"); + SAMPLE_VALUES.put("ID", "id-102"); + SAMPLE_VALUES.put("IDREF", "id-102"); + SAMPLE_VALUES.put("IDREFS", "id-102 id-103 id-100"); + SAMPLE_VALUES.put("int", "77"); + SAMPLE_VALUES.put("integer", "77"); + SAMPLE_VALUES.put("long", "214"); + SAMPLE_VALUES.put("negativeInteger", "-123"); + SAMPLE_VALUES.put("nonNegativeInteger", "2"); + SAMPLE_VALUES.put("nonPositiveInteger", "0"); + SAMPLE_VALUES.put("positiveInteger", "500"); + SAMPLE_VALUES.put("short", "476"); + SAMPLE_VALUES.put("string", "Joeseph"); + SAMPLE_VALUES.put("time", "13:02:00"); + SAMPLE_VALUES.put("base64Binary", "TWFu"); + SAMPLE_VALUES.put("hexBinary", "2CDB5F"); + SAMPLE_VALUES.put("QName", "f:foo"); + SAMPLE_VALUES.put("NOTATION", "f:bar"); + } + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testMap() throws Exception { + SimpleTypeMapperExtension extension = new SimpleTypeMapperExtension(); + TransformationContext context = EasyMock.createMock(TransformationContext.class); + Map<Class<?>, Object> metaData = new HashMap<Class<?>, Object>(); + EasyMock.expect(context.getMetadata()).andReturn(metaData).anyTimes(); + EasyMock.replay(context); + + NamespaceContext namespaceContext = EasyMock.createMock(NamespaceContext.class); + EasyMock.expect(namespaceContext.getNamespaceURI(EasyMock.eq("f"))).andReturn("http://foo") + .anyTimes(); + EasyMock.expect(namespaceContext.getPrefix(EasyMock.eq("http://foo"))).andReturn("f").anyTimes(); + EasyMock.replay(namespaceContext); + context.getMetadata().put(NamespaceContext.class, namespaceContext); + for (TypeInfo simpleType : SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.values()) { + String name = simpleType.getQName().getLocalPart(); + Object value = SAMPLE_VALUES.get(name); + if (value instanceof String[]) { + for (String s : (String[])value) { + Object obj = extension.toJavaObject(simpleType, s, context); + String str = extension.toXMLLiteral(simpleType, obj, context); + assertNotNull(str); + // assertTrue("[" + name + "] " + s + " " + str, + // str.contains((String) s)); + } + } else if (value instanceof String) { + Object obj = extension.toJavaObject(simpleType, (String)value, context); + String str = extension.toXMLLiteral(simpleType, obj, context); + assertNotNull(str); + // assertTrue("[" + name + "] " + value + " " + str, + // str.contains((String) value)); + } + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java new file mode 100644 index 0000000000..6f5dfc90e2 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.databinding.extension; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.TransformerRegistry; +import org.easymock.EasyMock; +import org.w3c.dom.Node; + +/** + * Test case for TransformerExtension + */ +public class TransformerExtensionTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testExtension() { + MyTransformer transformer = new MyTransformer(); + assertEquals(Node.class.getName(), transformer.getSourceDataBinding()); + assertEquals(XMLStreamReader.class.getName(), transformer.getTargetDataBinding()); + assertEquals(50, transformer.getWeight()); + TransformerRegistry registry = EasyMock.createMock(TransformerRegistry.class); + registry.registerTransformer(EasyMock.isA(Transformer.class)); + EasyMock + .expect(registry.getTransformer(transformer.getSourceDataBinding(), transformer.getTargetDataBinding())) + .andReturn(transformer); + EasyMock.replay(registry); + transformer.setTransformerRegistry(registry); + transformer.init(); + assertSame(transformer, registry.getTransformer(transformer.getSourceDataBinding(), transformer + .getTargetDataBinding())); + } + + private static class MyTransformer extends TransformerExtension<Node, XMLStreamReader> { + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java new file mode 100644 index 0000000000..4693025c11 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.databinding.extension; + +import java.math.BigInteger; +import java.util.Calendar; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +/** + * + */ +public class XSDDataTypeConverterTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testConvert() throws Exception { + XSDDataTypeConverter c = new XSDDataTypeConverter(); + assertEquals("123", c.parseAnySimpleType(c.printAnySimpleType("123"))); + assertEquals(true, c.parseBoolean(c.printBoolean(true))); + assertEquals(false, c.parseBoolean(c.printBoolean(false))); + assertEquals(123.0, c.parseDouble(c.printDouble(123.0))); + assertEquals(123.0f, c.parseFloat(c.printFloat(123.0f))); + assertEquals(64, c.parseByte(c.printByte((byte)64))); + assertEquals(123, c.parseInt(c.printInt(123))); + assertEquals(new BigInteger("123456"), c.parseInteger(c.printInteger(new BigInteger("123456")))); + assertEquals(123456L, c.parseLong(c.printLong(123456L))); + assertEquals((short)123, c.parseShort(c.printShort((short)123))); + + Calendar calendar = new GregorianCalendar(); + String s = c.printDate(calendar); + calendar = (GregorianCalendar)c.parseDate(s); + assertEquals(s, c.printDate(calendar)); + + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java new file mode 100644 index 0000000000..6efd61bea6 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.event; + + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractEventPublisherTestCase extends TestCase { + EventPublisher publisher; + + public void testFireListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.publish(event); + EasyMock.verify(publisher); + } + + public void testRemoveListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.removeListener(listener); + publisher.publish(event); + EasyMock.verify(publisher); + } + + public void testFalseFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(new FalseFilter(), listener); + publisher.publish(event); + EasyMock.verify(publisher); + } + + public void testTrueFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(new TrueFilter(), listener); + publisher.publish(event); + EasyMock.verify(publisher); + } + + protected void setUp() throws Exception { + super.setUp(); + publisher = new AbstractEventPublisher() { + }; + } + + private class TestEvent implements Event { + public Object getSource() { + return null; + } + } + + private class FalseFilter implements EventFilter { + + public boolean match(Event event) { + return false; + } + } + + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java new file mode 100644 index 0000000000..382a43f4ca --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import java.net.URI; +import java.util.List; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractComponentExtensionTestCase extends TestCase { + private Component composite; + + public void testGetService() throws Exception { + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(service); + composite.register(service); + assertNotNull(composite.getService("service")); + } + + public void testGetDefaultService() throws Exception { + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(service); + composite.register(service); + assertNotNull(composite.getService(null)); + } + + public void testGetReference() throws Exception { + Reference reference = EasyMock.createMock(Reference.class); + EasyMock.expect(reference.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(reference); + composite.register(reference); + assertNotNull(composite.getReference("service")); + } + + public void testDefaultReference() throws Exception { + Reference reference = EasyMock.createMock(Reference.class); + EasyMock.expect(reference.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(reference); + composite.register(reference); + assertNotNull(composite.getReference(null)); + } + + protected void setUp() throws Exception { + super.setUp(); + composite = new AbstractComponentExtension(new URI("foo")) { + + public Scope getScope() { + return null; + } + + public List<Wire> getWires(String name) { + throw new UnsupportedOperationException(); + } + + public void attachWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + public void attachWires(List<Wire> wires) { + throw new UnsupportedOperationException(); + } + + public void attachCallbackWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + public TargetInvoker createTargetInvoker(String targetName, Operation operation) + throws TargetInvokerCreationException { + return null; + } + }; + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java new file mode 100644 index 0000000000..ce3bee99f5 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import java.net.URI; +import java.util.List; + +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AtomicComponentExtensionTestCase extends TestCase { + private AtomicComponentExtension ext; + private URI uri; + + public void testURI() { + assertSame(uri, ext.getUri()); + } + + public void testRemoveInstance() throws Exception { + ScopeContainer scopeContainer = EasyMock.createMock(ScopeContainer.class); + EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE); + scopeContainer.remove(ext); + EasyMock.replay(scopeContainer); + ext.setScopeContainer(scopeContainer); + ext.removeInstance(); + EasyMock.verify(scopeContainer); + } + + protected void setUp() throws Exception { + super.setUp(); + uri = URI.create("http://example.com/foo"); + ext = new TestExtension(uri); + } + + private static class TestExtension extends AtomicComponentExtension { + + public TestExtension(URI uri) { + super(uri, null, null, 0, -1, -1); + } + + public TargetInvoker createTargetInvoker(String targetName, Operation operation) + throws TargetInvokerCreationException { + throw new AssertionFailedError(); + } + + public List<Wire> getWires(String name) { + throw new AssertionFailedError(); + } + + public void attachWire(Wire wire) { + throw new AssertionFailedError(); + } + + public void attachWires(List<Wire> wires) { + throw new AssertionFailedError(); + } + + public void attachCallbackWire(Wire wire) { + throw new AssertionFailedError(); + } + + public Object createInstance() throws ObjectCreationException { + throw new AssertionFailedError(); + } + + public Object getTargetInstance() throws TargetResolutionException { + throw new AssertionFailedError(); + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java new file mode 100644 index 0000000000..3aefb37b7f --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.eq; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.Implementation; + +/** + * @version $Rev$ $Date$ + */ +public class ComponentTypeLoaderExtensionTestCase extends TestCase { + + public void testRegistrationDeregistration() throws Exception { + Extension loader = new Extension(); + LoaderRegistry registry = createMock(LoaderRegistry.class); + registry.registerLoader(eq(Implementation.class), eq(loader)); + registry.unregisterLoader(eq(Implementation.class)); + EasyMock.replay(registry); + loader.setLoaderRegistry(registry); + loader.start(); + loader.stop(); + } + + + private class Extension extends ComponentTypeLoaderExtension<Implementation> { + + protected Class<Implementation> getImplementationClass() { + return Implementation.class; + } + + public void load(Implementation implementation, DeploymentContext context) throws LoaderException { + + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java new file mode 100644 index 0000000000..bf7bdc1f6f --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import java.lang.reflect.Type; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeComponentExtensionTestCase extends TestCase { + private Component composite; + + + public void testCreateTargetInvoker() throws Exception { + ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); + EasyMock.expect(binding.createTargetInvoker(EasyMock.eq("service"), EasyMock.isA(Operation.class))) + .andReturn(null); + EasyMock.replay(binding); + List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); + bindings.add(binding); + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce(); + EasyMock.replay(service); + composite.register(service); + Operation<Type> operation = new Operation<Type>("op", null, null, null); + composite.createTargetInvoker("service", operation); + EasyMock.verify(binding); + + } + + protected void setUp() throws Exception { + super.setUp(); + composite = new CompositeComponentExtension(new URI("foo")) { + + public List<Wire> getWires(String name) { + throw new UnsupportedOperationException(); + } + + public void attachWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + public void attachWires(List<Wire> wires) { + throw new UnsupportedOperationException(); + } + + public void attachCallbackWire(Wire wire) { + throw new UnsupportedOperationException(); + } + }; + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java new file mode 100644 index 0000000000..bf6e1d998d --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.ModelObject; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.isA; + +/** + * @version $Rev$ $Date$ + */ +public class LoaderExtensionTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testRegistrationDeregistration() throws Exception { + LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); + registry.registerLoader(isA(QName.class), isA(Extension.class)); + expectLastCall(); + registry.unregisterLoader(isA(QName.class), isA(Extension.class)); + expectLastCall(); + EasyMock.replay(registry); + Extension loader = new Extension(registry); + loader.start(); + loader.stop(); + } + + + private static class Extension extends LoaderExtension { + + public Extension(LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return new QName(""); + } + + public ModelObject load( + ModelObject object, XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + throw new AssertionError(); + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java new file mode 100644 index 0000000000..2691e06f3c --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class TargetInvokerExtensionSequenceTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testStart() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeStart("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(context, monitor, target); + Message msg = new MessageImpl(); + msg.pushCallbackUri(from); + msg.setBody("test"); + msg.setConversationSequence(Invoker.START); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + @SuppressWarnings("unchecked") + public void testContinue() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeContinue("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(context, monitor, target); + Message msg = new MessageImpl(); + msg.pushCallbackUri(from); + msg.setBody("test"); + msg.setConversationSequence(Invoker.CONTINUE); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + @SuppressWarnings("unchecked") + public void testEnd() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeEnd("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(context, monitor, target); + Message msg = new MessageImpl(); + msg.pushCallbackUri(from); + msg.setBody("test"); + msg.setConversationSequence(Invoker.END); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + @SuppressWarnings("unchecked") + public void testNone() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeNone("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(context, monitor, target); + Message msg = new MessageImpl(); + msg.pushCallbackUri(from); + msg.setBody("test"); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + protected void setUp() throws Exception { + super.setUp(); + + } + + private class Invoker extends TargetInvokerExtension { + private Target target; + + public Invoker(WorkContext workContext, ExecutionMonitor monitor, Target target) { + super(workContext); + this.target = target; + } + + public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { + if (sequence == NONE) { + target.invokeNone((String) payload); + } else if (sequence == START) { + target.invokeStart((String) payload); + } else if (sequence == CONTINUE) { + target.invokeContinue((String) payload); + } else if (sequence == END) { + target.invokeEnd((String) payload); + } + return null; + } + } + + private interface Target { + void invokeStart(String msg); + + void invokeContinue(String msg); + + void invokeEnd(String msg); + + void invokeNone(String msg); + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java new file mode 100644 index 0000000000..262cb2413f --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.extension; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class TargetInvokerExtensionTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testNonBlockingDispatch() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invoke("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(context, monitor, target); + Message msg = new MessageImpl(); + msg.pushCallbackUri(from); + msg.setBody("test"); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + protected void setUp() throws Exception { + super.setUp(); + + } + + private class Invoker extends TargetInvokerExtension { + private Target target; + + public Invoker(WorkContext workContext, ExecutionMonitor monitor, Target target) { + super(workContext); + this.target = target; + } + + public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { + target.invoke((String) payload); + return null; + } + } + + private interface Target { + void invoke(String msg); + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java new file mode 100644 index 0000000000..e50c1e32a2 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.idl.java; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod; +import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class JavaIDLUtilsTestCase extends TestCase { + private Method[] methods; + private List<Operation<?>> operations; + + public void testNoParamsFindMethod() { + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + Method method = findMethod(operation, methods); + assertEquals("foo", method.getName()); + assertEquals(0, method.getParameterTypes().length); + } + + public void testNoParamsFindOperation() throws Exception { + Method method = Foo.class.getMethod("foo"); + Operation ret = findOperation(method, operations); + assertEquals("foo", ret.getName()); + assertEquals(0, method.getParameterTypes().length); + } + + public void testParamsFindMethod() { + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<Type> type = new DataType<Type>(String.class, Object.class); + types.add(type); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + Method method = findMethod(operation, methods); + assertEquals("foo", method.getName()); + assertEquals(String.class, method.getParameterTypes()[0]); + } + + public void testParamsFindOperation() throws Exception { + Method method = Foo.class.getMethod("foo", String.class); + Operation ret = findOperation(method, operations); + assertEquals("foo", ret.getName()); + assertEquals(String.class, method.getParameterTypes()[0]); + } + + + public void testTooManyParamsFindMethod() { + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<Type> type = new DataType<Type>(String.class, Object.class); + DataType<Type> type2 = new DataType<Type>(String.class, Object.class); + types.add(type); + types.add(type2); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + Method method = findMethod(operation, methods); + assertNull(method); + } + + public void testDifferentParamsFindMethod() { + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<Type> type = new DataType<Type>(Integer.class, Object.class); + types.add(type); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + Method method = findMethod(operation, methods); + assertNull(method); + } + + public void testPrimitiveParamNoFindMethod() { + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<Type> type = new DataType<Type>(Integer.class, Object.class); + types.add(type); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + Method method = findMethod(operation, methods); + assertNull(method); + } + + public void testPrimitiveParamFindMethod() { + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<Type> type = new DataType<Type>(Integer.TYPE, Object.class); + types.add(type); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + Operation<Type> operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + Method method = findMethod(operation, methods); + assertEquals("foo", method.getName()); + assertEquals(Integer.TYPE, method.getParameterTypes()[0]); + } + + public void testPrimitiveParamFindOperation() throws NoSuchMethodException { + Method method = Foo.class.getMethod("foo", Integer.TYPE); + Operation<?> operation = findOperation(method, operations); + assertEquals(Integer.TYPE, operation.getInputType().getLogical().get(0).getPhysical()); + } + + + public void testNotFoundMethod() { + Operation<Type> operation = new Operation<Type>("not there", null, null, null, false, null, NO_CONVERSATION); + assertNull(findMethod(operation, methods)); + } + + protected void setUp() throws Exception { + super.setUp(); + methods = Foo.class.getMethods(); + + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + operations = new ArrayList<Operation<?>>(); + operations.add(operation); + + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + DataType<Type> type = new DataType<Type>(String.class, Object.class); + types.add(type); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + types = new ArrayList<DataType<Type>>(); + type = new DataType<Type>(String.class, Object.class); + DataType<Type> type2 = new DataType<Type>(String.class, Object.class); + types.add(type); + types.add(type2); + inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + types = new ArrayList<DataType<Type>>(); + type = new DataType<Type>(Integer.class, Object.class); + types.add(type); + inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + types = new ArrayList<DataType<Type>>(); + type = new DataType<Type>(Integer.TYPE, Object.class); + types.add(type); + inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + } + + private interface Foo { + void foo(); + + void foo(String foo); + + void foo(int b); + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java new file mode 100644 index 0000000000..45a3bd4d68 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.implementation.java; + +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; + +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.deployer.DeploymentContext; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractPropertyProcessorTestCase extends TestCase { + + private ImplementationProcessor processor; + + + public void testVisitMethod() throws Exception { + Method method = Foo.class.getMethod("setBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitMethod(method, type, null); + JavaMappedProperty<?> prop = type.getProperties().get("test"); + assertNotNull(prop.getDefaultValueFactory()); + } + + public void testVisitNoParamsMethod() throws Exception { + Method method = Foo.class.getMethod("setNoParamsBar"); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + try { + processor.visitMethod(method, type, null); + fail(); + } catch (IllegalPropertyException e) { + //expected + } + } + + public void testVisitNonVoidMethod() throws Exception { + Method method = Foo.class.getMethod("setBadBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + try { + processor.visitMethod(method, type, null); + fail(); + } catch (IllegalPropertyException e) { + //expected + } + } + + public void testDuplicateMethod() throws Exception { + Method method = Foo.class.getMethod("setBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitMethod(method, type, null); + try { + processor.visitMethod(method, type, null); + fail(); + } catch (DuplicatePropertyException e) { + //expected + } + } + + public void testVisitField() throws Exception { + Field field = Foo.class.getDeclaredField("d"); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitField(field, type, null); + JavaMappedProperty<?> prop = type.getProperties().get("test"); + assertNotNull(prop.getDefaultValueFactory()); + } + + public void testVisitConstructor() throws Exception { + Constructor<Foo> ctor = Foo.class.getConstructor(String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitConstructor(ctor, type, null); + ConstructorDefinition def = type.getConstructorDefinition(); + assertEquals("test", def.getInjectionNames().get(0)); + assertNotNull(type.getProperties().get("test")); + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + ImplementationProcessorService service = EasyMock.createMock(ImplementationProcessorService.class); + service.addName(EasyMock.isA(List.class), EasyMock.eq(0), EasyMock.eq("test")); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + ((List<Object>) EasyMock.getCurrentArguments()[0]).add("test"); + return null; + } + }); + EasyMock.replay(service); + processor = new TestProcessor(service); + } + + @Retention(RUNTIME) + private @interface Bar { + + } + + private class TestProcessor extends AbstractPropertyProcessor<Bar> { + + public TestProcessor(ImplementationProcessorService service) { + super(Bar.class, service); + } + + @SuppressWarnings("unchecked") + protected <T> void initProperty(JavaMappedProperty<T> property, + Bar annotation, + DeploymentContext context) { + property.setDefaultValueFactory(EasyMock.createMock(ObjectFactory.class)); + property.setName("test"); + } + + protected String getName(Bar annotation) { + return "test"; + } + } + + + private static class Foo { + + @Bar + protected String d; + + public Foo(String a, @Bar String b) { + } + + public Foo(@Bar String d) { + this.d = d; + } + + @Bar + public void setBar(String d) { + this.d = d; + } + + @Bar + public void setNoParamsBar() { + } + + @Bar + public String setBadBar(String d) { + return null; + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java new file mode 100644 index 0000000000..f8c991f7d4 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.loader; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class LoaderExceptionTestCase extends TestCase { + + public void testResourceURI() throws Exception { + LoaderException e = new LoaderException(); + e.setResourceURI("test"); + assertEquals("test", e.getResourceURI()); + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java new file mode 100644 index 0000000000..c7170e0597 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.model; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ComponentTypeTestCase extends TestCase { + + /** + * Verifies fragments are used to retrieve service names + */ + public void testSetServiceName() { + ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + ServiceDefinition definition = new ServiceDefinition(); + definition.setUri(URI.create("foo#bar")); + type.add(definition); + assertEquals(definition, type.getServices().get("bar")); + } + + /** + * Verifies fragments are used to retrieve service names + */ + public void testSetReferenceName() { + ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + ReferenceDefinition definition = new ReferenceDefinition(); + definition.setUri(URI.create("foo#bar")); + type.add(definition); + assertEquals(definition, type.getReferences().get("bar")); + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java new file mode 100644 index 0000000000..d348d2b3c8 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java @@ -0,0 +1,43 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.spi.model;
+
+import junit.framework.TestCase;
+
+public class CompositeComponentTypeTestCase extends TestCase {
+
+ public void testWireCreationAndRetrieval() throws Exception {
+ WireDefinition wire1 = new WireDefinition();
+ WireDefinition wire2 = new WireDefinition();
+
+ CompositeComponentType composite = new CompositeComponentType();
+ CompositeComponentType includedComposite = new CompositeComponentType();
+ includedComposite.add(wire1);
+ Include compositeInclude = new Include();
+ compositeInclude.setIncluded(includedComposite);
+
+ composite.add(compositeInclude);
+ composite.add(wire1);
+
+ assertEquals(1, composite.getDeclaredWires().size());
+ assertEquals(wire1, composite.getDeclaredWires().get(0));
+ assertEquals(2, composite.getWires().size());
+ }
+
+}
diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java new file mode 100644 index 0000000000..698b7835d9 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.model; + +import java.util.Arrays; + +import junit.framework.TestCase; + +public class IntentNameTestCase extends TestCase { + + public void testConstructor() throws Exception { + String case1 = "sec.confidentiality/message/body"; + IntentName intentName = new IntentName(case1); + assertEquals("sec", intentName.getDomain()); + assertEquals(case1, intentName.toString()); + assertTrue(Arrays.equals(new String[]{"confidentiality", "message", "body"}, intentName.getQualifiedNames())); + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java new file mode 100644 index 0000000000..de5f1719b0 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.model; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class OperationTestCase extends TestCase { + + public void testClone() throws Exception { + DataType<Class> stringType = new DataType<Class>("xml:string", String.class, String.class); + List<DataType<Class>> inputTypes = new ArrayList<DataType<Class>>(); + inputTypes.add(stringType); + DataType<List<DataType<Class>>> inputType = + new DataType<List<DataType<Class>>>("xml:string", Object[].class, inputTypes); + + DataType<Class> faultType = new DataType<Class>("xml:foo", String.class, String.class); + List<DataType<Class>> faultTypes = new ArrayList<DataType<Class>>(); + faultTypes.add(faultType); + + Operation<Class> operation1 = + new Operation<Class>("call", inputType, stringType, faultTypes, true, "xml:string", NO_CONVERSATION); + Operation<Class> operation2 = operation1.clone(); + assertEquals(operation1, operation2); + assertEquals(NO_CONVERSATION, operation2.getConversationSequence()); + assertEquals("call", operation2.getName()); + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java new file mode 100644 index 0000000000..a8a88626ec --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.model; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeTestCase extends TestCase { + + public void testEquals() throws Exception { + Scope scope = new Scope("COMPOSITE"); + assertTrue(scope.equals(Scope.COMPOSITE)); + } + + public void testEqualsNew() throws Exception { + Scope foo = new Scope("foo"); + Scope foo2 = new Scope("FOO"); + assertTrue(foo.equals(foo2)); + } + + public void testNotEquals() throws Exception { + Scope foo = new Scope("BAR"); + Scope foo2 = new Scope("FOO"); + assertFalse(foo.equals(foo2)); + } + + public void testNotEqualsDifferent() throws Exception { + Scope foo = new Scope("FOO"); + assertFalse(foo.equals(new Bar("FOO"))); + } + + public class Bar { + private String scope; + + public Bar(String scope) { + this.scope = scope; + } + } + + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java new file mode 100644 index 0000000000..4cf98d1542 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.model; + +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; + +import java.util.Map; +import java.util.HashMap; +import java.lang.reflect.Type; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ServiceContractTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testAddOperation() throws Exception { + ServiceContract<Type> contract = new TestContract(); + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); + ops.put("foo", operation); + contract.setOperations(ops); + assertEquals(contract, operation.getServiceContract()); + assertFalse(operation.isCallback()); + } + + public void testAddCallbackOperation() throws Exception { + ServiceContract<Type> contract = new TestContract(); + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); + ops.put("foo", operation); + contract.setCallbackOperations(ops); + assertEquals(contract, operation.getServiceContract()); + assertTrue(operation.isCallback()); + } + + @SuppressWarnings("unchecked") + public void testClone() throws Exception { + ServiceContract<Type> contract = new TestContract(); + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); + ops.put("foo", operation); + contract.setOperations(ops); + + operation = new Operation<Type>("bar", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> callbackOps = new HashMap<String, Operation<Type>>(); + ops.put("bar", operation); + contract.setCallbackOperations(callbackOps); + + ServiceContract<Type> copy = (ServiceContract<Type>) contract.clone(); + assertEquals(contract, copy); + } + + + private class TestContract extends ServiceContract<Type> { + + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java new file mode 100644 index 0000000000..be0d96f3ea --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.policy; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import static org.apache.tuscany.spi.policy.PolicyBuilderRegistry.EXTENSION; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + * @deprecated + */ +public class SourcePolicyBuilderExtensionTestCase extends TestCase { + + public void testRegister() throws Exception { + PolicyBuilderRegistry registry = EasyMock.createMock(PolicyBuilderRegistry.class); + registry.registerSourceBuilder(EasyMock.eq(EXTENSION), EasyMock.isA(MockPolicyBuilderExtension.class)); + EasyMock.replay(registry); + SourcePolicyBuilderExtension extension = new MockPolicyBuilderExtension(); + extension.setRegistry(registry); + extension.init(); + EasyMock.verify(registry); + } + + private static class MockPolicyBuilderExtension extends SourcePolicyBuilderExtension { + + public void build(ReferenceDefinition definition, Wire wire) throws BuilderException { + + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java new file mode 100644 index 0000000000..a044f6e507 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.policy; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.ServiceDefinition; +import static org.apache.tuscany.spi.policy.PolicyBuilderRegistry.EXTENSION; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class TargetPolicyBuilderExtensionTestCase extends TestCase { + + public void testRegister() throws Exception { + PolicyBuilderRegistry registry = EasyMock.createMock(PolicyBuilderRegistry.class); + registry.registerTargetBuilder(EasyMock.eq(EXTENSION), EasyMock.isA(MockPolicyBuilderExtension.class)); + EasyMock.replay(registry); + TargetPolicyBuilderExtension extension = new MockPolicyBuilderExtension(); + extension.setRegistry(registry); + extension.init(); + EasyMock.verify(registry); + } + + private static class MockPolicyBuilderExtension extends TargetPolicyBuilderExtension { + + public void build(ServiceDefinition definition, Wire wire) throws BuilderException { + + } + } +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java new file mode 100644 index 0000000000..832e3eb3a8 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.util; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class URIHelperTestCase extends TestCase { + + public void testBaseName() throws Exception { + URI uri = new URI("foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNameScheme() throws Exception { + URI uri = new URI("sca://foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNameSchemePath() throws Exception { + URI uri = new URI("sca://bar/foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNamePath() throws Exception { + URI uri = new URI("bar/foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNameFragment() throws Exception { + URI uri = new URI("#foo"); + assertEquals("#foo", UriHelper.getBaseName(uri)); + } + + public void testDefragmentedNameScheme() throws Exception { + URI uri = new URI("sca://foo/bar#bar"); + assertEquals("sca://foo/bar", UriHelper.getDefragmentedName(uri).toString()); + } + + public void testDefragmentedName() throws Exception { + URI uri = new URI("foo/bar#bar"); + assertEquals("foo/bar", UriHelper.getDefragmentedName(uri).toString()); + } + + public void testDefragmentedNoName() throws Exception { + URI uri = new URI("#bar"); + assertEquals("", UriHelper.getDefragmentedName(uri).toString()); + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java new file mode 100644 index 0000000000..87be31b23b --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.util.stax; + +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +/** + * Test case for StaxHelper + * + * @version $Revision$ $Date$ + * + */ +public class StaxUtilTestCase extends TestCase { + + public StaxUtilTestCase(String name) { + super(name); + } + + public void testSerialize() throws XMLStreamException { + + InputStream in = getClass().getClassLoader().getResourceAsStream("test.scdl"); + XMLStreamReader reader = StaxUtil.createReader(in); + StaxUtil.serialize(reader); + // TODO Do assertions + } + + public void testGetDocumentElementQName() throws XMLStreamException { + InputStream in = getClass().getClassLoader().getResourceAsStream("test.scdl"); + XMLStreamReader reader = StaxUtil.createReader(in); + String xml = StaxUtil.serialize(reader); + QName qname = StaxUtil.getDocumentElementQName(xml); + assertEquals("http://www.osoa.org/xmlns/sca/1.0", qname.getNamespaceURI()); + assertEquals("composite", qname.getLocalPart()); + } + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java new file mode 100644 index 0000000000..1b1b550ad3 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.wire; + +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractInvocationHandlerTestCase extends TestCase { + + public void testInvocation() throws Throwable { + InvocationHandler handler = new InvocationHandler(); + Interceptor interceptor = new MockInterceptor(); + TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); + EasyMock.replay(invoker); + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor); + EasyMock.replay(chain); + Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<URI>()); + assertEquals("response", resp); + } + + public void testShortCircuitInvocation() throws Throwable { + InvocationHandler handler = new InvocationHandler(); + TargetInvoker invoker = new MockInvoker(); + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.expect(chain.getHeadInterceptor()).andReturn(null); + EasyMock.expect(chain.getTargetInvoker()).andReturn(invoker); + EasyMock.replay(chain); + Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<URI>()); + assertEquals("response", resp); + } + + + private class MockInvoker implements TargetInvoker { + + public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { + assertEquals("foo", Array.get(payload, 0)); + return "response"; + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + fail(); + return null; + } + + public boolean isCacheable() { + return false; + } + + public void setCacheable(boolean cacheable) { + + } + + public boolean isOptimizable() { + return false; + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } + + private class InvocationHandler extends AbstractInvocationHandler { + + protected URI getFromAddress() { + return URI.create("from"); + } + + } + + private class MockInterceptor implements Interceptor { + + public Message invoke(Message msg) { + assertNotNull(msg.getCorrelationId()); + assertNotNull(msg.getTargetInvoker()); + assertNotNull(msg.getMessageId()); + assertNotNull(msg.getCallbackUris()); + assertEquals("foo", Array.get(msg.getBody(), 0)); + msg.setBody("response"); + return msg; + } + + public void setNext(Interceptor next) { + + } + + public Interceptor getNext() { + return null; + } + + public boolean isOptimizable() { + return false; + } + } + + +} diff --git a/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java new file mode 100644 index 0000000000..9b67ec53e4 --- /dev/null +++ b/sca-java-1.x/tags/kernel/2.0-alpha-incubating/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.spi.wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class ChainHolderTestCase extends TestCase { + + public void testClone() { + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.replay(chain); + ChainHolder holder = new ChainHolder(chain); + assertNotNull(holder.clone()); + } +} |