Search in sources :

Example 1 with IngestService

use of org.opencastproject.ingest.api.IngestService in project opencast by opencast.

the class IndexServiceImplTest method testCreateEventInputNormalExpectsCreatedEvent.

@Test
public void testCreateEventInputNormalExpectsCreatedEvent() 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.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());
    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) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) 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 2 with IngestService

use of org.opencastproject.ingest.api.IngestService in project opencast by opencast.

the class IndexServiceImplTest method setupIngestService.

private IngestService setupIngestService(MediaPackage mediapackage, Capture<InputStream> captureInputStream) throws MediaPackageException, HandleException, IOException, IngestException, NotFoundException {
    // Setup ingest service.
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    IngestService ingestService = EasyMock.createMock(IngestService.class);
    EasyMock.expect(ingestService.createMediaPackage()).andReturn(mediapackage).anyTimes();
    EasyMock.expect(ingestService.addTrack(EasyMock.anyObject(InputStream.class), EasyMock.anyString(), EasyMock.anyObject(MediaPackageElementFlavor.class), EasyMock.anyObject(MediaPackage.class))).andReturn(mediapackage).anyTimes();
    EasyMock.expect(ingestService.addCatalog(EasyMock.capture(captureInputStream), EasyMock.anyObject(String.class), EasyMock.anyObject(MediaPackageElementFlavor.class), EasyMock.anyObject(MediaPackage.class))).andReturn(mediapackage).anyTimes();
    EasyMock.expect(ingestService.addAttachment(EasyMock.capture(captureInputStream), EasyMock.anyObject(String.class), EasyMock.anyObject(MediaPackageElementFlavor.class), EasyMock.anyObject(MediaPackage.class))).andReturn(mediapackage).anyTimes();
    EasyMock.expect(ingestService.ingest(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(String.class), EasyMock.<Map<String, String>>anyObject())).andReturn(workflowInstance).anyTimes();
    EasyMock.replay(ingestService);
    return ingestService;
}
Also used : IngestService(org.opencastproject.ingest.api.IngestService) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with IngestService

use of org.opencastproject.ingest.api.IngestService in project opencast by opencast.

the class IngestRestServiceTest method testLegacyMediaPackageIdPropertyUsingIngest.

@Test
public void testLegacyMediaPackageIdPropertyUsingIngest() throws Exception {
    // Create a mock ingest service
    Capture<Map<String, String>> workflowConfigCapture = EasyMock.newCapture();
    IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
    EasyMock.expect(ingestService.createMediaPackage()).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.ingest(EasyMock.anyObject(MediaPackage.class), EasyMock.anyString(), EasyMock.capture(workflowConfigCapture))).andReturn(new WorkflowInstanceImpl());
    EasyMock.replay(ingestService);
    restService.setIngestService(ingestService);
    String mpId = "6f7a7850-3232-4719-9064-24c9bad2832f";
    MultivaluedMap<String, String> metadataMap = new MetadataMap<>();
    Response createMediaPackage = restService.createMediaPackage();
    MediaPackage mp = (MediaPackage) createMediaPackage.getEntity();
    metadataMap.add("mediaPackage", MediaPackageParser.getAsXml(mp));
    metadataMap.add(IngestRestService.WORKFLOW_INSTANCE_ID_PARAM, mpId);
    Response response = restService.ingest(metadataMap);
    Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
    Map<String, String> config = workflowConfigCapture.getValue();
    Assert.assertFalse(config.isEmpty());
    Assert.assertEquals(mpId, config.get(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY));
}
Also used : Response(javax.ws.rs.core.Response) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) IngestService(org.opencastproject.ingest.api.IngestService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.Test)

Example 4 with IngestService

use of org.opencastproject.ingest.api.IngestService in project opencast by opencast.

the class IngestRestServiceTest method setUp.

@Before
public void setUp() throws Exception {
    testDir = new File("./target", "ingest-rest-service-test");
    if (testDir.exists()) {
        FileUtils.deleteQuietly(testDir);
        logger.info("Removing  " + testDir.getAbsolutePath());
    } else {
        logger.info("Didn't Delete " + testDir.getAbsolutePath());
    }
    testDir.mkdir();
    restService = new IngestRestService();
    // Create a mock ingest service
    IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
    EasyMock.expect(ingestService.createMediaPackage()).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.createMediaPackage("1a6f70ab-4262-4523-9f8e-babce22a1ea8")).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(new UUIDIdBuilderImpl().fromString("1a6f70ab-4262-4523-9f8e-babce22a1ea8")));
    EasyMock.expect(ingestService.addAttachment((URI) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addCatalog((URI) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addTrack((URI) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addTrack((URI) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addAttachment((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addAttachment((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addCatalog((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addCatalog((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.addPartialTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), EasyMock.anyLong(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.replay(ingestService);
    // Set the service, and activate the rest endpoint
    restService.setIngestService(ingestService);
    restService.activate(null);
}
Also used : IngestService(org.opencastproject.ingest.api.IngestService) File(java.io.File) UUIDIdBuilderImpl(org.opencastproject.mediapackage.identifier.UUIDIdBuilderImpl) Before(org.junit.Before)

Example 5 with IngestService

use of org.opencastproject.ingest.api.IngestService in project opencast by opencast.

the class IngestRestServiceTest method setupAddZippedMediaPackageIngestService.

@SuppressWarnings({ "unchecked", "deprecation" })
private IngestService setupAddZippedMediaPackageIngestService() {
    // Create a mock ingest service
    IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
    try {
        EasyMock.expect(ingestService.addZippedMediaPackage(EasyMock.anyObject(InputStream.class), EasyMock.anyString(), EasyMock.anyObject(Map.class), EasyMock.anyLong())).andAnswer(() -> {
            limitVerifier.callback();
            return new WorkflowInstanceImpl();
        }).anyTimes();
        EasyMock.expect(ingestService.addZippedMediaPackage(EasyMock.anyObject(InputStream.class), EasyMock.anyString(), EasyMock.anyObject(Map.class))).andAnswer(() -> {
            limitVerifier.callback();
            return new WorkflowInstanceImpl();
        }).anyTimes();
    } catch (Exception e) {
        Assert.fail("Threw exception " + e.getMessage());
    }
    EasyMock.replay(ingestService);
    return ingestService;
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) IngestService(org.opencastproject.ingest.api.IngestService) IOException(java.io.IOException)

Aggregations

IngestService (org.opencastproject.ingest.api.IngestService)10 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 MediaPackage (org.opencastproject.mediapackage.MediaPackage)5 URI (java.net.URI)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 JSONObject (org.json.simple.JSONObject)3 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)3 Attachment (org.opencastproject.mediapackage.Attachment)3 Catalog (org.opencastproject.mediapackage.Catalog)3 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)3 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)3 Id (org.opencastproject.mediapackage.identifier.Id)3 IdImpl (org.opencastproject.mediapackage.identifier.IdImpl)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 AccessControlList (org.opencastproject.security.api.AccessControlList)3 AclScope (org.opencastproject.security.api.AclScope)3 AuthorizationService (org.opencastproject.security.api.AuthorizationService)3 SecurityService (org.opencastproject.security.api.SecurityService)3