Search in sources :

Example 6 with Id

use of org.opencastproject.mediapackage.identifier.Id 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)

Example 7 with Id

use of org.opencastproject.mediapackage.identifier.Id in project opencast by opencast.

the class ExecuteOnceWorkflowOperationHandlerTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Mocking just about everything, just testing the mediapackage parse
    String expectedTypeString = "catalog";
    String catalogId = "catalog-id";
    URI catUri = new URI("http://api.com/catalog");
    catalog = CatalogImpl.newInstance();
    catalog.addTag("engage-download");
    catalog.setIdentifier(catalogId);
    catalog.setURI(catUri);
    WorkflowOperationInstance operation = EasyMock.createMock(WorkflowOperationInstance.class);
    EasyMock.expect(operation.getId()).andReturn(123L).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXEC_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.PARAMS_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.LOAD_PROPERTY)).andReturn("123").anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_TAGS_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.OUTPUT_FILENAME_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.SET_WF_PROPS_PROPERTY)).andReturn("false").anyTimes();
    // these two need to supply a real string
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXPECTED_TYPE_PROPERTY)).andReturn(expectedTypeString).anyTimes();
    EasyMock.replay(operation);
    Id mpId = EasyMock.createMock(Id.class);
    MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
    mediaPackage.add((MediaPackageElement) EasyMock.anyObject());
    EasyMock.expect(mediaPackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.replay(mediaPackage);
    workspaceService = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspaceService.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(catUri).anyTimes();
    EasyMock.replay(workspaceService);
    workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(operation);
    EasyMock.replay(workflowInstance);
    // Override the waitForStatus method to not block the jobs
    execOnceWOH = new ExecuteOnceWorkflowOperationHandler() {

        @Override
        protected Result waitForStatus(long timeout, Job... jobs) {
            HashMap<Job, Status> map = Stream.mk(jobs).foldl(new HashMap<Job, Status>(), new Fn2<HashMap<Job, Status>, Job, HashMap<Job, Status>>() {

                @Override
                public HashMap<Job, Status> apply(HashMap<Job, Status> a, Job b) {
                    a.put(b, Status.FINISHED);
                    return a;
                }
            });
            return new Result(map);
        }
    };
    execOnceWOH.setWorkspace(workspaceService);
}
Also used : Status(org.opencastproject.job.api.Job.Status) HashMap(java.util.HashMap) Fn2(com.entwinemedia.fn.Fn2) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) Result(org.opencastproject.job.api.JobBarrier.Result) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 8 with Id

use of org.opencastproject.mediapackage.identifier.Id in project opencast by opencast.

the class PublishEngageWorkflowOperationHandlerTest method testDefaultPlayerPath.

@Test
public void testDefaultPlayerPath() throws URISyntaxException {
    URI engageURI = new URI("http://engage.org");
    String mpId = "mp-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(getOrgWithoutPlayerPath()).once();
    EasyMock.replay(element, mp, securityService);
    // Test default player path
    PublishEngageWorkflowOperationHandler publishEngagePublish = new PublishEngageWorkflowOperationHandler();
    publishEngagePublish.setSecurityService(securityService);
    URI result = publishEngagePublish.createEngageUri(engageURI, mp);
    assertEquals(engageURI.toString() + PublishEngageWorkflowOperationHandler.DEFAULT_PLAYER_PATH + "?id=" + mpId, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Example 9 with Id

use of org.opencastproject.mediapackage.identifier.Id in project opencast by opencast.

the class PublishEngageWorkflowOperationHandlerTest method testPlayerUrl.

@Test
public void testPlayerUrl() throws WorkflowOperationException, URISyntaxException {
    URI engageURI = new URI("http://engage.org");
    String mpId = "mp-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(getOrgWithPlayerPath()).once();
    EasyMock.replay(element, mp, securityService);
    // Test configured organization player path
    PublishEngageWorkflowOperationHandler publishEngagePublish = new PublishEngageWorkflowOperationHandler();
    publishEngagePublish.setSecurityService(securityService);
    URI result = publishEngagePublish.createEngageUri(engageURI, mp);
    assertEquals(engageURI.toString() + examplePlayer + "?id=" + mpId, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Example 10 with Id

use of org.opencastproject.mediapackage.identifier.Id in project opencast by opencast.

the class ConfigurablePublishWorkflowOperationHandlerTest method testTemplateReplacement.

@Test
public void testTemplateReplacement() throws WorkflowOperationException, URISyntaxException {
    URI elementUri = new URI("http://element.com/path/to/element/element.mp4");
    String mpId = "mp-id";
    String pubUUID = "test-uuid";
    String seriesId = "series-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    EasyMock.expect(element.getURI()).andStubReturn(elementUri);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andStubReturn(org);
    EasyMock.replay(element, mp, securityService);
    // Test player path and mediapackage id
    ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    URI result = configurePublish.populateUrlWithVariables("${player_path}${event_id}", mp, pubUUID);
    assertEquals(examplePlayer + "mp-id", result.toString());
    // Test without series
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
    assertEquals("/mp-id", result.toString());
    // Test with series
    mp = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    EasyMock.expect(mp.getSeries()).andStubReturn(seriesId);
    EasyMock.replay(mp);
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
    assertEquals("series-id/mp-id", result.toString());
    // Test publication uuid
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${publication_id}", mp, pubUUID);
    assertEquals(pubUUID, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)10 Id (org.opencastproject.mediapackage.identifier.Id)10 URI (java.net.URI)8 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)8 IdImpl (org.opencastproject.mediapackage.identifier.IdImpl)8 Test (org.junit.Test)7 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)6 SecurityService (org.opencastproject.security.api.SecurityService)6 Workspace (org.opencastproject.workspace.api.Workspace)6 InputStream (java.io.InputStream)5 Catalog (org.opencastproject.mediapackage.Catalog)5 JSONObject (org.json.simple.JSONObject)4 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)4 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)4 AccessControlList (org.opencastproject.security.api.AccessControlList)4 Date (java.util.Date)3 IngestService (org.opencastproject.ingest.api.IngestService)3 Attachment (org.opencastproject.mediapackage.Attachment)3 AclScope (org.opencastproject.security.api.AclScope)3 LinkedHashMap (java.util.LinkedHashMap)2