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());
}
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);
}
}
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);
}
}
}
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>"));
}
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]));
}
Aggregations