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);
}
}
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);
}
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());
}
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());
}
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());
}
Aggregations