diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:28 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:28 +0000 |
commit | 07b7dfd1a70ba222b899d9813f8c449dbf3b785f (patch) | |
tree | ecfc876747e6cfedee0a8533d87c19ac78a2dbd0 /branches/sca-java-1.1/modules/assembly/src/test/java/org/apache | |
parent | 6fadbc9cd1fcf03d0b3630f772d91df149b70428 (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835124 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.1/modules/assembly/src/test/java/org/apache')
8 files changed, 0 insertions, 800 deletions
diff --git a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java deleted file mode 100644 index 767b152624..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java +++ /dev/null @@ -1,214 +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.sca.assembly; - -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - - -/** - * Test building of assembly model instances using the assembly factory. - * - * @version $Rev$ $Date$ - */ -public class AssemblyFactoryTestCase extends TestCase { - - AssemblyFactory factory; - - @Override - public void setUp() throws Exception { - factory = new DefaultAssemblyFactory(); - } - - @Override - public void tearDown() throws Exception { - factory = null; - } - - public void testCreateComponent() { - createComponent("AccountServiceComponent1"); - } - - public void testCreateComponentType() { - createComponentType(); - } - - public void testCreateComposite() { - createComposite(); - } - - public void testCreateConstrainingType() { - createConstrainingType(); - } - - /** - * Create a composite - */ - Composite createComposite() { - Composite c = factory.createComposite(); - - Component c1 = createComponent("AccountServiceComponent1"); - c.getComponents().add(c1); - Component c2 = createComponent("AccountServiceComponent2"); - c.getComponents().add(c2); - - Wire w = factory.createWire(); - w.setSource(c1.getReferences().get(0)); - w.setTarget(c2.getServices().get(0)); - c.getWires().add(w); - - CompositeService cs = factory.createCompositeService(); - cs.setName("AccountService"); - cs.setPromotedService(c1.getServices().get(0)); - cs.setInterfaceContract(new TestInterfaceContract(factory)); - c.getServices().add(cs); - cs.getBindings().add(new TestBinding(factory)); - - CompositeReference cr = factory.createCompositeReference(); - cr.setName("StockQuoteService"); - cr.getPromotedReferences().add(c2.getReferences().get(1)); - cr.setInterfaceContract(new TestInterfaceContract(factory)); - c.getReferences().add(cr); - cr.getBindings().add(new TestBinding(factory)); - - return c; - } - - /** - * Create a new component - */ - Component createComponent(String name) { - Component c = factory.createComponent(); - c.setName(name); - - ConstrainingType constraint = createConstrainingType(); - c.setConstrainingType(constraint); - - Implementation i = new TestImplementation(factory); - c.setImplementation(i); - - ComponentProperty p = factory.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 = factory.createComponentReference(); - ref1.setName("accountDataService"); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setReference(i.getReferences().get(0)); - c.getReferences().add(ref1); - ref1.getBindings().add(new TestBinding(factory)); - - ComponentReference ref2 = factory.createComponentReference(); - ref2.setName("stockQuoteService"); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setReference(i.getReferences().get(1)); - c.getReferences().add(ref2); - ref2.getBindings().add(new TestBinding(factory)); - - ComponentService s = factory.createComponentService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - s.setService(i.getServices().get(0)); - c.getServices().add(s); - s.getBindings().add(new TestBinding(factory)); - - return c; - } - - /** - * Create a new component type - * - * @return - */ - ComponentType createComponentType() { - ComponentType ctype = factory.createComponentType(); - - Property p = factory.createProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - ctype.getProperties().add(p); - - Reference ref1 = factory.createReference(); - ref1.setName("accountDataService"); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref1); - ref1.getBindings().add(new TestBinding(factory)); - - Reference ref2 = factory.createReference(); - ref2.setName("stockQuoteService"); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref2); - ref2.getBindings().add(new TestBinding(factory)); - - Service s = factory.createService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - ctype.getServices().add(s); - s.getBindings().add(new TestBinding(factory)); - - return ctype; - } - - /** - * Create a new constraining type - * - * @return - */ - ConstrainingType createConstrainingType() { - ConstrainingType ctype = factory.createConstrainingType(); - - AbstractProperty p = factory.createAbstractProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - ctype.getProperties().add(p); - - AbstractReference ref1 = factory.createAbstractReference(); - ref1.setName("accountDataService"); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref1); - - AbstractReference ref2 = factory.createAbstractReference(); - ref2.setName("stockQuoteService"); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref2); - - AbstractService s = factory.createAbstractService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - ctype.getServices().add(s); - - return ctype; - } - -} diff --git a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java deleted file mode 100644 index 40d5f4e63f..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.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.sca.assembly; - - -/** - * A test interface model. - * - * @version $Rev$ $Date$ - */ -public class TestBinding implements Binding { - public TestBinding(AssemblyFactory factory) { - } - - public String getName() { - return null; - } - - public String getURI() { - return "http://test"; - } - - public void setName(String name) { - } - - public void setURI(String uri) { - } - - public void setUnresolved(boolean unresolved) { - } - - public boolean isUnresolved() { - return false; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } -} diff --git a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java deleted file mode 100644 index 61ca3945ea..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java +++ /dev/null @@ -1,61 +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.sca.assembly; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl; - -/** - * A test component implementation model. - * - * @version $Rev$ $Date$ - */ -public class TestImplementation extends ComponentTypeImpl implements Implementation { - public TestImplementation(AssemblyFactory factory) { - - 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/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java deleted file mode 100644 index dbe0cb8225..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.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.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/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java deleted file mode 100644 index ee6b95edc9..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java +++ /dev/null @@ -1,41 +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.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/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java deleted file mode 100644 index d94a7e93a3..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java +++ /dev/null @@ -1,30 +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.sca.assembly; - -import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; - -/** - * A test operation model. - * - * @version $Rev$ $Date$ - */ -public class TestOperation extends OperationImpl { - -} diff --git a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java deleted file mode 100644 index 854d15f546..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.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.sca.assembly.builder.impl; - -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; - -public class CompositeBuilderTestCase extends TestCase { - - private AssemblyFactory assemblyFactory; - - @Override - protected void setUp() throws Exception { - assemblyFactory = new DefaultAssemblyFactory(); - } - - @Override - protected void tearDown() throws Exception { - assemblyFactory = null; - } - - public void testFuseIncludes() { - Composite c1 = assemblyFactory.createComposite(); - c1.setName(new QName("http://foo", "C1")); - Component a = assemblyFactory.createComponent(); - a.setName("a"); - c1.getComponents().add(a); - CompositeService s = assemblyFactory.createCompositeService(); - s.setName("s"); - c1.getServices().add(s); - CompositeReference r = assemblyFactory.createCompositeReference(); - r.setName("r"); - c1.getReferences().add(r); - - Composite c2 = assemblyFactory.createComposite(); - c2.setName(new QName("http://foo", "C2")); - c1.getIncludes().add(c2); - Component b = assemblyFactory.createComponent(); - b.setName("b"); - c2.getComponents().add(b); - - Composite c = assemblyFactory.createComposite(); - c.setName(new QName("http://foo", "C")); - c.getIncludes().add(c1); - - new CompositeIncludeBuilderImpl(null).fuseIncludes(c); - - assertTrue(c.getComponents().get(0).getName().equals("a")); - assertTrue(c.getComponents().get(1).getName().equals("b")); - assertTrue(c.getServices().get(0).getName().equals("s")); - assertTrue(c.getReferences().get(0).getName().equals("r")); - } - - public void testExpandComposites() { - Composite c1 = assemblyFactory.createComposite(); - c1.setName(new QName("http://foo", "C1")); - Component a = assemblyFactory.createComponent(); - a.setName("a"); - c1.getComponents().add(a); - CompositeService s = assemblyFactory.createCompositeService(); - s.setName("s"); - c1.getServices().add(s); - CompositeReference r = assemblyFactory.createCompositeReference(); - r.setName("r"); - c1.getReferences().add(r); - - Composite c2 = assemblyFactory.createComposite(); - c2.setName(new QName("http://foo", "C2")); - Component b = assemblyFactory.createComponent(); - b.setName("b"); - c2.getComponents().add(b); - - Composite c = assemblyFactory.createComposite(); - c.setName(new QName("http://foo", "C")); - Component x = assemblyFactory.createComponent(); - x.setName("x"); - x.setImplementation(c1); - c.getComponents().add(x); - Component y = assemblyFactory.createComponent(); - y.setName("y"); - y.setImplementation(c2); - c.getComponents().add(y); - Component z = assemblyFactory.createComponent(); - z.setName("z"); - z.setImplementation(c1); - c.getComponents().add(z); - - new CompositeCloneBuilderImpl(null).expandCompositeImplementations(c); - - assertTrue(c.getComponents().get(0).getImplementation() != c1); - assertTrue(c.getComponents().get(1).getImplementation() != c2); - assertTrue(c.getComponents().get(2).getImplementation() != c1); - - Composite i = (Composite)c.getComponents().get(0).getImplementation(); - assertTrue(i.getComponents().get(0) != a); - assertTrue(i.getComponents().get(0).getName().equals("a")); - assertTrue(i.getServices().get(0).getName().equals("s")); - assertTrue(i.getServices().get(0) != s); - assertTrue(i.getReferences().get(0).getName().equals("r")); - assertTrue(i.getReferences().get(0) != r); - } - -} diff --git a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java b/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java deleted file mode 100644 index c8694966fe..0000000000 --- a/branches/sca-java-1.1/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java +++ /dev/null @@ -1,229 +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.sca.assembly.builder.impl; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.AbstractProperty; -import org.apache.tuscany.sca.assembly.AbstractReference; -import org.apache.tuscany.sca.assembly.AbstractService; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.ConstrainingType; -import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.TestBinding; -import org.apache.tuscany.sca.assembly.TestImplementation; -import org.apache.tuscany.sca.assembly.TestInterfaceContract; -import org.apache.tuscany.sca.assembly.Wire; -import org.junit.Test; - -/** - * @version $Rev$ $Date$ - */ -public class PrintUtilTestCase { - - private AssemblyFactory factory = new DefaultAssemblyFactory(); - - /** - * Create a composite - */ - Composite createComposite() { - Composite c = factory.createComposite(); - - Component c1 = createComponent("AccountServiceComponent1"); - c.getComponents().add(c1); - Component c2 = createComponent("AccountServiceComponent2"); - c.getComponents().add(c2); - - Wire w = factory.createWire(); - w.setSource(c1.getReferences().get(0)); - w.setTarget(c2.getServices().get(0)); - c.getWires().add(w); - - CompositeService cs = factory.createCompositeService(); - cs.setName("AccountService"); - cs.setPromotedService(c1.getServices().get(0)); - cs.setInterfaceContract(new TestInterfaceContract(factory)); - c.getServices().add(cs); - cs.getBindings().add(new TestBinding(factory)); - - CompositeReference cr = factory.createCompositeReference(); - cr.setName("StockQuoteService"); - cr.getPromotedReferences().add(c2.getReferences().get(1)); - cr.setInterfaceContract(new TestInterfaceContract(factory)); - c.getReferences().add(cr); - cr.getBindings().add(new TestBinding(factory)); - - return c; - } - - /** - * Create a new component - */ - Component createComponent(String name) { - Component c = factory.createComponent(); - c.setName(name); - - ConstrainingType constraint = createConstrainingType(); - c.setConstrainingType(constraint); - - Implementation i = new TestImplementation(factory); - c.setImplementation(i); - - ComponentProperty p = factory.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 = factory.createComponentReference(); - ref1.setName("accountDataService"); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setReference(i.getReferences().get(0)); - c.getReferences().add(ref1); - ref1.getBindings().add(new TestBinding(factory)); - - ComponentReference ref2 = factory.createComponentReference(); - ref2.setName("stockQuoteService"); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setReference(i.getReferences().get(1)); - c.getReferences().add(ref2); - ref2.getBindings().add(new TestBinding(factory)); - - ComponentService s = factory.createComponentService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - s.setService(i.getServices().get(0)); - c.getServices().add(s); - s.getBindings().add(new TestBinding(factory)); - - return c; - } - - /** - * Create a new component type - * - * @return - */ - ComponentType createComponentType() { - ComponentType ctype = factory.createComponentType(); - - Property p = factory.createProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - ctype.getProperties().add(p); - - Reference ref1 = factory.createReference(); - ref1.setName("accountDataService"); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref1); - ref1.getBindings().add(new TestBinding(factory)); - - Reference ref2 = factory.createReference(); - ref2.setName("stockQuoteService"); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref2); - ref2.getBindings().add(new TestBinding(factory)); - - Service s = factory.createService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - ctype.getServices().add(s); - s.getBindings().add(new TestBinding(factory)); - - return ctype; - } - - /** - * Create a new constraining type - * - * @return - */ - ConstrainingType createConstrainingType() { - ConstrainingType ctype = factory.createConstrainingType(); - - AbstractProperty p = factory.createAbstractProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - ctype.getProperties().add(p); - - AbstractReference ref1 = factory.createAbstractReference(); - ref1.setName("accountDataService"); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref1); - - AbstractReference ref2 = factory.createAbstractReference(); - ref2.setName("stockQuoteService"); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref2); - - AbstractService s = factory.createAbstractService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - ctype.getServices().add(s); - - return ctype; - } - - @Test - public void testPrint1() { - Composite composite = createComposite(); - StringWriter sw = new StringWriter(); - PrintUtil p = new PrintUtil(new PrintWriter(sw), true); - p.print(composite); - // System.out.println(sw.toString()); - } - - @Test - public void testPrint2() { - Composite composite = createComposite(); - StringWriter sw = new StringWriter(); - PrintUtil p = new PrintUtil(new PrintWriter(sw), false); - p.print(composite); - // System.out.println(sw.toString()); - } -} |