Java Code Examples for org.custommonkey.xmlunit.XMLUnit#setIgnoreWhitespace()
The following examples show how to use
org.custommonkey.xmlunit.XMLUnit#setIgnoreWhitespace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SuggestTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws FileNotFoundException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { XMLUnit.setIgnoreWhitespace(true); Common.connectAdmin(); writeOptions(Common.adminClient); Common.adminClient.newServerConfigManager().setServerRequestLogging(true); Common.connect(); // write three files for alert tests. XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write("/sample/suggestion.xml", new StringHandle("<suggest><string>FINDME</string>Something I love to suggest is sugar with savory succulent limes.</suggest>")); docMgr.write("/sample2/suggestion.xml", new StringHandle("<suggest>Something I hate to suggest is liver with lard.</suggest>")); }
Example 2
Source File: AnalysisEngineFactoryTest.java From uima-uimafit with Apache License 2.0 | 6 votes |
@Test public void serializeComponent() throws Exception { File reference = new File("src/test/resources/data/reference/SerializationTestAnnotator.xml"); File target = new File("target/test-output/AnalysisEngineFactoryTest/SerializationTestAnnotator.xml"); target.getParentFile().mkdirs(); AnalysisEngineDescription desc = createEngineDescription(SerializationTestAnnotator.class); try (OutputStream os = new FileOutputStream(target)) { desc.toXML(os); } String actual = FileUtils.readFileToString(target, "UTF-8"); String expected = FileUtils.readFileToString(reference, "UTF-8"); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(expected, actual); // assertEquals(expected, actual); }
Example 3
Source File: TckValidator.java From juddi with Apache License 2.0 | 6 votes |
public static void checkKeyInfo(KeyInfoType kit1, KeyInfoType kit2) { if (kit1 == null || kit2 == null) { assertEquals(kit1, kit2); return; } assertEquals(kit1.getId(), kit2.getId()); DOMResult domResult1 = new DOMResult(); DOMResult domResult2 = new DOMResult(); JAXB.marshal(kit1, domResult1); JAXB.marshal(kit2, domResult2); Document doc1 = (Document)domResult1.getNode(); DOMSource domSource1 = new DOMSource(doc1.getDocumentElement()); Document doc2 = (Document)domResult2.getNode(); DOMSource domSource2 = new DOMSource(doc2.getDocumentElement()); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(domSource1, domSource2); assertTrue("Key info elements should match", diff.similar()); }
Example 4
Source File: JaxbWlsTest.java From tomee with Apache License 2.0 | 6 votes |
public void marshallAndUnmarshall(final String xmlFile) throws Exception { final InputStream in = this.getClass().getClassLoader().getResourceAsStream(xmlFile); final String expected = readContent(in); final Object object = JaxbWls.unmarshal(WeblogicEjbJar.class, new ByteArrayInputStream(expected.getBytes())); final JAXBElement element = (JAXBElement) object; assertTrue(element.getValue() instanceof WeblogicEjbJar); final String actual = JaxbWls.marshal(WeblogicEjbJar.class, element); XMLUnit.setIgnoreWhitespace(true); try { final Diff myDiff = new DetailedDiff(new Diff(expected, actual)); assertTrue("Files are not similar " + myDiff, myDiff.similar()); } catch (final AssertionFailedError e) { assertEquals(expected, actual); throw e; } }
Example 5
Source File: WsdlTest.java From iaf with Apache License 2.0 | 6 votes |
protected void test(Wsdl wsdl, String testWsdl) throws IOException, SAXException, ParserConfigurationException, XMLStreamException, URISyntaxException, NamingException, ConfigurationException { wsdl.setDocumentation("test"); ByteArrayOutputStream out = new ByteArrayOutputStream(); wsdl.wsdl(out, "Test"); DocumentBuilder dbuilder = createDocumentBuilder(); Document result = dbuilder.parse(new ByteArrayInputStream(out.toByteArray())); Document expected = dbuilder.parse(getClass().getClassLoader().getResourceAsStream(testWsdl)); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); assertXMLEqual("expected xml (" + testWsdl + ") not similar to result xml:\n" + new String(out.toByteArray()), expected, result); zip(wsdl); }
Example 6
Source File: ResourceExtensionsTest.java From java-client-api with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws IOException { Common.connectAdmin(); resourceServices = Common.testFileToString(XQUERY_FILE); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); Map<String,String> namespaces = new HashMap<>(); namespaces.put("rapi", "http://marklogic.com/rest-api"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(namespaces); xpather = XMLUnit.newXpathEngine(); xpather.setNamespaceContext(namespaceContext); }
Example 7
Source File: FullRoundtripTest.java From dashencrypt with Mozilla Public License 2.0 | 6 votes |
@Test public void testEncrypt2_plain() throws Exception { File outputDir = File.createTempFile("FullRoundtrip", "testEncrypt2"); outputDir.delete(); outputDir.mkdir(); Main.main(new String[]{ "encrypt2", "-o", outputDir.getAbsolutePath(), new File(tos, "tears_of_steel/Tears_Of_Steel_1000000.mp4").getAbsolutePath(), new File(tos, "tears_of_steel/Tears_Of_Steel_1400000.mp4").getAbsolutePath(), new File(tos, "tears_of_steel/Tears_Of_Steel_800000.mp4").getAbsolutePath(), new File(tos, "tears_of_steel/Tears_Of_Steel_600000.mp4").getAbsolutePath(), new File(tos, "tears_of_steel/Tears_Of_Steel_128000_eng.mp4").getAbsolutePath(), new File(tos, "tears_of_steel/Tears_Of_Steel_128000_ita.mp4").getAbsolutePath(), }); XMLUnit.setIgnoreWhitespace(true); XMLAssert.assertXMLEqual(new InputSource(getClass().getResourceAsStream("testEncrypt2_plain.mpd")), new InputSource(new FileInputStream(new File(outputDir, "Manifest.mpd")))); FileUtils.deleteDirectory(outputDir); }
Example 8
Source File: XmlExpectationsHelper.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Parse the expected and actual content strings as XML and assert that the * two are "similar" -- i.e. they contain the same elements and attributes * regardless of order. * <p>Use of this method assumes the * <a href="http://xmlunit.sourceforge.net/">XMLUnit<a/> library is available. * @param expected the expected XML content * @param actual the actual XML content * @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Object...) * @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...) */ public void assertXmlEqual(String expected, String actual) throws Exception { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); Document control = XMLUnit.buildControlDocument(expected); Document test = XMLUnit.buildTestDocument(actual); Diff diff = new Diff(control, test); if (!diff.similar()) { AssertionErrors.fail("Body content " + diff.toString()); } }
Example 9
Source File: RadlFileAssemblerTest.java From RADL with Apache License 2.0 | 5 votes |
private void assertXmlEquals(File file1, File file2) throws Exception { XMLUnit.setIgnoreWhitespace(true); try (FileInputStream ins1 = new FileInputStream(file1)) { try (FileInputStream ins2 = new FileInputStream(file2)) { XMLAssert.assertXMLEqual("XML Compare", new InputSource(ins1), new InputSource(ins2)); } } }
Example 10
Source File: ODataXmlDeserializerTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() { XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setCompareUnmatched(false); }
Example 11
Source File: SxmpWriterTest.java From cloudhopper-commons with Apache License 2.0 | 5 votes |
@Test public void writeDeliverRequestWithTicketId0() throws Exception { DeliverRequest request = new DeliverRequest(); request.setAccount(new Account("customer1", "test1")); request.setOperatorId(20); request.setTicketId("THISISATESTTICKETID"); request.setReferenceId("TESTREF"); request.setSourceAddress(new MobileAddress(MobileAddress.Type.NETWORK, "40404")); request.setDestinationAddress(new MobileAddress(MobileAddress.Type.INTERNATIONAL, "+13135551212")); request.setText("Hello World"); StringWriter sw = new StringWriter(); SxmpWriter.write(sw, request); logger.debug(sw.toString()); StringBuilder expectedXML = new StringBuilder(200) .append("<?xml version=\"1.0\"?>\n") .append("<operation type=\"deliver\">\n") .append(" <account username=\"customer1\" password=\"test1\"/>\n") .append(" <deliverRequest referenceId=\"TESTREF\">\n") .append(" <ticketId>THISISATESTTICKETID</ticketId>") .append(" <operatorId>20</operatorId>\n") .append(" <priority>0</priority>\n") .append(" <sourceAddress type=\"network\">40404</sourceAddress>\n") .append(" <destinationAddress type=\"international\">+13135551212</destinationAddress>\n") .append(" <text encoding=\"UTF-8\">48656C6C6F20576F726C64</text>\n") .append(" </deliverRequest>\n") .append("</operation>\n") .append(""); // compare to actual correct submit response XMLUnit.setIgnoreWhitespace(true); Diff myDiff = new Diff(expectedXML.toString(), sw.toString()); DetailedDiff myDetailedDiff = new DetailedDiff(myDiff); Assert.assertTrue("XML are similar " + myDetailedDiff, myDetailedDiff.similar()); }
Example 12
Source File: Bug5446Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang"); final Document doc = loadDocument("/bug5446/xml/foo.xml"); final ContainerNode docNode = createDocNode(); Optional<DataContainerChild<? extends PathArgument, ?>> root = docNode.getChild(new NodeIdentifier(ROOT_QNAME)); assertTrue(root.orElse(null) instanceof ContainerNode); Optional<DataContainerChild<? extends PathArgument, ?>> child = ((ContainerNode) root.orElse(null)) .getChild(new NodeIdentifier(IP_ADDRESS_QNAME)); assertTrue(child.orElse(null) instanceof LeafNode); LeafNode<?> ipAdress = (LeafNode<?>) child.get(); Object value = ipAdress.getValue(); assertTrue(value instanceof byte[]); assertEquals("fwAAAQ==", Base64.getEncoder().encodeToString((byte[]) value)); DOMResult serializationResult = writeNormalizedNode(docNode, schemaContext); assertNotNull(serializationResult); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalize(true); String expectedXMLString = toString(doc.getDocumentElement()); String serializationResultXMLString = toString(serializationResult.getNode()); assertXMLEqual(expectedXMLString, serializationResultXMLString); }
Example 13
Source File: RssChannelHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Before public void setUp() { utf8 = Charset.forName("UTF-8"); converter = new RssChannelHttpMessageConverter(); XMLUnit.setIgnoreWhitespace(true); }
Example 14
Source File: TransferResourceTest.java From oodt with Apache License 2.0 | 4 votes |
/** * Tests that {@link TransferResource transfer resources} are marshalled to * the expected XML format. * @throws IOException if the {@link Diff} constructor fails * @throws JAXBException if the {@link JAXBContext} or {@link Marshaller} fail * @throws MimeTypeException if {@link MimeTypes#forName(String)} fails * @throws SAXException if the {@link Diff} constructor fails */ @Test public void testXmlMarshalling() throws IOException, JAXBException, MimeTypeException, SAXException { // Create a TransferResource using ProductType, Product, Metadata, Reference // and FileTransferStatus instances. Hashtable metadataEntries = new Hashtable<String, Object>(); metadataEntries.put("CAS.ProductReceivedTime", "2013-09-12T16:25:50.662Z"); Metadata metadata = new Metadata(); metadata.addMetadata(metadataEntries); Reference reference = new Reference("original", "dataStore", 1000, new MimeTypes().forName("text/plain")); ProductType productType = new ProductType("1", "GenericFile", "test type", "repository", "versioner"); Product product = new Product(); product.setProductId("123"); product.setProductName("test product"); product.setProductStructure(Product.STRUCTURE_FLAT); product.setProductType(productType); FileTransferStatus status = new FileTransferStatus(reference, 1000, 100, product); TransferResource resource = new TransferResource(product, metadata, status); // Generate the expected output. String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<transfer>" + "<productName>" + product.getProductName() + "</productName>" + "<productId>" + product.getProductId() + "</productId>" + "<productTypeName>" + productType.getName() + "</productTypeName>" + "<dataStoreReference>" + reference.getDataStoreReference() + "</dataStoreReference>" + "<origReference>" + reference.getOrigReference() + "</origReference>" + "<mimeType>" + reference.getMimeType().getName() + "</mimeType>" + "<fileSize>" + reference.getFileSize() + "</fileSize>" + "<totalBytes>" + reference.getFileSize() + "</totalBytes>" + "<bytesTransferred>" + status.getBytesTransferred() + "</bytesTransferred>" + "<percentComplete>" + status.computePctTransferred() * 100 + "</percentComplete>" + "<productReceivedTime>" + metadata.getAllValues().get(0) + "</productReceivedTime>" + "</transfer>"; // Set up a JAXB context and marshall the DatasetResource to XML. JAXBContext context = JAXBContext.newInstance(resource.getClass()); Marshaller marshaller = context.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(resource, writer); // Compare the expected and actual outputs. XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); Diff diff = new Diff(expectedXml, writer.toString()); assertTrue("The output XML was different to the expected XML: " + diff.toString(), diff.identical()); }
Example 15
Source File: TransformersTest.java From proarc with GNU General Public License v3.0 | 4 votes |
@After public void tearDown() { assertTrue(externalConnections.toString(), externalConnections.isEmpty()); XMLUnit.setIgnoreWhitespace(false); XMLUnit.setNormalizeWhitespace(false); }
Example 16
Source File: ReferenceResourceTest.java From oodt with Apache License 2.0 | 4 votes |
/** * Tests that {@link ReferenceResource reference resources} are marshalled to * the expected XML format. * @throws IOException if the {@link Diff} constructor fails * @throws JAXBException if the {@link JAXBContext} or {@link Marshaller} fail * @throws MimeTypeException if {@link MimeTypes#forName(String)} fails * @throws SAXException if the {@link Diff} constructor fails */ @Test public void testXmlMarshalling() throws IOException, JAXBException, MimeTypeException, SAXException { String productId = "123"; int refIndex = 0; // Create a new ReferenceResource using a Reference instance. Reference reference = new Reference("original", "dataStore", 1000, new MimeTypes().forName("text/plain")); ReferenceResource resource = new ReferenceResource(productId, refIndex, reference, new File("/tmp")); // Generate the expected output. String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<reference>" + "<productId>" + productId + "</productId>" + "<refIndex>" + refIndex + "</refIndex>" + "<dataStoreReference>" + reference.getDataStoreReference() + "</dataStoreReference>" + "<originalReference>" + reference.getOrigReference() + "</originalReference>" + "<mimeType>" + reference.getMimeType().getName() + "</mimeType>" + "<fileSize>" + reference.getFileSize() + "</fileSize>" + "</reference>"; // Set up a JAXB context and marshall the ReferenceResource to XML. JAXBContext context = JAXBContext.newInstance(resource.getClass()); Marshaller marshaller = context.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(resource, writer); // Compare the expected and actual outputs. XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); Diff diff = new Diff(expectedXml, writer.toString()); assertTrue("The output XML was different to the expected XML: " + diff.toString(), diff.identical()); }
Example 17
Source File: XCalDocumentTest.java From biweekly with BSD 2-Clause "Simplified" License | 4 votes |
@BeforeClass public static void beforeClass() { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); }
Example 18
Source File: CasToInlineXmlTest.java From uima-uimaj with Apache License 2.0 | 4 votes |
public void testCasToInlineXml() throws Exception { // Jira https://issues.apache.org/jira/browse/UIMA-2406 File typeSystemFile1 = JUnitExtension.getFile("ExampleCas/testTypeSystem_arrays.xml"); File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes_arrays.xml"); TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile1)); FsIndexDescription[] indexes = UIMAFramework.getXMLParser().parseFsIndexCollection(new XMLInputSource(indexesFile)) .getFsIndexes(); CAS srcCas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); JCas jcas = srcCas.getJCas(); jcas.setDocumentText("1 2 3 4 5 6 7 8 9"); OfShorts f = new OfShorts(jcas); ShortArray a = new ShortArray(jcas, 3); a.set(0, (short)0); a.set(1, (short)1); a.set(2, (short)2); f.setF1Shorts(a); f.addToIndexes(); OfStrings ss = new OfStrings(jcas); StringArray sa = new StringArray(jcas, 3); sa.set(0, "0s"); sa.set(1, "1s"); sa.set(2, "2s"); ss.setF1Strings(sa); ss.addToIndexes(); CasToInlineXml c2x = new CasToInlineXml(); String result = c2x.generateXML(srcCas).trim(); System.out.println(result); int s = result.indexOf("<Document>"); result = result.substring(s); result = canonicalizeNl(result); // Java 9 xml formatter formats the text with a new line and indentations String expected = "<Document>\n" + IND+"<uima.tcas.DocumentAnnotation sofa=\"Sofa\" begin=\"0\" end=\"17\" language=\"x-unspecified\">\n" + IND+IND+"<org.apache.uima.testTypeSystem_arrays.OfStrings sofa=\"Sofa\" begin=\"0\" end=\"0\" f1Strings=\"[0s,1s,2s]\"/>\n" + IND+IND+"<org.apache.uima.testTypeSystem_arrays.OfShorts sofa=\"Sofa\" begin=\"0\" end=\"0\" f1Shorts=\"[0,1,2]\"/>" + (Misc.isJava9ea() ? "\n " : "") + "1 2 3 4 5 6 7 8 9" + (Misc.isJava9ea() ? "\n " : "") + "</uima.tcas.DocumentAnnotation>\n" + "</Document>"; for (int i = 0; i < result.length(); i++ ) { if (result.charAt(i) != expected.charAt(i)) { System.out.format("Unequal compare at position %,d, char code result = %d, expected = %d%n", i, (int)result.charAt(i), (int)expected.charAt(i)); break; } } boolean whitespaceFlag = XMLUnit.getIgnoreWhitespace(); XMLUnit.setIgnoreWhitespace(true); try { XMLAssert.assertXMLEqual(expected, result); } finally { XMLUnit.setIgnoreWhitespace(whitespaceFlag); } // assertEquals(expected, result.trim()); }
Example 19
Source File: XCalReaderTest.java From biweekly with BSD 2-Clause "Simplified" License | 4 votes |
@BeforeClass public static void beforeClass() { XMLUnit.setIgnoreWhitespace(true); }
Example 20
Source File: SxmpWriterTest.java From cloudhopper-commons with Apache License 2.0 | 4 votes |
@Test public void write10SubmitRequestWithoutIncludingOptionalParams() throws Exception { SubmitRequest request = new SubmitRequest(SxmpParser.VERSION_1_0); request.setAccount(new Account("customer1", "test1")); request.setOperatorId(20); request.setDestinationAddress(new MobileAddress(MobileAddress.Type.PUSH_DESTINATION, "abcd1234fghi")); request.setText("Hello World"); // use a tree map to get guaranteed key order OptionalParamMap optParams = new OptionalParamMap(OptionalParamMap.TREE_MAP); optParams.put("A", new Integer(42)); optParams.put("b", "value with unicode and UTF8 extended chars: € £ æ - \u20AC \u0623 \u0647 \u0644 "); optParams.put("c", "'sample' with XML-excaping: \n&\r<>'\""); optParams.put("e", new Integer(-42)); optParams.put("f", new Double(3.14159)); optParams.put("g", new Integer(33445566)); optParams.put("h", new Long(123456789123456l)); request.setOptionalParams(optParams); StringWriter sw = new StringWriter(); SxmpWriter.write(sw, request); logger.debug("UTF8 OPTIONAL PARAMS: "+sw.toString()); StringBuilder expectedXML = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") .append("<operation type=\"submit\">\n") .append(" <account username=\"customer1\" password=\"test1\"/>\n") .append(" <submitRequest>\n") .append(" <operatorId>20</operatorId>\n") .append(" <priority>0</priority>\n") .append(" <deliveryReport>false</deliveryReport>\n") .append(" <destinationAddress type=\"push_destination\">abcd1234fghi</destinationAddress>\n") .append(" <text encoding=\"UTF-8\">48656C6C6F20576F726C64</text>\n") .append(" </submitRequest>\n") .append("</operation>\n") .append(""); // compare to actual correct submit response XMLUnit.setIgnoreWhitespace(true); Diff myDiff = new Diff(expectedXML.toString(), sw.toString()); DetailedDiff myDetailedDiff = new DetailedDiff(myDiff); Assert.assertTrue("XML are similar " + myDetailedDiff, myDetailedDiff.similar()); }