Search in sources :

Example 1 with Action

use of org.apache.axiom.testutils.concurrent.Action in project webservices-axiom by apache.

the class TestCreateXMLStreamReaderThreadSafety method runTest.

protected void runTest() throws Throwable {
    final XMLInputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.newNormalizedXMLInputFactory());
    ConcurrentTestUtils.testThreadSafety(new Action() {

        public void execute() throws Exception {
            String text = String.valueOf((int) (Math.random() * 10000));
            String xml = "<root>" + text + "</root>";
            XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
            assertEquals(XMLStreamReader.START_DOCUMENT, reader.getEventType());
            assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
            assertEquals(XMLStreamReader.CHARACTERS, reader.next());
            assertEquals(text, reader.getText());
            assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
            assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
            reader.close();
        }
    });
}
Also used : Action(org.apache.axiom.testutils.concurrent.Action) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 2 with Action

use of org.apache.axiom.testutils.concurrent.Action in project webservices-axiom by apache.

the class TestCreateXMLStreamWriterThreadSafety method runTest.

@SuppressWarnings("deprecation")
protected void runTest() throws Throwable {
    final XMLOutputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.newNormalizedXMLOutputFactory());
    ConcurrentTestUtils.testThreadSafety(new Action() {

        public void execute() throws Exception {
            String text = String.valueOf((int) (Math.random() * 10000));
            StringWriter out = new StringWriter();
            XMLStreamWriter writer = factory.createXMLStreamWriter(out);
            writer.writeStartElement("root");
            writer.writeCharacters(text);
            writer.writeEndElement();
            writer.writeEndDocument();
            writer.flush();
            writer.close();
            assertEquals("<root>" + text + "</root>", out.toString());
        }
    });
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) Action(org.apache.axiom.testutils.concurrent.Action) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

Action (org.apache.axiom.testutils.concurrent.Action)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1