use of org.opencastproject.metadata.dublincore.DublinCoreCatalog 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));
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerServiceImplTest method testTransactionCleanup.
@Test
public void testTransactionCleanup() throws Exception {
Date start = new Date();
Date end = new Date(System.currentTimeMillis() + 60000);
String captureDeviceID = "demo";
String seriesId = "series1";
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
MediaPackage mp = generateEvent(Opt.<String>none());
mp.setSeries(seriesId);
DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
addDublinCore(Opt.<String>none(), mp, event);
Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
SchedulerTransaction trx = schedSvc.createTransaction("new");
assertEquals("new", trx.getSource());
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
Opt<ARecord> record = result.getRecords().head();
assertFalse(record.isSome());
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.<Boolean>none());
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertTrue(record.isSome());
schedSvc.transactionOffsetMillis = 0;
schedSvc.cleanupTransactions();
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertFalse(record.isSome());
try {
schedSvc.getTransaction(trx.getId());
fail("Deleted transaction found!");
} catch (NotFoundException e) {
assertNotNull(e);
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerServiceImplTest method generateEvent.
protected static DublinCoreCatalog generateEvent(String captureDeviceID, Opt<String> eventId, Opt<String> title, Date startTime, Date endTime) {
DublinCoreCatalog dc = DublinCores.mkOpencastEpisode().getCatalog();
dc.set(PROPERTY_IDENTIFIER, eventId.getOr("1"));
dc.set(PROPERTY_TITLE, title.getOr("Demo event"));
dc.set(PROPERTY_CREATOR, "demo");
dc.set(PROPERTY_SUBJECT, "demo");
dc.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(startTime, endTime), Precision.Second));
dc.set(PROPERTY_SPATIAL, captureDeviceID);
dc.set(PROPERTY_CREATED, EncodingSchemeUtils.encodeDate(new Date(), Precision.Minute));
dc.set(PROPERTY_LANGUAGE, "demo");
dc.set(PROPERTY_CONTRIBUTOR, "demo");
dc.set(PROPERTY_DESCRIPTION, "demo");
return dc;
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerServiceImplTest method getSampleSeriesDublinCoreCatalog.
protected static DublinCoreCatalog getSampleSeriesDublinCoreCatalog(String seriesID) {
DublinCoreCatalog dc = DublinCores.mkOpencastSeries().getCatalog();
dc.set(PROPERTY_IDENTIFIER, seriesID);
dc.set(PROPERTY_TITLE, "Demo series");
dc.set(PROPERTY_LICENSE, "demo");
dc.set(PROPERTY_PUBLISHER, "demo");
dc.set(PROPERTY_CREATOR, "demo");
dc.set(PROPERTY_SUBJECT, "demo");
dc.set(PROPERTY_SPATIAL, "demo");
dc.set(PROPERTY_RIGHTS_HOLDER, "demo");
dc.set(PROPERTY_EXTENT, "3600000");
dc.set(PROPERTY_CREATED, EncodingSchemeUtils.encodeDate(new Date(), Precision.Minute));
dc.set(PROPERTY_LANGUAGE, "demo");
dc.set(PROPERTY_IS_REPLACED_BY, "demo");
dc.set(PROPERTY_TYPE, "demo");
dc.set(PROPERTY_AVAILABLE, EncodingSchemeUtils.encodeDate(new Date(), Precision.Minute));
dc.set(PROPERTY_REPLACES, "demo");
dc.set(PROPERTY_CONTRIBUTOR, "demo");
dc.set(PROPERTY_DESCRIPTION, "demo");
return dc;
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerServiceImplTest method checkIcalFeed.
private void checkIcalFeed(Map<String, String> caProps, String title) throws Exception {
final String cs = schedSvc.getCalendar(Opt.<String>none(), Opt.<String>none(), Opt.<Date>none());
final Calendar cal = new CalendarBuilder().build(new StringReader(cs));
assertEquals("number of entries", 1, cal.getComponents().size());
for (Object co : cal.getComponents()) {
final Component c = (Component) co;
assertEquals("SUMMARY property should contain the DC title", title, c.getProperty(Property.SUMMARY).getValue());
final Monadics.ListMonadic<Property> attachments = mlist(c.getProperties(Property.ATTACH)).map(Misc.<Object, Property>cast());
// episode dublin core
final List<DublinCoreCatalog> dcsIcal = attachments.filter(byParamNameAndValue("X-APPLE-FILENAME", "episode.xml")).map(parseDc.o(decodeBase64).o(getValue)).value();
assertEquals("number of episode DCs", 1, dcsIcal.size());
assertEquals("dcterms:title", title, dcsIcal.get(0).getFirst(PROPERTY_TITLE));
// capture agent properties
final List<Properties> caPropsIcal = attachments.filter(byParamNameAndValue("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties")).map(parseProperties.o(decodeBase64).o(getValue)).value();
assertEquals("number of CA property sets", 1, caPropsIcal.size());
assertTrue("CA properties", eqObj(caProps, caPropsIcal.get(0)));
}
}
Aggregations