use of org.apache.abdera.model.Entry in project camel by apache.
the class UpdatedDateFilterTest method testFilter.
@Test
public void testFilter() throws Exception {
Document<Feed> doc = AtomUtils.parseDocument("file:src/test/data/feed.atom");
assertNotNull(doc);
// timestamp from the feed to use as base
// 2007-11-13T13:35:25.014Z
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
cal.set(2007, Calendar.NOVEMBER, 13, 14, 35, 0);
EntryFilter filter = new UpdatedDateFilter(cal.getTime());
List<Entry> entries = doc.getRoot().getEntries();
// must reverse backwards
for (int i = entries.size() - 1; i > 0; i--) {
Entry entry = entries.get(i);
boolean valid = filter.isValidEntry(null, doc, entry);
// only the 3 last should be true
if (i > 3) {
assertEquals("not valid", false, valid);
} else {
assertEquals("valid", true, valid);
}
}
}
use of org.apache.abdera.model.Entry in project camel by apache.
the class AtomRouteTest method testFeedGetsUpdatedEvents.
@Test
public void testFeedGetsUpdatedEvents() throws Exception {
MockEndpoint endpoint = getMockEndpoint("mock:results");
endpoint.expectedMessageCount(7);
assertMockEndpointsSatisfied();
List<Exchange> list = endpoint.getReceivedExchanges();
String[] expectedTitles = { "Speaking at the Irish Java Technology Conference on Thursday and Friday", "a great presentation on REST, JAX-WS and JSR 311", "my slides on ActiveMQ and Camel from last weeks Dublin Conference", "webcast today on Apache ActiveMQ", "Feedback on my Camel talk at the IJTC conference", "More thoughts on RESTful Message Queues", "ActiveMQ webinar archive available" };
int counter = 0;
for (Exchange exchange : list) {
Entry entry = exchange.getIn().getBody(Entry.class);
assertNotNull("No entry found for exchange: " + exchange);
String expectedTitle = expectedTitles[counter];
String title = entry.getTitle();
assertEquals("Title of message " + counter, expectedTitle, title);
LOG.debug("<<<< " + entry);
counter++;
}
}
use of org.apache.abdera.model.Entry in project cxf by apache.
the class JAXRSAtomBookTest method testGetBooks.
@Test
public void testGetBooks() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/bookstore/books/feed";
Feed feed = getFeed(endpointAddress, null);
assertEquals("http://localhost:" + PORT + "/bookstore/bookstore/books/feed", feed.getBaseUri().toString());
assertEquals("Collection of Books", feed.getTitle());
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/feed", "resources/expected_atom_books_json.txt", "application/json");
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/jsonfeed", "resources/expected_atom_books_jsonfeed.txt", "application/json, text/html, application/xml;q=0.9," + " application/xhtml+xml, image/png, image/jpeg, image/gif," + " image/x-xbitmap, */*;q=0.1");
Entry entry = addEntry(endpointAddress);
entry = addEntry(endpointAddress + "/relative");
endpointAddress = "http://localhost:" + PORT + "/bookstore/bookstore/books/subresources/123";
entry = getEntry(endpointAddress, null);
assertEquals("CXF in Action", entry.getTitle());
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/entries/123", "resources/expected_atom_book_json.txt", "application/json");
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/entries/123?_type=" + "application/json", "resources/expected_atom_book_json.txt", "*/*");
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/entries/123?_type=" + "json", "resources/expected_atom_book_json.txt", "*/*");
// do the same using extension mappings
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/entries/123.json", "resources/expected_atom_book_json.txt", "*/*");
// do the same using extension mappings & matrix parameters
getAndCompareJson("http://localhost:" + PORT + "/bookstore/bookstore/books/entries/123.json;a=b", "resources/expected_atom_book_json_matrix.txt", "*/*");
}
use of org.apache.abdera.model.Entry in project cxf by apache.
the class JAXRSAtomBookTest method createBookEntry.
private Entry createBookEntry(int id, String name) throws Exception {
Book b = new Book();
b.setId(id);
b.setName(name);
Factory factory = Abdera.getNewFactory();
JAXBContext jc = JAXBContext.newInstance(Book.class);
Entry e = factory.getAbdera().newEntry();
e.setTitle(b.getName());
e.setId(Long.toString(b.getId()));
StringWriter writer = new StringWriter();
jc.createMarshaller().marshal(b, writer);
Content ct = factory.newContent(Content.Type.XML);
ct.setValue(writer.toString());
e.setContentElement(ct);
return e;
}
use of org.apache.abdera.model.Entry in project cxf by apache.
the class AtomUtils method createBookEntry.
public static Entry createBookEntry(Factory factory, Book b, String baseUri) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Book.class);
Entry e = factory.newEntry();
if (baseUri != null) {
e.setBaseUri(baseUri);
}
e.setTitle(b.getName());
e.setId(Long.toString(b.getId()));
StringWriter writer = new StringWriter();
jc.createMarshaller().marshal(b, writer);
e.setContent(writer.toString(), Content.Type.XML);
return e;
}
Aggregations