Search in sources :

Example 31 with MediaPackage

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());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) TakeSnapshot(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.TakeSnapshot) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) Date(java.util.Date) Test(org.junit.Test)

Example 32 with MediaPackage

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);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 33 with MediaPackage

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) HttpGet(org.apache.http.client.methods.HttpGet) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaInspectionService(org.opencastproject.inspection.api.MediaInspectionService) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowService(org.opencastproject.workflow.api.WorkflowService) SecurityService(org.opencastproject.security.api.SecurityService) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) JobImpl(org.opencastproject.job.api.JobImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) Header(org.apache.http.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 34 with MediaPackage

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());
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 35 with MediaPackage

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());
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) URI(java.net.URI) FileInputStream(java.io.FileInputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkingFileRepositoryImpl(org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryImpl) File(java.io.File) Test(org.junit.Test)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)407 Test (org.junit.Test)180 NotFoundException (org.opencastproject.util.NotFoundException)108 Job (org.opencastproject.job.api.Job)89 Date (java.util.Date)82 IOException (java.io.IOException)77 URI (java.net.URI)74 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)72 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)70 ArrayList (java.util.ArrayList)69 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)60 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)59 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 Path (javax.ws.rs.Path)53 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)52 Track (org.opencastproject.mediapackage.Track)48 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)48 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)45 HashSet (java.util.HashSet)43