Search in sources :

Example 31 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class InspectWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    uriMP = InspectWorkflowOperationHandler.class.getResource("/inspect_mediapackage.xml").toURI();
    uriMPUpdated = InspectWorkflowOperationHandler.class.getResource("/inspect_mediapackage_updated.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    mpUpdatedDC = builder.loadFromXml(uriMPUpdated.toURL().openStream());
    newTrack = (Track) mpUpdatedDC.getTracks()[0];
    // set up service
    operationHandler = new InspectWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    // set up mock metadata and metadata service providing it
    metadata = EasyMock.createNiceMock(MediaPackageMetadata.class);
    EasyMock.expect(metadata.getDate()).andReturn(DATE);
    EasyMock.expect(metadata.getLanguage()).andReturn(LANGUAGE);
    EasyMock.expect(metadata.getLicense()).andReturn(LICENSE);
    EasyMock.expect(metadata.getSeriesIdentifier()).andReturn(SERIES);
    EasyMock.expect(metadata.getSeriesTitle()).andReturn(SERIES_TITLE);
    EasyMock.expect(metadata.getTitle()).andReturn(TITLE);
    EasyMock.replay(metadata);
    // set up mock dublin core and dcService providing it
    DublinCoreCatalog dc = EasyMock.createStrictMock(DublinCoreCatalog.class);
    EasyMock.expect(dc.hasValue(DublinCore.PROPERTY_EXTENT)).andReturn(false);
    dc.set((EName) EasyMock.anyObject(), (DublinCoreValue) EasyMock.anyObject());
    EasyMock.expect(dc.hasValue(DublinCore.PROPERTY_CREATED)).andReturn(false);
    dc.set((EName) EasyMock.anyObject(), (DublinCoreValue) EasyMock.anyObject());
    dc.toXml((ByteArrayOutputStream) EasyMock.anyObject(), EasyMock.anyBoolean());
    // EasyMock.expect(dc.getIdentifier()).andReturn("123");
    EasyMock.replay(dc);
    dcService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
    EasyMock.expect(dcService.getMetadata((MediaPackage) EasyMock.anyObject())).andReturn(metadata);
    EasyMock.expect(dcService.load((InputStream) EasyMock.anyObject())).andReturn(dc);
    EasyMock.replay(dcService);
    operationHandler.setDublincoreService(dcService);
    // set up mock receipt and inspect service providing it
    job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(newTrack)).anyTimes();
    EasyMock.expect(job.getId()).andReturn(new Long(123));
    EasyMock.expect(job.getStatus()).andReturn(Status.FINISHED);
    EasyMock.expect(job.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job.getDateStarted()).andReturn(new Date());
    EasyMock.replay(job);
    // set up mock service registry
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job).anyTimes();
    EasyMock.replay(serviceRegistry);
    operationHandler.setServiceRegistry(serviceRegistry);
    inspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
    EasyMock.expect(inspectionService.enrich((Track) EasyMock.anyObject(), EasyMock.anyBoolean(), (Map<String, String>) EasyMock.anyObject())).andReturn(job);
    EasyMock.replay(inspectionService);
    operationHandler.setInspectionService(inspectionService);
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    // workspace.delete((String) EasyMock.anyObject(), (String) EasyMock.anyObject());
    URI newURI = new URI(NEW_DC_URL);
    EasyMock.expect(workspace.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(newURI);
    EasyMock.expect(workspace.getURI((String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(newURI);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/dublincore.xml").toURI()));
    EasyMock.replay(workspace);
    operationHandler.setWorkspace(workspace);
}
Also used : MediaPackageMetadata(org.opencastproject.metadata.api.MediaPackageMetadata) MediaInspectionService(org.opencastproject.inspection.api.MediaInspectionService) URI(java.net.URI) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) Date(java.util.Date) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 32 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class ConcatWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = InspectWorkflowOperationHandler.class.getResource("/concat_mediapackage.xml").toURI();
    URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/concatenated_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
    encodedTracks = mpEncode.getTracks();
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMP);
    EasyMock.replay(workspace);
    // set up mock receipt
    job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(job.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job.getDateStarted()).andReturn(new Date());
    EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
    EasyMock.replay(job);
    // set up mock service registry
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.replay(serviceRegistry);
    // set up service
    operationHandler = new ConcatWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) URI(java.net.URI) InspectWorkflowOperationHandler(org.opencastproject.workflow.handler.inspection.InspectWorkflowOperationHandler) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 33 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class OaiPmhPublicationServiceImplTest method testPublish.

