Search in sources :

Example 1 with Entry

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);
        }
    }
}
Also used : EntryFilter(org.apache.camel.component.feed.EntryFilter) Entry(org.apache.abdera.model.Entry) Calendar(java.util.Calendar) Feed(org.apache.abdera.model.Feed) Test(org.junit.Test)

Example 2 with Entry

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++;
    }
}
Also used : Exchange(org.apache.camel.Exchange) Entry(org.apache.abdera.model.Entry) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 3 with Entry

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", "*/*");
}
Also used : Entry(org.apache.abdera.model.Entry) Feed(org.apache.abdera.model.Feed) Test(org.junit.Test)

Example 4 with Entry

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;
}
Also used : Entry(org.apache.abdera.model.Entry) StringWriter(java.io.StringWriter) Content(org.apache.abdera.model.Content) Factory(org.apache.abdera.factory.Factory) JAXBContext(javax.xml.bind.JAXBContext)

Example 5 with Entry

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;
}
Also used : Entry(org.apache.abdera.model.Entry) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

Entry (org.apache.abdera.model.Entry)22 Test (org.junit.Test)9 Feed (org.apache.abdera.model.Feed)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 JAXBContext (javax.xml.bind.JAXBContext)2 Factory (org.apache.abdera.factory.Factory)2 FOMEntry (org.apache.abdera.parser.stax.FOMEntry)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 Metacard (ddf.catalog.data.Metacard)1 Dataset (edu.harvard.iq.dataverse.Dataset)1 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)1 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)1