Search in sources :

Example 16 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedController method create.

@POST
@Template(name = "/index.ftl")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Viewable create(@Valid @BeanParam FeedRequestBean request) {
    String[] urlArray = createUrls(request.getUrls()).stream().toArray(String[]::new);
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(null, urlArray).title(request.getTitle()).description(request.getDescription()).refreshPeriod(request.getRefreshPeriod()).build();
    feedService.save(feed);
    return new Viewable("/index.ftl", getModel());
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Viewable(org.glassfish.jersey.server.mvc.Viewable) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Template(org.glassfish.jersey.server.mvc.Template) ErrorTemplate(org.glassfish.jersey.server.mvc.ErrorTemplate)

Example 17 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class FeedDataStoreManager method createTask.

private void createTask(Serializable serializableEntity) {
    if (serializableEntity instanceof CombinedFeed) {
        CombinedFeed feed = (CombinedFeed) serializableEntity;
        ScheduledFuture<?> scheduledTask = scheduler.scheduleAtFixedRate(taskFactory.get(feed), START_DELAY, feed.getRefreshPeriod(), DEFAULT_TIME_UNIT);
        scheduledTasks.put(feed.getId(), scheduledTask);
    }
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)

Example 18 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class FeedDownloadTaskTest method testSuccess.

@Test
public void testSuccess() throws Exception {
    URL url = new URL("http://localhost");
    String id = "1";
    CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, singletonList(url)).refreshPeriod(5L).build();
    expect(datastore.get(feedId, CombinedFeed.class)).andReturn(feed);
    expect(downloader.apply(url)).andReturn(syndEntries());
    Capture<CombinedFeed> feedCapture = EasyMock.newCapture();
    expect(datastore.put(eq(id), capture(feedCapture))).andReturn(null);
    replayAll();
    testedClass.run();
    verifyAll();
    CombinedFeed capturedFeed = feedCapture.getValue();
    assertEquals(2, capturedFeed.getFeedEntries().size());
    for (FeedEntry entry : capturedFeed.getFeedEntries()) {
        if (TITLES[0].equals(entry.getTitle())) {
            assertEquals(feedEntries().get(0), entry);
        } else {
            assertEquals(feedEntries().get(1), entry);
        }
    }
}
Also used : FeedEntry(org.glassfish.jersey.examples.feedcombiner.model.FeedEntry) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) URL(java.net.URL) Test(org.junit.Test)

Example 19 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedControllerTest method testGetEntriesHTML.

@Test
public void testGetEntriesHTML() {
    String entityID = "1";
    CombinedFeed feedWithEntries = CombinedFeed.CombinedFeedBuilder.of(combinedFeed(entityID)).feedEntries(feedEntries()).build();
    datastore.put(entityID, feedWithEntries);
    Response response = target().path(entityID).request(TEXT_HTML_TYPE).get();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    String html = response.readEntity(String.class);
    assertTrue(html.contains("<td>title1</td>") && html.contains("<td>title2</td>"));
    assertTrue(html.contains("<td><a href=\"link1\">link1</a></td>") && html.contains("<td><a href=\"link2\">link2</a></td>"));
}
Also used : Response(javax.ws.rs.core.Response) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 20 with CombinedFeed

use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.

the class CombinedFeedControllerTest method testDelete.

@Test
public void testDelete() {
    CombinedFeed feed = combinedFeed("1");
    datastore.put(feed.getId(), feed);
    Response response = target("delete").path(feed.getId()).request().post(null);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    String html = response.readEntity(String.class);
    // HTML page does not contain a title of the deleted entity
    assertTrue(!html.contains(params[0]));
}
Also used : Response(javax.ws.rs.core.Response) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

CombinedFeed (org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)25 Test (org.junit.Test)19 Serializable (java.io.Serializable)7 Response (javax.ws.rs.core.Response)5 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 IOException (java.io.IOException)2 URL (java.net.URL)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 FeedEntry (org.glassfish.jersey.examples.feedcombiner.model.FeedEntry)2 ReadWriteLockDataStore (org.glassfish.jersey.examples.feedcombiner.store.ReadWriteLockDataStore)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1