From dc193f55e9ac990be96cd0cc5db7957126f33753 Mon Sep 17 00:00:00 2001 From: lresende Date: Sat, 17 Jan 2009 01:41:55 +0000 Subject: TUSCANY-2663 - Adding new test scenarios to anyElement test case git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@735202 13f79535-47bb-0310-9956-ffa450edef68 --- .../assembly/xml/AnyElementReadWriteTestCase.java | 95 ------------- .../xml/ReadWriteAnyAttributeTestCase.java | 118 ++++++++++++++++ .../assembly/xml/ReadWriteAnyElementTestCase.java | 148 +++++++++++++++++++++ .../assembly/xml/ReadWriteAttributeTestCase.java | 118 ---------------- 4 files changed, 266 insertions(+), 213 deletions(-) delete mode 100644 branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java create mode 100644 branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java create mode 100644 branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java delete mode 100644 branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java (limited to 'branches/sca-java-1.3.3/modules/assembly-xml') diff --git a/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java deleted file mode 100644 index abf0269c0f..0000000000 --- a/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/AnyElementReadWriteTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.xml; - -import java.io.ByteArrayOutputStream; -import java.io.InputStream; - -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.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.junit.Test; - -public class AnyElementReadWriteTestCase extends TestCase { - - private XMLInputFactory inputFactory; - String XML = ""; - private ExtensibleStAXArtifactProcessor staxProcessor; - - @Override - public void setUp() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); - inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints - .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, - inputFactory, 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(); - } - */ - - @Test - public void testReadWriteUnknownElementComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("UnknownElement.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.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java new file mode 100644 index 0000000000..5777a33277 --- /dev/null +++ b/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -0,0 +1,118 @@ +/* + * 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.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 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.contribution.processor.StAXAttributeProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteAnyAttributeTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); + + // implementation.java for CalculatorServiceComponent appears in a strange place as the + // java implementation extension is not loaded and hence they are loaded as any elements + private static final String XML = ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""+ + ""; + + @Override + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + + StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); + + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + } + + @Override + public void tearDown() throws Exception { + + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + is.close(); + } + + public void testWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite) staxProcessor.read(reader); + assertNotNull(composite); + is.close(); + + 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.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java new file mode 100644 index 0000000000..b26674d1d2 --- /dev/null +++ b/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class ReadWriteAnyElementTestCase { + private static final String XML_RECURSIVE_EXTENDED_ELEMENT = + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String XML_UNKNOWN_IMPL = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Before + public void setUp() throws Exception { + ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); + + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance(), null); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReadWriteExtendedRecursiveElement() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); + // System.out.println(bos.toString()); + + assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, bos.toString()); + bos.close(); + } + + @Test + public void testReadWriteUnknwonImpl() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } + + // @Test + @Ignore() + public void testReadWriteInvalidAttribute() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE)); + Composite composite = (Composite)staxProcessor.read(reader); + assertNotNull(composite); + reader.close(); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + + // used for debug comparison + // System.out.println(XML_UNKNOWN_IMPL); + // System.out.println(bos.toString()); + + assertEquals(XML_UNKNOWN_IMPL, bos.toString()); + bos.close(); + } + +} diff --git a/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java b/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java deleted file mode 100644 index 387405fd8d..0000000000 --- a/branches/sca-java-1.3.3/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.xml; - -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 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.contribution.processor.StAXAttributeProcessorExtensionPoint; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; - -/** - * Test reading SCA XML assemblies. - * - * @version $Rev$ $Date$ - */ -public class ReadWriteAttributeTestCase extends TestCase { - - private XMLInputFactory inputFactory; - private ExtensibleStAXArtifactProcessor staxProcessor; - - private static final QName ATTRIBUTE = new QName("http://test", "customAttribute"); - - // implementation.java for CalculatorServiceComponent appears in a strange place as the - // java implementation extension is not loaded and hence they are loaded as any elements - private static final String XML = ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""; - - @Override - public void setUp() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - inputFactory = XMLInputFactory.newInstance(); - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - - StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); - staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); - - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); - } - - @Override - public void tearDown() throws Exception { - - } - - public void testReadComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - is.close(); - } - - public void testWriteComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); - assertNotNull(composite); - is.close(); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); - System.out.println(bos.toString()); - - assertEquals(XML, bos.toString()); - } -} -- cgit v1.2.3