use of org.opencastproject.caption.api.CaptionService in project opencast by opencast.
the class AttachTranscriptionOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// Media package set up
URI mediaPackageURI = StartTranscriptionOperationHandlerTest.class.getResource("/mp.xml").toURI();
mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
URI dfxpURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_dfxp.xml").toURI();
String dfxpXml = FileUtils.readFileToString(new File(dfxpURI));
Attachment captionDfxp = (Attachment) MediaPackageElementParser.getFromXml(dfxpXml);
URI vttURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_vtt.xml").toURI();
String vttXml = FileUtils.readFileToString(new File(vttURI));
Attachment captionVtt = (Attachment) MediaPackageElementParser.getFromXml(vttXml);
// Service registry set up
job1 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job1.getId()).andReturn(1L);
EasyMock.expect(job1.getPayload()).andReturn(dfxpXml).anyTimes();
EasyMock.expect(job1.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job1.getDateCreated()).andReturn(new Date());
EasyMock.expect(job1.getDateStarted()).andReturn(new Date());
EasyMock.expect(job1.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job1);
job2 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job2.getId()).andReturn(2L);
EasyMock.expect(job2.getPayload()).andReturn(vttXml).anyTimes();
EasyMock.expect(job2.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job2.getDateCreated()).andReturn(new Date());
EasyMock.expect(job2.getDateStarted()).andReturn(new Date());
EasyMock.expect(job2.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job2);
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1);
EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job2);
EasyMock.replay(serviceRegistry);
// Transcription service set up
service = EasyMock.createStrictMock(TranscriptionService.class);
EasyMock.expect(service.getGeneratedTranscription("mpId1", "transcriptionJob")).andReturn(captionDfxp);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.expect(service.getGeneratedTranscription("mpId2", "transcriptionJob")).andReturn(captionVtt);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.replay(service);
// Caption service set up
captionService = EasyMock.createNiceMock(CaptionService.class);
// Workspace set up
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo(EasyMock.anyObject(URI.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(// just something valid
new URI("http://opencast.server.com/captions.xml"));
EasyMock.replay(workspace);
// Workflow set up
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("DCE-start-transcription");
def.setPublished(true);
workflowInstance = new WorkflowInstanceImpl(def, mediaPackage, null, null, null, null);
workflowInstance.setId(1);
operation = new WorkflowOperationInstanceImpl("attach-transcript", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(operation);
workflowInstance.setOperations(operationList);
// Operation handler set up
operationHandler = new AttachTranscriptionOperationHandler();
operationHandler.setTranscriptionService(service);
operationHandler.setServiceRegistry(serviceRegistry);
operationHandler.setCaptionService(captionService);
operationHandler.setWorkspace(workspace);
operationHandler.setJobBarrierPollingInterval(1L);
}
Aggregations