use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class WaveformServiceImplTest method testUpdated.
/**
* Test of updated method of class WaveformServiceImpl.
*/
@Test
public void testUpdated() throws Exception {
Dictionary<String, String> properties = new Hashtable<>();
properties.put(WaveformServiceImpl.WAVEFORM_IMAGE_WIDTH_MIN_CONFIG_KEY, "1000");
properties.put(WaveformServiceImpl.WAVEFORM_IMAGE_WIDTH_MAX_CONFIG_KEY, "2000");
properties.put(WaveformServiceImpl.WAVEFORM_IMAGE_WIDTH_PPM_CONFIG_KEY, "100");
properties.put(WaveformServiceImpl.WAVEFORM_IMAGE_HEIGHT_CONFIG_KEY, "480");
properties.put(WaveformServiceImpl.WAVEFORM_COLOR_CONFIG_KEY, "blue green 0x2A2A2A 323232CC");
properties.put(WaveformServiceImpl.WAVEFORM_SPLIT_CHANNELS_CONFIG_KEY, "false");
properties.put(WaveformServiceImpl.WAVEFORM_SCALE_CONFIG_KEY, "lin");
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getHostRegistrations()).andReturn(new ArrayList());
EasyMock.replay(serviceRegistry);
WaveformServiceImpl instance = new WaveformServiceImpl();
instance.setServiceRegistry(serviceRegistry);
try {
instance.updated(properties);
// we can not check private fields but it should not throw any exception
} catch (Exception e) {
fail("updated method should not throw any exceptions but has thrown: " + ExceptionUtils.getStackTrace(e));
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class AbstractJobProducerTest method setUp.
@Before
public void setUp() throws Exception {
serviceRegistry = createNiceMock(ServiceRegistry.class);
expect(serviceRegistry.count(JobProducerTest.JOB_TYPE, Status.DISPATCHING)).andReturn(2L).anyTimes();
expect(serviceRegistry.count(JobProducerTest.JOB_TYPE, Status.RUNNING)).andReturn(3L).anyTimes();
final Capture<Job> job = EasyMock.newCapture();
expect(serviceRegistry.updateJob(EasyMock.capture(job))).andAnswer(new IAnswer<Job>() {
@Override
public Job answer() throws Throwable {
return job.getValue();
}
});
SecurityService securityService = createNiceMock(SecurityService.class);
UserDirectoryService userDirectoryService = createNiceMock(UserDirectoryService.class);
OrganizationDirectoryService organizationDirectoryService = createNiceMock(OrganizationDirectoryService.class);
jobProducer = new JobProducerTest(serviceRegistry, securityService, userDirectoryService, organizationDirectoryService);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class JobBarrierTest method runWaitForJobsTest.
private void runWaitForJobsTest(Function<Long, TestJob> jobCreator) throws Exception {
// create a bunch of jobs
final Map<Long, TestJob> jobs = new HashMap<Long, TestJob>();
for (long i = (long) (Math.random() * 100.0D); i > 0; i--) {
jobs.put(i, jobCreator.apply(i));
}
logger.info("Waiting for " + jobs.size() + " jobs");
// create a service registry mock returning those jobs
final ServiceRegistry sr = createNiceMock(ServiceRegistry.class);
EasyMock.expect(sr.getJob(EasyMock.anyLong())).andAnswer(new IAnswer<Job>() {
@Override
public Job answer() throws Throwable {
final long jobId = (Long) (EasyMock.getCurrentArguments()[0]);
return jobs.get(jobId);
}
}).anyTimes();
EasyMock.replay(sr);
// wait for all jobs to complete
final JobBarrier.Result res = new JobBarrier(null, sr, 10, toArray(Job.class, jobs.values())).waitForJobs();
// check if there are still running jobs
final boolean noRunningJobs = mlist(jobs.values()).foldl(true, new Function2<Boolean, TestJob, Boolean>() {
@Override
public Boolean apply(Boolean sum, TestJob job) {
return sum && hasJobTerminated(job.getLastReportedStatus());
}
});
assertTrue("There are still some jobs running", noRunningJobs);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class TrustedHttpClientImplTest method setUp.
@Before
public void setUp() throws Exception {
// Setup bundle context for TrustedHttpClientImpl
bundleContextMock = createNiceMock(BundleContext.class);
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_USER_KEY)).andReturn("matterhorn_system_account");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_PASS_KEY)).andReturn("CHANGE_ME");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_KEY)).andReturn("3");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_BASE_TIME_KEY)).andReturn("0");
expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_MAXIMUM_VARIABLE_TIME_KEY)).andReturn("0");
replay(bundleContextMock);
componentContextMock = createNiceMock(ComponentContext.class);
expect(componentContextMock.getBundleContext()).andReturn(bundleContextMock).anyTimes();
replay(componentContextMock);
long currentJobId = 20L;
Job currentJob = createNiceMock(Job.class);
expect(currentJob.getId()).andReturn(currentJobId).anyTimes();
replay(currentJob);
securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
replay(securityService);
serviceRegistry = createNiceMock(ServiceRegistry.class);
expect(serviceRegistry.getCurrentJob()).andReturn(currentJob).anyTimes();
expect(serviceRegistry.getJob(currentJobId)).andReturn(currentJob).anyTimes();
replay(serviceRegistry);
client = new TrustedHttpClientImpl("matterhorn_system_account", "CHANGE_ME");
client.setServiceRegistry(serviceRegistry);
client.setSecurityService(securityService);
client.activate(componentContextMock);
// Setup responses.
String digestValue = "Digest realm=\"testrealm@host.com\"," + "qop=\"auth,auth-int\"," + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\"," + "opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"";
okResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 200, "Good to go"));
digestResponse = new BasicHttpResponse(new ProtocolVersion("Http", 1, 1), 401, "Unauthorized");
digestResponse.addHeader("WWW-Authenticate", digestValue);
nonceResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 401, "Nonce has expired/timed out"));
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class ServicesListProviderTest method setUp.
@Before
public void setUp() throws Exception {
serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
ServiceRegistration sr1 = new ServiceRegistrationInMemoryImpl(SERVICE_TYPE_1, "host1", "service-path-1", true);
ServiceRegistration sr2 = new ServiceRegistrationInMemoryImpl(SERVICE_TYPE_2, "host1", "service-path-2", false);
ServiceRegistration sr3 = new ServiceRegistrationInMemoryImpl(SERVICE_TYPE_3, "host1", "service-path-3", true);
EasyMock.expect(serviceRegistry.getServiceRegistrations()).andReturn(Arrays.asList(sr1, sr2, sr3)).anyTimes();
servicesListProvider = new ServicesListProvider();
servicesListProvider.setServiceRegistry(serviceRegistry);
servicesListProvider.activate(null);
servicesQuery = new ServicesListQuery();
EasyMock.replay(serviceRegistry);
}
Aggregations