Search in sources :

Example 1 with JobStatusDTO

use of org.candlepin.dto.api.v1.JobStatusDTO in project candlepin by candlepin.

the class PinsetterAsyncFilter method postProcess.

/**
 * {@inheritDoc}
 *
 * @param response the server response (provided by Resteasy)
 */
@Override
public void postProcess(ServerResponse response) {
    Object entity = response.getEntity();
    if (entity instanceof JobDetail) {
        JobDetail jobDetail = (JobDetail) entity;
        setJobPrincipal(jobDetail);
        JobStatus status = this.scheduleJob(jobDetail);
        response.setEntity(this.translator.translate(status, JobStatusDTO.class));
        response.setStatus(HttpResponseCodes.SC_ACCEPTED);
    } else if (entity instanceof JobDetail[]) {
        JobDetail[] details = (JobDetail[]) entity;
        JobStatus[] statuses = new JobStatus[details.length];
        int i = 0;
        for (JobDetail jobDetail : details) {
            setJobPrincipal(jobDetail);
            JobStatus status = this.scheduleJob(jobDetail);
            statuses[i++] = status;
        }
        JobStatusDTO[] dtoStatuses = new JobStatusDTO[statuses.length];
        for (int j = 0; j < statuses.length; j++) {
            dtoStatuses[j] = this.translator.translate(statuses[j], JobStatusDTO.class);
        }
        response.setEntity(dtoStatuses);
        response.setStatus(HttpResponseCodes.SC_ACCEPTED);
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobStatusDTO(org.candlepin.dto.api.v1.JobStatusDTO)

Example 2 with JobStatusDTO

use of org.candlepin.dto.api.v1.JobStatusDTO in project candlepin by candlepin.

the class PinsetterAsyncFilterTest method jobStatusSet.

@Test
public void jobStatusSet() throws PinsetterException {
    JobDetail detail = newJob(RefreshPoolsJob.class).build();
    JobStatus status = new JobStatus();
    JobStatusDTO statusDTO = new JobStatusDTO();
    when(response.getEntity()).thenReturn(detail);
    when(this.pinsetterKernel.scheduleSingleJob(detail)).thenReturn(status);
    when(this.translator.translate(status, JobStatusDTO.class)).thenReturn(statusDTO);
    this.interceptor.postProcess(response);
    verify(response).setEntity(statusDTO);
}
Also used : RefreshPoolsJob(org.candlepin.pinsetter.tasks.RefreshPoolsJob) JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobStatusDTO(org.candlepin.dto.api.v1.JobStatusDTO) Test(org.junit.Test)

Example 3 with JobStatusDTO

use of org.candlepin.dto.api.v1.JobStatusDTO in project candlepin by candlepin.

the class JobResourceTest method getStatusesByUuid.

@Test
public void getStatusesByUuid() {
    List<JobStatus> statuses = new ArrayList<>();
    JobStatus status = new JobStatus();
    statuses.add(status);
    CandlepinQuery query = mock(CandlepinQuery.class);
    when(query.list()).thenReturn(statuses);
    when(query.iterate()).thenReturn(new MockResultIterator(statuses.iterator()));
    when(query.iterate(anyInt(), anyBoolean())).thenReturn(new MockResultIterator(statuses.iterator()));
    when(jobCurator.findByConsumerUuid(eq("abcd"))).thenReturn(query);
    this.mockCPQueryTransform(query);
    Collection<JobStatusDTO> real = jobResource.getStatuses(null, "abcd", null).list();
    assertNotNull(real);
    assertEquals(1, real.size());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) JobStatusDTO(org.candlepin.dto.api.v1.JobStatusDTO) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Example 4 with JobStatusDTO

use of org.candlepin.dto.api.v1.JobStatusDTO in project candlepin by candlepin.

the class JobResourceTest method getStatusesByOwner.

@Test
public void getStatusesByOwner() {
    List<JobStatus> statuses = new ArrayList<>();
    JobStatus status = new JobStatus();
    statuses.add(status);
    CandlepinQuery query = mock(CandlepinQuery.class);
    when(query.list()).thenReturn(statuses);
    when(query.iterate()).thenReturn(new MockResultIterator(statuses.iterator()));
    when(query.iterate(anyInt(), anyBoolean())).thenReturn(new MockResultIterator(statuses.iterator()));
    when(jobCurator.findByOwnerKey(eq("admin"))).thenReturn(query);
    this.mockCPQueryTransform(query);
    Collection<JobStatusDTO> real = jobResource.getStatuses("admin", null, null).list();
    assertNotNull(real);
    assertEquals(1, real.size());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) JobStatusDTO(org.candlepin.dto.api.v1.JobStatusDTO) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Example 5 with JobStatusDTO

use of org.candlepin.dto.api.v1.JobStatusDTO in project candlepin by candlepin.

the class JobResourceTest method getStatusesByPrincipal.

@Test
public void getStatusesByPrincipal() {
    List<JobStatus> statuses = new ArrayList<>();
    JobStatus status = new JobStatus();
    statuses.add(status);
    CandlepinQuery query = mock(CandlepinQuery.class);
    when(query.list()).thenReturn(statuses);
    when(query.iterate()).thenReturn(new MockResultIterator(statuses.iterator()));
    when(query.iterate(anyInt(), anyBoolean())).thenReturn(new MockResultIterator(statuses.iterator()));
    when(jobCurator.findByPrincipalName(eq("admin"))).thenReturn(query);
    this.mockCPQueryTransform(query);
    Collection<JobStatusDTO> real = jobResource.getStatuses(null, null, "admin").list();
    assertNotNull(real);
    assertEquals(1, real.size());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) JobStatusDTO(org.candlepin.dto.api.v1.JobStatusDTO) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Aggregations

JobStatusDTO (org.candlepin.dto.api.v1.JobStatusDTO)5 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 CandlepinQuery (org.candlepin.model.CandlepinQuery)3 TransformedCandlepinQuery (org.candlepin.model.TransformedCandlepinQuery)3 MockResultIterator (org.candlepin.test.MockResultIterator)3 JobDetail (org.quartz.JobDetail)2 RefreshPoolsJob (org.candlepin.pinsetter.tasks.RefreshPoolsJob)1