Search in sources :

Example 1 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class ServersListProviderTest method setUp.

@Before
public void setUp() throws Exception {
    this.serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    serverListProvider = new ServersListProvider();
    List<HostRegistration> hosts = new ArrayList<HostRegistration>();
    hosts.add(new JaxbHostRegistration(HOST1, "1.1.1.1", 400000, 8, 8, true, false));
    hosts.add(new JaxbHostRegistration(HOST2, "1.1.1.2", 400000, 8, 8, true, true));
    hosts.add(new JaxbHostRegistration(HOST3, "1.1.1.3", 500000, 2, 8, false, false));
    hosts.add(new JaxbHostRegistration(HOST4, "1.1.1.4", 500000, 6, 8, true, true));
    EasyMock.expect(serviceRegistry.getHostRegistrations()).andReturn(hosts).anyTimes();
    serverListProvider.setServiceRegistry(serviceRegistry);
    serverListProvider.activate(null);
    EasyMock.replay(serviceRegistry);
}
Also used : JaxbHostRegistration(org.opencastproject.serviceregistry.api.JaxbHostRegistration) HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) JaxbHostRegistration(org.opencastproject.serviceregistry.api.JaxbHostRegistration) Before(org.junit.Before)

Example 2 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class JobUtilTest method setUp.

@Before
public void setUp() throws Exception {
    serviceRegistry = createNiceMock(ServiceRegistry.class);
    JobImpl job = new JobImpl(20);
    job.setPayload("a payload");
    Job finishedJob1 = new JobImpl(1);
    finishedJob1.setStatus(Status.FINISHED);
    Job finishedJob2 = new JobImpl(2);
    finishedJob2.setStatus(Status.FINISHED);
    Job finishedJob3 = new JobImpl(3);
    finishedJob3.setStatus(Status.FINISHED);
    expect(serviceRegistry.getJob(1)).andReturn(finishedJob1).anyTimes();
    expect(serviceRegistry.getJob(2)).andReturn(finishedJob2).anyTimes();
    expect(serviceRegistry.getJob(3)).andReturn(finishedJob3).anyTimes();
    expect(serviceRegistry.getJob(23)).andThrow(new NotFoundException()).anyTimes();
    expect(serviceRegistry.getJob(20)).andReturn(job).anyTimes();
    replay(serviceRegistry);
}
Also used : NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Before(org.junit.Before)

Example 3 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class OsgiIncidentServiceTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    final EntityManagerFactory emf = PersistenceUtil.newTestEntityManagerFactory(AbstractIncidentService.PERSISTENCE_UNIT_NAME);
    penv = PersistenceEnvs.persistenceEnvironment(emf);
    // Mock up a job
    Job job = createNiceMock(Job.class);
    expect(job.getProcessingHost()).andStubReturn(PROCESSING_HOST);
    expect(job.getJobType()).andStubReturn(JOB_TYPE);
    expect(job.getCreator()).andStubReturn("creator");
    expect(job.getOrganization()).andStubReturn("organization");
    replay(job);
    // Mock up a service registry
    final ServiceRegistry serviceRegistry = createNiceMock(ServiceRegistry.class);
    expect(serviceRegistry.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();
    replay(serviceRegistry);
    // Mock up a workflow service
    final WorkflowService workflowService = createNiceMock(WorkflowService.class);
    replay(workflowService);
    incidentService = new AbstractIncidentService() {

        @Override
        protected ServiceRegistry getServiceRegistry() {
            return serviceRegistry;
        }

        @Override
        protected WorkflowService getWorkflowService() {
            return workflowService;
        }

        @Override
        protected PersistenceEnv getPenv() {
            return PersistenceEnvs.persistenceEnvironment(emf);
        }
    };
    incidents = new Incidents(serviceRegistry, incidentService);
}
Also used : IAnswer(org.easymock.IAnswer) PersistenceEnv(org.opencastproject.util.persistence.PersistenceEnv) WorkflowService(org.opencastproject.workflow.api.WorkflowService) EntityManagerFactory(javax.persistence.EntityManagerFactory) Incidents(org.opencastproject.serviceregistry.api.Incidents) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Before(org.junit.Before)

Example 4 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class SearchServiceImplTest method testPopulateIndex.

@SuppressWarnings("unchecked")
@Test
public void testPopulateIndex() throws Exception {
    // This service registry must return a list of jobs
    List<String> args = new ArrayList<String>();
    args.add(new DefaultOrganization().getId());
    List<Job> jobs = new ArrayList<Job>();
    for (long i = 0; i < 10; i++) {
        MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
        mediaPackage.setIdentifier(IdBuilderFactory.newInstance().newIdBuilder().createNew());
        searchDatabase.storeMediaPackage(mediaPackage, acl, new Date());
        String payload = MediaPackageParser.getAsXml(mediaPackage);
        Job job = new JobImpl(i);
        job.setArguments(args);
        job.setPayload(payload);
        job.setStatus(Status.FINISHED);
        jobs.add(job);
    }
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.createJob((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (List<String>) EasyMock.anyObject(), (String) EasyMock.anyObject(), EasyMock.anyBoolean())).andReturn(new JobImpl()).anyTimes();
    EasyMock.expect(serviceRegistry.updateJob((Job) EasyMock.anyObject())).andReturn(new JobImpl()).anyTimes();
    EasyMock.expect(serviceRegistry.getJobs((String) EasyMock.anyObject(), (Status) EasyMock.anyObject())).andReturn(jobs).anyTimes();
    EasyMock.replay(serviceRegistry);
    service.setServiceRegistry(serviceRegistry);
    OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(orgDirectory);
    service.setOrganizationDirectoryService(orgDirectory);
    // We should have nothing in the search index
    assertEquals(0, service.getByQuery(new SearchQuery()).size());
    service.populateIndex("System Admin");
    // This time we should have 10 results
    assertEquals(10, service.getByQuery(new SearchQuery()).size());
}
Also used : Status(org.opencastproject.job.api.Job.Status) SearchQuery(org.opencastproject.search.api.SearchQuery) JobImpl(org.opencastproject.job.api.JobImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) MediaPackage(org.opencastproject.mediapackage.MediaPackage) List(java.util.List) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Test(org.junit.Test)

Example 5 with ServiceRegistry

use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.

the class ComposeWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = InspectWorkflowOperationHandler.class.getResource("/compose_mediapackage.xml").toURI();
    URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/compose_encode_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
    encodedTracks = mpEncode.getTracks();
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMP);
    EasyMock.replay(workspace);
    // set up mock receipt
    job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(job.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job.getDateStarted()).andReturn(new Date());
    EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
    EasyMock.replay(job);
    // set up mock service registry
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.replay(serviceRegistry);
    // set up service
    operationHandler = new ComposeWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) URI(java.net.URI) InspectWorkflowOperationHandler(org.opencastproject.workflow.handler.inspection.InspectWorkflowOperationHandler) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) 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