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;
}
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);
}
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");
}
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");
}
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)));
}
Aggregations