use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class ComposerServiceTest method testMux.
@Test
public void testMux() throws Exception {
assertTrue(sourceVideoOnly.isFile());
assertTrue(sourceAudioOnly.isFile());
// Need different media files
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(sourceVideoOnly).once();
EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(sourceAudioOnly).once();
EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(sourceVideoOnly.toURI()).anyTimes();
composerService.setWorkspace(workspace);
EasyMock.replay(workspace);
Job job = composerService.mux(sourceVideoTrack, sourceAudioTrack, "mux-av.work");
MediaPackageElementParser.getFromXml(job.getPayload());
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
URI mediaPackageURI = IBMWatsonTranscriptionServiceTest.class.getResource("/mp.xml").toURI();
mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
URI audioUrl = IBMWatsonTranscriptionServiceTest.class.getResource("/audio.ogg").toURI();
audioFile = new File(audioUrl);
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(IBMWatsonTranscriptionService.ENABLED_CONFIG, "true");
props.put(IBMWatsonTranscriptionService.IBM_WATSON_USER_CONFIG, "user");
props.put(IBMWatsonTranscriptionService.IBM_WATSON_PSW_CONFIG, "psw");
props.put(IBMWatsonTranscriptionService.COMPLETION_CHECK_BUFFER_CONFIG, 0);
props.put(IBMWatsonTranscriptionService.MAX_PROCESSING_TIME_CONFIG, 0);
props.put(IBMWatsonTranscriptionService.NOTIFICATION_EMAIL_CONFIG, "anyone@opencast.org");
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(cc.getProperties()).andReturn(props).anyTimes();
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://THIS_SERVER");
EasyMock.expect(bc.getProperty("org.opencastproject.security.digest.user")).andReturn("matterhorn_system_account");
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
Map<String, String> orgProps = new HashMap<String, String>();
orgProps.put(IBMWatsonTranscriptionService.ADMIN_URL_PROPERTY, "http://ADMIN_SERVER");
org = new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, null, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, orgProps);
User user = new JaxbUser("admin", null, "test", org, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org));
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
IncidentService incident = EasyMock.createNiceMock(IncidentService.class);
smtpService = EasyMock.createNiceMock(SmtpService.class);
smtpService.send((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
EasyMock.expectLastCall().once();
EasyMock.replay(bc, cc, securityService, orgDirectory, userDirectory, incident, smtpService);
// Mocks for WorkflowDispatcher test
assetManager = EasyMock.createNiceMock(AssetManager.class);
wfService = EasyMock.createNiceMock(WorkflowService.class);
workspace = EasyMock.createNiceMock(Workspace.class);
// Database
database = new TranscriptionDatabase();
database.setEntityManagerFactory(PersistenceUtil.newTestEntityManagerFactory("org.opencastproject.transcription.ibmwatson.persistence"));
database.activate(null);
httpClient = EasyMock.createNiceMock(CloseableHttpClient.class);
service = new IBMWatsonTranscriptionService() {
@Override
protected CloseableHttpClient makeHttpClient() {
return httpClient;
}
};
ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, incident);
service.setOrganizationDirectoryService(orgDirectory);
service.setSecurityService(securityService);
service.setServiceRegistry(serviceRegistry);
service.setUserDirectoryService(userDirectory);
service.setWorkspace(workspace);
service.setDatabase(database);
service.setAssetManager(assetManager);
service.setWorkflowService(wfService);
service.setSmtpService(smtpService);
service.activate(cc);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class AnalyzeAudioWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
URI soxTrackUri = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox-track.xml").toURI();
URI soxEncodeUri = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox-encode-track.xml").toURI();
String soxTrackXml = IOUtils.toString(soxTrackUri.toURL().openStream());
String encodeTrackXml = IOUtils.toString(soxEncodeUri.toURL().openStream());
instance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(instance.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(instance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
EasyMock.replay(instance);
DefaultOrganization org = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, org));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
EasyMock.replay(incidentService);
ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(null, securityService, userDirectoryService, organizationDirectoryService, incidentService);
Job analyzeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Analyze", null, soxTrackXml, false);
analyzeJob.setStatus(Status.FINISHED);
analyzeJob = serviceRegistry.updateJob(analyzeJob);
Job encodeJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Encode", null, encodeTrackXml, false);
encodeJob.setStatus(Status.FINISHED);
encodeJob = serviceRegistry.updateJob(encodeJob);
SoxService sox = EasyMock.createNiceMock(SoxService.class);
EasyMock.expect(sox.analyze((Track) EasyMock.anyObject())).andReturn(analyzeJob).anyTimes();
EasyMock.replay(sox);
ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
EasyMock.expect(composer.encode((Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(encodeJob);
EasyMock.replay(composer);
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.replay(workspace);
// set up the handler
operationHandler = new AnalyzeAudioWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setComposerService(composer);
operationHandler.setSoxService(sox);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.
the class NormalizeAudioWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
URI soxTrackUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-track.xml").toURI();
URI normalizedTrackUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/normalized-track.xml").toURI();
URI soxEncodeUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-encode-track.xml").toURI();
URI soxMuxUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-mux-track.xml").toURI();
String soxTrackXml = IOUtils.toString(soxTrackUri.toURL().openStream());
String encodeTrackXml = IOUtils.toString(soxEncodeUri.toURL().openStream());
String normalizedTrackXml = IOUtils.toString(normalizedTrackUri.toURL().openStream());
String muxedTrackXml = IOUtils.toString(soxMuxUri.toURL().openStream());
instance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(instance.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(instance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
EasyMock.replay(instance);
DefaultOrganization org = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, org));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
EasyMock.replay(incidentService);
ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(null, securityService, userDirectoryService, organizationDirectoryService, incidentService);
Job analyzeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Analyze", null, soxTrackXml, false);
analyzeJob.setStatus(Status.FINISHED);
analyzeJob = serviceRegistry.updateJob(analyzeJob);
Job normalizeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Normalize", null, normalizedTrackXml, false);
normalizeJob.setStatus(Status.FINISHED);
normalizeJob = serviceRegistry.updateJob(normalizeJob);
Job encodeJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Encode", null, encodeTrackXml, false);
encodeJob.setStatus(Status.FINISHED);
encodeJob = serviceRegistry.updateJob(encodeJob);
Job muxJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Mux", null, muxedTrackXml, false);
muxJob.setStatus(Status.FINISHED);
muxJob = serviceRegistry.updateJob(muxJob);
SoxService sox = EasyMock.createNiceMock(SoxService.class);
EasyMock.expect(sox.analyze((Track) EasyMock.anyObject())).andReturn(analyzeJob).anyTimes();
EasyMock.expect(sox.normalize((Track) EasyMock.anyObject(), (Float) EasyMock.anyObject())).andReturn(normalizeJob).anyTimes();
EasyMock.replay(sox);
ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
EasyMock.expect(composer.encode((Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(encodeJob);
EasyMock.expect(composer.mux((Track) EasyMock.anyObject(), (Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(muxJob);
EasyMock.replay(composer);
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(new URI("fooVideo.flv"));
EasyMock.replay(workspace);
// set up the handler
operationHandler = new NormalizeAudioWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setComposerService(composer);
operationHandler.setSoxService(sox);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.workspace.api.Workspace 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