@Test
public void testPublish() throws MediaPackageException, PublicationException, ServiceRegistryException {
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    Job dummyJob = EasyMock.createMock(Job.class);
    Capture<List<String>> jobArgsCapture = EasyMock.newCapture();
    EasyMock.expect(serviceRegistry.createJob(eq(OaiPmhPublicationService.JOB_TYPE), eq(OaiPmhPublicationServiceImpl.Operation.Publish.toString()), capture(jobArgsCapture))).andReturn(dummyJob).once();
    EasyMock.replay(serviceRegistry);
    service.setServiceRegistry(serviceRegistry);
    Job j = service.publish(mp, "default", Collections.set("catalog-1", "catalog-2", "track-1"), Collections.set("track-1"), true);
    Assert.assertSame(dummyJob, j);
    List<String> jobArgs = jobArgsCapture.getValue();
    // test job arguments
    Assert.assertEquals(5, jobArgs.size());
    Assert.assertTrue(jobArgs.get(0).contains("<mediapackage "));
    Assert.assertEquals("default", jobArgs.get(1));
    String downloadDistributionIdsArg = jobArgs.get(2);
    Assert.assertNotNull(downloadDistributionIdsArg);
    Assert.assertTrue(downloadDistributionIdsArg.contains("catalog-1"));
    Assert.assertTrue(downloadDistributionIdsArg.contains("catalog-2"));
    Assert.assertTrue(downloadDistributionIdsArg.contains("track-1"));
    String streamingDistributionIdsArg = jobArgs.get(3);
    Assert.assertNotNull(streamingDistributionIdsArg);
    Assert.assertTrue(!streamingDistributionIdsArg.contains("catalog-1"));
    Assert.assertTrue(!streamingDistributionIdsArg.contains("catalog-2"));
    Assert.assertTrue(streamingDistributionIdsArg.contains("track-1"));
    Assert.assertTrue(BooleanUtils.toBoolean(jobArgs.get(4)));
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) EasyMock.anyString(org.easymock.EasyMock.anyString) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 34 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class TimelinePreviewsServiceImplTest method testCreateTimelinePreviewImages.

/**
 * Test of createTimelinePreviewImages method of class TimelinePreviewsServiceImpl.
 * @throws java.lang.Exception
 */
@Test
public void testCreateTimelinePreviewImages() throws Exception {
    Job expectedJob = new JobImpl(1);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.createJob(EasyMock.eq(TimelinePreviewsServiceImpl.JOB_TYPE), EasyMock.eq(TimelinePreviewsServiceImpl.Operation.TimelinePreview.toString()), (List<String>) EasyMock.anyObject(), EasyMock.anyFloat())).andReturn(expectedJob);
    EasyMock.replay(serviceRegistry);
    TimelinePreviewsServiceImpl instance = new TimelinePreviewsServiceImpl();
    instance.setServiceRegistry(serviceRegistry);
    Job job = instance.createTimelinePreviewImages(track, 10);
    assertEquals(expectedJob, job);
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 35 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry 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);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbUser(org.opencastproject.security.api.JaxbUser) TranscriptionDatabase(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabase) URI(java.net.URI) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) WorkflowService(org.opencastproject.workflow.api.WorkflowService) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AssetManager(org.opencastproject.assetmanager.api.AssetManager) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) SmtpService(org.opencastproject.kernel.mail.SmtpService) JaxbRole(org.opencastproject.security.api.JaxbRole) JSONObject(org.json.simple.JSONObject) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

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