Search in sources :

Example 1 with DefaultNodeMatcher

use of org.xmlunit.diff.DefaultNodeMatcher in project spring-framework by spring-projects.

the class AtomFeedHttpMessageConverterTests method write.

@Test
public void write() throws IOException, SAXException {
    Feed feed = new Feed("atom_1.0");
    feed.setTitle("title");
    Entry entry1 = new Entry();
    entry1.setId("id1");
    entry1.setTitle("title1");
    Entry entry2 = new Entry();
    entry2.setId("id2");
    entry2.setTitle("title2");
    List<Entry> entries = new ArrayList<>(2);
    entries.add(entry1);
    entries.add(entry2);
    feed.setEntries(entries);
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(feed, null, outputMessage);
    assertEquals("Invalid content-type", new MediaType("application", "atom+xml", StandardCharsets.UTF_8), outputMessage.getHeaders().getContentType());
    String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" + "<entry><id>id1</id><title>title1</title></entry>" + "<entry><id>id2</id><title>title2</title></entry></feed>";
    NodeMatcher nm = new DefaultNodeMatcher(ElementSelectors.byName);
    assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo(expected).ignoreWhitespace().withNodeMatcher(nm));
}
Also used : Entry(com.rometools.rome.feed.atom.Entry) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) ArrayList(java.util.ArrayList) MediaType(org.springframework.http.MediaType) Feed(com.rometools.rome.feed.atom.Feed) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) NodeMatcher(org.xmlunit.diff.NodeMatcher) Test(org.junit.Test)

Example 2 with DefaultNodeMatcher

use of org.xmlunit.diff.DefaultNodeMatcher in project jabref by JabRef.

the class BibTeXMLExporterTestFiles method testPerformExport.

@Test
public final void testPerformExport() throws IOException, SaveException {
    String xmlFileName = filename.replace(".bib", ".xml");
    Path importFile = resourceDir.resolve(filename);
    String tempFilename = tempFile.getCanonicalPath();
    List<BibEntry> entries = testImporter.importDatabase(importFile, StandardCharsets.UTF_8).getDatabase().getEntries();
    bibtexmlExportFormat.performExport(databaseContext, tempFile.getPath(), charset, entries);
    Builder control = Input.from(Files.newInputStream(resourceDir.resolve(xmlFileName)));
    Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
    Assert.assertThat(test, CompareMatcher.isSimilarTo(control).withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) Builder(org.xmlunit.builder.Input.Builder) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) Test(org.junit.Test)

Example 3 with DefaultNodeMatcher

use of org.xmlunit.diff.DefaultNodeMatcher in project jabref by JabRef.

the class MSBibExportFormatTestFiles method testPerformExport.

@Test
public final void testPerformExport() throws IOException, SaveException {
    String xmlFileName = filename.replace(".bib", ".xml");
    Path importFile = resourceDir.resolve(filename);
    String tempFilename = tempFile.getCanonicalPath();
    List<BibEntry> entries = testImporter.importDatabase(importFile, StandardCharsets.UTF_8).getDatabase().getEntries();
    msBibExportFormat.performExport(databaseContext, tempFile.getPath(), charset, entries);
    Builder control = Input.from(Files.newInputStream(resourceDir.resolve(xmlFileName)));
    Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
    assertThat(test, CompareMatcher.isSimilarTo(control).withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) Builder(org.xmlunit.builder.Input.Builder) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) Test(org.junit.Test)

Example 4 with DefaultNodeMatcher

use of org.xmlunit.diff.DefaultNodeMatcher in project jabref by JabRef.

the class ModsExportFormatTestFiles method testImportAsModsAndExportAsMods.

@Test
public final void testImportAsModsAndExportAsMods() throws Exception {
    String xmlFileName = filename.replace(".bib", ".xml");
    String tempFilename = tempFile.getCanonicalPath();
    Path xmlFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI());
    List<BibEntry> entries = modsImporter.importDatabase(xmlFile, charset).getDatabase().getEntries();
    modsExportFormat.performExport(databaseContext, tempFile.getPath(), charset, entries);
    Builder control = Input.from(Files.newInputStream(xmlFile));
    Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
    Assert.assertThat(test, CompareMatcher.isSimilarTo(control).withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) Builder(org.xmlunit.builder.Input.Builder) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) Test(org.junit.Test)

Example 5 with DefaultNodeMatcher

use of org.xmlunit.diff.DefaultNodeMatcher in project jabref by JabRef.

the class ModsExportFormatTestFiles method testPerformExport.

@Test
public final void testPerformExport() throws Exception {
    String xmlFileName = filename.replace(".bib", ".xml");
    String tempFilename = tempFile.getCanonicalPath();
    List<BibEntry> entries = bibtexImporter.importDatabase(importFile, charset).getDatabase().getEntries();
    Path xmlFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI());
    modsExportFormat.performExport(databaseContext, tempFile.getPath(), charset, entries);
    Builder control = Input.from(Files.newInputStream(xmlFile));
    Builder test = Input.from(Files.newInputStream(Paths.get(tempFilename)));
    Assert.assertThat(test, CompareMatcher.isSimilarTo(control).withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) Builder(org.xmlunit.builder.Input.Builder) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 DefaultNodeMatcher (org.xmlunit.diff.DefaultNodeMatcher)5 Path (java.nio.file.Path)4 BibEntry (org.jabref.model.entry.BibEntry)4 Builder (org.xmlunit.builder.Input.Builder)4 Entry (com.rometools.rome.feed.atom.Entry)1 Feed (com.rometools.rome.feed.atom.Feed)1 ArrayList (java.util.ArrayList)1 MediaType (org.springframework.http.MediaType)1 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)1 NodeMatcher (org.xmlunit.diff.NodeMatcher)1