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)));
}
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));
}
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);
}
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");
}
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);
}
Aggregations