Search in sources :

Example 1 with InstrumentedDataSource

use of org.apache.axiom.testutils.activation.InstrumentedDataSource in project webservices-axiom by apache.

the class TestCloseWithSystemId method runTest.

@Override
protected void runTest() throws Throwable {
    InstrumentedDataSource ds = new InstrumentedDataSource(new URLDataSource(XMLSample.SIMPLE.getUrl()));
    DataSourceRegistration registration = DataSourceRegistry.registerDataSource(ds);
    try {
        OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StreamSource(registration.getURL().toExternalForm()));
        builder.getDocumentElement();
        builder.close();
        // Since the caller doesn't have control over the stream, the builder is responsible
        // for closing it.
        assertThat(ds.getOpenStreamCount()).isEqualTo(0);
    } finally {
        registration.unregister();
    }
}
Also used : InstrumentedDataSource(org.apache.axiom.testutils.activation.InstrumentedDataSource) URLDataSource(javax.activation.URLDataSource) StreamSource(javax.xml.transform.stream.StreamSource) DataSourceRegistration(org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 2 with InstrumentedDataSource

use of org.apache.axiom.testutils.activation.InstrumentedDataSource in project webservices-axiom by apache.

the class TestParseURI method runTest.

protected void runTest() throws Throwable {
    InstrumentedDataSource ds = new InstrumentedDataSource(new URLDataSource(XMLSample.SIMPLE.getUrl()));
    DataSourceRegistration registration = DataSourceRegistry.registerDataSource(ds);
    try {
        DocumentBuilder builder = dbf.newDocumentBuilder();
        Document document = builder.parse(registration.getURL().toExternalForm());
        assertThat(document.getDocumentElement().getLocalName()).isEqualTo("root");
        assertThat(ds.getOpenStreamCount()).isEqualTo(0);
    } finally {
        registration.unregister();
    }
}
Also used : InstrumentedDataSource(org.apache.axiom.testutils.activation.InstrumentedDataSource) URLDataSource(javax.activation.URLDataSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DataSourceRegistration(org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration) Document(org.w3c.dom.Document)

Aggregations

URLDataSource (javax.activation.URLDataSource)2 InstrumentedDataSource (org.apache.axiom.testutils.activation.InstrumentedDataSource)2 DataSourceRegistration (org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 StreamSource (javax.xml.transform.stream.StreamSource)1 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)1 Document (org.w3c.dom.Document)1