Search in sources :

Example 1 with DataSourceRegistration

use of org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration 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 DataSourceRegistration

use of org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration 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)

Example 3 with DataSourceRegistration

use of org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration in project webservices-axiom by apache.

the class DataSourceRegistryTest method test.

public void test() throws Exception {
    RandomDataSource ds = new RandomDataSource(1000);
    DataSourceRegistration registration = DataSourceRegistry.registerDataSource(ds);
    try {
        // We must be able to connect to the URL after converting it to a String
        URL url = new URL(registration.getURL().toString());
        URLConnection connection = url.openConnection();
        IOTestUtils.compareStreams(connection.getInputStream(), "actual", ds.getInputStream(), "expected");
    } finally {
        registration.unregister();
    }
}
Also used : RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSourceRegistration(org.apache.axiom.testutils.net.protocol.mem.DataSourceRegistration) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

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