Search in sources :

Example 16 with ServiceRegistry

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

the class LiveScheduleServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    mimeType = MimeTypes.parseMimeType(MIME_TYPE);
    // Osgi Services
    serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    searchService = EasyMock.createNiceMock(SearchService.class);
    seriesService = EasyMock.createNiceMock(SeriesService.class);
    captureAgentService = EasyMock.createNiceMock(CaptureAgentStateService.class);
    EasyMock.expect(captureAgentService.getAgentCapabilities("demo-capture-agent")).andReturn(new Properties());
    downloadDistributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
    EasyMock.expect(downloadDistributionService.getDistributionType()).andReturn(LiveScheduleServiceImpl.DEFAULT_LIVE_DISTRIBUTION_SERVICE).anyTimes();
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://someUrl"));
    dublinCoreService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
    assetManager = EasyMock.createNiceMock(AssetManager.class);
    authService = new AuthorizationServiceMock();
    organizationService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    Organization defOrg = new DefaultOrganization();
    Map<String, String> orgProps = new HashMap<String, String>();
    orgProps.put(LiveScheduleServiceImpl.PLAYER_PROPERTY, PATH_TO_PLAYER);
    orgProps.put(LiveScheduleServiceImpl.ENGAGE_URL_PROPERTY, ENGAGE_URL);
    org = new JaxbOrganization(ORG_ID, "Test Organization", defOrg.getServers(), defOrg.getAdminRole(), defOrg.getAnonymousRole(), orgProps);
    EasyMock.expect(organizationService.getOrganization(ORG_ID)).andReturn(org).anyTimes();
    // Live service configuration
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(LiveScheduleServiceImpl.LIVE_STREAMING_URL, STREAMING_SERVER_URL);
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_MIME_TYPE, "video/x-flv");
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_NAME, STREAM_NAME);
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_RESOLUTION, "1920x540,960x270");
    props.put(LiveScheduleServiceImpl.LIVE_TARGET_FLAVORS, "presenter/delivery");
    cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc);
    EasyMock.expect(cc.getProperties()).andReturn(props);
    EasyMock.replay(bc, cc);
    service = new LiveScheduleServiceImpl();
    service.setJobPollingInterval(1L);
    service.setSearchService(searchService);
    service.setSeriesService(seriesService);
    service.setCaptureAgentService(captureAgentService);
    service.setServiceRegistry(serviceRegistry);
    service.setWorkspace(workspace);
    service.setDublinCoreService(dublinCoreService);
    service.setAssetManager(assetManager);
    service.setAuthorizationService(authService);
    service.setOrganizationService(organizationService);
    service.activate(cc);
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashMap(java.util.HashMap) Properties(java.util.Properties) URI(java.net.URI) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) SearchService(org.opencastproject.search.api.SearchService) CaptureAgentStateService(org.opencastproject.capture.admin.api.CaptureAgentStateService) AssetManager(org.opencastproject.assetmanager.api.AssetManager) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DownloadDistributionService(org.opencastproject.distribution.api.DownloadDistributionService) SeriesService(org.opencastproject.series.api.SeriesService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Workspace(org.opencastproject.workspace.api.Workspace) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 17 with ServiceRegistry

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

the class AnimateServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    // Skip tests if synfig is not installed
    Assume.assumeTrue(runSynfigTests);
    // create animate service
    animateService = new AnimateServiceImpl();
    // create the needed mocks
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    Workspace workspace = EasyMock.createMock(Workspace.class);
    final String directory = testFolder.newFolder().getAbsolutePath();
    EasyMock.expect(workspace.rootDirectory()).andReturn(directory).anyTimes();
    final Capture<String> collection = EasyMock.newCapture();
    final Capture<String> name = EasyMock.newCapture();
    final Capture<InputStream> in = EasyMock.newCapture();
    EasyMock.expect(workspace.putInCollection(capture(collection), capture(name), capture(in))).andAnswer(() -> {
        File output = new File(directory, "out.mp4");
        FileUtils.copyInputStreamToFile(in.getValue(), output);
        return output.toURI();
    }).once();
    // Finish setting up the mocks
    EasyMock.replay(bc, cc, workspace);
    ServiceRegistry serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
    final Capture<String> type = EasyMock.newCapture();
    final Capture<String> operation = EasyMock.newCapture();
    final Capture<List<String>> args = EasyMock.newCapture();
    EasyMock.expect(serviceRegistry.createJob(capture(type), capture(operation), capture(args), EasyMock.anyFloat())).andAnswer(() -> {
        // you could do work here to return something different if you needed.
        Job job = new JobImpl(0);
        job.setJobType(type.getValue());
        job.setOperation(operation.getValue());
        job.setArguments(args.getValue());
        job.setPayload(animateService.process(job));
        return job;
    }).anyTimes();
    EasyMock.replay(serviceRegistry);
    animateService.setServiceRegistry(serviceRegistry);
    animateService.setWorkspace(workspace);
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 18 with ServiceRegistry

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

the class TimelinePreviewsServiceImplTest method testUpdated.

/**
 * Test of updated method of class TimelinePreviewsServiceImpl.
 * @throws java.lang.Exception
 */
@Test
public void testUpdated() throws Exception {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put(TimelinePreviewsServiceImpl.OPT_RESOLUTION_X, "200");
    properties.put(TimelinePreviewsServiceImpl.OPT_RESOLUTION_Y, "90");
    properties.put(TimelinePreviewsServiceImpl.OPT_OUTPUT_FORMAT, ".jpg");
    properties.put(TimelinePreviewsServiceImpl.OPT_MIMETYPE, "image/jpg");
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getHostRegistrations()).andReturn(new ArrayList());
    EasyMock.replay(serviceRegistry);
    TimelinePreviewsServiceImpl instance = new TimelinePreviewsServiceImpl();
    instance.setServiceRegistry(serviceRegistry);
    try {
        instance.updated(properties);
        // we cannot check private fields but it should not throw any exception
        assertEquals(200, instance.resolutionX);
        assertEquals(90, instance.resolutionY);
        assertEquals(".jpg", instance.outputFormat);
        assertEquals("image/jpg", instance.mimetype);
    } catch (Exception e) {
        fail("updated method should not throw any exceptions but has thrown: " + ExceptionUtils.getStackTrace(e));
    }
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Test(org.junit.Test)

Example 19 with ServiceRegistry

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

the class StartTranscriptionOperationHandlerTest 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());
    // Service registry set up
    Job job1 = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job1.getId()).andReturn(1L);
    EasyMock.expect(job1.getPayload()).andReturn(null).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);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1);
    EasyMock.replay(serviceRegistry);
    // Transcription service set up
    service = EasyMock.createStrictMock(TranscriptionService.class);
    capturedTrack = Capture.newInstance();
    EasyMock.expect(service.startTranscription(EasyMock.anyObject(String.class), EasyMock.capture(capturedTrack))).andReturn(null);
    EasyMock.replay(service);
    // 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("start-transcript", OperationState.RUNNING);
    List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
    operationList.add(operation);
    workflowInstance.setOperations(operationList);
    // Operation handler set up
    operationHandler = new StartTranscriptionOperationHandler();
    operationHandler.setTranscriptionService(service);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : TranscriptionService(org.opencastproject.transcription.api.TranscriptionService) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) 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) Before(org.junit.Before)

