Search in sources :

Example 1 with Feed

use of com.rometools.rome.feed.atom.Feed in project spring-mvc-showcase by spring-projects.

the class MessageConvertersController method writeFeed.

@GetMapping("/atom")
public Feed writeFeed() {
    Feed feed = new Feed();
    feed.setFeedType("atom_1.0");
    feed.setTitle("My Atom feed");
    return feed;
}
Also used : Feed(com.rometools.rome.feed.atom.Feed) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with Feed

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

the class AtomFeedHttpMessageConverterTests method write.

@Test
public void write() throws IOException {
    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);
    assertThat(outputMessage.getHeaders().getContentType()).as("Invalid content-type").isEqualTo(ATOM_XML_UTF8);
    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(XmlContent.of(outputMessage.getBodyAsString(StandardCharsets.UTF_8))).isSimilarToIgnoringWhitespace(expected, nm);
}
Also used : Entry(com.rometools.rome.feed.atom.Entry) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) ArrayList(java.util.ArrayList) Feed(com.rometools.rome.feed.atom.Feed) DefaultNodeMatcher(org.xmlunit.diff.DefaultNodeMatcher) NodeMatcher(org.xmlunit.diff.NodeMatcher) Test(org.junit.jupiter.api.Test)

Example 3 with Feed

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

the class AtomFeedHttpMessageConverterTests method writeOtherContentTypeParameters.

@Test
public void writeOtherContentTypeParameters() throws IOException {
    MockHttpOutputMessage message = new MockHttpOutputMessage();
    MediaType contentType = new MediaType("application", "atom+xml", singletonMap("type", "feed"));
    converter.write(new Feed("atom_1.0"), contentType, message);
    assertThat(message.getHeaders().getContentType().getParameters()).as("Invalid content-type").hasSize(2).containsEntry("type", "feed").containsEntry("charset", "UTF-8");
}
Also used : MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) MediaType(org.springframework.http.MediaType) Feed(com.rometools.rome.feed.atom.Feed) Test(org.junit.jupiter.api.Test)

Example 4 with Feed

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

the class AtomFeedHttpMessageConverterTests method read.

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

Example 5 with Feed

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

the class AtomFeedHttpMessageConverterTests method writeOtherCharset.

@Test
public void writeOtherCharset() throws IOException {
    Feed feed = new Feed("atom_1.0");
    feed.setTitle("title");
    String encoding = "ISO-8859-1";
    feed.setEncoding(encoding);
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(feed, null, outputMessage);
    assertThat(outputMessage.getHeaders().getContentType()).as("Invalid content-type").isEqualTo(new MediaType("application", "atom+xml", Charset.forName(encoding)));
}
Also used : MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) MediaType(org.springframework.http.MediaType) Feed(com.rometools.rome.feed.atom.Feed) Test(org.junit.jupiter.api.Test)

Aggregations

Feed (com.rometools.rome.feed.atom.Feed)5 Test (org.junit.jupiter.api.Test)4 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)3 Entry (com.rometools.rome.feed.atom.Entry)2 MediaType (org.springframework.http.MediaType)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 DefaultNodeMatcher (org.xmlunit.diff.DefaultNodeMatcher)1 NodeMatcher (org.xmlunit.diff.NodeMatcher)1