Search in sources :

Example 1 with Target

use of org.opencastproject.assetmanager.api.query.Target in project opencast by opencast.

the class LiveScheduleServiceImplTest method setUpAssetManager.

private void setUpAssetManager(MediaPackage mp) {
    version = EasyMock.createNiceMock(Version.class);
    snapshot = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(snapshot.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId()).anyTimes();
    EasyMock.expect(snapshot.getVersion()).andReturn(version);
    ARecord aRec = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot)).anyTimes();
    Stream<ARecord> recStream = Stream.mk(aRec);
    Predicate p = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(p.and(p)).andReturn(p).anyTimes();
    AResult r = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(r.getSize()).andReturn(1L).anyTimes();
    EasyMock.expect(r.getRecords()).andReturn(recStream).anyTimes();
    Target t = EasyMock.createNiceMock(Target.class);
    ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery).anyTimes();
    EasyMock.expect(selectQuery.run()).andReturn(r).anyTimes();
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    EasyMock.expect(query.snapshot()).andReturn(t).anyTimes();
    EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p).anyTimes();
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery).anyTimes();
    VersionField v = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(v.isLatest()).andReturn(p).anyTimes();
    EasyMock.expect(query.version()).andReturn(v).anyTimes();
    EasyMock.expect(assetManager.createQuery()).andReturn(query).anyTimes();
    EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) Version(org.opencastproject.assetmanager.api.Version) VersionField(org.opencastproject.assetmanager.api.query.VersionField) AResult(org.opencastproject.assetmanager.api.query.AResult) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Predicate(org.opencastproject.assetmanager.api.query.Predicate)

Example 2 with Target

use of org.opencastproject.assetmanager.api.query.Target in project opencast by opencast.

the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunTranscriptionCompletedState.

@Test
public void testWorkflowDispatcherRunTranscriptionCompletedState() throws Exception {
    database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.updateJobControl(JOB_ID, TranscriptionJobControl.Status.TranscriptionComplete.name());
    // Mocks for query, result, etc
    Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
    ARecord aRec = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
    Stream<ARecord> recStream = Stream.mk(aRec);
    Predicate p = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(p.and(p)).andReturn(p);
    AResult r = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(r.getSize()).andReturn(1L);
    EasyMock.expect(r.getRecords()).andReturn(recStream);
    Target t = EasyMock.createNiceMock(Target.class);
    ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
    EasyMock.expect(selectQuery.run()).andReturn(r);
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    EasyMock.expect(query.snapshot()).andReturn(t);
    EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
    VersionField v = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(v.isLatest()).andReturn(p);
    EasyMock.expect(query.version()).andReturn(v);
    EasyMock.expect(assetManager.createQuery()).andReturn(query);
    EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
    Capture<Set<String>> capturedMpIds = Capture.newInstance();
    WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
    EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
    List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
    wfList.add(new WorkflowInstanceImpl());
    Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
    Workflows wfs = EasyMock.createNiceMock(Workflows.class);
    EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
    service.setWfUtil(wfs);
    EasyMock.replay(wfService, wfs);
    WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
    dispatcher.run();
    // Check if only one mp has a workflow created for it
    Assert.assertEquals(1, capturedMpIds.getValue().size());
    // And if it was the correct one
    Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
    // Check if status in db was updated
    TranscriptionJobControl job = database.findByJob(JOB_ID);
    Assert.assertNotNull(job);
    Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
Also used : TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) Set(java.util.Set) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) Workflows(org.opencastproject.assetmanager.util.Workflows) VersionField(org.opencastproject.assetmanager.api.query.VersionField) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowDispatcher(org.opencastproject.transcription.ibmwatson.IBMWatsonTranscriptionService.WorkflowDispatcher) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) ConfiguredWorkflow(org.opencastproject.workflow.api.ConfiguredWorkflow) Predicate(org.opencastproject.assetmanager.api.query.Predicate) Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) AResult(org.opencastproject.assetmanager.api.query.AResult) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Test(org.junit.Test)

Example 3 with Target

use of org.opencastproject.assetmanager.api.query.Target in project opencast by opencast.

the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunProgressState.

