summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca')
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessorTestCase.java108
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java88
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java151
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java192
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java85
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java157
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java205
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java157
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java109
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java143
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java82
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StripURISpacesTestCase.java78
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java62
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java83
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java35
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java186
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java109
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java137
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java100
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/MockPolicy.java39
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java230
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java58
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java161
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java307
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java83
25 files changed, 3145 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessorTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessorTestCase.java
new file mode 100644
index 0000000000..3f4a74ba03
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessorTestCase.java
@@ -0,0 +1,108 @@
+/*
+ * 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.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.ProcessorContext;
+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.monitor.Monitor;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CompositeProcessorTestCase {
+ private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+
+ private static final String OASIS_COMPOSITE =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
+ + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" "
+ + "xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\" "
+ + "targetNamespace=\"http://store\" "
+ + "name=\"store\">"
+ + "<component name=\"Catalog\">"
+ + " <implementation.java class=\"services.FruitsCatalogImpl\"/>"
+ + "</component>"
+ + "</composite>";
+
+ private static final String OSOA_COMPOSITE =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" "
+ + "xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\" "
+ + "targetNamespace=\"http://store\" "
+ + "name=\"store\">"
+ + "<component name=\"Catalog\">"
+ + " <implementation.java class=\"services.FruitsCatalogImpl\"/>"
+ + "</component>"
+ + "</composite>";
+
+ private static XMLInputFactory inputFactory;
+ private static XMLOutputFactory outputFactory;
+ private static StAXArtifactProcessor<Object> staxProcessor;
+ private static Monitor monitor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ monitor = context.getMonitor();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory);
+ }
+
+ @Test
+ public void testReadOASISSpecVersion() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OASIS_COMPOSITE));
+ Object result = staxProcessor.read(reader, context);
+ assertNotNull(result);
+ if( result instanceof Composite) {
+ Composite composite = (Composite) result;
+ assertEquals(SCA11_NS, composite.getSpecVersion());
+ }
+ reader.close();
+ }
+
+ @Test
+ public void testReadOSOASpecVersion() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OSOA_COMPOSITE));
+ Object result = staxProcessor.read(reader, context);
+ assertNotNull(result);
+ if( result instanceof Composite) {
+ throw new Exception("Error, unsupported OSOA namespace being parsed as valid !");
+ }
+ reader.close();
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java
new file mode 100644
index 0000000000..0d5e69bd61
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java
@@ -0,0 +1,88 @@
+/*
+ * 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.ProcessorContext;
+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;
+ private ProcessorContext context;
+
+ @Before
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory);
+ }
+
+
+ @Test
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Multiplicity.composite");
+ Composite composite = staxProcessor.read(is, Composite.class, context);
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+ bos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+
+ 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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java
new file mode 100644
index 0000000000..155c0c5a47
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/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.ProcessorContext;
+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<Object> staxProcessor;
+ private static XMLInputFactory inputFactory;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+ }
+
+ @Test
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context);
+ assertNotNull(composite);
+ assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator"));
+ 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.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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
new file mode 100644
index 0000000000..473e483d31
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
@@ -0,0 +1,192 @@
+/*
+ * 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.HashMap;
+
+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.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.ProcessorContext;
+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.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+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<Object> documentProcessor;
+ private static ModelResolver resolver;
+ private static XMLInputFactory inputFactory;
+ private static StAXArtifactProcessor<Object> staxProcessor;
+ private static ValidatorHandler handler;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+
+ resolver = new DefaultModelResolver();
+ handler = getValidationHandler();
+
+ }
+
+ @Test
+ public void testValidateAssembly() throws Exception {
+ 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()));
+
+ }
+
+ private static ValidatorHandler getValidationHandler() throws SAXException {
+ SchemaFactory schemaFactory;
+ try {
+ schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ schemaFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ } catch (Error e) {
+ // Some old JDKs don't support XMLSchema validation
+ return null;
+ } catch (Exception e) {
+ // Some old JDKs don't support XMLSchema validation
+ return null;
+ }
+ Schema schema = schemaFactory.newSchema(ReadDocumentTestCase.class.getClassLoader().getResource(TUSCANY_11_XSD));
+ ValidatorHandler handler = schema.newValidatorHandler();
+ return handler;
+ }
+
+ @Test
+ public void testValidateImplementation() throws Exception {
+ 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 {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(registry, new HashMap<String, String>());
+ schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString());
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas);
+ DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(registry);
+ factories.addFactory(validatingInputFactory);
+
+ CompositeDocumentProcessor compositeDocumentProcessor =
+ new CompositeDocumentProcessor(factories, staxProcessor);
+
+ URL url = getClass().getResource("Calculator.composite");
+ URI uri = URI.create("Calculator.composite");
+ Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url, context);
+ assertNotNull(composite);
+ }
+
+ @Test
+ public void testValidateBinding() throws Exception {
+ 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 {
+
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(registry, new HashMap<String, String>());
+ schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString());
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas);
+ DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(registry);
+ factories.addFactory(validatingInputFactory);
+ CompositeDocumentProcessor compositeDocumentProcessor =
+ new CompositeDocumentProcessor(factories, staxProcessor);
+
+ URL url = getClass().getResource("RMIBindingTest.composite");
+ URI uri = URI.create("RMIBindingTest.composite");
+ Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url, context);
+ assertNotNull(composite);
+ }
+
+ @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, context);
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite, context);
+
+ url = getClass().getResource("TestAllCalculator.composite");
+ uri = URI.create("TestAllCalculator.composite");
+ Composite composite = (Composite)documentProcessor.read(null, uri, url, context);
+
+ documentProcessor.resolve(composite, resolver, context);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java
new file mode 100644
index 0000000000..05d320b211
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java
@@ -0,0 +1,85 @@
+/*
+ * 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.ProcessorContext;
+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<Object> staxProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+ }
+
+
+ @Test
+ public void testReadComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader, context));
+ is.close();
+ }
+
+ @Test
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader, context));
+ is.close();
+
+ }
+
+ @Test
+ public void testReadCompositeAndWireIt() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader, context));
+ is.close();
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java
new file mode 100644
index 0000000000..cbe3cfa09c
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java
@@ -0,0 +1,157 @@
+/*
+ * 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.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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 String XML = "<?xml version='1.0' encoding='UTF-8'?>"+
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" " +
+ "targetNamespace=\"http://calc\" " +
+ "name=\"Calculator\">"+
+ "<component name=\"AddServiceComponent\" xmlns:test=\"http://test\" test:customAttribute=\"customValue\">"+
+ "<implementation.java class=\"calculator.AddServiceImpl\" />"+
+ "</component>"+
+ "</composite>";
+
+ private XMLInputFactory inputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+ private ProcessorContext context;
+
+ /**
+ * 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();
+ context = new ProcessorContext(extensionPoints);
+ 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());
+ }
+
+ /**
+ * 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, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML);
+ // System.out.println(bos.toString());
+
+ //assertEquals(XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyComposite(composite);
+ }
+
+ /**
+ * 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, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML);
+ // System.out.println(bos.toString());
+
+ // assertEquals(XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyComposite(composite);
+ }
+
+ private void verifyComposite(Composite c) {
+ assertEquals("Calculator", c.getName().getLocalPart());
+ assertEquals(1, c.getComponents().size());
+ Component component = c.getComponents().get(0);
+ assertEquals("AddServiceComponent", component.getName());
+ assertEquals(1, component.getAttributeExtensions().size());
+ Extension extension = component.getAttributeExtensions().get(0);
+ assertEquals("customAttribute", extension.getQName().getLocalPart());
+ assertEquals("http://test", extension.getQName().getNamespaceURI());
+ assertEquals("customValue", extension.getValue());
+ }
+} \ No newline at end of file
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
new file mode 100644
index 0000000000..ddbd70e567
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java
@@ -0,0 +1,205 @@
+/*
+ * 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.StringReader;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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 =
+ "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" targetNamespace=\"http://temp\" name=\"RecursiveExtendedElement\">" +
+ "<unknownElement>" +
+ "<subUnknownElement1 attribute=\"anyAttribute\" />" +
+ "<subUnknownElement2 />" +
+ "</unknownElement>" +
+ "</composite>";
+
+ private static final String XML_UNKNOWN_IMPL =
+ "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" targetNamespace=\"http://temp\" name=\"aaaa\" autowire=\"false\">" +
+ "<component name=\"unknownImpl\">" +
+ "<implementation.unknown class=\"raymond\" />" +
+ "<service name=\"service\">" +
+ "<binding.ws />" +
+ "</service>" +
+ "</component>" +
+ "</composite>";
+
+ private static final String XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE =
+ "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" targetNamespace=\"http://temp\" name=\"aaaa\" autowire=\"false\">" +
+ "<component name=\"unknownImpl\">" +
+ "<implementation.unknown class=\"raymond\" />" +
+ "<service name=\"service\" requires=\"\">" +
+ "<binding.ws />" +
+ "</service>" +
+ "</component>" +
+ "</composite>";
+
+
+ private ValidatingXMLInputFactory inputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+ private ProcessorContext context;
+
+ @Before
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+
+ FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testReadWriteExtendedRecursiveElement() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT));
+ ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor());
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyExtendedElementComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // 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();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyExtendedElementComposite(composite);
+ }
+
+ private void verifyExtendedElementComposite(Composite composite) throws XMLStreamException {
+
+ assertEquals("RecursiveExtendedElement", composite.getName().getLocalPart());
+ assertEquals(1, composite.getExtensions().size());
+ Extension ext1 = (Extension) composite.getExtensions().get(0);
+ assertEquals("unknownElement", ext1.getQName().getLocalPart());
+ assertEquals("http://docs.oasis-open.org/ns/opencsa/sca/200912", ext1.getQName().getNamespaceURI());
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader((String)ext1.getValue()));
+ reader.next();
+ assertEquals("unknownElement", reader.getLocalName());
+ reader.next();
+ assertEquals("subUnknownElement1", reader.getLocalName());
+ assertEquals(1, reader.getAttributeCount());
+ assertEquals("attribute", reader.getAttributeLocalName(0));
+ assertEquals("anyAttribute", reader.getAttributeValue(0));
+
+ reader.close();
+
+ }
+
+ @Test
+ public void testReadWriteUnknwonImpl() throws Exception {
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL));
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyUnknownImplComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML_UNKNOWN_IMPL);
+ // System.out.println(bos.toString());
+
+ // assertEquals(XML_UNKNOWN_IMPL, bos.toString());
+ bos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyUnknownImplComposite(composite);
+ }
+
+ private void verifyUnknownImplComposite(Composite composite) {
+
+ assertEquals("aaaa", composite.getName().getLocalPart());
+ assertEquals(1, composite.getComponents().size());
+ Component component = composite.getComponents().get(0);
+ assertEquals("unknownImpl", component.getName());
+ assertEquals(1, component.getServices().size());
+ assertEquals("service", component.getServices().get(0).getName());
+ assertEquals(1, component.getExtensions().size());
+ Extension ext = (Extension) component.getExtensions().get(0);
+ assertEquals("http://docs.oasis-open.org/ns/opencsa/sca/200912", ext.getQName().getNamespaceURI());
+ assertEquals("implementation.unknown", ext.getQName().getLocalPart());
+
+ }
+
+ // @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, context);
+ assertNotNull(composite);
+ reader.close();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // 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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java
new file mode 100644
index 0000000000..2a6fd9ca65
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteBindingSCATestCase.java
@@ -0,0 +1,157 @@
+/*
+ * 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.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Extension;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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: 1041915 $ $Date: 2010-12-03 17:10:49 +0000 (Fri, 03 Dec 2010) $
+ */
+public class ReadWriteBindingSCATestCase {
+
+ private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" " +
+ "targetNamespace=\"http://calc\" " +
+ "name=\"Calculator\">"+
+ "<component name=\"AddServiceComponent\" xmlns:test=\"http://test\" test:customAttribute=\"customValue\">"+
+ "<implementation.java class=\"calculator.AddServiceImpl\" />"+
+ "</component>"+
+ "</composite>";
+
+ private XMLInputFactory inputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+ private ProcessorContext context;
+
+ /**
+ * 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();
+ context = new ProcessorContext(extensionPoints);
+ 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());
+ }
+
+ /**
+ * 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, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML);
+ // System.out.println(bos.toString());
+
+ //assertEquals(XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyComposite(composite);
+ }
+
+ /**
+ * 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, context);
+ assertNotNull(composite);
+ reader.close();
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+
+ // used for debug comparison
+ // System.out.println(XML);
+ // System.out.println(bos.toString());
+
+ // assertEquals(XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ verifyComposite(composite);
+ }
+
+ private void verifyComposite(Composite c) {
+ assertEquals("Calculator", c.getName().getLocalPart());
+ assertEquals(1, c.getComponents().size());
+ Component component = c.getComponents().get(0);
+ assertEquals("AddServiceComponent", component.getName());
+ assertEquals(1, component.getAttributeExtensions().size());
+ Extension extension = component.getAttributeExtensions().get(0);
+ assertEquals("customAttribute", extension.getQName().getLocalPart());
+ assertEquals("http://test", extension.getQName().getNamespaceURI());
+ assertEquals("customValue", extension.getValue());
+ }
+} \ No newline at end of file
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java
new file mode 100644
index 0000000000..b3ccdd8201
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java
@@ -0,0 +1,109 @@
+/*
+ * 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.ByteArrayInputStream;
+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.ProcessorContext;
+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$ $Date$
+ */
+public class ReadWriteLocalCompositeTestCase {
+
+ private XMLInputFactory inputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+ private ProcessorContext context;
+
+ private static final String LOCAL_COMPOSITE_XML = "<?xml version='1.0' encoding='UTF-8'?>"+
+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" targetNamespace=\"http://localcalc\" name=\"LocalCalculator\" local=\"true\">"+
+ "</composite>";
+
+ @Before
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ 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());
+ }
+
+ @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, context);
+ 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, context);
+ assertNotNull(composite);
+ assertTrue(composite.isLocal());
+ is.close();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+ System.out.println(bos.toString());
+
+ // assertEquals(LOCAL_COMPOSITE_XML, bos.toString());
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+ assertNotNull(composite);
+ assertTrue(composite.isLocal());
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
new file mode 100644
index 0000000000..df588e3504
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
@@ -0,0 +1,143 @@
+/*
+ * 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.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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$ $Date$
+ */
+public class ResolvePolicyTestCase {
+
+ private static URLArtifactProcessor<Object> documentProcessor;
+ private static ModelResolver resolver;
+ private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ resolver = new DefaultModelResolver();
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
+
+ // Create StAX processors
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+ }
+
+ 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, context);
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite, context);
+
+ url = getClass().getResource("TestAllCalculator.composite");
+ uri = URI.create("TestAllCalculator.composite");
+ Composite composite = (Composite)documentProcessor.read(null, uri, url, context);
+
+ documentProcessor.resolve(composite, resolver, context);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java
new file mode 100644
index 0000000000..28e679da4a
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.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 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.contribution.processor.ProcessorContext;
+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;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ resolver = new DefaultModelResolver();
+ }
+
+ @Test
+ public void testResolveComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ StAXArtifactProcessor<Composite> compositeReader = staxProcessors.getProcessor(Composite.class);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite nestedComposite = compositeReader.read(reader, context);
+ is.close();
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite, context);
+
+ is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeReader.read(reader, context);
+ is.close();
+
+ compositeReader.resolve(composite, resolver, context);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StripURISpacesTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StripURISpacesTestCase.java
new file mode 100644
index 0000000000..8d9bc72389
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StripURISpacesTestCase.java
@@ -0,0 +1,78 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+
+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.assembly.CompositeService;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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 StripURISpacesTestCase {
+
+ private static XMLInputFactory inputFactory;
+ private static StAXArtifactProcessor<Object> staxProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance());
+ }
+
+
+
+ @Test
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorURISpaces.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ assertNotNull(composite);
+ is.close();
+
+ CompositeService compositeService = (CompositeService)composite.getServices().get(0);
+ assertNotNull(compositeService);
+
+ // Promoted component name with leading and training spaces removed
+ assertEquals("CalculatorServiceComponent", compositeService.getPromotedComponent().getName());
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java
new file mode 100644
index 0000000000..b6f4c11ac2
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java
@@ -0,0 +1,62 @@
+/*
+ * 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.ProcessorContext;
+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<String> {
+ private static final QName ATTRIBUTE = new QName("http://test", "customAttribute");
+
+ public QName getArtifactType() {
+ return ATTRIBUTE;
+ }
+
+ public String read(QName attributeName, XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ return reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart());
+ }
+
+ public void write(String value, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+ writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI());
+ writer.writeAttribute(ATTRIBUTE.getLocalPart(), value);
+ }
+
+ public Class<String> getModelType() {
+ return String.class;
+ }
+
+ public void resolve(String arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
+
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java
new file mode 100644
index 0000000000..cfec8dee7a
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java
@@ -0,0 +1,83 @@
+/*
+ * 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.ProcessorContext;
+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<PolicyExpression> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public PolicyExpression read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ return new MockPolicyImplOne();
+ }
+
+ public void write(PolicyExpression arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException,
+ XMLStreamException {
+ }
+
+ public Class<PolicyExpression> getModelType() {
+ return PolicyExpression.class;
+ }
+
+ public void resolve(PolicyExpression arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
+ }
+
+ public class MockPolicyImplOne implements PolicyExpression {
+ public <T> T getPolicy() {
+ return null;
+ }
+
+ public void setName(QName name) {
+ }
+
+ public <T> 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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java
new file mode 100644
index 0000000000..5e3fa15b69
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java
new file mode 100644
index 0000000000..3845fff14a
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/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.OperationSelector;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.WireFormat;
+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, PolicySubject {
+ private String name;
+ private String uri;
+ private List<Object> extensions = new ArrayList<Object>();
+
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ 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<Object> 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();
+ }
+
+ public List<PolicySet> getPolicySets() {
+ // TODO Auto-generated method stub
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ // TODO Auto-generated method stub
+ return requiredIntents;
+ }
+
+ public ExtensionType getExtensionType() {
+ // TODO Auto-generated method stub
+ return bindingType;
+ }
+
+ public void setExtensionType(ExtensionType type) {
+ this.bindingType = type;
+ }
+
+ public QName getType() {
+ return TYPE;
+ }
+
+ private class TestSCABindingType implements ExtensionType {
+ private QName name = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200912","binding");
+ public QName getBaseType() {
+ return BINDING_BASE;
+ }
+
+ public QName getType() {
+ return name;
+ }
+
+ public void setType(QName type) {
+ }
+
+ public List<Intent> getAlwaysProvidedIntents() {
+ return Collections.emptyList();
+ }
+
+ public List<Intent> getMayProvidedIntents() {
+ return Collections.emptyList();
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+ }
+
+ public WireFormat getRequestWireFormat() {
+ return null;
+ }
+
+ public void setRequestWireFormat(WireFormat wireFormat) {
+ }
+
+ public WireFormat getResponseWireFormat() {
+ return null;
+ }
+
+ public void setResponseWireFormat(WireFormat wireFormat) {
+ }
+
+ public OperationSelector getOperationSelector() {
+ return null;
+ }
+
+ public void setOperationSelector(OperationSelector operationSelector) {
+ }
+
+ @Override
+ public String getDelegateBindingType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDelegateBindingType(String delegateBindingType) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getDelegateBindingURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDelegateBindingURI(String delegateBindingURI) {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java
new file mode 100644
index 0000000000..543aaf9893
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java
@@ -0,0 +1,109 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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.definitions.Definitions;
+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<Object> staxProcessor;
+ private static ModelResolver resolver;
+ private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+ resolver = new DefaultModelResolver();
+
+ FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl();
+ modelFactories.addFactory(scaBindingFactory);
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
+ }
+
+ @Test
+ public void testResolveComposite() throws Exception {
+ Composite nestedComposite = readComposite("Calculator.composite");
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite, context);
+
+ Composite composite = readComposite("TestAllCalculator.composite");
+
+ URL url = getClass().getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context);
+ assertNotNull(scaDefns);
+
+ policyDefinitionsProcessor.resolve(scaDefns, resolver, context);
+
+ staxProcessor.resolve(composite, resolver, context);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+ private Composite readComposite(String resource) throws XMLStreamException, ContributionReadException, IOException {
+ InputStream is = getClass().getResourceAsStream(resource);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+ is.close();
+ return composite;
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java
new file mode 100644
index 0000000000..11d146e55e
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java
@@ -0,0 +1,137 @@
+/*
+ * 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.SCABindingFactory;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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.definitions.Definitions;
+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 URLArtifactProcessor<Definitions> policyDefinitionsProcessor;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory);
+ resolver = new DefaultModelResolver();
+
+ FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl();
+ modelFactories.addFactory(scaBindingFactory);
+
+ 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, context);
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+ bos.close();
+ System.out.println("Writtent ouput is:\n" + bos);
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class, context);
+
+ verifyComposite(composite);
+
+ }
+
+ @Test
+ public void testReadWireWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ Composite composite = staxProcessor.read(is, Composite.class, context);
+
+ URL url = getClass().getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context);
+ assertNotNull(scaDefns);
+ policyDefinitionsProcessor.resolve(scaDefns, resolver, context);
+
+ staxProcessor.resolve(composite, resolver, context);
+ // compositeBuilder.build(composite, null, monitor);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos, context);
+ }
+
+ @Test
+ public void testReadWriteComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
+ ComponentType componentType = staxProcessor.read(is, ComponentType.class, context);
+ staxProcessor.resolve(componentType, resolver, context);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(componentType, bos, context);
+ }
+
+
+ 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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java
new file mode 100644
index 0000000000..6371e87040
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.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 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.ProcessorContext;
+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<Composite> compositeProcessor;
+ private static XMLOutputFactory outputFactory;
+ private static XMLInputFactory inputFactory;
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+
+ 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, context);
+ 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, context);
+ writer.close();
+ System.out.println("Writtent ouput is:\n" + bos);
+
+ // Read again
+ is = new ByteArrayInputStream(bos.toByteArray());
+ reader = inputFactory.createXMLStreamReader(is);
+ composite = compositeProcessor.read(reader, context);
+
+ // Compare
+ component = composite.getComponents().get(0);
+ implementation = (Composite)component.getImplementation();
+
+ assertEquals(qname, implementation.getName());
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/MockPolicy.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/MockPolicy.java
new file mode 100644
index 0000000000..58e6e534b9
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/MockPolicy.java
@@ -0,0 +1,39 @@
+/*
+ * 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.definitions.xml;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Mocked Policy
+ */
+public class MockPolicy {
+ 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/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java
new file mode 100644
index 0000000000..f99b81f73f
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java
@@ -0,0 +1,230 @@
+/*
+ * 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.definitions.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 java.util.Hashtable;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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.BindingType;
+import org.apache.tuscany.sca.policy.ImplementationType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentMap;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.Qualifier;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadDocumentTestCase {
+
+ private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor = null;
+ private static Definitions definitions;
+ private static Map<QName, Intent> intentTable = new Hashtable<QName, Intent>();
+ private static Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
+ private static Map<QName, BindingType> bindingTypesTable = new Hashtable<QName, BindingType>();
+ private static Map<QName, ImplementationType> implTypesTable = new Hashtable<QName, ImplementationType>();
+ public static final String scaNamespace = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+ public static final String namespace = "http://test";
+
+ private static final QName secureWsPolicy = new QName(namespace, "SecureWSPolicy");
+ private static final QName confidentiality = new QName(namespace, "confidentiality");
+ private static final QName integrity = new QName(namespace, "integrity");
+ private static final QName messageProtection = new QName(namespace, "messageProtection");
+ private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ private static final QName confidentiality_message = new QName(namespace, "confidentiality.message");
+ private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy");
+ private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies");
+ private static final QName securityPolicy = new QName(namespace, "SecurityPolicy");
+ private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity");
+ private static final QName wsBinding = new QName(scaNamespace, "binding.ws");
+ private static final QName javaImpl = new QName(scaNamespace, "implementation.java");
+ private static ProcessorContext context;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
+
+ // Create StAX processors
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class);
+
+ URL url = ReadDocumentTestCase.class.getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ definitions = policyDefinitionsProcessor.read(null, uri, url, context);
+
+ for (Intent intent : definitions.getIntents()) {
+ intentTable.put(intent.getName(), intent);
+ for (Intent i : intent.getQualifiedIntents()) {
+ intentTable.put(i.getName(), i);
+ }
+ }
+
+ for (PolicySet policySet : definitions.getPolicySets()) {
+ policySetTable.put(policySet.getName(), policySet);
+ }
+
+ for (BindingType bindingType : definitions.getBindingTypes()) {
+ bindingTypesTable.put(bindingType.getType(), bindingType);
+ }
+
+ for (ImplementationType implType : definitions.getImplementationTypes()) {
+ implTypesTable.put(implType.getType(), implType);
+ }
+ }
+
+ @Test
+ public void testReadSCADefinitions() throws Exception {
+ assertNotNull(definitions);
+
+ assertNotNull(intentTable.get(confidentiality));
+ assertNotNull(intentTable.get(messageProtection));
+ assertNotNull(intentTable.get(confidentiality_transport));
+ assertTrue(intentTable.get(confidentiality).getDescription().length() > 0);
+
+ assertNotNull(policySetTable.get(secureReliablePolicy));
+ assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2);
+ assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2);
+
+ assertNotNull(policySetTable.get(secureMessagingPolicies));
+ assertEquals(2, policySetTable.get(secureMessagingPolicies).getIntentMaps().get(0).getQualifiers().size());
+ //assertTrue(policySetTable.get(secureWsPolicy).getPolicies().get(0) instanceof org.apache.neethi.Policy);
+
+ assertEquals(bindingTypesTable.size(), 1);
+ assertNotNull(bindingTypesTable.get(wsBinding));
+ assertEquals(implTypesTable.size(), 1);
+ assertNotNull(implTypesTable.get(javaImpl));
+ }
+
+ private boolean isRealizedBy(PolicySet policySet, Intent intent) {
+ if (intent.getName().getLocalPart().indexOf('.') == -1) {
+ return policySet.getProvidedIntents().contains(intent);
+ }
+ for (IntentMap map : policySet.getIntentMaps()) {
+ for (Qualifier q : map.getQualifiers()) {
+ if (q.getIntent().equals(intent)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private int getNumberOfQualifiedPolicies(PolicySet policySet) {
+ int count = 0;
+ for(IntentMap intentMap: policySet.getIntentMaps()) {
+ for(Qualifier q: intentMap.getQualifiers()) {
+ count += q.getPolicies().size();
+ }
+ }
+ return count;
+ }
+
+ @Test
+ public void testResolveSCADefinitions() throws Exception {
+ Intent i1 = intentTable.get(messageProtection);
+ assertTrue(!i1.getRequiredIntents().isEmpty());
+ assertNull(i1.getRequiredIntents().get(0).getDescription());
+
+ QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ Intent i2 = intentTable.get(confidentiality_transport);
+ assertNotNull(i2.getQualifiableIntent());
+
+ PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy);
+ PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies);
+ PolicySet securityPolicySet = policySetTable.get(securityPolicy);
+
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+ assertTrue(secureMessagingPolicySet.isUnresolved());
+ assertEquals(3, getNumberOfQualifiedPolicies(securityPolicySet));
+
+ //testing to ensure that inclusion of referred policy sets has not happened
+ PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity);
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getIntentMaps().isEmpty());
+
+ BindingType wsBindingType = bindingTypesTable.get(wsBinding);
+ assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(wsBindingType.getMayProvidedIntents().get(0).getDescription());
+
+ ImplementationType javaImplType = implTypesTable.get(javaImpl);
+ assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(javaImplType.getMayProvidedIntents().get(0).getDescription());
+
+ ModelResolver resolver = new DefaultModelResolver();
+ policyDefinitionsProcessor.resolve(definitions, resolver, context);
+ //builder.build(scaDefinitions);
+
+ //testing if policy intents have been linked have property been linked up
+ assertNotNull(i1.getRequiredIntents().get(0).getDescription());
+ // assertNotNull(i2.getQualifiableIntent().getDescription());
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+
+ //testing if policysets have been properly linked up with intents
+ assertFalse(secureMessagingPolicySet.isUnresolved());
+ assertTrue(isRealizedBy(secureMessagingPolicySet, intentTable.get(confidentiality)));
+ assertTrue(isRealizedBy(secureMessagingPolicySet, intentTable.get(confidentiality_transport)));
+
+ //testing if intent maps have been properly mapped to policies
+ assertFalse(securityPolicySet.isUnresolved());
+ assertTrue(isRealizedBy(securityPolicySet, intentTable.get(confidentiality)));
+ assertTrue(isRealizedBy(securityPolicySet, intentTable.get(confidentiality_message)));
+
+ //testing for inclusion of referred policysets
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getIntentMaps().get(0).getQualifiers().isEmpty());
+ assertTrue(isRealizedBy(basicAuthMsgProtSecurityPolicySet, intentTable.get(confidentiality_transport)));
+
+ assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(wsBindingType.getMayProvidedIntents().get(0).getDescription());
+
+ assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(javaImplType.getMayProvidedIntents().get(0).getDescription());
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java
new file mode 100644
index 0000000000..a148e33029
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java
@@ -0,0 +1,58 @@
+/*
+ * 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.definitions.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.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A PolicyProcessor used for testing.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<MockPolicy> {
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public MockPolicy read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ return new MockPolicy();
+ }
+
+ public void write(MockPolicy arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+ }
+
+ public Class<MockPolicy> getModelType() {
+ return MockPolicy.class;
+ }
+
+ public void resolve(MockPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
+
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
new file mode 100644
index 0000000000..d2b0775361
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
@@ -0,0 +1,161 @@
+/*
+ * 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.policy.xml;
+
+import static org.apache.tuscany.sca.policy.xml.PolicyXPathFunction.normalize;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathFactory;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ *
+ */
+public class PolicyXPathFunctionResolverTestCase {
+ private static XPath xpath;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ XPathFactory factory = XPathFactory.newInstance();
+ xpath = factory.newXPath();
+ xpath.setNamespaceContext(new NamespaceContextImpl());
+ xpath.setXPathFunctionResolver(new PolicyXPathFunctionResolver(xpath.getNamespaceContext()));
+ }
+
+ @Test
+ public void testIntentsRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ String str = "//sca:composite/sca:component[IntentRefs('sca:confidentiality')]";
+ str = normalize(str, "sca");
+ // Test the rewrite of xpath so that the self:node() is passed into the SCA function
+ XPathExpression exp = xpath.compile(str);
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testIntentsRef2() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ String str = " //sca:composite/sca:component[sca:IntentRefs('sca:confidentiality')]";
+ str = normalize(str, "sca");
+ // Test the rewrite of xpath so that the self:node() is passed into the SCA function
+ XPathExpression exp = xpath.compile(str);
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testIntentsRef3() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ String str = " IntentRefs('sca:confidentiality') ";
+ str = normalize(str, "sca");
+ // Test the rewrite of xpath so that the self:node() is passed into the SCA function
+ XPathExpression exp = xpath.compile(str);
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ Assert.assertEquals(1, nodes.getLength());
+ }
+ @Test
+ public void testURIRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile(normalize("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]","sca"));
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testInterfaceRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]","sca"));
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testOperationRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]","sca"));
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ private static class NamespaceContextImpl implements NamespaceContext {
+
+ private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+
+ public String getNamespaceURI(String prefix) {
+ if ("sca".equals(prefix)) {
+ return SCA11_NS;
+ } else {
+ return null;
+ }
+ }
+
+ public String getPrefix(String namespaceURI) {
+ if (SCA11_NS.equals(namespaceURI)) {
+ return "sca";
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String namespaceURI) {
+ if (SCA11_NS.equals(namespaceURI)) {
+ return Collections.singleton("sca").iterator();
+ }
+ return null;
+ }
+
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
new file mode 100644
index 0000000000..b91308cfb0
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
@@ -0,0 +1,307 @@
+/*
+ * 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.policy.xml;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+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.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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.apache.tuscany.sca.policy.BindingType;
+import org.apache.tuscany.sca.policy.ExtensionType;
+import org.apache.tuscany.sca.policy.ExternalAttachment;
+import org.apache.tuscany.sca.policy.ImplementationType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentMap;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.Qualifier;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadDocumentTestCase {
+
+ private ModelResolver resolver;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private ProcessorContext context;
+
+ private static final QName elementToProcess =
+ new QName("http://docs.oasis-open.org/ns/opencsa/sca/200912", "implementationType");
+
+ private Map<QName, Intent> intentTable = new Hashtable<QName, Intent>();
+ private Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
+ private Map<QName, BindingType> bindingTypesTable = new Hashtable<QName, BindingType>();
+ private Map<QName, ImplementationType> implTypesTable = new Hashtable<QName, ImplementationType>();
+ private Map<QName, ExternalAttachment> attachmentsTable = new Hashtable<QName, ExternalAttachment>();
+
+ private static final String scaNamespace = "http://docs.oasis-open.org/ns/opencsa/sca/200912";
+ private static final String namespace = "http://test";
+
+ private static final QName confidentiality = new QName(namespace, "confidentiality");
+ private static final QName integrity = new QName(namespace, "integrity");
+ private static final QName messageProtection = new QName(namespace, "messageProtection");
+ private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ private static final QName confidentiality_message = new QName(namespace, "confidentiality.message");
+ private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy");
+ private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies");
+ private static final QName securityPolicy = new QName(namespace, "SecurityPolicy");
+ private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity");
+ private static final QName wsBinding = new QName(scaNamespace, "binding.ws");
+ private static final QName javaImpl = new QName(scaNamespace, "implementation.java");
+ private static final QName testPolicySetOne = new QName(namespace, "TestPolicySetOne");
+
+ @Before
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ resolver = new DefaultModelResolver();
+ context = new ProcessorContext(extensionPoints);
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+
+ URL url = getClass().getResource("test_definitions.xml");
+ InputStream urlStream = url.openStream();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
+ reader.next();
+
+ //position on the right element qname to get processed
+ while (reader.hasNext()) {
+ reader.next();
+ int event = reader.getEventType();
+ if (event == START_ELEMENT && reader.getName().equals(elementToProcess)) {
+ break;
+ }
+ }
+ while (true) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT: {
+ Object artifact = staxProcessor.read(reader, context);
+ if (artifact instanceof PolicySet) {
+ PolicySet policySet = (PolicySet)artifact;
+ policySet.setName(new QName(namespace, policySet.getName().getLocalPart()));
+ policySetTable.put(policySet.getName(), policySet);
+ } else if (artifact instanceof Intent) {
+ Intent intent = (Intent)artifact;
+ intent.setName(new QName(namespace, intent.getName().getLocalPart()));
+ intentTable.put(intent.getName(), intent);
+ for (Intent i : intent.getQualifiedIntents()) {
+ i.setName(new QName(namespace, i.getName().getLocalPart()));
+ intentTable.put(i.getName(), i);
+ resolver.addModel(i, context);
+ }
+ } else if (artifact instanceof BindingType) {
+ BindingType bindingType = (BindingType)artifact;
+ bindingTypesTable.put(bindingType.getType(), bindingType);
+ } else if (artifact instanceof ImplementationType) {
+ ImplementationType implType = (ImplementationType)artifact;
+ implTypesTable.put(implType.getType(), implType);
+ } else if ( artifact instanceof ExternalAttachment) {
+ ExternalAttachment attachment = (ExternalAttachment)artifact;
+ attachmentsTable.put(attachment.getPolicySets().get(0).getName(), attachment);
+ }
+
+ if (artifact != null) {
+ resolver.addModel(artifact, context);
+ }
+
+ break;
+ }
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ } else {
+ break;
+ }
+ }
+ urlStream.close();
+ }
+
+ @Test
+ public void testReadSCADefinitions() throws Exception {
+ assertNotNull(intentTable.get(confidentiality));
+ assertNotNull(intentTable.get(messageProtection));
+ assertNotNull(intentTable.get(confidentiality_transport));
+ assertTrue(intentTable.get(confidentiality).getDescription().length() > 0);
+
+ assertNotNull(policySetTable.get(secureReliablePolicy));
+ assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2);
+ assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2);
+
+ assertNotNull(policySetTable.get(secureMessagingPolicies));
+ assertEquals(2, policySetTable.get(secureMessagingPolicies).getIntentMaps().get(0).getQualifiers().get(0).getPolicies().size());
+
+ assertEquals(bindingTypesTable.size(), 1);
+ assertNotNull(bindingTypesTable.get(wsBinding));
+ assertEquals(implTypesTable.size(), 1);
+ assertNotNull(implTypesTable.get(javaImpl));
+
+ // Test external attachments
+ assertEquals(1, attachmentsTable.size());
+ assertNotNull(attachmentsTable.get(policySetTable.get(testPolicySetOne).getName()));
+ }
+
+ private int getNumberOfQualifiedPolicies(PolicySet policySet) {
+ int count = 0;
+ for(IntentMap intentMap: policySet.getIntentMaps()) {
+ for(Qualifier q: intentMap.getQualifiers()) {
+ count += q.getPolicies().size();
+ }
+ }
+ return count;
+ }
+
+ @Test
+ public void testResolution() throws Exception {
+ assertTrue(!intentTable.get(messageProtection).getRequiredIntents().isEmpty());
+ Intent profileIntent = intentTable.get(new QName(namespace, "messageProtection"));
+ assertNull(profileIntent.getRequiredIntents().get(0).getDescription());
+
+ QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ assertTrue(intentTable.get(confidentiality_transport) instanceof Intent);
+ Intent qualifiedIntent = (Intent)intentTable.get(new QName(namespace, "confidentiality.transport"));
+ assertNull(qualifiedIntent.getDescription());
+ assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription());
+
+ PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy);
+ PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies);
+ PolicySet securityPolicySet = policySetTable.get(securityPolicy);
+
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+ assertTrue(secureMessagingPolicySet.isUnresolved());
+ assertEquals(2, getNumberOfQualifiedPolicies(securityPolicySet));
+
+ //testing to ensure that inclusion of referred policy sets has not happened
+ PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity);
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getIntentMaps().isEmpty());
+
+ ExtensionType wsBindingType = bindingTypesTable.get(wsBinding);
+ assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(wsBindingType.getMayProvidedIntents().get(0).getDescription());
+
+ ExtensionType javaImplType = implTypesTable.get(javaImpl);
+ assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(javaImplType.getMayProvidedIntents().get(0).getDescription());
+
+ ExternalAttachment attachment = attachmentsTable.values().iterator().next();
+ PolicySet psOne = policySetTable.get(testPolicySetOne);
+ assertEquals(psOne, attachment.getPolicySets().get(0));
+
+ List<Intent> intents = new ArrayList<Intent>(intentTable.values());
+
+ for (Intent intent : intents) {
+ staxProcessor.resolve(intent, resolver, context);
+ }
+
+ for (PolicySet policySet : policySetTable.values()) {
+ if (policySet.getReferencedPolicySets().isEmpty())
+ staxProcessor.resolve(policySet, resolver, context);
+ }
+
+ for (PolicySet policySet : policySetTable.values()) {
+ if (!policySet.getReferencedPolicySets().isEmpty())
+ staxProcessor.resolve(policySet, resolver, context);
+ }
+
+ for (ExtensionType bindingType : bindingTypesTable.values()) {
+ staxProcessor.resolve(bindingType, resolver, context);
+ }
+
+ for (ExtensionType implType : implTypesTable.values()) {
+ staxProcessor.resolve(implType, resolver, context);
+ }
+
+ for ( ExternalAttachment ea : attachmentsTable.values()) {
+ staxProcessor.resolve(ea, resolver, context);
+ }
+
+ //testing if policy intents have been linked have property been linked up
+ assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription());
+ assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription());
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+
+ //testing if policysets have been properly linked up with intents
+ assertFalse(secureMessagingPolicySet.isUnresolved());
+ assertTrue(isRealizedBy(secureMessagingPolicySet, intentTable.get(confidentiality)));
+ assertTrue(isRealizedBy(secureMessagingPolicySet, intentTable.get(confidentiality_transport)));
+
+ //testing if intent maps have been properly mapped to policies
+ assertFalse(securityPolicySet.isUnresolved());
+ assertTrue(isRealizedBy(securityPolicySet, intentTable.get(confidentiality)));
+ assertTrue(isRealizedBy(securityPolicySet, intentTable.get(confidentiality_message)));
+
+ //testing for inclusion of referred policysets
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getIntentMaps().isEmpty());
+ assertTrue(isRealizedBy(basicAuthMsgProtSecurityPolicySet, intentTable.get(confidentiality_transport)));
+
+ assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(wsBindingType.getMayProvidedIntents().get(0).getDescription());
+
+ assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(javaImplType.getMayProvidedIntents().get(0).getDescription());
+
+
+ }
+
+ private boolean isRealizedBy(PolicySet policySet, Intent intent) {
+ if (intent.getName().getLocalPart().indexOf('.') == -1) {
+ return policySet.getProvidedIntents().contains(intent);
+ }
+ for (IntentMap map : policySet.getIntentMaps()) {
+ for (Qualifier q : map.getQualifiers()) {
+ if (q.getIntent().equals(intent)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java
new file mode 100644
index 0000000000..aea2c3adb8
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java
@@ -0,0 +1,83 @@
+/*
+ * 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.policy.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.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.policy.PolicyExpression;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<PolicyExpression> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public PolicyExpression read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ return new MockPolicyImplOne();
+ }
+
+ public void write(PolicyExpression arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException {
+ }
+
+ public Class<PolicyExpression> getModelType() {
+ // TODO Auto-generated method stub
+ return PolicyExpression.class;
+ }
+
+ public void resolve(PolicyExpression arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
+
+ }
+
+ public class MockPolicyImplOne implements PolicyExpression {
+ public <T> T getPolicy() {
+ return null;
+ }
+
+ public void setName(QName name) {
+ }
+
+ public <T> 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) {
+ }
+
+ }
+}