@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));
  }
Exemplo n.º 2
0
 /** Build Feed Meta Data. */
 @Override
 protected void buildFeedMetadata(
     Map<String, Object> model, Feed feed, HttpServletRequest request) {
   setAtomTitle(
       model.get("feedTitle") == null ? "Survey Published " : model.get("feedTitle").toString());
   feed.setId(getAtomTitle());
   feed.setTitle(getAtomTitle());
 }
  @Test
  public void writeOtherCharset() throws IOException, SAXException {
    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);

    assertEquals(
        "Invalid content-type",
        new MediaType("application", "atom+xml", Charset.forName(encoding)),
        outputMessage.getHeaders().getContentType());
  }
Exemplo n.º 4
0
  protected void buildFeedMetadata(
      Map<String, Object> model, Feed feed, HttpServletRequest request) {
    Blog blog = blogService.readBlogById(Blog.DEFAULT_ID);
    String language = LocaleContextHolder.getLocale().getLanguage();

    feed.setTitle(blog.getTitle(language));
    Content info = new Content();
    info.setValue(blog.getTitle(language));
    feed.setInfo(info);

    ArrayList<Link> links = new ArrayList<>();
    Link link = new Link();
    UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
    link.setHref(builder.buildAndExpand().toUriString());
    links.add(link);
    feed.setOtherLinks(links);
    //		feed.setIcon("http://" + settings.getAsString(Setting.Key.SITE_URL) +
    // "resources/default/img/favicon.ico");
  }