Search in sources :

Example 26 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class JdbcUtilTest method testWarningsToXml.

@Test
public void testWarningsToXml() throws SAXException {
    String expected = getExpectedWarningXml();
    XmlWriter writer = new XmlWriter();
    PrettyPrintFilter ppf = new PrettyPrintFilter(writer);
    try (SaxElementBuilder seb = new SaxElementBuilder(ppf)) {
        JdbcUtil.warningsToXml(getWarnings(), seb);
        MatchUtils.assertXmlEquals(expected, writer.toString());
    }
}
Also used : SaxElementBuilder(nl.nn.adapterframework.xml.SaxElementBuilder) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter) Test(org.junit.Test)

Example 27 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class XmlUtilsTest method testIdentityTransformWithDefaultEntityResolver.

@Test
public void testIdentityTransformWithDefaultEntityResolver() throws Exception {
    // External EntityResolving is still possible with the XMLEntityResolver
    Resource resource = Resource.getResource(new TestScopeProvider(), "XmlUtils/EntityResolution/in-file-entity-c-temp.xml");
    SAXException thrown = assertThrows(SAXException.class, () -> {
        XmlUtils.parseXml(resource, new XmlWriter());
    });
    String errorMessage = "Cannot get resource for publicId [null] with systemId [file:///c:/temp/test.xml] in scope [URLResource ";
    assertTrue("SaxParseException should start with [Cannot get resource ...] but is [" + thrown.getMessage() + "]", thrown.getMessage().startsWith(errorMessage));
}
Also used : TestScopeProvider(nl.nn.adapterframework.testutil.TestScopeProvider) Resource(nl.nn.adapterframework.core.Resource) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 28 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class XmlParserTest method testParseXmlResourceWithExternalEntityInjection.

@Test
@Ignore("requires proper setup on the classpath filesystem. In order for this test to pass properly, the file referenced by the external entity in the input file must exist on the file system. " + "I currently consider it too much of a hassle to automate this setup in a way that works for both Windows and Linux")
public void testParseXmlResourceWithExternalEntityInjection() throws IOException, SAXException, ParserConfigurationException {
    Resource input = Resource.getResource("/XmlUtils/EntityResolution/in-file-entity-c-temp.xml");
    String expected = TestFileUtils.getTestFile("/XmlUtils/EntityResolution/out-resolved.xml");
    XmlWriter writer = new XmlWriter();
    XmlUtils.parseXml(input, writer);
    MatchUtils.assertXmlEquals(expected, writer.toString());
}
Also used : Resource(nl.nn.adapterframework.core.Resource) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class XmlParserTest method testParseXmlNoRelativeEntityInjection.

@Test
public void testParseXmlNoRelativeEntityInjection() throws IOException, SAXException {
    URL input = TestFileUtils.getTestFileURL("/XmlUtils/EntityResolution/in-relative-entity.xml");
    String expected = TestFileUtils.getTestFile("/XmlUtils/EntityResolution/out-not-resolved.xml");
    XmlWriter writer = new XmlWriter();
    InputSource source = Message.asInputSource(input);
    XmlUtils.parseXml(source, writer);
    MatchUtils.assertXmlEquals(expected, writer.toString());
}
Also used : InputSource(org.xml.sax.InputSource) URL(java.net.URL) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Example 30 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class XmlParserTest method testParseXmlResourceWithRelativeEntityInjection.

@Test
public void testParseXmlResourceWithRelativeEntityInjection() throws IOException, SAXException, ParserConfigurationException {
    Resource input = Resource.getResource("/XmlUtils/EntityResolution/in-relative-entity.xml");
    String expected = TestFileUtils.getTestFile("/XmlUtils/EntityResolution/out-resolved.xml");
    XmlWriter writer = new XmlWriter();
    XmlUtils.parseXml(input, writer);
    MatchUtils.assertXmlEquals(expected, writer.toString());
}
Also used : Resource(nl.nn.adapterframework.core.Resource) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Aggregations

XmlWriter (nl.nn.adapterframework.xml.XmlWriter)33 Test (org.junit.Test)15 PrettyPrintFilter (nl.nn.adapterframework.xml.PrettyPrintFilter)11 ContentHandler (org.xml.sax.ContentHandler)11 SAXException (org.xml.sax.SAXException)9 Resource (nl.nn.adapterframework.core.Resource)7 IOException (java.io.IOException)6 StringWriter (java.io.StringWriter)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Writer (java.io.Writer)4 XmlTee (nl.nn.adapterframework.stream.xml.XmlTee)4 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 URL (java.net.URL)3 ValidatorHandler (javax.xml.validation.ValidatorHandler)3 ConfigurationDigester (nl.nn.adapterframework.configuration.ConfigurationDigester)3 Message (nl.nn.adapterframework.stream.Message)3 JsonWriter (nl.nn.adapterframework.stream.json.JsonWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 Properties (java.util.Properties)2