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"));
}
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());
}
}
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();
}
}
Aggregations