XmlTransformerImpl implements XmlTransformer { @Override public String transform(Document xmlDocument, Source xslSource, Optional<Params> params, Optional<URIResolver> uriResolver) { return transformToStreamResult(new DOMSource(xmlDocument), xslSource, params, uriResolver).getOutputStream().toString(); } XmlTransformerImpl(SimpleMarshaller marshaller); @Override String transform(Document xmlDocument, Source xslSource,
			Optional<Params> params, Optional<URIResolver> uriResolver); @Override String transform(Document xmlDocument, String xslFileName,
			Optional<Params> params, Optional<URIResolver> uriResolver); @Override String transform(Object obj, String xslFileName,
			Optional<Params> params, Optional<URIResolver> uriResolver); @Override String transform(Source xmlSource, Source xslSource,
			Optional<Params> params, Optional<URIResolver> uriResolver); @Override String transform(String xml, String xslFileName,
			Optional<Params> params, Optional<URIResolver> uriResolver);  }
@Test public void testTransformDocumentSourceOptionalOfParamsOptionalOfURIResolver() throws SAXException, IOException { final Document xmlDocument = documentXmlConverter.loadDocument(doc); final StreamSource xslSource = new StreamSource(Thread.currentThread() .getContextClassLoader().getResourceAsStream(xslName)); final String actualOutput = sut.transform(xmlDocument, xslSource, params, uriResolver); assertTrue(compareXMLs(docTransformed, actualOutput, ignoreList) .similar()); }
@Test public void testTransformDocumentStringOptionalOfParamsOptionalOfURIResolver() { final Document xmlDocument = documentXmlConverter.loadDocument(doc); final String xslFileName = xslUrl; final String actualOutput = sut.transform(xmlDocument, xslFileName, params, uriResolver); assertTrue(compareXMLs(docTransformed, actualOutput, ignoreList) .similar()); }
@Test public void testTransformObjectStringOptionalOfParamsOptionalOfURIResolver() throws SimpleMarshallerException, UnsupportedEncodingException { final Object obj = mock(Object.class); final ByteArrayOutputStream byteArrayOutputStream = mock(ByteArrayOutputStream.class); when(marshaller.marshalAsByteArrayOutputStream(obj)).thenReturn( byteArrayOutputStream); when(byteArrayOutputStream.toByteArray()).thenReturn( doc.getBytes("UTF-8")); final String xslFileName = xslUrl; final String actualOutput = sut.transform(obj, xslFileName, params, uriResolver); assertTrue(compareXMLs(docTransformed, actualOutput, ignoreList) .similar()); }
@Test public void testTransformSourceSourceOptionalOfParamsOptionalOfURIResolver() throws UnsupportedEncodingException { final Source xmlSource = new StreamSource(new ByteArrayInputStream( doc.getBytes("UTF-8"))); final Source xslSource = new StreamSource(Thread.currentThread() .getContextClassLoader().getResourceAsStream(xslName)); final String actualOutput = sut.transform(xmlSource, xslSource, params, uriResolver); assertTrue(compareXMLs(docTransformed, actualOutput, ignoreList) .similar()); }
@Test public void testTransformStringStringOptionalOfParamsOptionalOfURIResolver() { final String actualOutput = sut.transform(doc, xslUrl, params, uriResolver); assertTrue(compareXMLs(docTransformed, actualOutput, ignoreList) .similar()); }