protected void setUp() throws Exception { XMLUnit.setIgnoreWhitespace(true); }
private void regenerateContext() { namespaceContext = new SimpleNamespaceContext(namespaces); }
public class IgnoreNamedElementsDifferenceListener implements DifferenceListener { private Set<String> blackList = new HashSet<String>(); public IgnoreNamedElementsDifferenceListener(String ... elementNames) { for (String name : elementNames) { blackList.add(name); } } public int differenceFound(Difference difference) { if (difference.getId() == DifferenceConstants.TEXT_VALUE_ID) { if (blackList.contains(difference.getControlNodeDetail().getNode().getParentNode().getNodeName())) { return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } } return DifferenceListener.RETURN_ACCEPT_DIFFERENCE; } public void skippedComparison(Node node, Node node1) { } }
public static void assertXmlEquals(String expected, String actual) throws Exception { XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(expected, actual); Assert.assertTrue(diff.toString(), diff.similar()); } }
public static void assertXmlSimilar(CharSequence expected, CharSequence actual) throws SAXException, IOException { Diff diff = new Diff(expected.toString(), actual.toString()); diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); assertXMLEqual(diff, true); } }
public PomAssert(String content) { this.content = content; this.eng = XMLUnit.newXpathEngine(); Map<String, String> context = new LinkedHashMap<>(); context.put("pom", "http://maven.apache.org/POM/4.0.0"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(context); this.eng.setNamespaceContext(namespaceContext); try { this.doc = XMLUnit.buildControlDocument(content); } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse XML", ex); } this.parentPom = parseParent(); parseProperties(); parseDependencies(); parseBoms(); parseRepositories(); }
@Override public boolean matches(Object item) { XpathEngine engine = XMLUnit.newXpathEngine(); engine.setNamespaceContext(namespaceContext); try { List<Node> nodes = nodeCollection(engine.getMatchingNodes(xPath, (Document) item)); return matcher.matches(nodes); } catch (XpathException e) { return false; } }
public void setUp() throws Exception { super.setUp(); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); setErrorMessage(null); }
@Override public void describeMismatch(Object item, Description description) { XpathEngine engine = XMLUnit.newXpathEngine(); engine.setNamespaceContext(namespaceContext); try { List<Node> nodes = nodeCollection(engine.getMatchingNodes(xPath, (Document) item)); matcher.describeMismatch(nodes, description); if (showXML != null) { printDom((Document) item, showXML); } } catch (XpathException e) { description.appendText("exception occured: ").appendText(e.getMessage()); } } };
@Test public void verifyBasicItem() throws Exception { Item simpleItem = new Item(); String simpleCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' />"; assertXMLEqual(simpleCtrl, simpleItem.toXML(null).toString()); Item idItem = new Item("uniqueid"); String idCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' id='uniqueid'/>"; assertXMLEqual(idCtrl, idItem.toXML(null).toString()); Item itemWithNodeId = new Item("testId", "testNode"); String nodeIdCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' id='testId' node='testNode' />"; assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML(null).toString()); }
@Test(dataProvider = "DocData") public void testSpellout(String tokenised, String expected) throws Exception { Document tokenisedDoc; Document expectedDoc; String tokens = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\" xml:lang=\"fr\"><p><s><t>" + tokenised + "</t></s></p></maryxml>"; tokenisedDoc = DomUtils.parseDocument(tokens); String words = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\" xml:lang=\"fr\"><p><s><mtu orig=\"" + tokenised + "\"><t>" + expected + "</t></mtu></s></p></maryxml>"; expectedDoc = DomUtils.parseDocument(words); module.checkForNumbers(tokenisedDoc); Diff diff = XMLUnit.compareXML(expectedDoc, tokenisedDoc); Assert.assertTrue(diff.identical()); }
public int differenceFound(Difference diff) { String nodeName = diff.getTestNodeDetail().getNode().getNodeName(); if( sequenceDoesNotMatter.contains(nodeName) && diff.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID ) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } logger.info( "! {}", diff.getTestNodeDetail().getNode().getNodeName()); return RETURN_ACCEPT_DIFFERENCE; }
public int differenceFound(Difference diff) { String nodeName = diff.getTestNodeDetail().getNode().getNodeName(); if (nodeName.equals("conditionExpression") || nodeName.equals("language")) { logger.info(diff.toString()); return RETURN_ACCEPT_DIFFERENCE; } return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; }
@Test public void verifyPayloadItem() throws Exception { SimplePayload payload = new SimplePayload("<data xmlns='https://example.org'>This is the payload</data>"); PayloadItem<SimplePayload> simpleItem = new PayloadItem<>(payload); String simpleCtrl = "<item xmlns='http://jabber.org/protocol/pubsub'>" + payload.toXML(null) + "</item>"; assertXMLEqual(simpleCtrl, simpleItem.toXML(null).toString()); PayloadItem<SimplePayload> idItem = new PayloadItem<>("uniqueid", payload); String idCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' id='uniqueid'>" + payload.toXML(null) + "</item>"; assertXMLEqual(idCtrl, idItem.toXML(null).toString()); PayloadItem<SimplePayload> itemWithNodeId = new PayloadItem<>("testId", "testNode", payload); String nodeIdCtrl = "<item xmlns='http://jabber.org/protocol/pubsub' id='testId' node='testNode'>" + payload.toXML(null) + "</item>"; assertXMLEqual(nodeIdCtrl, itemWithNodeId.toXML(null).toString()); }
@Test public void testOneWord() throws SynthesisException, ParserConfigurationException, SAXException, IOException, ParseException, MaryConfigurationException { String lemma = "7"; mary.setOutputType(MaryDataType.WORDS.name()); Document doc = mary.generateXML(lemma); String words = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\"><p><s><t>" + lemma + "</t></s></p></maryxml>"; Document expectedDoc = DomUtils.parseDocument(words); module.expand(expectedDoc); Diff diff = XMLUnit.compareXML(expectedDoc, doc); // issue where LocalMaryInterface#generateXML and DomUtils#parseDocument dont build the document in same order Assert.assertFalse(diff.identical()); }
protected void setUp() throws Exception { XMLUnit.setIgnoreWhitespace(true); }
@Test public void validateSimplePresence() throws Exception { // CHECKSTYLE:OFF String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>"; Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza)); assertXMLEqual(stanza, presence.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); // CHECKSTYLE:ON }
@Test public void shouldReturnValidIQStanzaXML() throws Exception { String control = XMLBuilder.create("data") .a("xmlns", "http://jabber.org/protocol/ibb") .a("seq", "0") .a("sid", "i781hf64") .t("DATA") .asString(outputProperties); DataPacketExtension data = new DataPacketExtension("i781hf64", 0, "DATA"); assertXMLEqual(control, data.toXML(null).toString()); }
@Test public void checkSlotRequestCreationWithoutContentType() throws SAXException, IOException { SlotRequest slotRequest = new SlotRequest(JidTestUtil.DOMAIN_BARE_JID_1, "my_romeo.png", 52523); Assert.assertEquals("my_romeo.png", slotRequest.getFilename()); Assert.assertEquals(52523, slotRequest.getSize()); Assert.assertEquals(null, slotRequest.getContentType()); assertXMLEqual(testRequestWithoutContentType, slotRequest.getChildElementXML().toString()); }
@Test public void checkSlotRequestCreation() throws SAXException, IOException { SlotRequest slotRequest = new SlotRequest(JidTestUtil.DOMAIN_BARE_JID_1, "my_juliet.png", 23456, "image/jpeg"); Assert.assertEquals("my_juliet.png", slotRequest.getFilename()); Assert.assertEquals(23456, slotRequest.getSize()); Assert.assertEquals("image/jpeg", slotRequest.getContentType()); assertXMLEqual(testRequest, slotRequest.getChildElementXML().toString()); }