Search in sources :

Example 1 with XML

use of org.apache.axiom.ts.dimension.serialization.XML in project webservices-axiom by apache.

the class TestSerializeWithXSITypeAttribute method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    // Serialize the SOAP body; this should generate an additional namespace declaration
    // to for the namespace used in the value of the xsi:type attribute.
    XML xml = serializationStrategy.serialize(envelope.getBody());
    // No deserialize the result and test that the attribute value can be resolved.
    OMElement element = ((OMMetaFactorySPI) metaFactory).createOMBuilder(StAXParserConfiguration.DEFAULT, xml.getInputSource()).getDocumentElement().getFirstElement().getFirstElement();
    assertThat(element.resolveQName(element.getAttributeValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "type")))).isEqualTo(new QName("http://ws.apache.org/axis2/user", "myData"));
}
Also used : XML(org.apache.axiom.ts.dimension.serialization.XML) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 2 with XML

use of org.apache.axiom.ts.dimension.serialization.XML in project webservices-axiom by apache.

the class TestSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = TestDocument.DOCUMENT1.createOMSourcedElement(factory, push, destructive);
    OMDataSource ds = element.getDataSource();
    OMContainer parent = elementContext.wrap(element);
    boolean parentComplete = parent != null && parent.isComplete();
    expansionStrategy.apply(element);
    boolean consuming = expansionStrategy.isConsumedAfterSerialization(push, destructive, serializationStrategy);
    for (int iteration = 0; iteration < count; iteration++) {
        boolean expectException = iteration != 0 && (consuming || serializeParent && !serializationStrategy.isCaching() && !parentComplete);
        XML result;
        try {
            result = serializationStrategy.serialize(serializeParent ? parent : element);
            if (expectException) {
                fail("Expected exception");
            }
        } catch (Exception ex) {
            if (!expectException) {
                throw ex;
            } else {
                continue;
            }
        }
        InputSource expectedXML = new InputSource(new StringReader(TestDocument.DOCUMENT1.getContent()));
        if (serializeParent) {
            expectedXML = elementContext.getControl(expectedXML);
        }
        assertAbout(xml()).that(result.getInputSource()).hasSameContentAs(expectedXML);
        // the sourced element should be expanded.
        if (expansionStrategy.isExpandedAfterSerialization(push, destructive, serializationStrategy)) {
            assertTrue(element.isExpanded());
            assertEquals("OMSourcedElement completion status", !consuming, element.isComplete());
        } else {
            assertFalse(element.isExpanded());
        }
        if (parent != null && !serializeParent) {
            // Operations on the OMSourcedElement should have no impact on the parent
            assertEquals("Parent completion status", parentComplete, parent.isComplete());
        }
    }
    if (ds instanceof PullOMDataSource) {
        assertFalse(((PullOMDataSource) ds).hasUnclosedReaders());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) InputSource(org.xml.sax.InputSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) AbstractPullOMDataSource(org.apache.axiom.om.ds.AbstractPullOMDataSource) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMDataSource(org.apache.axiom.om.OMDataSource) AbstractPullOMDataSource(org.apache.axiom.om.ds.AbstractPullOMDataSource) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) XML(org.apache.axiom.ts.dimension.serialization.XML) StringReader(java.io.StringReader) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMContainer(org.apache.axiom.om.OMContainer)

Example 3 with XML

use of org.apache.axiom.ts.dimension.serialization.XML in project webservices-axiom by apache.

the class TestSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    OMXMLParserWrapper builder = file.getAdapter(XMLSampleAdapter.class).getBuilder(metaFactory);
    try {
        OMContainer container = containerExtractor.getContainer(builder);
        // We need to clone the InputSource objects so that we can dump their contents
        // if the test fails
        InputSource[] control = duplicateInputSource(containerExtractor.getControl(file.getInputStream()));
        XML actual = serializationStrategy.serialize(container);
        try {
            // Configure the InputSources such that external entities can be resolved
            String systemId = new URL(file.getUrl(), "dummy.xml").toString();
            control[0].setSystemId(systemId);
            InputSource actualIS = actual.getInputSource();
            actualIS.setSystemId(systemId);
            assertAbout(xml()).that(actualIS).ignoringElementContentWhitespace().hasSameContentAs(control[0]);
        } catch (Throwable ex) {
            System.out.println("Control:");
            dumpInputSource(control[1]);
            System.out.println("Actual:");
            actual.dump(System.out);
            throw ex;
        }
        if (serializationStrategy.isCaching()) {
            assertTrue(container.isComplete());
        } else {
            // TODO: need to investigate why assertConsumed is not working here
            assertFalse(container.isComplete());
        //                assertConsumed(element);
        }
    } finally {
        builder.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) XML(org.apache.axiom.ts.dimension.serialization.XML) XMLSampleAdapter(org.apache.axiom.ts.om.XMLSampleAdapter) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) OMContainer(org.apache.axiom.om.OMContainer) URL(java.net.URL)

Aggregations

XML (org.apache.axiom.ts.dimension.serialization.XML)3 OMContainer (org.apache.axiom.om.OMContainer)2 InputSource (org.xml.sax.InputSource)2 StringReader (java.io.StringReader)1 URL (java.net.URL)1 QName (javax.xml.namespace.QName)1 OMDataSource (org.apache.axiom.om.OMDataSource)1 OMElement (org.apache.axiom.om.OMElement)1 OMFactory (org.apache.axiom.om.OMFactory)1 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 AbstractPullOMDataSource (org.apache.axiom.om.ds.AbstractPullOMDataSource)1 AbstractPushOMDataSource (org.apache.axiom.om.ds.AbstractPushOMDataSource)1 XMLSampleAdapter (org.apache.axiom.ts.om.XMLSampleAdapter)1 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)1