use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.
the class WorkflowStatisticsTest method setUp.
@Before
public void setUp() throws Exception {
// always start with a fresh solr root directory
sRoot = new File(getStorageRoot());
try {
FileUtils.forceMkdir(sRoot);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
workflowDefinitions = new ArrayList<WorkflowDefinition>();
workflowHandlers = new HashSet<HandlerRegistration>();
String opId = "op";
WorkflowOperationDefinition op = new WorkflowOperationDefinitionImpl(opId, "Pausing operation", null, true);
WorkflowOperationHandler opHandler = new ResumableTestWorkflowOperationHandler(opId, Action.PAUSE, Action.CONTINUE);
HandlerRegistration handler = new HandlerRegistration(opId, opHandler);
workflowHandlers.add(handler);
// create operation handlers for our workflows
for (int i = 1; i <= WORKFLOW_DEFINITION_COUNT; i++) {
WorkflowDefinition workflowDef = new WorkflowDefinitionImpl();
workflowDef.setId("def-" + i);
for (int opCount = 1; opCount <= OPERATION_COUNT; opCount++) {
workflowDef.add(op);
}
workflowDefinitions.add(workflowDef);
}
// instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
service = new WorkflowServiceImpl() {
@Override
public Set<HandlerRegistration> getRegisteredHandlers() {
return workflowHandlers;
}
};
scanner = new WorkflowDefinitionScanner();
service.addWorkflowDefinitionScanner(scanner);
// security service
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);
service.setSecurityService(securityService);
AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.replay(authzService);
service.setAuthorizationService(authzService);
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
EasyMock.replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
List<Organization> organizationList = new ArrayList<Organization>();
organizationList.add(organization);
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
service.setMessageSender(messageSender);
MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
EasyMock.replay(mds);
service.addMetadataService(mds);
// Register the workflow definitions
for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
service.registerWorkflowDefinition(workflowDefinition);
}
// Mock the workspace
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
EasyMock.replay(workspace);
// Mock the service registry
ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
// Create the workflow database (solr)
dao = new WorkflowServiceSolrIndex();
dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
dao.setSecurityService(securityService);
dao.setServiceRegistry(serviceRegistry);
dao.setAuthorizationService(authzService);
dao.setOrgDirectory(organizationDirectoryService);
dao.activate("System Admin");
service.setDao(dao);
service.setServiceRegistry(serviceRegistry);
service.setSecurityService(securityService);
service.activate(null);
// Crate a media package
InputStream is = null;
try {
MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
is = WorkflowStatisticsTest.class.getResourceAsStream("/mediapackage-1.xml");
mediaPackage = mediaPackageBuilder.loadFromXml(is);
IOUtils.closeQuietly(is);
Assert.assertNotNull(mediaPackage.getIdentifier());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
// Register the workflow service with the service registry
serviceRegistry.registerService(service);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.
the class WorkflowOperationSkippingTest method setUp.
@Before
public void setUp() throws Exception {
sRoot = new File(getStorageRoot());
try {
FileUtils.forceMkdir(sRoot);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
// create operation handlers for our workflows
succeedingOperationHandler = new SucceedingWorkflowOperationHandler(mediapackage1);
handlerRegistrations = new HashSet<HandlerRegistration>();
handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
// instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
service = new WorkflowServiceImpl() {
@Override
public Set<HandlerRegistration> getRegisteredHandlers() {
return handlerRegistrations;
}
};
scanner = new WorkflowDefinitionScanner();
service.addWorkflowDefinitionScanner(scanner);
MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
EasyMock.replay(mds);
service.addMetadataService(mds);
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
EasyMock.replay(workspace);
// 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);
service.setSecurityService(securityService);
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
EasyMock.replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
List<Organization> organizationList = new ArrayList<Organization>();
organizationList.add(organization);
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
dao = new WorkflowServiceSolrIndex();
dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.replay(authzService);
service.setAuthorizationService(authzService);
dao.setServiceRegistry(serviceRegistry);
dao.setSecurityService(securityService);
dao.setAuthorizationService(authzService);
dao.setOrgDirectory(organizationDirectoryService);
dao.activate("System Admin");
service.setDao(dao);
service.setServiceRegistry(serviceRegistry);
service.setMessageSender(messageSender);
service.setUserDirectoryService(userDirectoryService);
service.activate(null);
InputStream is = null;
try {
is = WorkflowOperationSkippingTest.class.getResourceAsStream("/workflow-definition-skipping.xml");
workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
service.registerWorkflowDefinition(workingDefinition);
IOUtils.closeQuietly(is);
MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
is = WorkflowOperationSkippingTest.class.getResourceAsStream("/mediapackage-1.xml");
mediapackage1 = mediaPackageBuilder.loadFromXml(is);
IOUtils.closeQuietly(is);
Assert.assertNotNull(mediapackage1.getIdentifier());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl in project opencast by opencast.
the class DownloadDistributionServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
distributionRoot = new File(mediaPackageRoot, "static");
service = new DownloadDistributionServiceImpl();
StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
EasyMock.replay(statusLine);
HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.replay(response);
final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {
@Override
public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
return StandAloneTrustedHttpClientImpl.run(httpClient, req);
}
}).anyTimes();
EasyMock.replay(httpClient);
defaultOrganization = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
service.setServiceRegistry(serviceRegistry);
service.setTrustedHttpClient(httpClient);
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
service.setWorkspace(workspace);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
final URI uri = (URI) EasyMock.getCurrentArguments()[0];
final String[] pathElems = uri.getPath().split("/");
final String file = pathElems[pathElems.length - 1];
return new File(mediaPackageRoot, file);
}
}).anyTimes();
EasyMock.replay(workspace);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
Dictionary<String, Object> p = new Hashtable<String, Object>();
p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
EasyMock.replay(bc, cc);
service.activate(cc);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl 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.serviceregistry.api.ServiceRegistryInMemoryImpl 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