use of org.opencastproject.scheduler.api.TechnicalMetadata in project opencast by opencast.
the class SchedulerServiceImplTest method testPersistence.
@Test
public void testPersistence() 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);
String catalogId = addDublinCore(Opt.<String>none(), mp, event);
Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
EasyMock.reset(seriesService);
EasyMock.expect(seriesService.getSeries(seriesId)).andThrow(new NotFoundException()).once();
EasyMock.expect(seriesService.isOptOut(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(seriesService);
assertEquals("mod0", schedSvc.getScheduleLastModified(captureDeviceID));
// Store event
schedSvc.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
try {
MediaPackage mp2 = (MediaPackage) mp.clone();
mp2.setIdentifier(new UUIDIdBuilderImpl().createNew());
schedSvc.addEvent(start, end, captureDeviceID, userIds, mp2, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
Assert.fail();
} catch (SchedulerConflictException e) {
Assert.assertNotNull(e);
}
MediaPackage mediaPackage = schedSvc.getMediaPackage(mp.getIdentifier().compact());
assertEquals(seriesId, mediaPackage.getSeries());
DublinCoreCatalog eventLoaded = schedSvc.getDublinCore(mp.getIdentifier().compact());
assertEquals(event.getFirst(PROPERTY_TITLE), eventLoaded.getFirst(PROPERTY_TITLE));
// the returned map is of type com.entwinemedia.fn.data.ImmutableMapWrapper which
// does not delegate equals and hashcode so it is necessary to create a HashMap from it
TechnicalMetadata technicalMetadata = schedSvc.getTechnicalMetadata(mp.getIdentifier().compact());
assertEquals(mp.getIdentifier().compact(), technicalMetadata.getEventId());
assertEquals(captureDeviceID, technicalMetadata.getAgentId());
assertEquals(start, technicalMetadata.getStartDate());
assertEquals(end, technicalMetadata.getEndDate());
assertEquals(false, technicalMetadata.isOptOut());
assertEquals(userIds, technicalMetadata.getPresenters());
assertTrue(technicalMetadata.getRecording().isNone());
assertTrue(technicalMetadata.getCaptureAgentConfiguration().size() >= caProperties.size());
assertEquals(wfProperties, new HashMap<>(schedSvc.getWorkflowConfig(mp.getIdentifier().compact())));
String lastModified = schedSvc.getScheduleLastModified(captureDeviceID);
assertNotEquals("mod0", lastModified);
eventLoaded.set(PROPERTY_TITLE, "Something more");
addDublinCore(Opt.some(catalogId), mp, eventLoaded);
userIds.add("user3");
userIds.remove("user1");
mp.setSeries("series2");
// Update event
schedSvc.updateEvent(mp.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.some(userIds), Opt.some(mp), Opt.some(wfProperties), Opt.some(caProperties), Opt.some(Opt.some(true)), SchedulerService.ORIGIN);
mediaPackage = schedSvc.getMediaPackage(mp.getIdentifier().compact());
assertEquals("series2", mediaPackage.getSeries());
DublinCoreCatalog eventReloaded = schedSvc.getDublinCore(mp.getIdentifier().compact());
assertEquals("Something more", eventReloaded.getFirst(PROPERTY_TITLE));
technicalMetadata = schedSvc.getTechnicalMetadata(mp.getIdentifier().compact());
assertEquals(mp.getIdentifier().compact(), technicalMetadata.getEventId());
assertEquals(captureDeviceID, technicalMetadata.getAgentId());
assertEquals(start, technicalMetadata.getStartDate());
assertEquals(end, technicalMetadata.getEndDate());
assertEquals(true, technicalMetadata.isOptOut());
assertEquals(userIds, technicalMetadata.getPresenters());
assertTrue(technicalMetadata.getRecording().isNone());
assertTrue(technicalMetadata.getCaptureAgentConfiguration().size() >= caProperties.size());
String updatedLastModified = schedSvc.getScheduleLastModified(captureDeviceID);
assertNotEquals("mod0", updatedLastModified);
assertNotEquals(lastModified, updatedLastModified);
assertTrue(schedSvc.getCaptureAgentConfiguration(mp.getIdentifier().compact()).size() >= caProperties.size());
}
Aggregations