diff options
author | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-03 17:10:49 +0000 |
---|---|---|
committer | bdaniel <bdaniel@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-03 17:10:49 +0000 |
commit | f35490cae676e10fac7e2a963bffea134b655369 (patch) | |
tree | c70fb755022d0d9187933fc09ea4a1e2f63a2734 /sca-java-2.x/trunk | |
parent | b45ddbd9b965d35bca5c6974c7ab2cceda794fb2 (diff) |
Modify test cases so that they aren't checking for an exact string. Different parser implementations can return strings that are equivalent but different in some trivial way
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1041915 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
3 files changed, 97 insertions, 10 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java index 28a2bb6851..cbe3cfa09c 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -22,6 +22,7 @@ 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; @@ -29,7 +30,9 @@ 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; @@ -47,7 +50,7 @@ import org.junit.Test; 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\" " + + "<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\">"+ @@ -94,6 +97,8 @@ public class ReadWriteAnyAttributeTestCase { assertNotNull(composite); reader.close(); + verifyComposite(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); staxProcessor.write(composite, bos, context); @@ -101,7 +106,11 @@ public class ReadWriteAnyAttributeTestCase { // System.out.println(XML); // System.out.println(bos.toString()); - assertEquals(XML, bos.toString()); + //assertEquals(XML, bos.toString()); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + composite = staxProcessor.read(bis, Composite.class, context); + verifyComposite(composite); } /** @@ -118,6 +127,8 @@ public class ReadWriteAnyAttributeTestCase { assertNotNull(composite); reader.close(); + verifyComposite(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); staxProcessor.write(composite, bos, context); @@ -125,6 +136,22 @@ public class ReadWriteAnyAttributeTestCase { // System.out.println(XML); // System.out.println(bos.toString()); - assertEquals(XML, 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/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java index 7a36c1d97d..ddbd70e567 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java @@ -21,13 +21,17 @@ 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; @@ -101,24 +105,54 @@ public class ReadWriteAnyElementTestCase { 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()); +// System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); +// System.out.println(bos.toString()); - assertEquals(XML_RECURSIVE_EXTENDED_ELEMENT, 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); } - @Test + 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); @@ -126,13 +160,33 @@ public class ReadWriteAnyElementTestCase { // System.out.println(XML_UNKNOWN_IMPL); // System.out.println(bos.toString()); - assertEquals(XML_UNKNOWN_IMPL, 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); } - // @Test + 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); diff --git a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java index fc675dcdce..b3ccdd8201 100644 --- a/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java +++ b/sca-java-2.x/trunk/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java @@ -23,6 +23,7 @@ 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; @@ -98,6 +99,11 @@ public class ReadWriteLocalCompositeTestCase { staxProcessor.write(composite, bos, context); System.out.println(bos.toString()); - assertEquals(LOCAL_COMPOSITE_XML, 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()); } } |