Example 20 with ServiceRegistry

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

the class OaiPmhPublicationRestServiceTest method testPublishUsingRemoteService.

@Test
public void testPublishUsingRemoteService() throws Exception {
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.addCreator(CREATOR);
    // 
    final ServiceRegistry registry = EasyMock.createNiceMock(ServiceRegistry.class);
    final ServiceRegistration registration = EasyMock.createNiceMock(ServiceRegistration.class);
    EasyMock.expect(registration.getHost()).andReturn(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort()).anyTimes();
    EasyMock.expect(registration.getPath()).andReturn(url.getPath()).anyTimes();
    EasyMock.expect(registry.getServiceRegistrationsByLoad(EasyMock.anyString())).andReturn(ListBuilders.SIA.mk(registration)).anyTimes();
    EasyMock.replay(registry, registration);
    final OaiPmhPublicationServiceRemoteImpl remote = new OaiPmhPublicationServiceRemoteImpl();
    remote.setTrustedHttpClient(new TestHttpClient());
    remote.setRemoteServiceManager(registry);
    // 
    final Job job = remote.publish(mp, "mmp", new HashSet<String>(), new HashSet<String>(), false);
    assertEquals(job.getUri(), JOB_URI);
}
Also used : OaiPmhPublicationServiceRemoteImpl(org.opencastproject.publication.oaipmh.remote.OaiPmhPublicationServiceRemoteImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) 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