Search in sources :

Example 1 with Entry

use of com.rometools.rome.feed.atom.Entry in project spring-framework by spring-projects.

the class AtomFeedHttpMessageConverterTests method read.

@Test
public void read() throws IOException {
    InputStream is = getClass().getResourceAsStream("atom.xml");
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
    inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", StandardCharsets.UTF_8));
    Feed result = converter.read(Feed.class, inputMessage);
    assertEquals("title", result.getTitle());
    assertEquals("subtitle", result.getSubtitle().getValue());
    List<?> entries = result.getEntries();
    assertEquals(2, entries.size());
    Entry entry1 = (Entry) entries.get(0);
    assertEquals("id1", entry1.getId());
    assertEquals("title1", entry1.getTitle());
    Entry entry2 = (Entry) entries.get(1);
    assertEquals("id2", entry2.getId());
    assertEquals("title2", entry2.getTitle());
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) Entry(com.rometools.rome.feed.atom.Entry) InputStream(java.io.InputStream) MediaType(org.springframework.http.MediaType) Feed(com.rometools.rome.feed.atom.Feed) Test(org.junit.Test)

Example 2 with Entry

use of com.rometools.rome.feed.atom.Entry 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)

Aggregations

Entry (com.rometools.rome.feed.atom.Entry)2 Feed (com.rometools.rome.feed.atom.Feed)2 Test (org.junit.Test)2 MediaType (org.springframework.http.MediaType)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)1 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)1 DefaultNodeMatcher (org.xmlunit.diff.DefaultNodeMatcher)1 NodeMatcher (org.xmlunit.diff.NodeMatcher)1