diff options
Diffstat (limited to 'sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly')
6 files changed, 414 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java new file mode 100644 index 0000000000..20fd74d46e --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java @@ -0,0 +1,170 @@ +/* + * 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.sca.assembly; + +import javax.xml.namespace.QName; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test building of assembly model instances using the assembly factory. + * + * @version $Rev$ $Date$ + */ +public class AssemblyFactoryTestCase { + + private static AssemblyFactory assemblyFactory; + + @BeforeClass + public static void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + } + + @Test + public void testCreateComponent() { + createComponent("AccountServiceComponent1"); + } + + @Test + public void testCreateComponentType() { + createComponentType(); + } + + @Test + public void testCreateComposite() { + createComposite(); + } + + /** + * Create a composite + */ + Composite createComposite() { + Composite c = assemblyFactory.createComposite(); + + Component c1 = createComponent("AccountServiceComponent1"); + c.getComponents().add(c1); + Component c2 = createComponent("AccountServiceComponent2"); + c.getComponents().add(c2); + + Wire w = assemblyFactory.createWire(); + w.setSource(c1.getReferences().get(0)); + w.setTarget(c2.getServices().get(0)); + c.getWires().add(w); + + CompositeService cs = assemblyFactory.createCompositeService(); + cs.setName("AccountService"); + cs.setPromotedService(c1.getServices().get(0)); + cs.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + c.getServices().add(cs); + cs.getBindings().add(new TestBinding(assemblyFactory)); + + CompositeReference cr = assemblyFactory.createCompositeReference(); + cr.setName("StockQuoteService"); + cr.getPromotedReferences().add(c2.getReferences().get(1)); + cr.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + c.getReferences().add(cr); + cr.getBindings().add(new TestBinding(assemblyFactory)); + + return c; + } + + /** + * Create a new component + */ + Component createComponent(String name) { + Component c = assemblyFactory.createComponent(); + c.setName(name); + + Implementation i = new TestImplementation(assemblyFactory); + c.setImplementation(i); + + ComponentProperty p = assemblyFactory.createComponentProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + p.setProperty(i.getProperties().get(0)); + c.getProperties().add(p); + + ComponentReference ref1 = assemblyFactory.createComponentReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref1.setReference(i.getReferences().get(0)); + c.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(assemblyFactory)); + + ComponentReference ref2 = assemblyFactory.createComponentReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref2.setReference(i.getReferences().get(1)); + c.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(assemblyFactory)); + + ComponentService s = assemblyFactory.createComponentService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + s.setService(i.getServices().get(0)); + c.getServices().add(s); + s.getBindings().add(new TestBinding(assemblyFactory)); + + return c; + } + + /** + * Create a new component type + * + * @return + */ + ComponentType createComponentType() { + ComponentType ctype = assemblyFactory.createComponentType(); + + Property p = assemblyFactory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + Reference ref1 = assemblyFactory.createReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(assemblyFactory)); + + Reference ref2 = assemblyFactory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(assemblyFactory)); + + Service s = assemblyFactory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(assemblyFactory)); + ctype.getServices().add(s); + s.getBindings().add(new TestBinding(assemblyFactory)); + + return ctype; + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java new file mode 100644 index 0000000000..a09f7af06c --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.BindingImpl; + +/** + * A test interface model. + * + * @version $Rev$ $Date$ + */ +public class TestBinding extends BindingImpl implements Binding { + private final static QName TYPE = new QName("http://test", "binding.test"); + + public TestBinding(AssemblyFactory factory) { + super(TYPE); + } + + public String getName() { + return null; + } + + public String getURI() { + return "http://test"; + } + + public boolean isUnresolved() { + return false; + } + + public WireFormat getRequestWireFormat() { + return null; + } + + public void setRequestWireFormat(WireFormat wireFormat) { + } + + public WireFormat getResponseWireFormat() { + return null; + } + + public void setResponseWireFormat(WireFormat wireFormat) { + } + + public OperationSelector getOperationSelector() { + return null; + } + + public void setOperationSelector(OperationSelector operationSelector) { + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java new file mode 100644 index 0000000000..6777c33ff1 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java @@ -0,0 +1,61 @@ +/* + * 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.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; + +/** + * A test component implementation model. + * + * @version $Rev$ $Date$ + */ +public class TestImplementation extends ImplementationImpl implements Implementation { + public TestImplementation(AssemblyFactory factory) { + super(new QName("http://test", "implementation.test")); + Property p = factory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + getProperties().add(p); + + Reference ref1 = factory.createReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + Reference ref2 = factory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + Service s = factory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java new file mode 100644 index 0000000000..dbe0cb8225 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl; + +/** + * A test interface model. + * + * @version $Rev$ $Date$ + */ +public class TestInterface extends InterfaceImpl implements Interface { + + public TestInterface(AssemblyFactory factory) { + + setRemotable(true); + + Operation operation = new TestOperation(); + operation.setName("test"); + getOperations().add(operation); + + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java new file mode 100644 index 0000000000..24be8a3e7d --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java @@ -0,0 +1,41 @@ +/* + * 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.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl; + +/** + * A test interface contract model. + * + * @version $Rev$ $Date$ + */ +public class TestInterfaceContract extends InterfaceContractImpl implements InterfaceContract { + + public TestInterfaceContract(AssemblyFactory factory) { + + TestInterface testInterface = new TestInterface(factory); + setInterface(testInterface); + + TestInterface testCallbackInterface = new TestInterface(factory); + setCallbackInterface(testCallbackInterface); + + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java new file mode 100644 index 0000000000..d94a7e93a3 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java @@ -0,0 +1,30 @@ +/* + * 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.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; + +/** + * A test operation model. + * + * @version $Rev$ $Date$ + */ +public class TestOperation extends OperationImpl { + +} |