diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-28 22:14:46 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-28 22:14:46 +0000 |
commit | e68b19a201820b1b67ac197d384c25ba8cbf5400 (patch) | |
tree | e799cad8d28eaf833626bd5dccd6a1da2a52d617 /java/sca/modules/builder | |
parent | 772451f5ff7650b5e7bc0f64922bac8b7af6e802 (diff) |
Refactor the builder implementations into tuscany-builder module
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819750 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/builder')
-rw-r--r-- | java/sca/modules/builder/pom.xml | 8 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java | 129 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java | 138 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Calculator.composite (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite) | 0 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite1.composite (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite) | 0 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite2.composite (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite) | 0 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite3.composite (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite) | 0 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite4.composite (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite) | 0 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/definitions.xml (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml) | 0 | ||||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.odg (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg) | bin | 15518 -> 15518 bytes | |||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.png (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png) | bin | 4041817 -> 4041817 bytes | |||
-rw-r--r-- | java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/test_definitions.xml (renamed from java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml) | 0 |
12 files changed, 267 insertions, 8 deletions
diff --git a/java/sca/modules/builder/pom.xml b/java/sca/modules/builder/pom.xml index 520e89f35d..33db479180 100644 --- a/java/sca/modules/builder/pom.xml +++ b/java/sca/modules/builder/pom.xml @@ -52,14 +52,6 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-implementation-java</artifactId> - <version>2.0-SNAPSHOT</version> - <scope>test</scope> - </dependency> - - - <dependency> - <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-contribution</artifactId> <version>2.0-SNAPSHOT</version> </dependency> diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java new file mode 100644 index 0000000000..e8d065cdcd --- /dev/null +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java @@ -0,0 +1,129 @@ +/* + * 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.builder.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev$ $Date$ + */ +public class BuildPolicyTestCase { + private static URLArtifactProcessor<Object> documentProcessor; + private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; + private static ModelResolver resolver; + private static CompositeBuilder compositeBuilder; + private static Composite composite; + private static Monitor monitor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + + compositeBuilder = + extensionPoints.getExtensionPoint(BuilderExtensionPoint.class) + .getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + List<Definitions> policyDefinitions = new ArrayList<Definitions>(); + resolver = new DefaultModelResolver(); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); + monitor = monitorFactory.createMonitor(); + + URLArtifactProcessorExtensionPoint documentProcessors = + new DefaultURLArtifactProcessorExtensionPoint(extensionPoints); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = + extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); + + URL url = BuildPolicyTestCase.class.getResource("Calculator.composite"); + URI uri = URI.create("TestAllCalculator.composite"); + composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + url = BuildPolicyTestCase.class.getResource("test_definitions.xml"); + uri = URI.create("test_definitions.xml"); + Definitions definitions = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(definitions); + policyDefinitions.add(definitions); + + documentProcessor.resolve(definitions, resolver); + documentProcessor.resolve(composite, resolver); + + compositeBuilder.build(composite, definitions, monitor); + } + + @Test + @Ignore("There are so many errors with this composite the builder doesn't have enough to go on") + public void testPolicyIntentInheritance() throws Exception { + String namespaceUri = "http://test"; + + PolicySubject policiedComposite = composite; + assertEquals(policiedComposite.getRequiredIntents().size(), 1); + assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), + new QName(namespaceUri, "tuscanyIntent_1")); + + Component component = composite.getComponents().get(0); + Endpoint ep = component.getServices().get(0).getEndpoints().get(0); + EndpointReference epr = component.getReferences().get(0).getEndpointReferences().get(0); + + System.out.println(ep.getRequiredIntents()); + System.out.println(epr.getRequiredIntents()); + } + +} diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java new file mode 100644 index 0000000000..f309331fff --- /dev/null +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java @@ -0,0 +1,138 @@ +/* + * 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.builder.impl; + +import static org.junit.Assert.assertTrue; + +import javax.xml.namespace.QName; + +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; +import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test the CompositeBuilder. + * + * @version $Rev$ $Date$ + */ +public class CompositeBuilderTestCase { + + private static AssemblyFactory assemblyFactory; + private static Monitor monitor; + + @BeforeClass + public static void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + MonitorFactory mf = new DefaultMonitorFactory(); + monitor = mf.createMonitor(); + } + + @Test + public void testFuseIncludes() throws Exception { + 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().build(c, null, monitor); + + 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")); + } + + @Test + public void testExpandComposites() throws Exception { + 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().build(c, null, monitor); + + 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/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Calculator.composite index d6082a936d..d6082a936d 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Calculator.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite1.composite index 105a478842..105a478842 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite1.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite2.composite index d3d5bafdfc..d3d5bafdfc 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite2.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite3.composite index 12aa35b694..12aa35b694 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite3.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite4.composite index 141ff2a4ea..141ff2a4ea 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite4.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/definitions.xml index fe76d0038a..fe76d0038a 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/definitions.xml diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.odg Binary files differindex a010bb1bf1..a010bb1bf1 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.odg diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.png Binary files differindex e1f78f6423..e1f78f6423 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.png diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/test_definitions.xml index dac8e384e3..dac8e384e3 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/test_definitions.xml |