null, null, null, null, null);
List<Entry> entries = new LinkedList<Entry>();
entries.add(entry);
Feed feed = feedDoc.buildFeed(id, title, updated, rights, authors,
categories, contributors, links, feedAttrs, extensions,
generator, null, icon, logo, entries);
assertNotNull(feed);
assertNotNull(feed.getAttribute("xml:lang"));
assertNull(feed.getAttribute("bunk"));
// read and write a full feed.
feed = feedDoc.readFeedToBean(mega);
assertNotNull(feedDoc.getLibVersion());
BufferedWriter out = new BufferedWriter(new FileWriter(
"target/mega.xml"));
out.write(feed.toString());
out.flush();
out.close();
feedDoc.writeFeedDoc(new FileOutputStream(new File(
"target/mega2.xml")), feed, feedDoc.getEncoding(), feedDoc
.getXmlVersion());
assertNotNull(feed.getId());
assertNull(feed.getGenerator().getAttribute("notHere"));
assertNotNull(feed.getAuthor("Bill Brown"));
assertNotNull(feed.getContributor("Bill Brown"));
assertNotNull(feed.getLink("self"));
assertNull(feed.getLink("self").getContent());
assertNull(feed.getLink(null));
assertNotNull(feed.getId().getAttribute("local:something"));
assertNull(feed.getId().getAttribute("bunk"));
assertNull(feed.getCategory("math").getAttribute("anythingWrong"));
assertNull(feed.getCategory("math").getContent());
assertNotNull(feed.getIcon().getAttribute("local:testAttr"));
assertNotNull(feed.getLogo().getAttribute("local:testAttr"));
assertNotNull(feed.getRights().getAttribute("xmlns"));
assertNull(feed.getRights().getAttribute("sayWhat"));
assertNotNull(feed.getUpdated().getDateTime());
assertNull(feed.getSubtitle().getAttribute("sayWhat"));
// sort the entries:
feed = feedDoc.sortEntries(feed, Summary.class, "asc");
feed = feedDoc.sortEntries(feed, Title.class, "desc");
feed = feedDoc.sortEntries(feed, Updated.class, "asc");
// this wont sort anything.
try {
feed = feedDoc.sortEntries(feed, Author.class, "asc");
fail("should not get here.");
} catch (AtomSpecException e) {
assertEquals(e.getMessage(),
"The feed entries cannot be sorted by an invalid type 'Author'.");
}
XMLStreamWriter writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(
new FileOutputStream("target/dump1.xml"));
feedDoc.writeFeedDoc(writer, feed, null, null);
int fileName = 1;
for (Entry ent : feed.getEntries()) {
out = new BufferedWriter(new FileWriter("target/"
+ (fileName++) + ".xml"));
out.write(ent.toString());
out.flush();
out.close();
if (ent
.getId()
.getAtomUri()
.equals(
"http://colorfulsoftware.localhost/colorfulsoftware/projects/atomsphere/atom.xml#About")) {
Author auth = ent.getAuthor("Bill Brown");
assertNotNull(ent.getAttribute("xmlns"));
assertNotNull(auth);
assertNotNull(auth.getAttribute("local:testAttr"));
Attribute attr1 = auth.getAttribute("local:testAttr");
assertFalse(attr1.equals(auth.getAttribute("local:blank")));
assertNull(auth.getAttribute("local:blank"));
assertNotNull(auth.getExtension("test:test"));
assertNull(auth.getExtension("local:bunky"));
assertNull(ent.getAuthor("some other dude"));
assertNotNull(ent.getContributor("Bill Brown"));
assertNull(ent.getContributor("some other dude"));
assertNotNull(ent.getCategory("science"));
assertNull(ent.getCategory("nothing"));
assertNotNull(ent.getLink("alternate"));
assertNull(ent.getLink("http://www.fakeness.net"));
assertNotNull(ent.getExtension("local:element"));
assertNull(ent.getExtension("local:notthere"));
assertNotNull(ent.getPublished().getAttribute("xmlns"));
assertNotNull(ent.getPublished().getDateTime());
assertNull(ent.getSummary().getAttribute("sayWhat"));
Contributor cont = ent.getContributor("Bill Brown");
assertNotNull(cont);
assertNotNull(cont.getExtension("test:test"));
assertNotNull(cont.getAttribute("local:testAttr"));
attr1 = cont.getAttribute("local:testAttr");
assertFalse(attr1.equals(auth.getAttribute("local:blank")));
assertNull(auth.getAttribute("local:blank"));
assertNotNull(auth.getExtension("test:test"));
assertNull(auth.getExtension("local:bunky"));
assertNull(ent.getAuthor("some other dude"));
assertNotNull(ent.getContributor("Bill Brown"));
assertNull(ent.getContributor("some other dude"));
assertNotNull(ent.getCategory("science"));
assertNull(ent.getCategory("nothing"));
assertNotNull(ent.getLink("alternate"));
assertNull(ent.getLink("http://www.fakeness.net"));
assertNotNull(ent.getExtension("local:element"));
assertNull(ent.getExtension("local:notthere"));
}
// test the source attribute
if (ent.getSource() != null) {
Source source = ent.getSource();
assertNotNull(source.getAttribute("xmlns:sort"));
assertNotNull(source.getAuthor("The Minority Directory"));
assertNotNull(source.getContributor("The People"));
assertNotNull(source.getCategory("purpose"));
assertNotNull(source.getLink("self"));
assertNotNull(source.getExtension("sort:asc"));
}
}
// re read the written feed and check the data.
feed = feedDoc.readFeedToBean(new File("target/dump1.xml"));
assertNotNull(feed);
assertNotNull(feed.getCategories());
List<Category> cats = feed.getCategories();
for (Category cat : cats) {
assertNotNull(cat.getTerm());
if (!cat.getTerm().getValue().equals("thing")
&& !cat.getTerm().getValue().equals("undefined")) {
assertNotNull(cat.getLabel());
assertNotNull(cat.getScheme());
}
}
List<Link> lnks = feed.getLinks();
for (Link lnk : lnks) {
assertNotNull(lnk.getHref());
assertNotNull(lnk.getHreflang());
assertNotNull(lnk.getTitle());
assertNotNull(lnk.getType());