use of org.opencastproject.serviceregistry.api.ServiceRegistry 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.serviceregistry.api.ServiceRegistry 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.serviceregistry.api.ServiceRegistry 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);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class DuplicateEventWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
operationHandler = new DuplicateEventWorkflowOperationHandler();
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = getClass().getResource("/duplicate-event_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
workspace = createNiceMock(Workspace.class);
assetManager = createNiceMock(AssetManager.class);
distributionService = createNiceMock(DistributionService.class);
serviceRegistry = createNiceMock(ServiceRegistry.class);
operationHandler.setWorkspace(workspace);
operationHandler.setAssetManager(assetManager);
operationHandler.setDistributionService(distributionService);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class SilenceDetectionWorkflowOperationHandlerTest method testStartOperation.
@Test
public void testStartOperation() throws WorkflowOperationException, SilenceDetectionFailedException, NotFoundException, ServiceRegistryException, MediaPackageException, SmilException, MalformedURLException, JAXBException, SAXException, IOException {
Smil smil = smilService.fromXml(new File(smilURI)).getSmil();
Job job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(smil.toXML()).anyTimes();
EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(silenceDetectionServiceMock.detect((Track) EasyMock.anyObject(), (Track[]) EasyMock.anyObject())).andReturn(job);
EasyMock.expect(workspaceMock.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(smilURI);
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
silenceDetectionOperationHandler.setServiceRegistry(serviceRegistry);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
EasyMock.replay(job, serviceRegistry, silenceDetectionServiceMock, workspaceMock);
WorkflowInstanceImpl workflowInstance = getWorkflowInstance(mp, getDefaultConfiguration());
WorkflowOperationResult result = silenceDetectionOperationHandler.start(workflowInstance, null);
Assert.assertNotNull("SilenceDetectionWorkflowOperationHandler workflow operation returns null " + "but should be an instantiated WorkflowOperationResult", result);
EasyMock.verify(silenceDetectionServiceMock, workspaceMock);
WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
String smilFlavorSubtypeProperty = worflowOperationInstance.getConfiguration("smil-flavor-subtype");
// test media package contains new smil catalog
MediaPackageElementFlavor smilPartialFlavor = new MediaPackageElementFlavor("*", smilFlavorSubtypeProperty);
Catalog[] smilCatalogs = mp.getCatalogs(smilPartialFlavor);
Assert.assertTrue("Media package should contain a smil catalog", smilCatalogs != null && smilCatalogs.length > 0);
}
Aggregations