use of org.opencastproject.scheduler.endpoint.SchedulerRestService in project opencast by opencast.
the class SchedulerServiceImplTest method testCalendarNotModified.
@Test
public void testCalendarNotModified() throws Exception {
HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.replay(request);
SchedulerRestService restService = new SchedulerRestService();
restService.setService(schedSvc);
String device = "Test Device";
// Store an event
MediaPackage mediaPackage = generateEvent(Opt.<String>none());
DublinCoreCatalog dublinCore = generateEvent(device, new Date(), new Date(System.currentTimeMillis() + 60000));
addDublinCore(Opt.<String>none(), mediaPackage, dublinCore);
schedSvc.addEvent(new Date(), new Date(System.currentTimeMillis() + 60000), device, Collections.<String>emptySet(), mediaPackage, Collections.<String, String>emptyMap(), Collections.<String, String>emptyMap(), Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
// Request the calendar without specifying an etag. We should get a 200 with the iCalendar in the response body
Response response = restService.getCalendar(device, null, null, request);
Assert.assertNotNull(response.getEntity());
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
final String etag = (String) response.getMetadata().getFirst(HttpHeaders.ETAG);
EasyMock.reset(request);
EasyMock.expect(request.getHeader("If-None-Match")).andAnswer(new IAnswer<String>() {
@Override
public String answer() throws Throwable {
return etag;
}
}).anyTimes();
EasyMock.replay(request);
// Request using the etag from the first response. We should get a 304 (not modified)
response = restService.getCalendar(device, null, null, request);
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus());
Assert.assertNull(response.getEntity());
// Update the event and clear to cache to make sure it's reloaded
schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.some(wfPropertiesUpdated), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
// Try using the same old etag. We should get a 200, since the event has changed
response = restService.getCalendar(device, null, null, request);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
Assert.assertNotNull(response.getEntity());
final String secondEtag = (String) response.getMetadata().getFirst(HttpHeaders.ETAG);
Assert.assertNotNull(secondEtag);
Assert.assertFalse(etag.equals(secondEtag));
EasyMock.reset(request);
EasyMock.expect(request.getHeader("If-None-Match")).andAnswer(new IAnswer<String>() {
@Override
public String answer() throws Throwable {
return secondEtag;
}
}).anyTimes();
EasyMock.replay(request);
// do opt out update
schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.some(Opt.some(true)), SchedulerService.ORIGIN);
Assert.assertTrue(schedSvc.isOptOut(mediaPackage.getIdentifier().compact()));
// Try using the same old etag. We should get a 200, since the event has changed
response = restService.getCalendar(device, null, null, request);
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
Assert.assertNotNull(response.getEntity());
String thirdEtag = (String) response.getMetadata().getFirst(HttpHeaders.ETAG);
Assert.assertNotNull(thirdEtag);
Assert.assertFalse(secondEtag.equals(thirdEtag));
}
Aggregations