use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AssetManagerMessageReceiverImplTest method testUpdateCreator.
@Test
public void testUpdateCreator() throws Exception {
MediaPackage mediaPackage = new MediaPackageBuilderImpl().loadFromXml(getClass().getResourceAsStream("/jobs_mediapackage1.xml"));
TakeSnapshot takeSnapshot = AssetManagerItem.add(workspace, mediaPackage, new AccessControlList(), 0, new Date());
// Test initial set of creator
assetManager.execute(takeSnapshot);
Event event = index.getEventResult();
assertNotNull(event);
assertEquals("Current user is expected to be creator as no other creator has been set explicitly", "Creator", event.getCreator());
// Test updating creator
event.setCreator("Hans");
index.setInitialEvent(event);
assetManager.execute(takeSnapshot);
event = index.getEventResult();
assertNotNull(event);
assertEquals("Creator has been updated", "Hans", event.getCreator());
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IngestServiceImplTest method testContentDisposition.
@Test
public void testContentDisposition() throws Exception {
MediaPackage mediaPackage = null;
mediaPackage = service.createMediaPackage();
try {
mediaPackage = service.addTrack(URI.create("http://www.test.com/testfile"), null, mediaPackage);
} catch (Exception e) {
Assert.fail("Unable to read content dispostion filename!");
}
try {
mediaPackage = service.addTrack(urlTrackNoFilename, null, mediaPackage);
Assert.fail("Allowed adding content without filename!");
} catch (Exception e) {
Assert.assertNotNull(e);
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IngestServiceImplTest method setUp.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
FileUtils.forceMkdir(ingestTempDir);
// set up service and mock workspace
wfr = EasyMock.createNiceMock(WorkingFileRepository.class);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlAttachment);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackage);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackageOld);
workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(workflowInstanceID);
EasyMock.expect(workflowInstance.getState()).andReturn(WorkflowState.STOPPED);
final Capture<MediaPackage> mp = EasyMock.newCapture();
workflowService = EasyMock.createNiceMock(WorkflowService.class);
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), EasyMock.capture(mp), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowInstance.getMediaPackage()).andAnswer(new IAnswer<MediaPackage>() {
@Override
public MediaPackage answer() throws Throwable {
return mp.getValue();
}
});
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject(), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowService.getWorkflowDefinitionById((String) EasyMock.anyObject())).andReturn(new WorkflowDefinitionImpl());
EasyMock.expect(workflowService.getWorkflowById(EasyMock.anyLong())).andReturn(workflowInstance);
SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
Map<String, String> properties = new HashMap<>();
properties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, "sample");
properties.put("agent-name", "matterhorn-agent");
EasyMock.expect(schedulerService.getCaptureAgentConfiguration(EasyMock.anyString())).andReturn(properties).anyTimes();
EasyMock.expect(schedulerService.getDublinCore(EasyMock.anyString())).andReturn(DublinCores.read(urlCatalog1.toURL().openStream())).anyTimes();
MediaPackage schedulerMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest.xml"), "UTF-8"));
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(schedulerMediaPackage).anyTimes();
EasyMock.replay(wfr, workflowInstance, workflowService, schedulerService);
User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization(), "test"));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
HttpEntity entity = EasyMock.createMock(HttpEntity.class);
InputStream is = getClass().getResourceAsStream("/av.mov");
byte[] movie = IOUtils.toByteArray(is);
IOUtils.closeQuietly(is);
EasyMock.expect(entity.getContent()).andReturn(new ByteArrayInputStream(movie)).anyTimes();
EasyMock.replay(entity);
StatusLine statusLine = EasyMock.createMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(200).anyTimes();
EasyMock.replay(statusLine);
Header contentDispositionHeader = EasyMock.createMock(Header.class);
EasyMock.expect(contentDispositionHeader.getValue()).andReturn("attachment; filename=fname.mp4").anyTimes();
EasyMock.replay(contentDispositionHeader);
HttpResponse httpResponse = EasyMock.createMock(HttpResponse.class);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.expect(httpResponse.getFirstHeader("Content-Disposition")).andReturn(contentDispositionHeader).anyTimes();
EasyMock.expect(httpResponse.getEntity()).andReturn(entity).anyTimes();
EasyMock.replay(httpResponse);
TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpGet) EasyMock.anyObject())).andReturn(httpResponse).anyTimes();
EasyMock.replay(httpClient);
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
EasyMock.replay(authorizationService);
MediaInspectionService mediaInspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
EasyMock.expect(mediaInspectionService.enrich(EasyMock.anyObject(MediaPackageElement.class), EasyMock.anyBoolean())).andAnswer(new IAnswer<Job>() {
private int i = 0;
@Override
public Job answer() throws Throwable {
TrackImpl element = (TrackImpl) EasyMock.getCurrentArguments()[0];
element.setDuration(20000L);
if (i % 2 == 0) {
element.addStream(new VideoStreamImpl());
} else {
element.addStream(new AudioStreamImpl());
}
i++;
JobImpl succeededJob = new JobImpl();
succeededJob.setStatus(Status.FINISHED);
succeededJob.setPayload(MediaPackageElementParser.getAsXml(element));
return succeededJob;
}
}).anyTimes();
EasyMock.replay(mediaInspectionService);
service = new IngestServiceImpl();
service.setHttpClient(httpClient);
service.setAuthorizationService(authorizationService);
service.setWorkingFileRepository(wfr);
service.setWorkflowService(workflowService);
service.setSecurityService(securityService);
service.setSchedulerService(schedulerService);
service.setMediaInspectionService(mediaInspectionService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
serviceRegistry.registerService(service);
service.setServiceRegistry(serviceRegistry);
service.defaultWorkflowDefinionId = "sample";
serviceRegistry.registerService(service);
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IngestServiceImplTest method testThinClient.
@Test
public void testThinClient() throws Exception {
MediaPackage mediaPackage = null;
mediaPackage = service.createMediaPackage();
mediaPackage = service.addTrack(urlTrack, MediaPackageElements.PRESENTATION_SOURCE, mediaPackage);
mediaPackage = service.addCatalog(urlCatalog1, MediaPackageElements.EPISODE, mediaPackage);
mediaPackage = service.addAttachment(urlAttachment, MediaPackageElements.MEDIAPACKAGE_COVER_FLAVOR, mediaPackage);
WorkflowInstance instance = service.ingest(mediaPackage);
Assert.assertEquals(1, mediaPackage.getTracks().length);
Assert.assertEquals(1, mediaPackage.getCatalogs().length);
Assert.assertEquals(1, mediaPackage.getAttachments().length);
Assert.assertEquals(workflowInstanceID, instance.getId());
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class IngestServiceImplTest method testSmilCreation.
@Test
public void testSmilCreation() throws Exception {
service.setWorkingFileRepository(new WorkingFileRepositoryImpl() {
@Override
public URI put(String mediaPackageID, String mediaPackageElementID, String filename, InputStream in) throws IOException {
File file = new File(FileUtils.getTempDirectory(), mediaPackageElementID);
file.deleteOnExit();
FileUtils.write(file, IOUtils.toString(in), "UTF-8");
return file.toURI();
}
@Override
public InputStream get(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException {
File file = new File(FileUtils.getTempDirectory(), mediaPackageElementID);
return new FileInputStream(file);
}
});
URI presenterUri = URI.create("http://localhost:8080/presenter.mp4");
URI presenterUri2 = URI.create("http://localhost:8080/presenter2.mp4");
URI presentationUri = URI.create("http://localhost:8080/presentation.mp4");
MediaPackage mediaPackage = service.createMediaPackage();
Catalog[] catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(0, catalogs.length);
mediaPackage = service.addPartialTrack(presenterUri, MediaPackageElements.PRESENTER_SOURCE_PARTIAL, 60000L, mediaPackage);
mediaPackage = service.addPartialTrack(presenterUri2, MediaPackageElements.PRESENTER_SOURCE_PARTIAL, 120000L, mediaPackage);
mediaPackage = service.addPartialTrack(presentationUri, MediaPackageElements.PRESENTATION_SOURCE_PARTIAL, 0L, mediaPackage);
catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(0, catalogs.length);
service.ingest(mediaPackage);
catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(1, catalogs.length);
Assert.assertEquals(MimeTypes.SMIL, catalogs[0].getMimeType());
Either<Exception, Document> eitherDoc = XmlUtil.parseNs(new InputSource(catalogs[0].getURI().toURL().openStream()));
Assert.assertTrue(eitherDoc.isRight());
Document document = eitherDoc.right().value();
Assert.assertEquals(1, document.getElementsByTagName("par").getLength());
Assert.assertEquals(2, document.getElementsByTagName("seq").getLength());
Assert.assertEquals(2, document.getElementsByTagName("video").getLength());
Assert.assertEquals(1, document.getElementsByTagName("audio").getLength());
}
Aggregations