use of org.apereo.portal.io.xml.XmlTestException in project uPortal by Jasig.
the class AbstractDom4jImporterExporterTest method testDom4jRoundTripWithComment.
@Test
public void testDom4jRoundTripWithComment() throws Exception {
final TestDom4jImporter importer = new TestDom4jImporter();
final TestDom4jExporter exporter = new TestDom4jExporter();
exporter.setXmlUtilities(new XmlUtilitiesImpl());
final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
final InputStream resource = this.getClass().getResourceAsStream("/org/apereo/portal/io/xml/crn/pilot-lo.fragment-layout.xml");
final XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(resource);
final Tuple<String, Element> result = importer.unmarshal(new StAXSource(xmlEventReader));
assertNotNull(result);
final StringWriter writer = new StringWriter();
exporter.marshal(result, new StreamResult(writer));
final String marshalResult = writer.toString();
assertNotNull(marshalResult);
XMLUnit.setIgnoreWhitespace(true);
try {
Diff d = new Diff(new InputStreamReader(this.getClass().getResourceAsStream("/org/apereo/portal/io/xml/crn/pilot-lo.fragment-layout.xml")), new StringReader(marshalResult));
assertTrue("Upgraded data doesn't match expected data: " + d, d.similar());
} catch (Exception e) {
throw new XmlTestException("Failed to assert similar between marshall output and expected XML", marshalResult, e);
} catch (Error e) {
throw new XmlTestException("Failed to assert similar between marshall output and expected XML", marshalResult, e);
}
}
use of org.apereo.portal.io.xml.XmlTestException in project uPortal by Jasig.
the class AbstractDom4jImporterExporterTest method testDom4jCommentFiltering.
@Test
public void testDom4jCommentFiltering() throws Exception {
final TestDom4jImporter importer = new TestDom4jImporter();
final TestDom4jExporter exporter = new TestDom4jExporter();
exporter.setXmlUtilities(new XmlUtilitiesImpl());
final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
final InputStream resource = this.getClass().getResourceAsStream("/org/apereo/portal/io/xml/crn/pilot-lo.fragment-layout.xml");
final XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(resource);
final Tuple<String, Element> result = importer.unmarshal(new StAXSource(xmlEventReader));
assertNotNull(result);
final Element document = result.getSecond();
final List<org.dom4j.Node> comments = document.selectNodes("//comment()");
for (final org.dom4j.Node comment : comments) {
comment.detach();
}
final StringWriter writer = new StringWriter();
exporter.marshal(result, new StreamResult(writer));
final String marshalResult = writer.toString();
assertNotNull(marshalResult);
XMLUnit.setIgnoreWhitespace(true);
try {
Diff d = new Diff(new InputStreamReader(this.getClass().getResourceAsStream("/org/apereo/portal/io/xml/crn/filtered-pilot-lo.fragment-layout.xml")), new StringReader(marshalResult));
assertTrue("Upgraded data doesn't match expected data: " + d, d.similar());
} catch (Exception e) {
throw new XmlTestException("Failed to assert similar between marshall output and expected XML", marshalResult, e);
} catch (Error e) {
throw new XmlTestException("Failed to assert similar between marshall output and expected XML", marshalResult, e);
}
}
use of org.apereo.portal.io.xml.XmlTestException in project uPortal by Jasig.
the class XSLTComponentTest method testXSLTComponent.
@Test
public void testXSLTComponent() throws Exception {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final XMLEventReader xmlEventReader = this.getXmlEventReader("juser.xml");
final PipelineEventReaderImpl<XMLEventReader, XMLEvent> cacheableEventReader = new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(xmlEventReader);
final Transformer transformer = this.getTransformer("columns.xsl");
final StAXPipelineComponent targetComponent = EasyMock.createMock(StAXPipelineComponent.class);
final TransformerSource transformerSource = EasyMock.createMock(TransformerSource.class);
EasyMock.expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(cacheableEventReader);
EasyMock.expect(transformerSource.getTransformer(mockReq, mockRes)).andReturn(transformer);
EasyMock.replay(targetComponent, transformerSource);
final XSLTComponent xsltComponent = new XSLTComponent();
xsltComponent.setWrappedComponent(targetComponent);
xsltComponent.setTransformerSource(transformerSource);
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = xsltComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(eventReader);
final String output = this.serializeXMLEventReader(eventReader.getEventReader());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setFeature("http://xml.org/sax/features/namespaces", false);
dbf.setFeature("http://xml.org/sax/features/validation", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final DocumentBuilder db = dbf.newDocumentBuilder();
XMLUnit.setIgnoreWhitespace(true);
try {
final Document expected = db.parse(this.getClass().getResourceAsStream("/org/apereo/portal/rendering/xslt/expected.xml"), "/org/apereo/portal/rendering/xslt/expected.xml");
final Document actual = db.parse(new InputSource(new StringReader(output)));
Diff d = new Diff(expected, actual);
assertTrue("Upgraded data doesn't match expected data: " + d, d.similar());
} catch (Exception e) {
throw new XmlTestException("Failed to assert similar between XSLT output and expected XML", output, e);
} catch (Error e) {
throw new XmlTestException("Failed to assert similar between XSLT output and expected XML", output, e);
}
EasyMock.verify(targetComponent, transformerSource);
}
Aggregations