Search in sources :

Example 26 with ServiceRegistry

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));
    }
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) Test(org.junit.Test)

Example 27 with ServiceRegistry

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);
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 28 with ServiceRegistry

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);
}
Also used : HashMap(java.util.HashMap) IAnswer(org.easymock.IAnswer) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry)

Example 29 with ServiceRegistry

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"));
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) JaxbUser(org.opencastproject.security.api.JaxbUser) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) BundleContext(org.osgi.framework.BundleContext) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 30 with ServiceRegistry

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);
}
Also used : ServiceRegistrationInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistrationInMemoryImpl) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) ServicesListQuery(org.opencastproject.index.service.resources.list.query.ServicesListQuery) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Before(org.junit.Before)

Aggregations

ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)40 Job (org.opencastproject.job.api.Job)29 Before (org.junit.Before)24 URI (java.net.URI)18 Workspace (org.opencastproject.workspace.api.Workspace)17 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)13 File (java.io.File)11 Date (java.util.Date)9 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)9 SecurityService (org.opencastproject.security.api.SecurityService)9 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)8 List (java.util.List)7 Track (org.opencastproject.mediapackage.Track)7 JobImpl (org.opencastproject.job.api.JobImpl)6 JaxbUser (org.opencastproject.security.api.JaxbUser)6 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)6 BundleContext (org.osgi.framework.BundleContext)6 ComponentContext (org.osgi.service.component.ComponentContext)6