@Test
public void testWorkflowDispatcherRunProgressState() throws Exception {
    InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PULLED_TRANSCRIPTION_FILE);
    database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), 0);
    database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    EasyMock.expect(workspace.putInCollection(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://anything"));
    EasyMock.replay(workspace);
    HttpEntity httpEntity = EasyMock.createNiceMock(HttpEntity.class);
    EasyMock.expect(httpEntity.getContent()).andReturn(stream);
    CloseableHttpResponse response = EasyMock.createNiceMock(CloseableHttpResponse.class);
    StatusLine status = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(response.getStatusLine()).andReturn(status).anyTimes();
    EasyMock.expect(response.getEntity()).andReturn(httpEntity).anyTimes();
    EasyMock.expect(status.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
    EasyMock.replay(httpEntity, response, status);
    Capture<HttpGet> capturedGet = Capture.newInstance();
    EasyMock.expect(httpClient.execute(EasyMock.capture(capturedGet))).andReturn(response);
    EasyMock.replay(httpClient);
    // enrich(q.select(q.snapshot()).where(q.mediaPackageId(mpId).and(q.version().isLatest())).run()).getSnapshots();
    // Mocks for query, result, etc
    Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
    ARecord aRec = EasyMock.createNiceMock(ARecord.class);
    EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
    Stream<ARecord> recStream = Stream.mk(aRec);
    Predicate p = EasyMock.createNiceMock(Predicate.class);
    EasyMock.expect(p.and(p)).andReturn(p);
    AResult r = EasyMock.createNiceMock(AResult.class);
    EasyMock.expect(r.getSize()).andReturn(1L);
    EasyMock.expect(r.getRecords()).andReturn(recStream);
    Target t = EasyMock.createNiceMock(Target.class);
    ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
    EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
    EasyMock.expect(selectQuery.run()).andReturn(r);
    AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
    EasyMock.expect(query.snapshot()).andReturn(t);
    EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
    EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
    VersionField v = EasyMock.createNiceMock(VersionField.class);
    EasyMock.expect(v.isLatest()).andReturn(p);
    EasyMock.expect(query.version()).andReturn(v);
    EasyMock.expect(assetManager.createQuery()).andReturn(query);
    EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
    Capture<Set<String>> capturedMpIds = Capture.newInstance();
    WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
    EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
    List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
    wfList.add(new WorkflowInstanceImpl());
    Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
    Workflows wfs = EasyMock.createNiceMock(Workflows.class);
    EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
    service.setWfUtil(wfs);
    EasyMock.replay(wfService, wfs);
    WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
    dispatcher.run();
    // Check if it called the external service to get the results
    Assert.assertEquals("https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions/" + JOB_ID, capturedGet.getValue().getURI().toString());
    // Check if only one mp has a workflow created for it
    Assert.assertEquals(1, capturedMpIds.getValue().size());
    // And if it was the correct one
    Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
    // Check if status in db was updated
    TranscriptionJobControl job = database.findByJob(JOB_ID);
    Assert.assertNotNull(job);
    Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
Also used : Set(java.util.Set) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) WorkflowDispatcher(org.opencastproject.transcription.ibmwatson.IBMWatsonTranscriptionService.WorkflowDispatcher) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) Predicate(org.opencastproject.assetmanager.api.query.Predicate) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) AResult(org.opencastproject.assetmanager.api.query.AResult) TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) Workflows(org.opencastproject.assetmanager.util.Workflows) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VersionField(org.opencastproject.assetmanager.api.query.VersionField) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) ConfiguredWorkflow(org.opencastproject.workflow.api.ConfiguredWorkflow) StatusLine(org.apache.http.StatusLine) Snapshot(org.opencastproject.assetmanager.api.Snapshot) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Test(org.junit.Test)

Aggregations

Snapshot (org.opencastproject.assetmanager.api.Snapshot)3 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)3 ARecord (org.opencastproject.assetmanager.api.query.ARecord)3 AResult (org.opencastproject.assetmanager.api.query.AResult)3 ASelectQuery (org.opencastproject.assetmanager.api.query.ASelectQuery)3 Predicate (org.opencastproject.assetmanager.api.query.Predicate)3 Target (org.opencastproject.assetmanager.api.query.Target)3 VersionField (org.opencastproject.assetmanager.api.query.VersionField)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 Test (org.junit.Test)2 Workflows (org.opencastproject.assetmanager.util.Workflows)2 WorkflowDispatcher (org.opencastproject.transcription.ibmwatson.IBMWatsonTranscriptionService.WorkflowDispatcher)2 TranscriptionJobControl (org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl)2 ConfiguredWorkflow (org.opencastproject.workflow.api.ConfiguredWorkflow)2 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)2 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)2 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)2 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1