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
This commit is contained in:
parent
b45ddbd9b9
commit
f35490cae6
3 changed files with 97 additions and 10 deletions
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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,6 +105,8 @@ public class ReadWriteAnyElementTestCase {
|
|||
assertNotNull(composite);
|
||||
reader.close();
|
||||
|
||||
verifyExtendedElementComposite(composite);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
staxProcessor.write(composite, bos, context);
|
||||
|
||||
|
@ -108,17 +114,45 @@ public class ReadWriteAnyElementTestCase {
|
|||
// 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue