use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class OaiPmhPublicationServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
mp = MediaPackageSupport.loadFromClassPath("/mediapackage.xml");
mp2 = MediaPackageSupport.loadFromClassPath("/mediapackage2.xml");
validOaiPmhRepositories = Collections.list("default");
OaiPmhServerInfo oaiPmhServerInfo = EasyMock.createNiceMock(OaiPmhServerInfo.class);
EasyMock.expect(oaiPmhServerInfo.hasRepo(anyString())).andAnswer(() -> validOaiPmhRepositories.contains((String) EasyMock.getCurrentArguments()[0])).anyTimes();
EasyMock.expect(oaiPmhServerInfo.getMountPoint()).andReturn(OAI_PMH_SERVER_MOUNT_POINT).anyTimes();
DefaultOrganization org = new DefaultOrganization() {
@Override
public Map<String, String> getProperties() {
HashMap<String, String> props = new HashMap<>();
props.putAll(DEFAULT_PROPERTIES);
props.put(ORG_CFG_OAIPMH_SERVER_HOSTURL, OAI_PMH_SERVER_URL);
return props;
}
};
HashSet<JaxbRole> roles = new HashSet<JaxbRole>();
roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org, ""));
User user = new JaxbUser("admin", "test", org, roles);
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();
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, EasyMock.createNiceMock(IncidentService.class));
// Finish setting up the mocks
EasyMock.replay(oaiPmhServerInfo, orgDirectory, userDirectory, securityService);
service = new OaiPmhPublicationServiceImpl();
service.setOaiPmhServerInfo(oaiPmhServerInfo);
service.setSecurityService(securityService);
service.setServiceRegistry(serviceRegistry);
// mock streaming/download distribution jobs dispatching
AbstractJobProducer distributionJobProducerMock = new AbstractJobProducer("distribute") {
@Override
protected ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
protected SecurityService getSecurityService() {
return securityService;
}
@Override
protected UserDirectoryService getUserDirectoryService() {
return userDirectory;
}
@Override
protected OrganizationDirectoryService getOrganizationDirectoryService() {
return orgDirectory;
}
@Override
protected String process(Job job) throws Exception {
return job.getPayload();
}
@Override
public boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException {
return true;
}
};
serviceRegistry.registerService(distributionJobProducerMock);
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class SeriesServicePersistenceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Mock up a security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
User user = new JaxbUser("admin", "test", new DefaultOrganization(), new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, new DefaultOrganization()));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
seriesDatabase = new SeriesServiceDatabaseImpl();
seriesDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SeriesServiceDatabaseImpl.PERSISTENCE_UNIT));
DublinCoreCatalogService dcService = new DublinCoreCatalogService();
seriesDatabase.setDublinCoreService(dcService);
seriesDatabase.setSecurityService(securityService);
seriesDatabase.activate(null);
InputStream in = null;
try {
in = getClass().getResourceAsStream("/dublincore.xml");
testCatalog = dcService.load(in);
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.security.api.SecurityService 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);
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class AnalyzeAudioWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
URI soxTrackUri = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox-track.xml").toURI();
URI soxEncodeUri = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox-encode-track.xml").toURI();
String soxTrackXml = IOUtils.toString(soxTrackUri.toURL().openStream());
String encodeTrackXml = IOUtils.toString(soxEncodeUri.toURL().openStream());
instance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(instance.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(instance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
EasyMock.replay(instance);
DefaultOrganization org = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, org));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
EasyMock.replay(incidentService);
ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(null, securityService, userDirectoryService, organizationDirectoryService, incidentService);
Job analyzeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Analyze", null, soxTrackXml, false);
analyzeJob.setStatus(Status.FINISHED);
analyzeJob = serviceRegistry.updateJob(analyzeJob);
Job encodeJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Encode", null, encodeTrackXml, false);
encodeJob.setStatus(Status.FINISHED);
encodeJob = serviceRegistry.updateJob(encodeJob);
SoxService sox = EasyMock.createNiceMock(SoxService.class);
EasyMock.expect(sox.analyze((Track) EasyMock.anyObject())).andReturn(analyzeJob).anyTimes();
EasyMock.replay(sox);
ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
EasyMock.expect(composer.encode((Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(encodeJob);
EasyMock.replay(composer);
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.replay(workspace);
// set up the handler
operationHandler = new AnalyzeAudioWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setComposerService(composer);
operationHandler.setSoxService(sox);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class NormalizeAudioWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
URI soxTrackUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-track.xml").toURI();
URI normalizedTrackUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/normalized-track.xml").toURI();
URI soxEncodeUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-encode-track.xml").toURI();
URI soxMuxUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-mux-track.xml").toURI();
String soxTrackXml = IOUtils.toString(soxTrackUri.toURL().openStream());
String encodeTrackXml = IOUtils.toString(soxEncodeUri.toURL().openStream());
String normalizedTrackXml = IOUtils.toString(normalizedTrackUri.toURL().openStream());
String muxedTrackXml = IOUtils.toString(soxMuxUri.toURL().openStream());
instance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(instance.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(instance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
EasyMock.replay(instance);
DefaultOrganization org = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, org));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
EasyMock.replay(incidentService);
ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(null, securityService, userDirectoryService, organizationDirectoryService, incidentService);
Job analyzeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Analyze", null, soxTrackXml, false);
analyzeJob.setStatus(Status.FINISHED);
analyzeJob = serviceRegistry.updateJob(analyzeJob);
Job normalizeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Normalize", null, normalizedTrackXml, false);
normalizeJob.setStatus(Status.FINISHED);
normalizeJob = serviceRegistry.updateJob(normalizeJob);
Job encodeJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Encode", null, encodeTrackXml, false);
encodeJob.setStatus(Status.FINISHED);
encodeJob = serviceRegistry.updateJob(encodeJob);
Job muxJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Mux", null, muxedTrackXml, false);
muxJob.setStatus(Status.FINISHED);
muxJob = serviceRegistry.updateJob(muxJob);
SoxService sox = EasyMock.createNiceMock(SoxService.class);
EasyMock.expect(sox.analyze((Track) EasyMock.anyObject())).andReturn(analyzeJob).anyTimes();
EasyMock.expect(sox.normalize((Track) EasyMock.anyObject(), (Float) EasyMock.anyObject())).andReturn(normalizeJob).anyTimes();
EasyMock.replay(sox);
ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
EasyMock.expect(composer.encode((Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(encodeJob);
EasyMock.expect(composer.mux((Track) EasyMock.anyObject(), (Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(muxJob);
EasyMock.replay(composer);
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(new URI("fooVideo.flv"));
EasyMock.replay(workspace);
// set up the handler
operationHandler = new NormalizeAudioWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setComposerService(composer);
operationHandler.setSoxService(sox);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
Aggregations