Search in sources :

Example 31 with Attachment

use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.

the class LiveScheduleServiceImplTest method testReplaceAndDistributeAcl.

@Test
public void testReplaceAndDistributeAcl() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/live-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype><url>http://host/security-policy-episode.xml</url></attachment>");
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(String.class), EasyMock.anyBoolean())).andReturn(job).once();
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    replayServices();
    service.setDownloadDistributionService(downloadDistributionService);
    AccessControlList acl = new AccessControlList(new AccessControlEntry("user", "read", true));
    MediaPackage mp1 = service.replaceAndDistributeAcl(mp, acl);
    Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
    Assert.assertNotNull(atts);
    Assert.assertEquals(1, atts.length);
    Attachment att = atts[0];
    Assert.assertEquals("http://host/security-policy-episode.xml", att.getURI().toString());
    Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
    EasyMock.verify(downloadDistributionService);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Attachment(org.opencastproject.mediapackage.Attachment) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Test(org.junit.Test)

Example 32 with Attachment

use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.

the class LiveScheduleServiceImplTest method testAddAndDistributeElements.

@Test
public void testAddAndDistributeElements() throws Exception {
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
    DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
    EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
    Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job).once();
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    replayServices();
    Snapshot s = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(s.getMediaPackage()).andReturn(mp);
    EasyMock.replay(s);
    service.setDownloadDistributionService(downloadDistributionService);
    MediaPackage mp1 = service.addAndDistributeElements(s);
    Catalog[] catalogs = mp1.getCatalogs(MediaPackageElements.EPISODE);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    Catalog catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/episode.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/episode", catalog.getFlavor().toString());
    catalogs = mp1.getCatalogs(MediaPackageElements.SERIES);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/series.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/series", catalog.getFlavor().toString());
    Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
    Assert.assertNotNull(atts);
    Assert.assertEquals(1, atts.length);
    Attachment att = atts[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml", att.getURI().toString());
    Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
    EasyMock.verify(downloadDistributionService, workspace);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Example 33 with Attachment

use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.

the class TestRestService method newAuthorizationService.

private static AuthorizationService newAuthorizationService() {
    AccessControlList acl = new AccessControlList();
    Attachment attachment = new AttachmentImpl();
    MediaPackage mediapackage;
    try {
        mediapackage = new MediaPackageBuilderImpl().createNew();
    } catch (MediaPackageException e) {
        throw new RuntimeException(e);
    }
    AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.expect(authorizationService.setAcl((MediaPackage) EasyMock.anyObject(), (AclScope) EasyMock.anyObject(), (AccessControlList) EasyMock.anyObject())).andReturn(Tuple.tuple(mediapackage, attachment));
    EasyMock.replay(authorizationService);
    return authorizationService;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl)

Example 34 with Attachment

use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.

the class IndexServiceImplTest method testCreateEventInputNormalExpectsCreatedScheduledEvent.

@Test
public void testCreateEventInputNormalExpectsCreatedScheduledEvent() throws Exception {
    String expectedTitle = "Test Event Creation";
    String username = "akm220";
    String org = "mh_default_org";
    String[] creators = new String[] {};
    Id mpId = new IdImpl("mp-id");
    String testResourceLocation = "/events/create-scheduled-event.json";
    JSONObject metadataJson = (JSONObject) parser.parse(IOUtils.toString(IndexServiceImplTest.class.getResourceAsStream(testResourceLocation)));
    Capture<Catalog> result = EasyMock.newCapture();
    Capture<String> mediapackageIdResult = EasyMock.newCapture();
    Capture<String> catalogIdResult = EasyMock.newCapture();
    Capture<String> filenameResult = EasyMock.newCapture();
    Capture<InputStream> catalogResult = EasyMock.newCapture();
    Capture<String> mediapackageTitleResult = EasyMock.newCapture();
    SecurityService securityService = setupSecurityService(username, org);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIdResult), EasyMock.capture(catalogIdResult), EasyMock.capture(filenameResult), EasyMock.capture(catalogResult))).andReturn(new URI("catalog.xml"));
    EasyMock.replay(workspace);
    // Create Common Event Catalog UI Adapter
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Setup mediapackage.
    MediaPackage mediapackage = EasyMock.createMock(MediaPackage.class);
    mediapackage.add(EasyMock.capture(result));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {});
    EasyMock.expect(mediapackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.expect(mediapackage.getCreators()).andReturn(creators);
    mediapackage.addCreator("");
    EasyMock.expectLastCall();
    mediapackage.setTitle(EasyMock.capture(mediapackageTitleResult));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getElements()).andReturn(new MediaPackageElement[] {}).anyTimes();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {}).anyTimes();
    EasyMock.expect(mediapackage.getSeries()).andReturn(null).anyTimes();
    mediapackage.setSeries(EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackage);
    IngestService ingestService = setupIngestService(mediapackage, Capture.<InputStream>newInstance());
    // Setup Authorization Service
    Tuple<MediaPackage, Attachment> returnValue = new Tuple<MediaPackage, Attachment>(mediapackage, null);
    AuthorizationService authorizationService = EasyMock.createMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.setAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class), EasyMock.anyObject(AccessControlList.class))).andReturn(returnValue);
    EasyMock.replay(authorizationService);
    CaptureAgentStateService captureAgentStateService = setupCaptureAgentStateService();
    Capture<Date> captureStart = EasyMock.newCapture();
    Capture<Date> captureEnd = EasyMock.newCapture();
    SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
    schedulerService.addEvent(EasyMock.capture(captureStart), EasyMock.capture(captureEnd), EasyMock.anyString(), EasyMock.<Set<String>>anyObject(), EasyMock.anyObject(MediaPackage.class), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Opt<Boolean>>anyObject(), EasyMock.<Opt<String>>anyObject(), EasyMock.anyString());
    EasyMock.expectLastCall().once();
    EasyMock.replay(schedulerService);
    // Run Test
    IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
    indexServiceImpl.setAuthorizationService(setupAuthorizationService(mediapackage));
    indexServiceImpl.setIngestService(ingestService);
    indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.setSecurityService(securityService);
    indexServiceImpl.setUserDirectoryService(noUsersUserDirectoryService);
    indexServiceImpl.setWorkspace(workspace);
    indexServiceImpl.setCaptureAgentStateService(captureAgentStateService);
    indexServiceImpl.setSchedulerService(schedulerService);
    String scheduledEvent = indexServiceImpl.createEvent(metadataJson, mediapackage);
    Assert.assertEquals(mediapackage.getIdentifier().compact(), scheduledEvent);
    assertTrue("The catalog must be added to the mediapackage", result.hasCaptured());
    assertEquals("The catalog should have been added to the correct mediapackage", mpId.toString(), mediapackageIdResult.getValue());
    assertTrue("The catalog should have a new id", catalogIdResult.hasCaptured());
    assertTrue("The catalog should have a new filename", filenameResult.hasCaptured());
    assertTrue("The catalog should have been added to the input stream", catalogResult.hasCaptured());
    assertTrue("The mediapackage should have had its title updated", catalogResult.hasCaptured());
    assertEquals("The mediapackage title should have been updated.", expectedTitle, mediapackageTitleResult.getValue());
    assertTrue("The catalog should have been created", catalogResult.hasCaptured());
    assertTrue(captureStart.hasCaptured());
    assertTrue(captureEnd.hasCaptured());
    Assert.assertEquals(new Date(DateTimeSupport.fromUTC("2008-03-16T14:00:00Z")), captureStart.getValue());
    Assert.assertEquals(new Date(DateTimeSupport.fromUTC("2008-03-16T14:01:00Z")), captureEnd.getValue());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) Attachment(org.opencastproject.mediapackage.Attachment) AclScope(org.opencastproject.security.api.AclScope) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) CaptureAgentStateService(org.opencastproject.capture.admin.api.CaptureAgentStateService) IngestService(org.opencastproject.ingest.api.IngestService) InputStream(java.io.InputStream) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) Date(java.util.Date) JSONObject(org.json.simple.JSONObject) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Tuple(org.opencastproject.util.data.Tuple) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 35 with Attachment

