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