From 875ac5d246878b199c393e9700c8a085c8939333 Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 19 Mar 2009 17:02:07 +0000 Subject: [maven-release-plugin] copy for branch tb3 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@756088 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/assembly/xml/BuildPolicyTestCase.java | 151 ++++++++++++++ .../xml/MultiplicityReadWriteTestCase.java | 86 ++++++++ .../tuscany/sca/assembly/xml/ReadAllTestCase.java | 151 ++++++++++++++ .../sca/assembly/xml/ReadDocumentTestCase.java | 224 +++++++++++++++++++++ .../tuscany/sca/assembly/xml/ReadTestCase.java | 91 +++++++++ .../xml/ReadWriteAnyAttributeTestCase.java | 132 ++++++++++++ .../assembly/xml/ReadWriteAnyElementTestCase.java | 147 ++++++++++++++ .../xml/ReadWriteLocalCompositeTestCase.java | 100 +++++++++ .../sca/assembly/xml/ResolvePolicyTestCase.java | 171 ++++++++++++++++ .../tuscany/sca/assembly/xml/ResolveTestCase.java | 103 ++++++++++ .../sca/assembly/xml/TestAttributeProcessor.java | 61 ++++++ .../sca/assembly/xml/TestPolicyProcessor.java | 82 ++++++++ .../assembly/xml/TestSCABindingFactoryImpl.java | 35 ++++ .../sca/assembly/xml/TestSCABindingImpl.java | 186 +++++++++++++++++ .../tuscany/sca/assembly/xml/WireTestCase.java | 148 ++++++++++++++ .../tuscany/sca/assembly/xml/WriteAllTestCase.java | 158 +++++++++++++++ .../sca/assembly/xml/WriteNamespacesTestCase.java | 95 +++++++++ .../tuscany/sca/assembly/xml/Calculator.composite | 59 ++++++ .../xml/CalculatorComponent.constrainingType | 34 ++++ .../sca/assembly/xml/CalculatorImpl.componentType | 31 +++ .../sca/assembly/xml/Multiplicity.composite | 32 +++ .../sca/assembly/xml/NestedCalculator.composite | 29 +++ .../sca/assembly/xml/RMIBindingTest.composite | 44 ++++ .../sca/assembly/xml/TestAllCalculator.composite | 127 ++++++++++++ .../sca/assembly/xml/TestAllDivide.composite | 56 ++++++ .../assembly/xml/TestAllPolicyCalculator.composite | 125 ++++++++++++ .../sca/assembly/xml/another_test_definitions.xml | 96 +++++++++ .../tuscany/sca/assembly/xml/local.composite | 27 +++ .../tuscany/sca/assembly/xml/test_definitions.xml | 206 +++++++++++++++++++ 29 files changed, 2987 insertions(+) create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite create mode 100644 sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml (limited to 'sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test') diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java new file mode 100644 index 0000000000..f624f77b81 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java @@ -0,0 +1,151 @@ +/* + * 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.xml; + +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.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +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.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; +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: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $ + */ +public class BuildPolicyTestCase { + private static URLArtifactProcessor documentProcessor; + private static URLArtifactProcessor 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); + SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); + modelFactories.addFactory(scaBindingFactory); + compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + List policyDefinitions = new ArrayList(); + resolver = new DefaultModelResolver(); + + MonitorFactory monitorFactory = new DefaultMonitorFactory(); + monitor = monitorFactory.createMonitor(); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + 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("CalculatorComponent.constrainingType"); + URI uri = URI.create("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = BuildPolicyTestCase.class.getResource("TestAllPolicyCalculator.composite"); + uri = URI.create("TestAllCalculator.constrainingType"); + composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + url = BuildPolicyTestCase.class.getResource("another_test_definitions.xml"); + uri = URI.create("another_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, null, monitor); + */ + } + + //@Test + @Ignore("The inheritance will be calculated differently in OASIS SCA") + public void testPolicyIntentInheritance() throws Exception { + String namespaceUri = "http://test"; + + PolicySubject policiedComposite = (PolicySubject)composite; + assertEquals(policiedComposite.getRequiredIntents().size(), 1); + assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), new QName(namespaceUri, "tuscanyIntent_1")); + + //1 defined for composite, 2 defined for the service, 1 defined and 3 inherited for the promoted service (4) + assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 7); + //1 from the operation defined in this service and 2 from the operation defined in the promoted service + assertEquals(composite.getServices().get(0).getRequiredIntents().get(3).getName(), new QName(namespaceUri, "tuscanyIntent_3")); + //bindings will have only 2 intents since duplications will be cut out + assertEquals(((PolicySubject)composite.getServices().get(0).getBindings().get(0)).getRequiredIntents().size(), 3); + + assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 5); + assertEquals(composite.getReferences().get(0).getRequiredIntents().get(1).getName(), new QName(namespaceUri, "tuscanyIntent_1")); + assertEquals(((PolicySubject)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 3); + + assertEquals(composite.getComponents().get(0).getRequiredIntents().size(), 3); + assertEquals(composite.getComponents().get(0).getRequiredIntents().get(2).getName(), new QName(namespaceUri, "tuscanyIntent_1")); + assertEquals(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().size(), 4); + assertEquals(composite.getComponents().get(0).getServices().get(0).getCallback().getRequiredIntents().size(), 4); + assertEquals(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().size(), 5); + } + + @Test + public void testDummy() throws Exception { + + } +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java new file mode 100644 index 0000000000..4e74c55949 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java @@ -0,0 +1,86 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.Before; +import org.junit.Test; + +/** + * Test writing SCA XML assemblies. + * + * TUSCANY-2662 + * + * @version $Rev$ $Date$ + */ +public class MultiplicityReadWriteTestCase { + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + @Before + public void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + } + + + @Test + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Multiplicity.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + + verifyComposite(composite); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + composite = staxProcessor.read(bis, Composite.class); + + verifyComposite(composite); + + } + + + private void verifyComposite(Composite composite) { + assertEquals(composite.getComponents().get(0).getReferences().get(0).getMultiplicity(), Multiplicity.ZERO_N); + assertEquals(composite.getReferences().get(0).getMultiplicity(), Multiplicity.ONE_N); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java new file mode 100644 index 0000000000..54d8f3d260 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java @@ -0,0 +1,151 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; + +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +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.Property; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadAllTestCase { + private static StAXArtifactProcessor staxProcessor; + private static XMLInputFactory inputFactory; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + inputFactory = XMLInputFactory.newInstance(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + } + + @Test + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + assertNotNull(composite); + assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator")); + assertEquals(composite.getConstrainingType().getName(), new QName("http://calc", "CalculatorComponent")); + assertTrue(composite.isLocal()); + assertFalse(composite.getAutowire() == Boolean.TRUE); + assertEquals(((PolicySubject)composite).getRequiredIntents().get(0).getName(), new QName("http://test", + "confidentiality")); + assertEquals(((PolicySubject)composite).getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + + Composite include = composite.getIncludes().get(0); + assertEquals(include.getName(), new QName("http://calc", "TestAllDivide")); + + CompositeService calcCompositeService = (CompositeService)composite.getServices().get(0); + assertEquals(calcCompositeService.getName(), "CalculatorService"); + assertTrue(calcCompositeService.getPromotedService().isUnresolved()); + assertEquals(calcCompositeService.getPromotedService().getName(), + "CalculatorService"); + assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + Callback calcServiceCallback = calcCompositeService.getCallback(); + assertNotNull(calcServiceCallback); + assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + + Component calcComponent = composite.getComponents().get(0); + assertEquals(calcComponent.getName(), "CalculatorServiceComponent"); + assertEquals(calcComponent.getAutowire(), Boolean.FALSE); + assertEquals(calcComponent.getConstrainingType().getName(), new QName("http://calc", + "CalculatorComponent")); + assertEquals(calcComponent.getRequiredIntents().get(0).getName(), new QName("http://test", + "confidentiality")); + assertEquals(calcComponent.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + + ComponentService calcComponentService = calcComponent.getServices().get(0); + assertEquals(calcComponentService.getName(), "CalculatorService"); + assertEquals(calcComponentService.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + + ComponentReference calcComponentReference = calcComponent.getReferences().get(0); + assertEquals(calcComponentReference.getName(), "addService"); + assertEquals(calcComponentReference.getAutowire(), Boolean.FALSE); + assertEquals(calcComponentReference.isWiredByImpl(), false); + assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + + Property property = calcComponent.getProperties().get(0); + assertEquals(property.getName(), "round"); + Document doc = (Document) property.getValue(); + Element element = doc.getDocumentElement(); + String value = element.getTextContent(); + assertEquals(value, "true"); + assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean")); + assertEquals(property.isMany(), false); + + CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0); + assertEquals(calcCompositeReference.getName(), "MultiplyService"); + assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved()); + assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(), + "CalculatorServiceComponent/multiplyService"); + assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + // TODO test operations + Callback calcCallback = calcCompositeReference.getCallback(); + assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(), + new QName("http://test", "confidentiality")); + assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy")); + assertNotNull(calcCallback); + // TODO test operations + + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java new file mode 100644 index 0000000000..e1d1794f3c --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java @@ -0,0 +1,224 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.net.URI; +import java.net.URL; + +import javax.xml.XMLConstants; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.ValidatorHandler; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +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.processor.ValidationSchemaExtensionPoint; +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.DefaultFactoryExtensionPoint; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev$ $Date$ + */ +public class ReadDocumentTestCase { + private static final String TUSCANY_11_XSD = "tuscany-sca-1.1.xsd"; + + private static URLArtifactProcessor documentProcessor; + private static ModelResolver resolver; + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor staxProcessor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + inputFactory = XMLInputFactory.newInstance(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + + resolver = new DefaultModelResolver(); + } + + @Test + public void testValidateAssembly() throws Exception { + + SchemaFactory schemaFactory; + try { + schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } catch (Error e) { + // Some old JDKs don't support XMLSchema validation + return; + } catch (Exception e) { + // Some old JDKs don't support XMLSchema validation + return; + } + Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD)); + ValidatorHandler handler = schema.newValidatorHandler(); + + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + URL url = getClass().getResource("Calculator.composite"); + XMLReader reader = parserFactory.newSAXParser().getXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setContentHandler(handler); + reader.parse(new InputSource(url.openStream())); + + } + + @Test + public void testValidateImplementation() throws Exception { + + SchemaFactory schemaFactory; + try { + schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } catch (Error e) { + // Some old JDKs don't support XMLSchema validation + return; + } catch (Exception e) { + // Some old JDKs don't support XMLSchema validation + return; + } + Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD)); + ValidatorHandler handler = schema.newValidatorHandler(); + + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + URL url = getClass().getResource("Calculator.composite"); + XMLReader reader = parserFactory.newSAXParser().getXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setContentHandler(handler); + reader.parse(new InputSource(url.openStream())); + } + + @Test + public void testReadImplementation() throws Exception { + + ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); + schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString()); + XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null); + DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()); + factories.addFactory(validatingInputFactory); + + CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories , staxProcessor, null); + + URL url = getClass().getResource("Calculator.composite"); + URI uri = URI.create("Calculator.composite"); + Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url); + assertNotNull(composite); + } + + @Test + public void testValidateBinding() throws Exception { + + SchemaFactory schemaFactory; + try { + schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } catch (Error e) { + // Some old JDKs don't support XMLSchema validation + return; + } catch (Exception e) { + // Some old JDKs don't support XMLSchema validation + return; + } + Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD)); + ValidatorHandler handler = schema.newValidatorHandler(); + + SAXParserFactory parserFactory = SAXParserFactory.newInstance(); + URL url = getClass().getResource("RMIBindingTest.composite"); + XMLReader reader = parserFactory.newSAXParser().getXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespaces", true); + reader.setContentHandler(handler); + reader.parse(new InputSource(url.openStream())); + } + + @Test + public void testReadBinding() throws Exception { + + ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); + schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString()); + XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null); + DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()); + factories.addFactory(validatingInputFactory); + CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories , staxProcessor, null); + + URL url = getClass().getResource("RMIBindingTest.composite"); + URI uri = URI.create("RMIBindingTest.composite"); + Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url); + assertNotNull(composite); + } + + @Test + public void testResolveConstrainingType() throws Exception { + + URL url = getClass().getResource("CalculatorComponent.constrainingType"); + URI uri = URI.create("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.constrainingType"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + @Test + public void testResolveComposite() throws Exception { + URL url = getClass().getResource("Calculator.composite"); + URI uri = URI.create("Calculator.composite"); + Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.composite"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java new file mode 100644 index 0000000000..beeb6feaea --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java @@ -0,0 +1,91 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase { + + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor staxProcessor; + + @BeforeClass + public static void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + + @Test + public void testReadComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + } + + @Test + public void testReadConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + + } + + @Test + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + + } + + @Test + public void testReadCompositeAndWireIt() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(staxProcessor.read(reader)); + is.close(); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java new file mode 100644 index 0000000000..a4f0da5ae9 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -0,0 +1,132 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.Test; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAnyAttributeTestCase { + + private static final QName EXTENDED_ATTRIBUTE = new QName("http://test", "customAttribute"); + + private static final String XML = ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + + /** + * Initialize the test environment + * This takes care to register attribute processors when provided + * + * @param attributeProcessor + * @throws Exception + */ + private void init(StAXAttributeProcessor attributeProcessor) throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + if(attributeProcessor != null) { + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(attributeProcessor); + } + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + /** + * Read and Write a composite that has a extended attribute + * and a particular attribute processor + * @throws Exception + */ + @Test + public void testReadWriteCompositeWithAttributeProcessor() throws Exception { + init(new TestAttributeProcessor()); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + } + + /** + * Read and Write a composite that has a extended attribute + * but no particular processor for it + * @throws Exception + */ + @Test + public void testDefaultReadWriteComposite() throws Exception { + init(null); + + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML); + // System.out.println(bos.toString()); + + assertEquals(XML, bos.toString()); + } +} \ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java new file mode 100644 index 0000000000..256c706035 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java @@ -0,0 +1,147 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class ReadWriteAnyElementTestCase { + private static final String XML_RECURSIVE_EXTENDED_ELEMENT = + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String XML_UNKNOWN_IMPL = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReadWriteExtendedRecursiveElement() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); + // System.out.println(bos.toString()); + + assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); + bos.close(); + } + + @Test + public void testReadWriteUnknwonImpl() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } + + // @Test + @Ignore() + public void testReadWriteInvalidAttribute() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } +} \ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java new file mode 100644 index 0000000000..6c8aa9acc9 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java @@ -0,0 +1,100 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev: 711584 $ $Date: 2008-11-05 15:07:03 +0000 (Wed, 05 Nov 2008) $ + */ +public class ReadWriteLocalCompositeTestCase { + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + private static final String LOCAL_COMPOSITE_XML = ""+ + ""+ + ""; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("local.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + assertTrue(composite.isLocal()); + is.close(); + } + + @Test + public void testWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("local.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + assertTrue(composite.isLocal()); + is.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + System.out.println(bos.toString()); + + assertEquals(LOCAL_COMPOSITE_XML, bos.toString()); + } +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java new file mode 100644 index 0000000000..c4519ef338 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java @@ -0,0 +1,171 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +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.definitions.Definitions; +import org.apache.tuscany.sca.policy.PolicySubject; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $ + */ +public class ResolvePolicyTestCase { + + private static URLArtifactProcessor documentProcessor; + private static ModelResolver resolver; + private static URLArtifactProcessor policyDefinitionsProcessor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + resolver = new DefaultModelResolver(); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); + + // Create StAX processors + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); + } + + @Test + public void testResolveConstrainingType() throws Exception { + + URL url = getClass().getResource("CalculatorComponent.constrainingType"); + URI uri = URI.create("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.constrainingType"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(composite); + + url = getClass().getResource("test_definitions.xml"); + uri = URI.create("test_definitions.xml"); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + preResolvePolicyTests(composite); + documentProcessor.resolve(scaDefns, resolver); + documentProcessor.resolve(composite, resolver); + + // Comment out the post resolving test + // postResolvePolicyTests(composite); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + private void preResolvePolicyTests(Composite composite) { + assertNull(((PolicySubject)composite).getRequiredIntents().get(0).getDescription()); + assertTrue(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().isEmpty()); + + assertNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + + assertNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + + assertNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertTrue(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + } + + private void postResolvePolicyTests(Composite composite) { + assertNotNull(((PolicySubject)composite).getRequiredIntents().get(0).getDescription()); + assertFalse(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(((PolicySubject)composite).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + assertNotNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + assertNotNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + assertNotNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + assertNotNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription()); + assertFalse(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty()); + assertNotNull(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription()); + + + } + + @Test + public void testResolveComposite() throws Exception { + URL url = getClass().getResource("Calculator.composite"); + URI uri = URI.create("Calculator.composite"); + Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + url = getClass().getResource("TestAllCalculator.composite"); + uri = URI.create("TestAllCalculator.composite"); + Composite composite = (Composite)documentProcessor.read(null, uri, url); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java new file mode 100644 index 0000000000..cc8a88f3d5 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java @@ -0,0 +1,103 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +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.junit.BeforeClass; +import org.junit.Test; + + +/** + * Test resolving SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ResolveTestCase { + + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessorExtensionPoint staxProcessors; + private static ModelResolver resolver; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + resolver = new DefaultModelResolver(); + } + + @Test + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + StAXArtifactProcessor constrainingTypeReader = staxProcessors.getProcessor(ConstrainingType.class); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = constrainingTypeReader.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + StAXArtifactProcessor compositeReader = staxProcessors.getProcessor(Composite.class); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + assertNotNull(composite); + + compositeReader.resolve(composite, resolver); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + @Test + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + StAXArtifactProcessor compositeReader = staxProcessors.getProcessor(Composite.class); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = compositeReader.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + + compositeReader.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java new file mode 100644 index 0000000000..1a100c25b1 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.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.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Policy Processor used for testing. + * + * @version $Rev$ $Date$ + */ +public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor { + private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); + + public QName getArtifactType() { + return ATTRIBUTE; + } + + public String read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + return reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart()); + } + + public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI()); + writer.writeAttribute(ATTRIBUTE.getLocalPart(), value); + } + + public Class getModelType() { + return String.class; + } + + public void resolve(String arg0, ModelResolver arg1) throws ContributionResolveException { + + } +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java new file mode 100644 index 0000000000..e1a149494d --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java @@ -0,0 +1,82 @@ +/* + * 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.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.policy.PolicyExpression; + +/** + * A PolicyExpression Processor used for testing. + * + * @version $Rev$ $Date$ + */ +public class TestPolicyProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); + } + + public PolicyExpression read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + return new MockPolicyImplOne(); + } + + public void write(PolicyExpression arg0, XMLStreamWriter arg1) throws ContributionWriteException, + XMLStreamException { + } + + public Class getModelType() { + return PolicyExpression.class; + } + + public void resolve(PolicyExpression arg0, ModelResolver arg1) throws ContributionResolveException { + } + + public class MockPolicyImplOne implements PolicyExpression { + public T getPolicy() { + return null; + } + + public void setName(QName name) { + } + + public void setPolicy(T policy) { + } + + public QName getName() { + return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + } +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java new file mode 100644 index 0000000000..c423df6f7d --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; + +/** + * A factory for the SCA binding model. + * + * @version $Rev$ $Date$ + */ +public class TestSCABindingFactoryImpl implements SCABindingFactory { + public SCABinding createSCABinding() { + return new TestSCABindingImpl(); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java new file mode 100644 index 0000000000..d41881dc37 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java @@ -0,0 +1,186 @@ +/* + * 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.xml; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * A test cheel for the SCA binding. + * + * @version $Rev$ $Date$ + */ +public class TestSCABindingImpl implements SCABinding, OptimizableBinding, PolicySubject { + private String name; + private String uri; + private List extensions = new ArrayList(); + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private ExtensionType bindingType = new TestSCABindingType(); + + /** + * Constructs a new SCA binding. + */ + protected TestSCABindingImpl() { + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List getExtensions() { + return extensions; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** + * @return the targetComponent + */ + public Component getTargetComponent() { + return targetComponent; + } + + /** + * @param targetComponent the targetComponent to set + */ + public void setTargetComponent(Component targetComponent) { + this.targetComponent = targetComponent; + } + + /** + * @return the targetComponentService + */ + public ComponentService getTargetComponentService() { + return targetComponentService; + } + + /** + * @param targetComponentService the targetComponentService to set + */ + public void setTargetComponentService(ComponentService targetComponentService) { + this.targetComponentService = targetComponentService; + } + + /** + * @return the targetBinding + */ + public Binding getTargetBinding() { + return targetBinding; + } + + /** + * @param targetBinding the targetBinding to set + */ + public void setTargetBinding(Binding targetBinding) { + this.targetBinding = targetBinding; + } + + public List getPolicySets() { + // TODO Auto-generated method stub + return policySets; + } + + public List getRequiredIntents() { + // TODO Auto-generated method stub + return requiredIntents; + } + + public ExtensionType getType() { + // TODO Auto-generated method stub + return bindingType; + } + + public void setType(ExtensionType type) { + this.bindingType = type; + } + + private class TestSCABindingType implements ExtensionType { + private QName name = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903","binding"); + public QName getBaseType() { + return BINDING_BASE; + } + + public QName getType() { + return name; + } + + public void setType(QName type) { + } + + public List getAlwaysProvidedIntents() { + return Collections.emptyList(); + } + + public List getMayProvidedIntents() { + return Collections.emptyList(); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java new file mode 100644 index 0000000000..5235df5037 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java @@ -0,0 +1,148 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +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.interfacedef.InterfaceContractMapper; +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 wiring of SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WireTestCase { + + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor staxProcessor; + private static ModelResolver resolver; + private static URLArtifactProcessor policyDefinitionsProcessor; + private static CompositeBuilder compositeBuilder; + private static Monitor monitor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + resolver = new DefaultModelResolver(); + + MonitorFactory monitorFactory = new DefaultMonitorFactory(); + monitor = monitorFactory.createMonitor(); + + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); + modelFactories.addFactory(scaBindingFactory); + compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); + } + + @Test + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + is.close(); + assertNotNull(composite); + + URL url = getClass().getResource("test_definitions.xml"); + URI uri = URI.create("test_definitions.xml"); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + policyDefinitionsProcessor.resolve(scaDefns, resolver); + + staxProcessor.resolve(composite, resolver); + compositeBuilder.build(composite, null, monitor); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + @Test + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = (Composite)staxProcessor.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + is.close(); + + URL url = getClass().getResource("test_definitions.xml"); + URI uri = URI.create("test_definitions.xml"); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + policyDefinitionsProcessor.resolve(scaDefns, resolver); + + staxProcessor.resolve(composite, resolver); + compositeBuilder.build(composite, null, monitor); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java new file mode 100644 index 0000000000..cf86aec6f4 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java @@ -0,0 +1,158 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +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.interfacedef.InterfaceContractMapper; +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 writing SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WriteAllTestCase { + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + private static ExtensibleStAXArtifactProcessor staxProcessor; + private static ModelResolver resolver; + private static CompositeBuilder compositeBuilder; + private static URLArtifactProcessor policyDefinitionsProcessor; + private static Monitor monitor; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + resolver = new DefaultModelResolver(); + + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); + modelFactories.addFactory(scaBindingFactory); + compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); + + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + MonitorFactory monitorFactory = new DefaultMonitorFactory(); + monitor = monitorFactory.createMonitor(); + + URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); + } + + @Test + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + + verifyComposite(composite); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + composite = staxProcessor.read(bis, Composite.class); + + verifyComposite(composite); + + } + + @Test + public void testReadWireWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + + URL url = getClass().getResource("test_definitions.xml"); + URI uri = URI.create("test_definitions.xml"); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + assertNotNull(scaDefns); + policyDefinitionsProcessor.resolve(scaDefns, resolver); + + staxProcessor.resolve(composite, resolver); + compositeBuilder.build(composite, null, monitor); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + } + + @Test + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = staxProcessor.read(is, ComponentType.class); + staxProcessor.resolve(componentType, resolver); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, bos); + } + + @Test + public void testReadWriteConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = staxProcessor.read(is, ConstrainingType.class); + staxProcessor.resolve(constrainingType, resolver); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(constrainingType, bos); + } + + private void verifyComposite(Composite composite) { + assertEquals(composite.getProperties().get(0).getName(),"prop1"); + assertEquals(composite.getProperties().get(0).isMany(), true); + assertEquals(composite.getProperties().get(1).getName(),"prop2"); + assertEquals(composite.getProperties().get(1).isMustSupply(), true); + assertEquals(composite.getProperties().get(0).getXSDType(), new QName("http://foo", "MyComplexType")); + assertEquals(composite.getProperties().get(1).getXSDElement(), new QName("http://foo", "MyComplexPropertyValue1")); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java new file mode 100644 index 0000000000..dedd0d0660 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java @@ -0,0 +1,95 @@ +/* + * 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.xml; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test writing SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WriteNamespacesTestCase { + private static StAXArtifactProcessor compositeProcessor; + private static XMLOutputFactory outputFactory; + private static XMLInputFactory inputFactory; + + @BeforeClass + public static void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + outputFactory = modelFactories.getFactory(XMLOutputFactory.class); + //outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + inputFactory = modelFactories.getFactory(XMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + compositeProcessor = artifactProcessors.getProcessor(Composite.class); + } + + @Test + public void testReadWriteComposite() throws Exception { + + // Read + InputStream is = getClass().getResourceAsStream("NestedCalculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeProcessor.read(reader); + Component component = composite.getComponents().get(0); + Composite implementation = (Composite)component.getImplementation(); + QName qname = implementation.getName(); + + // Write + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); + compositeProcessor.write(composite, writer); + System.out.println(bos); + + // Read again + is = new ByteArrayInputStream(bos.toByteArray()); + reader = inputFactory.createXMLStreamReader(is); + composite = compositeProcessor.read(reader); + + // Compare + component = composite.getComponents().get(0); + implementation = (Composite)component.getImplementation(); + + assertEquals(qname, implementation.getName()); + } + +} diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite new file mode 100644 index 0000000000..961a40b841 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType new file mode 100644 index 0000000000..9a43d44377 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..2f4518a42c --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite new file mode 100644 index 0000000000..d713a381f9 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Multiplicity.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite new file mode 100644 index 0000000000..bf3676c585 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite new file mode 100644 index 0000000000..9f40faa806 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite new file mode 100644 index 0000000000..65e709f9b1 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AValue + InterestingURI + + + BValue + BoringURI + + + + + 123 + + + 123 + 123 + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite new file mode 100644 index 0000000000..998a49226b --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite new file mode 100644 index 0000000000..661270d341 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AValue + InterestingURI + + + BValue + BoringURI + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml new file mode 100644 index 0000000000..bb1f3118ce --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml @@ -0,0 +1,96 @@ + + + + + + + + Sample Intent + + + + + + + Sample Intent + + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + + + + Sample Intent + + + \ No newline at end of file diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite new file mode 100644 index 0000000000..6aa2ab4979 --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/local.composite @@ -0,0 +1,27 @@ + + + + + diff --git a/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml new file mode 100644 index 0000000000..c59fb3537b --- /dev/null +++ b/sandbox/ant/sca/branches/tb3/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + Test Intent + + + + + + Protect messages from unauthorized reading or modification + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ... + + + + + ... + + + + + + + + + + + sp:X509v3 + + + + + + + + + + + + + + + + + + Protect messages from unauthorized reading or modification + + + + + + Protect messages from unauthorized reading or modification + + + + + + + Communitcation thro this binding must prevent + unauthorized users from reading the messages. + + + + + + + + Communitcation thro this binding must prevent + unauthorized modification of the messages. + + + + + + Communitcation thro this binding required + Authentication. + + + + + + All messages to and from this implementation must be logged + + + + + + Need to figure out some description for this + + + + \ No newline at end of file -- cgit v1.2.3