diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-15 18:30:56 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-15 18:30:56 +0000 |
commit | 6e273517868e587a4884f41374b224b8020345ea (patch) | |
tree | 5071a4113babc8a05aaa01ec68db6677fd553191 /branches/sca-java-1.3.2/modules/assembly-xml/src | |
parent | db98976cfa9a672b8c8a378aa15ff44c9d83aaeb (diff) |
TUSCANY-2538 - Merging changes from trunk to add default processor to handle unknown content in composite files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695573 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.3.2/modules/assembly-xml/src')
4 files changed, 85 insertions, 16 deletions
diff --git a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java index ae187d0805..111a517552 100644 --- a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java +++ b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java @@ -94,6 +94,7 @@ public class ReadDocumentTestCase extends TestCase { reader.setFeature("http://xml.org/sax/features/namespaces", true); reader.setContentHandler(handler); reader.parse(new InputSource(url.openStream())); + } public void testValidateImplementation() throws Exception { diff --git a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java index 437b8928b1..9b88ad3a3d 100644 --- a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java +++ b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java @@ -49,21 +49,22 @@ public class ReadWriteAttributeTestCase extends TestCase { private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); - private static final String XML = - "<?xml version='1.0' encoding='UTF-8'?>" + - "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\">" + - "<service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\" />" + - "<component name=\"CalculatorServiceComponent\" customAttribute=\"customValue\">" + - "<reference name=\"addService\" target=\"AddServiceComponent\" />" + - "<reference name=\"subtractService\" target=\"SubtractServiceComponent\" />"+ - "<reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" />" + - "<reference name=\"divideService\" target=\"DivideServiceComponent\" />" + - "</component>"+ - "<component name=\"AddServiceComponent\" />" + - "<component name=\"SubtractServiceComponent\" />" + - "<component name=\"MultiplyServiceComponent\" />" + - "<component name=\"DivideServiceComponent\" />" + - "</composite>"; + private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+ + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\">"+ + "<service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\">"+ + "<interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.CalculatorService\" />"+ + "</service>"+ + "<component name=\"CalculatorServiceComponent\" customAttribute=\"customValue\">"+ + "<reference name=\"addService\" target=\"AddServiceComponent\" />"+ + "<reference name=\"subtractService\" target=\"SubtractServiceComponent\" />"+ + "<reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" />"+ + "<reference name=\"divideService\" target=\"DivideServiceComponent\" />"+ + "</component>"+ + "<component name=\"AddServiceComponent\" />"+ + "<component name=\"SubtractServiceComponent\" />"+ + "<component name=\"MultiplyServiceComponent\" />"+ + "<component name=\"DivideServiceComponent\" />"+ + "</composite>"; @Override public void setUp() throws Exception { @@ -100,6 +101,7 @@ public class ReadWriteAttributeTestCase extends TestCase { ByteArrayOutputStream bos = new ByteArrayOutputStream(); staxProcessor.write(composite, bos); + System.out.println(bos.toString()); assertEquals(XML, bos.toString()); } diff --git a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java new file mode 100644 index 0000000000..3c1d9ba88e --- /dev/null +++ b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java @@ -0,0 +1,60 @@ +package org.apache.tuscany.sca.assembly.xml; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.Iterator; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.junit.Test; +import org.w3c.dom.Document; + +public class TestReadWriteUnkonwnElement extends TestCase { + + private XMLInputFactory inputFactory; + String XML = "<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.CalculatorService\" /></service><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" target=\"AddServiceComponent\" /><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\" /><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /><x:unknownElement xmlns:x=\"http://x\" uknAttr=\"attribute1\"><x:subUnknownElement1 uknAttr1=\"attribute1\" /><x:subUnknownElement2 /></x:unknownElement></composite>"; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Override + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @Override + public void tearDown() throws Exception { + } + + @Test + public void testReadWriteComposite() throws Exception{ + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + System.out.println(bos.toString()); + assertEquals(XML,bos.toString()); + bos.close(); + + is.close(); + } + +} diff --git a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite index 4546fddb2d..85f6a39243 100644 --- a/branches/sca-java-1.3.2/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite +++ b/branches/sca-java-1.3.2/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite @@ -18,6 +18,7 @@ * under the License.
-->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:x="http://x"
xmlns:calc="http://calc" targetNamespace="http://calc"
name="Calculator">
@@ -25,7 +26,6 @@ <service name="CalculatorService" promote="CalculatorServiceComponent">
<interface.java interface="calculator.CalculatorService"/>
</service>
-
<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
<reference name="addService" target="AddServiceComponent"/>
@@ -49,5 +49,11 @@ <component name="DivideServiceComponent">
<implementation.java class="calculator.DivideServiceImpl"/>
</component>
+
+ <x:unknownElement uknAttr="attribute1">
+ <x:subUnknownElement1 uknAttr1="attribute1"/>
+ <x:subUnknownElement2/>
+ </x:unknownElement>
+
</composite>
|