use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestGetXMLStreamReader method runTest.
@Override
protected final void runTest() throws Throwable {
InputStream in = file.getInputStream();
try {
XMLStreamReader expected = StAXUtils.createXMLStreamReader(TEST_PARSER_CONFIGURATION, file.getUrl().toString(), in);
try {
OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(file.getUrl().toString()));
try {
XMLStreamReader actual = containerExtractor.getContainer(builder).getXMLStreamReader(cache);
XMLStreamReaderComparator comparator = new XMLStreamReaderComparator(containerExtractor.filter(expected), containerExtractor.filter(actual));
builderFactory.configureXMLStreamReaderComparator(comparator);
comparator.compare();
} finally {
builder.close();
}
} finally {
expected.close();
}
} finally {
in.close();
}
}
use of org.apache.axiom.om.OMXMLParserWrapper 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();
}
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestGetDocumentElementWithIllFormedDocument method runTest.
@Override
protected void runTest() throws Throwable {
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<!--comment1-->"));
try {
builder.getDocumentElement();
fail("Expected OMException");
} catch (OMException ex) {
// Expected
}
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestReadAttachmentBeforeRootPartComplete method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
// Programmatically create the message
OMElement orgRoot = factory.createOMElement("root", null);
OMElement orgChild1 = factory.createOMElement("child1", null, orgRoot);
DataSource ds = new RandomDataSource(54321, 4096);
orgChild1.addChild(factory.createOMText(new DataHandler(ds), true));
// Create a child with a large text content and insert it after the binary node.
// If we don't do this, then the root part may be buffered entirely by the parser,
// and the test would not be effective.
OMElement orgChild2 = factory.createOMElement("child2", null, orgRoot);
String s = RandomUtils.randomString(128 * 1024);
orgChild2.setText(s);
// Serialize the message
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
MemoryBlob blob = Blobs.createMemoryBlob();
OutputStream out = blob.getOutputStream();
orgRoot.serialize(out, format);
out.close();
// Parse the message
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build());
OMElement root = builder.getDocumentElement();
OMElement child1 = (OMElement) root.getFirstOMChild();
OMText text = (OMText) child1.getFirstOMChild();
assertTrue(text.isBinary());
// Access the DataHandler
DataHandler dh = text.getDataHandler();
IOTestUtils.compareStreams(ds.getInputStream(), dh.getInputStream());
OMElement child2 = (OMElement) child1.getNextOMSibling();
assertFalse(child2.isComplete());
assertEquals(s, child2.getText());
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestDetachWithStream method runTest.
@Override
protected final void runTest() throws Throwable {
InstrumentedStream stream = streamType.instrumentStream(streamType.getStream(XMLSample.LARGE));
OMXMLParserWrapper builder;
if (useStreamSource) {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), streamType.createStreamSource(stream));
} else {
builder = streamType.getAdapter(StreamTypeAdapter.class).createOMBuilder(metaFactory.getOMFactory(), stream);
}
long countBeforeDetach = stream.getCount();
builder.detach();
assertThat(stream.getCount()).isGreaterThan(countBeforeDetach);
assertThat(stream.isClosed()).isFalse();
stream.close();
builder.getDocument().build();
}
Aggregations