use of org.osgi.service.component.ComponentContext 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.osgi.service.component.ComponentContext in project opencast by opencast.
the class StreamingDistributionServiceTest method testStreamingUrlSetUp.
@Test
public void testStreamingUrlSetUp() throws URISyntaxException {
// List of expected streaming URLs
final String[] outputStreamingUrls = new String[] { "rtmp://noschema.myserver.com/my/path/to/server", null, null, "rtmp://withrtmp.test.ext/another/path", "rtmps://withrtmps.anothertest.test/path/to/server", null };
// Set up mocks for testing
BundleContext bc = createNiceMock(BundleContext.class);
ComponentContext cc = createNiceMock(ComponentContext.class);
for (String url : inputStreamingUrls) expect(bc.getProperty(WowzaAdaptiveStreamingDistributionService.STREAMING_URL_KEY)).andReturn(url);
expect(bc.getProperty(WowzaAdaptiveStreamingDistributionService.ADAPTIVE_STREAMING_URL_KEY)).andReturn("a/valid/url").anyTimes();
expect(cc.getBundleContext()).andReturn(bc).anyTimes();
replay(bc);
replay(cc);
// Test service instance
for (int i = 0; i < inputStreamingUrls.length; i++) {
WowzaAdaptiveStreamingDistributionService sds = new WowzaAdaptiveStreamingDistributionService();
sds.activate(cc);
if (outputStreamingUrls[i] == null)
assertEquals(null, sds.streamingUri);
else
assertEquals(new URI(outputStreamingUrls[i]), sds.streamingUri);
}
}
use of org.osgi.service.component.ComponentContext 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.osgi.service.component.ComponentContext in project opencast by opencast.
the class StaticFileRestServiceTest method getComponentContext.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static ComponentContext getComponentContext(String useWebserver, long maxSize) {
// Create BundleContext
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
EasyMock.expect(bundleContext.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn(SERVER_URL);
EasyMock.expect(bundleContext.getProperty(StaticFileRestService.STATICFILES_UPLOAD_MAX_SIZE_KEY)).andReturn(Long.toString(maxSize));
EasyMock.replay(bundleContext);
// Create ComponentContext
Dictionary properties = new Properties();
if (useWebserver != null) {
properties.put(StaticFileRestService.STATICFILES_WEBSERVER_ENABLED_KEY, useWebserver);
}
properties.put(StaticFileRestService.STATICFILES_WEBSERVER_URL_KEY, WEBSERVER_URL);
ComponentContext cc = EasyMock.createMock(ComponentContext.class);
EasyMock.expect(cc.getProperties()).andReturn(properties).anyTimes();
EasyMock.expect(cc.getBundleContext()).andReturn(bundleContext).anyTimes();
EasyMock.replay(cc);
return cc;
}
use of org.osgi.service.component.ComponentContext in project acs-aem-commons by Adobe-Consulting-Services.
the class AbstractDispatcherCacheHeaderFilterTest method setup.
@Before
@SuppressWarnings("rawtypes")
public void setup() throws Exception {
properties = new Hashtable<String, Object>();
String[] patterns = new String[] { pattern };
properties.put(AbstractDispatcherCacheHeaderFilter.PROP_FILTER_PATTERN, patterns);
params = new HashMap();
agents = new HashSet<String>();
filter = new AbstractDispatcherCacheHeaderFilter() {
@Override
protected String getHeaderName() {
return headerName;
}
@Override
protected String getHeaderValue() {
return headerValue;
}
@Override
protected void doActivate(ComponentContext context) throws Exception {
}
};
when(componentContext.getProperties()).thenReturn(properties);
when(componentContext.getBundleContext()).thenReturn(bundleContext);
when(bundleContext.registerService(anyString(), any(), (Dictionary) any())).thenReturn(serviceRegistration);
when(request.getMethod()).thenReturn("GET");
when(request.getParameterMap()).thenReturn(params);
final Map<String, Object> attributes = new HashMap<>();
doAnswer(i -> attributes.put(i.getArgumentAt(0, String.class), i.getArgumentAt(1, Object.class))).when(request).setAttribute(any(), any());
when(request.getAttribute(any())).thenAnswer(i -> attributes.get(i.getArgumentAt(0, String.class)));
}
Aggregations