Search in sources :

Example 36 with ServiceRegistry

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);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ComposerService(org.opencastproject.composer.api.ComposerService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) SoxService(org.opencastproject.sox.api.SoxService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) Track(org.opencastproject.mediapackage.Track) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 37 with 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);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ComposerService(org.opencastproject.composer.api.ComposerService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) SoxService(org.opencastproject.sox.api.SoxService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) Track(org.opencastproject.mediapackage.Track) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 38 with 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);
}
Also used : TranscriptionService(org.opencastproject.transcription.api.TranscriptionService) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Attachment(org.opencastproject.mediapackage.Attachment) URI(java.net.URI) Date(java.util.Date) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) CaptionService(org.opencastproject.caption.api.CaptionService) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 39 with ServiceRegistry

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);
}
Also used : AssetManager(org.opencastproject.assetmanager.api.AssetManager) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) URI(java.net.URI) DistributionService(org.opencastproject.distribution.api.DistributionService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 40 with 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);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) Smil(org.opencastproject.smil.entity.api.Smil) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) File(java.io.File) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Track(org.opencastproject.mediapackage.Track) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Aggregations

ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)40 Job (org.opencastproject.job.api.Job)29 Before (org.junit.Before)24 URI (java.net.URI)18 Workspace (org.opencastproject.workspace.api.Workspace)17 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)13 File (java.io.File)11 Date (java.util.Date)9 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)9 SecurityService (org.opencastproject.security.api.SecurityService)9 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)8 List (java.util.List)7 Track (org.opencastproject.mediapackage.Track)7 JobImpl (org.opencastproject.job.api.JobImpl)6 JaxbUser (org.opencastproject.security.api.JaxbUser)6 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)6 BundleContext (org.osgi.framework.BundleContext)6 ComponentContext (org.osgi.service.component.ComponentContext)6