use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.

the class IndexServiceImplTest method testCreateEventInputNoWorkflowConfigurationExpectsCreatedEvent.

@Test
public void testCreateEventInputNoWorkflowConfigurationExpectsCreatedEvent() throws Exception {
    String expectedTitle = "Test Event Creation";
    String username = "akm220";
    String org = "mh_default_org";
    String[] creators = new String[] {};
    Id mpId = new IdImpl("mp-id");
    String testResourceLocation = "/events/create-event-no-workflow-configuration.json";
    JSONObject metadataJson = (JSONObject) parser.parse(IOUtils.toString(IndexServiceImplTest.class.getResourceAsStream(testResourceLocation)));
    Capture<Catalog> result = EasyMock.newCapture();
    Capture<String> mediapackageIdResult = EasyMock.newCapture();
    Capture<String> catalogIdResult = EasyMock.newCapture();
    Capture<String> filenameResult = EasyMock.newCapture();
    Capture<InputStream> catalogResult = EasyMock.newCapture();
    Capture<String> mediapackageTitleResult = EasyMock.newCapture();
    SecurityService securityService = setupSecurityService(username, org);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIdResult), EasyMock.capture(catalogIdResult), EasyMock.capture(filenameResult), EasyMock.capture(catalogResult))).andReturn(new URI("catalog.xml"));
    EasyMock.replay(workspace);
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Setup mediapackage.
    MediaPackage mediapackage = EasyMock.createMock(MediaPackage.class);
    mediapackage.add(EasyMock.capture(result));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.expect(mediapackage.getCreators()).andReturn(creators);
    mediapackage.addCreator("");
    EasyMock.expectLastCall();
    mediapackage.setTitle(EasyMock.capture(mediapackageTitleResult));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getElements()).andReturn(new MediaPackageElement[] {}).anyTimes();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {}).anyTimes();
    EasyMock.expect(mediapackage.getSeries()).andReturn(null).anyTimes();
    mediapackage.setSeries(EasyMock.anyString());
    EasyMock.expectLastCall();
    mediapackage.setSeriesTitle(EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackage);
    IngestService ingestService = setupIngestService(mediapackage, Capture.<InputStream>newInstance());
    // Setup Authorization Service
    Tuple<MediaPackage, Attachment> returnValue = new Tuple<MediaPackage, Attachment>(mediapackage, null);
    AuthorizationService authorizationService = EasyMock.createMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.setAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class), EasyMock.anyObject(AccessControlList.class))).andReturn(returnValue);
    EasyMock.replay(authorizationService);
    // Run Test
    IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
    indexServiceImpl.setAuthorizationService(setupAuthorizationService(mediapackage));
    indexServiceImpl.setIngestService(ingestService);
    indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.setUserDirectoryService(noUsersUserDirectoryService);
    indexServiceImpl.setSecurityService(securityService);
    indexServiceImpl.setWorkspace(workspace);
    indexServiceImpl.createEvent(metadataJson, mediapackage);
    assertTrue("The catalog must be added to the mediapackage", result.hasCaptured());
    assertEquals("The catalog should have been added to the correct mediapackage", mpId.toString(), mediapackageIdResult.getValue());
    assertTrue("The catalog should have a new id", catalogIdResult.hasCaptured());
    assertTrue("The catalog should have a new filename", filenameResult.hasCaptured());
    assertTrue("The catalog should have been added to the input stream", catalogResult.hasCaptured());
    assertTrue("The mediapackage should have had its title updated", catalogResult.hasCaptured());
    assertEquals("The mediapackage title should have been updated.", expectedTitle, mediapackageTitleResult.getValue());
    assertTrue("The catalog should have been created", catalogResult.hasCaptured());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Attachment(org.opencastproject.mediapackage.Attachment) AclScope(org.opencastproject.security.api.AclScope) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) IngestService(org.opencastproject.ingest.api.IngestService) InputStream(java.io.InputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) JSONObject(org.json.simple.JSONObject) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Tuple(org.opencastproject.util.data.Tuple) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Aggregations

Attachment (org.opencastproject.mediapackage.Attachment)64 MediaPackage (org.opencastproject.mediapackage.MediaPackage)28 URI (java.net.URI)24 IOException (java.io.IOException)20 Job (org.opencastproject.job.api.Job)20 NotFoundException (org.opencastproject.util.NotFoundException)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)18 Track (org.opencastproject.mediapackage.Track)16 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)16 Test (org.junit.Test)15 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)15 Catalog (org.opencastproject.mediapackage.Catalog)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)12 InputStream (java.io.InputStream)11 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 AttachmentImpl (org.opencastproject.mediapackage.attachment.AttachmentImpl)8 Workspace (org.opencastproject.workspace.api.Workspace)8