diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:11:56 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:11:56 +0000 |
commit | 9bed5ae38c581999db465b42b504026a7097af95 (patch) | |
tree | a32b086a857a4556b8aec1aa9ed3a586efd9461e /branches/pre-spec-changes/kernel/spi/src/test/java | |
parent | ece4fd35da7b7fc76264776f81705e6b5b52d3e0 (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835141 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/pre-spec-changes/kernel/spi/src/test/java')
37 files changed, 0 insertions, 3319 deletions
diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java deleted file mode 100644 index 72739d56c4..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java deleted file mode 100644 index 1f5faa5f9e..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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()); - } - - public void testCompoundName() throws Exception { - QualifiedName name = new QualifiedName("Foo/Bar"); - assertEquals("Foo", name.getPartName()); - assertEquals("Bar", name.getPortName()); - } - - public void testCompoundMultiName() throws Exception { - QualifiedName name = new QualifiedName("Foo/Bar/Baz"); - assertEquals("Foo", name.getPartName()); - assertEquals("Bar/Baz", name.getPortName()); - } - - public void testInvalidName() throws Exception { - try { - new QualifiedName("/Foo/Bar"); - fail("Invalid name exception not thrown"); - } catch (InvalidNameException e) { - //expected - } - } - - public void testQualifiedName() throws Exception { - QualifiedName name = new QualifiedName("Foo/Bar"); - assertEquals("Foo/Bar", name.getQualifiedName()); - } - - public void testToString() throws Exception { - QualifiedName name = new QualifiedName("Foo/Bar"); - assertEquals("Foo/Bar", name.toString()); - } - -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java deleted file mode 100644 index 44e6bd7927..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 testAddContext() throws Exception { - TuscanyRuntimeException e = new TestException(); - e.addContextName("foo"); - e.addContextName("bar"); - assertEquals("foo", e.returnContextNames().get(0)); - assertEquals("bar", e.returnContextNames().get(1)); - } - - public void testEmptyContext() throws Exception { - TuscanyRuntimeException e = new TestException(); - assertEquals(0, e.returnContextNames().size()); - } - - public void testEmptyGetMessage() throws Exception { - TuscanyRuntimeException e = new TestException(); - e.getMessage(); - } - - public void testFullMessage() throws Exception { - TuscanyRuntimeException e = new TestException(); - e.addContextName("foo"); - e.getMessage(); - } - - - private class TestException extends TuscanyRuntimeException { - - public TestException() { - } - - public TestException(String message, String identifier) { - super(message, identifier); - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/annotation/ConstructorAnnotationTest.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/annotation/ConstructorAnnotationTest.java deleted file mode 100644 index affd52df42..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/annotation/ConstructorAnnotationTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.annotation; - -import java.util.Arrays; - -import org.osoa.sca.annotations.Constructor; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorAnnotationTest extends TestCase { - public void testSingleName() throws NoSuchMethodException { - Constructor ann = Foo1.class.getConstructor(String.class).getAnnotation(Constructor.class); - assertNotNull(ann); - String[] names = ann.value(); - assertTrue(Arrays.equals(new String[]{"prop"}, names)); - } - - public void testMultipleNames() throws NoSuchMethodException { - Constructor ann = Foo1.class.getConstructor(String.class, String.class).getAnnotation(Constructor.class); - assertNotNull(ann); - String[] names = ann.value(); - assertTrue(Arrays.equals(new String[]{"prop", "ref"}, names)); - } - - public static class Foo1 { - @Constructor({"prop", "ref"}) - public Foo1(String prop, String ref) { - } - - @Constructor("prop") - public Foo1(String prop) { - } - } - - public static class Foo2 { - public Foo2(@Autowire String prop, - @Autowire String ref) { - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java deleted file mode 100644 index 4f99d3b7ec..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 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 org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AbstractSCAObjectTestCase extends TestCase { - - public void testFireListener() { - SCAObject object = new TestSCAObject("foo", null); - 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() { - SCAObject object = new TestSCAObject("foo", null); - 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() { - SCAObject object = new TestSCAObject("foo", null); - Event event = new TestEvent(); - RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); - EasyMock.replay(listener); - object.addListener(new FalseFilter(), listener); - object.publish(event); - } - - public void testTrueFilterListener() { - SCAObject object = new TestSCAObject("foo", null); - 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() { - SCAObject object = new TestSCAObject("foo", null); - assertNotNull(object.toString()); - } - - public void testGetName() { - SCAObject object = new TestSCAObject("foo", null); - assertEquals("foo", object.getName()); - } - - - public void testToPrepare() throws Exception { - SCAObject object = new TestSCAObject("foo", null); - object.prepare(); - } - - public void testCanonicalName() { - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getCanonicalName()).andReturn("foo"); - EasyMock.replay(parent); - TestSCAObject test = new TestSCAObject("bar", parent); - assertEquals("foo/bar", test.getCanonicalName()); - } - - private class TestSCAObject extends AbstractSCAObject { - public TestSCAObject(String name, CompositeComponent parent) { - super(name, parent); - } - - public Scope getScope() { - return null; - } - - } - - 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java deleted file mode 100644 index 40843dea94..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java deleted file mode 100644 index b4b5f6a39a..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java deleted file mode 100644 index c955352812..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.idl.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"); - 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java deleted file mode 100644 index 6f5dfc90e2..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java deleted file mode 100644 index 4693025c11..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java deleted file mode 100644 index 6efd61bea6..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java deleted file mode 100644 index 1e81311765..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.component.ScopeContainer; -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.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AtomicComponentExtensionTestCase extends TestCase { - - public void testIsEagerInit() throws Exception { - TestExtension ext = new TestExtension(); - ext.isEagerInit(); - } - - public void testPrepare() throws Exception { - TestExtension ext = new TestExtension(); - Operation<Type> operation = new Operation<Type>("foo", null, null, null); - InboundInvocationChain chain = EasyMock.createMock(InboundInvocationChain.class); - EasyMock.expect(chain.getOperation()).andReturn(operation); - chain.prepare(); - chain.setTargetInvoker(EasyMock.isA(TargetInvoker.class)); - EasyMock.replay(chain); - - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(operation, chain); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getInvocationChains()).andReturn(chains); - EasyMock.expect(wire.getServiceName()).andReturn("Service").atLeastOnce(); - EasyMock.replay(wire); - - ext.addInboundWire(wire); - ext.prepare(); - - EasyMock.verify(chain); - EasyMock.verify(wire); - - } - - public void testInit() throws Exception { - TestExtension ext = new TestExtension(); - ext.init(null); - } - - public void testDestroy() throws Exception { - TestExtension ext = new TestExtension(); - ext.destroy(null); - } - - public void testInboundWire() throws Exception { - TestExtension ext = new TestExtension(); - ext.getInboundWire(null); - } - - public void testRemoveInstance() throws Exception { - ScopeContainer container = EasyMock.createMock(ScopeContainer.class); - EasyMock.expect(container.getScope()).andReturn(Scope.COMPOSITE); - container.remove(EasyMock.isA(AtomicComponentExtension.class)); - EasyMock.replay(container); - TestExtension ext = new TestExtension(container); - ext.removeInstance(); - EasyMock.verify(container); - } - - private class TestExtension extends AtomicComponentExtension { - public TestExtension() { - super(null, null, null, null, null, null, 0); - } - - public TestExtension(ScopeContainer scopeContainer) { - super(null, null, null, null, null, null, 0); - setScopeContainer(scopeContainer); - } - - public Object createInstance() throws ObjectCreationException { - return null; - } - - public Object getTargetInstance() throws TargetResolutionException { - return null; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) { - return new TargetInvoker() { - - public Object invokeTarget(final Object payload, final short sequence) - throws InvocationTargetException { - return null; - } - - public Message invoke(Message msg) throws InvocationRuntimeException { - 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(); - } - }; - } - - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java deleted file mode 100644 index 54229633eb..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 org.apache.tuscany.spi.component.CompositeComponent; -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; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; - -/** - * @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(CompositeComponent parent, Implementation implementation, - DeploymentContext deploymentContext) throws LoaderException { - - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionAutowireTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionAutowireTestCase.java deleted file mode 100644 index 9d9df81104..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionAutowireTestCase.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * 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.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -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 CompositeComponentExtensionAutowireTestCase extends TestCase { - private CompositeComponent composite; - private ServiceContract<?> contract; - private ServiceContract<?> contract2; - - public void testAutowireAtomicComponent() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - List<InboundWire> wires = new ArrayList<InboundWire>(); - wires.add(wire); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(component); - composite.register(component); - assertEquals(wire, composite.resolveAutowire(Foo.class)); - } - - public void testAutowireSystemAtomicComponent() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - List<InboundWire> wires = new ArrayList<InboundWire>(); - wires.add(wire); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(component); - composite.register(component); - assertEquals(wire, composite.resolveSystemAutowire(Foo.class)); - } - - public void testAutowireSystemCompositeComponent() throws Exception { - // configure service - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - - // configure system service - InboundWire systemWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(systemWire.getServiceContract()).andReturn(contract2).atLeastOnce(); - EasyMock.expect(systemWire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(systemWire); - ServiceBinding systemBinding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(systemBinding.getInboundWire()).andReturn(systemWire).atLeastOnce(); - EasyMock.replay(systemBinding); - Service systemService = EasyMock.createMock(Service.class); - EasyMock.expect(systemService.getName()).andReturn("systemService").atLeastOnce(); - EasyMock.expect(systemService.isSystem()).andReturn(true).atLeastOnce(); - systemService.getServiceBindings(); - List<ServiceBinding> systemBindings = new ArrayList<ServiceBinding>(); - systemBindings.add(systemBinding); - EasyMock.expectLastCall().andReturn(systemBindings).atLeastOnce(); - EasyMock.replay(systemService); - - CompositeComponent child = new MockComposite(true); - child.register(service); - child.register(systemService); - composite.register(child); - // since the child is registered under the system hierarchy, its services should not be visible from the - // applicaiton hierarchy - assertNull(composite.resolveAutowire(Foo.class)); - assertEquals(systemWire, composite.resolveSystemAutowire(Bar.class)); - } - - public void testAutowireCompositeComponent() throws Exception { - // configure service - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - - // configure system service - InboundWire systemWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(systemWire.getServiceContract()).andReturn(contract2).atLeastOnce(); - EasyMock.expect(systemWire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(systemWire); - ServiceBinding systemBinding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(systemBinding.getInboundWire()).andReturn(systemWire).atLeastOnce(); - EasyMock.replay(systemBinding); - Service systemService = EasyMock.createMock(Service.class); - EasyMock.expect(systemService.getName()).andReturn("systemService").atLeastOnce(); - EasyMock.expect(systemService.isSystem()).andReturn(true).atLeastOnce(); - systemService.getServiceBindings(); - List<ServiceBinding> systemBindings = new ArrayList<ServiceBinding>(); - systemBindings.add(systemBinding); - EasyMock.expectLastCall().andReturn(systemBindings).atLeastOnce(); - EasyMock.replay(systemService); - - CompositeComponent child = new MockComposite(); - child.register(service); - child.register(systemService); - composite.register(child); - // since the child is registered under the application hierarchy, its services should not be visible from the - // system hierarchy - assertEquals(wire, composite.resolveAutowire(Foo.class)); - assertNull(composite.resolveSystemAutowire(Bar.class)); - } - - public void testAutowireSystemService() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(wire, composite.resolveSystemExternalAutowire(Foo.class)); - } - - public void testAutowireService() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(wire, composite.resolveExternalAutowire(Foo.class)); - } - - public void testAutowireReference() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Reference reference = EasyMock.createMock(Reference.class); - EasyMock.expect(reference.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(reference.isSystem()).andReturn(false).atLeastOnce(); - reference.getReferenceBindings(); - List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(reference); - composite.register(reference); - assertEquals(wire, composite.resolveAutowire(Foo.class)); - } - - public void testAutowireSystemReference() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Reference reference = EasyMock.createMock(Reference.class); - EasyMock.expect(reference.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(reference.isSystem()).andReturn(true).atLeastOnce(); - reference.getReferenceBindings(); - List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(reference); - composite.register(reference); - assertEquals(wire, composite.resolveSystemAutowire(Foo.class)); - } - - - protected void setUp() throws Exception { - super.setUp(); - contract = new ServiceContract<Object>(Foo.class) { - - }; - contract2 = new ServiceContract<Object>(Bar.class) { - - }; - composite = new MockComposite(); - } - - private interface Foo { - - } - - private interface Bar { - - } - - private static class MockComposite extends CompositeComponentExtension { - private boolean system; - - public MockComposite() { - super("foo", null, null, null); - } - - public MockComposite(boolean system) { - super("foo", null, null, null); - this.system = system; - } - - public boolean isSystem() { - return system; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) - throws TargetInvokerCreationException { - throw new UnsupportedOperationException(); - } - - public void setScopeContainer(ScopeContainer scopeContainer) { - throw new UnsupportedOperationException(); - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java deleted file mode 100644 index 9eaedb04f4..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * 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.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -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 CompositeComponentExtensionTestCase extends TestCase { - private CompositeComponent composite; - private ServiceContract<?> contract; - - public void testDefaultInboundWire() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(wire, composite.getInboundWire(null)); - } - - public void testNoLocalBinding() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(new QName("foo", "foo")).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertNull(composite.getInboundWire("service")); - } - - public void testDefaultSystemInboundWire() throws Exception { - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce(); - service.getServiceBindings(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(wire, composite.getInboundSystemWire(null)); - } - - public void testMoreThanOneServiceGetDefault() throws Exception { - Service service1 = EasyMock.createMock(Service.class); - EasyMock.expect(service1.getName()).andReturn("service1").atLeastOnce(); - EasyMock.expect(service1.isSystem()).andReturn(false).atLeastOnce(); - service1.getServiceBindings(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.replay(service1); - - Service service2 = EasyMock.createMock(Service.class); - EasyMock.expect(service2.getName()).andReturn("service2").atLeastOnce(); - EasyMock.expect(service2.isSystem()).andReturn(false).atLeastOnce(); - service2.getServiceBindings(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.replay(service2); - - composite.register(service1); - composite.register(service2); - assertNull(composite.getInboundWire(null)); - assertNull(composite.getInboundSystemWire(null)); - } - - public void testInboundWire() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING); - wire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertNotNull(composite.getInboundWire("service")); - } - - public void testInboundWires() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING); - wire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(1, composite.getInboundWires().size()); - } - - public void testInboundWiresNonLocalBinding() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getBindingType()).andReturn(new QName("foo", "foo")); - wire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(0, composite.getInboundWires().size()); - } - - - public void testGetOutboundWires() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - inboundWire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(inboundWire); - - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.expect(outboundWire.getBindingType()).andReturn(Wire.LOCAL_BINDING); - EasyMock.replay(outboundWire); - - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(inboundWire).atLeastOnce(); - EasyMock.expect(binding.getOutboundWire()).andReturn(outboundWire).atLeastOnce(); - EasyMock.replay(binding); - Reference reference = EasyMock.createMock(Reference.class); - EasyMock.expect(reference.getName()).andReturn("reference").atLeastOnce(); - EasyMock.expect(reference.isSystem()).andReturn(false).atLeastOnce(); - List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>(); - bindings.add(binding); - EasyMock.expect(reference.getReferenceBindings()).andReturn(bindings).atLeastOnce(); - EasyMock.replay(reference); - composite.register(reference); - Map<String, List<OutboundWire>> wires = composite.getOutboundWires(); - assertEquals(1, wires.get("reference").size()); - } - - public void testGetOutboundWiresWithNonLocalBinding() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - QName qName = new QName("foo", "foo"); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inboundWire.getBindingType()).andReturn(qName); - inboundWire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(inboundWire); - - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.expect(outboundWire.getBindingType()).andReturn(qName); - EasyMock.replay(outboundWire); - - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(inboundWire).atLeastOnce(); - EasyMock.expect(binding.getOutboundWire()).andReturn(outboundWire).atLeastOnce(); - EasyMock.replay(binding); - Reference reference = EasyMock.createMock(Reference.class); - EasyMock.expect(reference.getName()).andReturn("reference").atLeastOnce(); - EasyMock.expect(reference.isSystem()).andReturn(false).atLeastOnce(); - List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>(); - bindings.add(binding); - EasyMock.expect(reference.getReferenceBindings()).andReturn(bindings).atLeastOnce(); - EasyMock.replay(reference); - composite.register(reference); - Map<String, List<OutboundWire>> wires = composite.getOutboundWires(); - assertEquals(0, wires.get("reference").size()); - } - - public void testInboundSystemWire() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING); - wire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertNotNull(composite.getInboundSystemWire("service")); - } - - public void testInboundSystemWires() throws Exception { - ServiceContract<Object> contract = new ServiceContract<Object>(Object.class) { - }; - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING); - wire.getServiceContract(); - EasyMock.expectLastCall().andReturn(contract).atLeastOnce(); - EasyMock.replay(wire); - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce(); - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(binding); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - assertEquals(wire, composite.getInboundSystemWires().iterator().next()); - } - - protected void setUp() throws Exception { - super.setUp(); - contract = new ServiceContract<Object>(Object.class) { - - }; - composite = new CompositeComponentExtension("foo", null, null, null) { - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) - throws TargetInvokerCreationException { - throw new UnsupportedOperationException(); - } - - public void setScopeContainer(ScopeContainer scopeContainer) { - throw new UnsupportedOperationException(); - } - }; - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java deleted file mode 100644 index 84175d8578..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.component.CompositeComponent; -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(CompositeComponent parent, - ModelObject object, XMLStreamReader reader, - DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { - throw new AssertionError(); - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ReferenceBindingExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ReferenceBindingExtensionTestCase.java deleted file mode 100644 index e48d72e7fb..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ReferenceBindingExtensionTestCase.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apache.tuscany.spi.extension; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.component.Reference; -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.model.ServiceContract; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ReferenceBindingExtensionTestCase extends TestCase { - - public void testScope() throws Exception { - ReferenceBindingExtension binding = new MockBindingExtension(); - assertEquals(Scope.SYSTEM, binding.getScope()); - } - - public void testPrepare() throws Exception { - ReferenceBindingExtension binding = new MockBindingExtension(); - binding.prepare(); - } - - public void testIsSystemNoParent() throws Exception { - ReferenceBindingExtension binding = new MockBindingExtension(); - assertFalse(binding.isSystem()); - } - - public void testIsSystem() throws Exception { - Reference reference = EasyMock.createMock(Reference.class); - EasyMock.expect(reference.isSystem()).andReturn(true); - EasyMock.replay(reference); - ReferenceBindingExtension binding = new MockBindingExtension(); - binding.setReference(reference); - assertTrue(binding.isSystem()); - } - - public void testIsNotSystem() throws Exception { - Reference reference = EasyMock.createMock(Reference.class); - EasyMock.expect(reference.isSystem()).andReturn(false); - EasyMock.replay(reference); - ReferenceBindingExtension binding = new MockBindingExtension(); - binding.setReference(reference); - assertFalse(binding.isSystem()); - } - - private static class MockBindingExtension extends ReferenceBindingExtension { - public MockBindingExtension() { - super(null, null); - } - - public QName getBindingType() { - return null; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) - throws TargetInvokerCreationException { - return null; - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ReferenceTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ReferenceTestCase.java deleted file mode 100644 index 60d7a4d908..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ReferenceTestCase.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.util.HashMap; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.InvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; - -/** - * @version $Rev$ $Date$ - */ -public class ReferenceTestCase extends TestCase { - - public void testScope() throws Exception { - TestReferenceBinding ref = new TestReferenceBinding(); - assertEquals(Scope.SYSTEM, ref.getScope()); - } - - public void testPrepare() throws Exception { - InboundInvocationChain chain = createMock(InboundInvocationChain.class); - Operation<Type> operation = new Operation<Type>("test", null, null, null, false, null, NO_CONVERSATION); - chain.setTargetInvoker(null); - expectLastCall(); - chain.getOperation(); - expectLastCall().andReturn(operation); - chain.prepare(); - expectLastCall(); - InboundWire wire = createMock(InboundWire.class); - wire.getInvocationChains(); - Map<Operation, InvocationChain> chains = new HashMap<Operation, InvocationChain>(); - chains.put(operation, chain); - expectLastCall().andReturn(chains); - OutboundWire outboundWire = createMock(OutboundWire.class); - outboundWire.getTargetName(); - expectLastCall().andReturn(new QualifiedName("foo/bar")); - replay(chain); - replay(wire); - replay(outboundWire); - TestReferenceBinding ref = new TestReferenceBinding(); - ref.setInboundWire(wire); - ref.setOutboundWire(outboundWire); - ref.prepare(); - } - - private class TestReferenceBinding extends ReferenceBindingExtension { - public TestReferenceBinding() { - super(null, null); - } - - public QName getBindingType() { - return null; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { - return null; - } - - - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ServiceBindingExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ServiceBindingExtensionTestCase.java deleted file mode 100644 index 5570ee1fbb..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ServiceBindingExtensionTestCase.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ServiceBindingExtensionTestCase extends TestCase { - - public void testScope() throws Exception { - ServiceBindingExtension binding = new ServiceBindingExtension(null, null) { - public QName getBindingType() { - return null; - } - }; - assertEquals(Scope.SYSTEM, binding.getScope()); - } - - public void testPrepare() throws Exception { - ServiceBindingExtension binding = new ServiceBindingExtension(null, null) { - public QName getBindingType() { - return null; - } - }; - binding.prepare(); - } - - public void testIsSystemNoParent() throws Exception { - ServiceBindingExtension binding = new ServiceBindingExtension(null, null) { - public QName getBindingType() { - return null; - } - }; - assertFalse(binding.isSystem()); - } - - public void testIsSystem() throws Exception { - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.isSystem()).andReturn(true); - EasyMock.replay(service); - ServiceBindingExtension binding = new ServiceBindingExtension(null, null) { - public QName getBindingType() { - return null; - } - }; - binding.setService(service); - assertTrue(binding.isSystem()); - } - - public void testIsNotSystem() throws Exception { - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.isSystem()).andReturn(false); - EasyMock.replay(service); - ServiceBindingExtension binding = new ServiceBindingExtension(null, null) { - public QName getBindingType() { - return null; - } - }; - binding.setService(service); - assertFalse(binding.isSystem()); - } - -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java deleted file mode 100644 index 21d5ee763c..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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.util.LinkedList; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class TargetInvokerExtensionSequenceTestCase extends TestCase { - - @SuppressWarnings("unchecked") - public void testStart() { - Object from = new Object(); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.replay(wire); - WorkContext context; - context = EasyMock.createMock(WorkContext.class); - context.setCurrentCallbackRoutingChain(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(wire, context, monitor, target); - Message msg = new MessageImpl(); - msg.pushFromAddress(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() { - Object from = new Object(); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.replay(wire); - WorkContext context; - context = EasyMock.createMock(WorkContext.class); - context.setCurrentCallbackRoutingChain(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(wire, context, monitor, target); - Message msg = new MessageImpl(); - msg.pushFromAddress(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() { - Object from = new Object(); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.replay(wire); - WorkContext context; - context = EasyMock.createMock(WorkContext.class); - context.setCurrentCallbackRoutingChain(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(wire, context, monitor, target); - Message msg = new MessageImpl(); - msg.pushFromAddress(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() { - Object from = new Object(); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.replay(wire); - WorkContext context; - context = EasyMock.createMock(WorkContext.class); - context.setCurrentCallbackRoutingChain(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(wire, context, monitor, target); - Message msg = new MessageImpl(); - msg.pushFromAddress(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(InboundWire wire, WorkContext workContext, ExecutionMonitor monitor, - TargetInvokerExtensionSequenceTestCase.Target target) { - super(wire, workContext, monitor); - 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java deleted file mode 100644 index 56d069005d..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.util.LinkedList; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class TargetInvokerExtensionTestCase extends TestCase { - - @SuppressWarnings("unchecked") - public void testNonBlockingDispatch() { - Object from = new Object(); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.replay(wire); - WorkContext context; - context = EasyMock.createMock(WorkContext.class); - context.setCurrentCallbackRoutingChain(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(wire, context, monitor, target); - Message msg = new MessageImpl(); - msg.pushFromAddress(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(InboundWire wire, WorkContext workContext, ExecutionMonitor monitor, Target target) { - super(wire, workContext, monitor); - 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java deleted file mode 100644 index e50c1e32a2..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java deleted file mode 100644 index 18887880fe..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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.component.CompositeComponent; -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(null, 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(null, 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(null, 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(null, method, type, null); - try { - processor.visitMethod(null, 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(null, 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(null, 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, - CompositeComponent parent, - 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java deleted file mode 100644 index f8c991f7d4..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java deleted file mode 100644 index d348d2b3c8..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java +++ /dev/null @@ -1,43 +0,0 @@ -/*
- * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java deleted file mode 100644 index 7bd2e61ba4..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java +++ /dev/null @@ -1,16 +0,0 @@ -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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java deleted file mode 100644 index de5f1719b0..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java deleted file mode 100644 index a8a88626ec..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java deleted file mode 100644 index 4cf98d1542..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java deleted file mode 100644 index 38f432ffac..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.OutboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -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, OutboundWire wire) throws BuilderException { - - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java deleted file mode 100644 index 58488236e2..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.InboundWire; - -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, InboundWire wire) throws BuilderException { - - } - } -} diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/MockSCAExternalizable.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/MockSCAExternalizable.java deleted file mode 100644 index 8c85d4eb95..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/MockSCAExternalizable.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.io.Serializable; - -import org.apache.tuscany.spi.component.ReactivationException; -import org.apache.tuscany.spi.component.SCAExternalizable; -import org.apache.tuscany.spi.component.WorkContext; - -/** - * @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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/MockSerializable.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/MockSerializable.java deleted file mode 100644 index 3f34e1d0c7..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/MockSerializable.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/SCAObjectInputStreamTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/SCAObjectInputStreamTestCase.java deleted file mode 100644 index 0a34210b6c..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/util/SCAObjectInputStreamTestCase.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectOutputStream; - -import org.apache.tuscany.spi.component.WorkContext; - -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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInboundInvocationHandlerTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInboundInvocationHandlerTestCase.java deleted file mode 100644 index 39611054e8..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.apache.tuscany.spi.wire; - -import java.lang.reflect.Array; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AbstractInboundInvocationHandlerTestCase extends TestCase { - - public void testInvocation() throws Throwable { - InvocationHandler handler = new InvocationHandler(); - Interceptor interceptor = new MockInterceptor(); - TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.replay(invoker); - InboundInvocationChain chain = EasyMock.createMock(InboundInvocationChain.class); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor); - EasyMock.replay(chain); - Object resp = handler.invoke(chain, invoker, new String[]{"foo"}); - assertEquals("response", resp); - } - - - private class InvocationHandler extends AbstractInboundInvocationHandler { - - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - assertNotNull(msg.getCorrelationId()); - assertNotNull(msg.getTargetInvoker()); - assertNotNull(msg.getMessageId()); - 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; - } - } - - -}
\ No newline at end of file diff --git a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java deleted file mode 100644 index 617a055e78..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractOutboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.apache.tuscany.spi.wire; - -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.util.LinkedList; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AbstractOutboundInvocationHandlerTestCase extends TestCase { - - public void testInvocation() throws Throwable { - InvocationHandler handler = new InvocationHandler(); - Interceptor interceptor = new MockInterceptor(); - TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.replay(invoker); - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor); - EasyMock.replay(chain); - Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<Object>()); - assertEquals("response", resp); - } - - public void testShortCircuitInvocation() throws Throwable { - InvocationHandler handler = new InvocationHandler(); - TargetInvoker invoker = new MockInvoker(); - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.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<Object>()); - 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 AbstractOutboundInvocationHandler { - - protected Object getFromAddress() { - return new Object(); - } - - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - assertNotNull(msg.getCorrelationId()); - assertNotNull(msg.getTargetInvoker()); - assertNotNull(msg.getMessageId()); - assertNotNull(msg.getCallbackRoutingChain()); - 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/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/OutboundChainHolderTestCase.java b/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/OutboundChainHolderTestCase.java deleted file mode 100644 index cbce805151..0000000000 --- a/branches/pre-spec-changes/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/OutboundChainHolderTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 OutboundChainHolderTestCase extends TestCase { - - public void testClone() { - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.replay(chain); - OutboundChainHolder holder = new OutboundChainHolder(chain); - assertNotNull(holder.clone()); - } -} |