Search in sources :

Example 21 with ServiceRegistry

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

the class OaiPmhPublicationServiceImplTest method testUpdateMetadata.

@Test
public void testUpdateMetadata() throws PublicationException, ServiceRegistryException, MediaPackageException {
    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.UpdateMetadata.toString()), capture(jobArgsCapture))).andReturn(dummyJob).once();
    EasyMock.replay(serviceRegistry);
    service.setServiceRegistry(serviceRegistry);
    Set<String> flavorsSet = Collections.set("dublincore/*", "security/*");
    Set<String> tagsSet = Collections.set("archive", "other");
    Job j = service.updateMetadata(mp, "default", flavorsSet, tagsSet, true);
    Assert.assertSame(dummyJob, j);
    // test job arguments
    List<String> jobArgs = jobArgsCapture.getValue();
    Assert.assertEquals(5, jobArgs.size());
    Assert.assertTrue(jobArgs.get(0).contains("<mediapackage "));
    Assert.assertEquals("default", jobArgs.get(1));
    Assert.assertEquals(StringUtils.join(flavorsSet, OaiPmhPublicationServiceImpl.SEPARATOR), jobArgs.get(2));
    Assert.assertEquals(StringUtils.join(tagsSet, OaiPmhPublicationServiceImpl.SEPARATOR), jobArgs.get(3));
    Assert.assertTrue(Boolean.valueOf(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 22 with ServiceRegistry

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

the class OaiPmhPublicationServiceImplTest method testRetract.

@Test
public void testRetract() throws NotFoundException, 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.Retract.toString()), capture(jobArgsCapture))).andReturn(dummyJob).once();
    EasyMock.replay(serviceRegistry);
    service.setServiceRegistry(serviceRegistry);
    Job j = service.retract(mp2, "default");
    Assert.assertSame(dummyJob, j);
    // test job arguments
    List<String> jobArgs = jobArgsCapture.getValue();
    Assert.assertEquals(2, jobArgs.size());
    Assert.assertTrue(jobArgs.get(0).contains("<mediapackage "));
    Assert.assertEquals("default", jobArgs.get(1));
}
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 23 with ServiceRegistry

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

the class CleanupWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    cleanupWOH = new CleanupWorkflowOperationHandler();
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getBaseUri()).andReturn(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX)).anyTimes();
    EasyMock.replay(workspace);
    cleanupWOH.setWorkspace(workspace);
    List<ServiceRegistration> wfrServiceRegistrations = new ArrayList<ServiceRegistration>();
    wfrServiceRegistrations.add(createWfrServiceRegistration(HOSTNAME_NODE1, WFR_URL_PREFIX));
    wfrServiceRegistrations.add(createWfrServiceRegistration(HOSTNAME_NODE2, WFR_URL_PREFIX));
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getServiceRegistrationsByType(EasyMock.eq(WorkingFileRepository.SERVICE_TYPE))).andReturn(wfrServiceRegistrations).anyTimes();
    Job currentJob = EasyMock.createNiceMock(Job.class);
    currentJob.setArguments((List<String>) EasyMock.anyObject());
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(currentJob).anyTimes();
    EasyMock.expect(serviceRegistry.updateJob((Job) EasyMock.anyObject())).andReturn(currentJob).anyTimes();
    EasyMock.expect(serviceRegistry.getChildJobs(EasyMock.anyLong())).andReturn(new ArrayList<Job>()).anyTimes();
    EasyMock.replay(serviceRegistry, currentJob);
    cleanupWOH.setServiceRegistry(serviceRegistry);
    TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    HttpResponse httpResponse = EasyMock.createNiceMock(HttpResponse.class);
    StatusLine responseStatusLine = EasyMock.createNiceMock(StatusLine.class);
    EasyMock.expect(responseStatusLine.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
    EasyMock.expect(httpResponse.getStatusLine()).andReturn(responseStatusLine).anyTimes();
    EasyMock.expect(httpClient.execute(StoreUrisArgumentMatcher.createMatcher(deletedFilesURIs, UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX)))).andReturn(httpResponse).anyTimes();
    EasyMock.replay(httpClient, httpResponse, responseStatusLine);
    cleanupWOH.setTrustedHttpClient(httpClient);
}
Also used : TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) StatusLine(org.apache.http.StatusLine) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Before(org.junit.Before)

Example 24 with ServiceRegistry

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

the class WorkflowServiceSolrIndexTest method setUp.

@Before
public void setUp() throws Exception {
    // security service
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    OrganizationDirectoryService orgDirectroy = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectroy.getOrganization((String) EasyMock.anyObject())).andReturn(securityService.getOrganization()).anyTimes();
    EasyMock.replay(orgDirectroy);
    // Create a job with a workflow as its payload
    List<Job> jobs = new ArrayList<>();
    Job job = new JobImpl();
    WorkflowInstanceImpl workflow = new WorkflowInstanceImpl();
    workflow.setId(123);
    workflow.setCreator(securityService.getUser());
    workflow.setOrganization(securityService.getOrganization());
    workflow.setState(WorkflowState.INSTANTIATED);
    workflow.setMediaPackage(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    String jobPayload = WorkflowParser.toXml(workflow);
    job.setPayload(jobPayload);
    job.setOrganization(securityService.getOrganization().getId());
    jobs.add(job);
    // Mock up the service registry to return the job
    ServiceRegistry serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.count(WorkflowService.JOB_TYPE, null)).andReturn(1L);
    EasyMock.expect(serviceRegistry.getJobs(WorkflowService.JOB_TYPE, null)).andReturn(jobs);
    EasyMock.expect(serviceRegistry.getJob(123)).andReturn(job);
    EasyMock.expect(serviceRegistry.getJobPayloads("START_WORKFLOW")).andReturn(Collections.singletonList(jobPayload));
    EasyMock.replay(serviceRegistry);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    // Now create the dao
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
    dao.setServiceRegistry(serviceRegistry);
    dao.setSecurityService(securityService);
    dao.setOrgDirectory(orgDirectroy);
    dao.activate("System Admin");
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) JobImpl(org.opencastproject.job.api.JobImpl) SecurityService(org.opencastproject.security.api.SecurityService) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 25 with ServiceRegistry

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

the class WaveformServiceImplTest method testGenerateWaveformImage.

/**
 * Test of createWaveformImage method of class WaveformServiceImpl.
 */
@Test
public void testGenerateWaveformImage() throws Exception {
    Job expectedJob = new JobImpl(1);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.createJob(EasyMock.eq(WaveformServiceImpl.JOB_TYPE), EasyMock.eq(WaveformServiceImpl.Operation.Waveform.toString()), (List<String>) EasyMock.anyObject(), EasyMock.anyFloat())).andReturn(expectedJob);
    EasyMock.replay(serviceRegistry);
    WaveformServiceImpl instance = new WaveformServiceImpl();
    instance.setServiceRegistry(serviceRegistry);
    Job job = instance.createWaveformImage(dummyTrack);
    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)

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