use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class UnpauseJobTest method ensureJobCancelledWhenJobClassNoLongerExists.
@Test
public void ensureJobCancelledWhenJobClassNoLongerExists() throws Exception {
JobDetail detail = Mockito.mock(JobDetail.class);
JobKey key = new JobKey("fake-job");
when(detail.getKey()).thenReturn(key);
// Allowing setting the value of JobStatus.jobClass since it is private.
// Do not want to expose the setter.
Class<? extends JobStatus> statusClass = JobStatus.class;
Field jobClassField = statusClass.getDeclaredField("jobClass");
jobClassField.setAccessible(true);
JobStatus status = new JobStatus();
jobClassField.set(status, "unknown.class");
status.setState(JobStatus.JobState.CREATED);
assertEquals("unknown.class", status.getJobClass());
List<JobStatus> jl = new ArrayList<>();
jl.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(jl);
when(jobCurator.findWaitingJobs()).thenReturn(query);
unpauseJob.execute(ctx);
assertEquals(JobStatus.JobState.CANCELED, status.getState());
assertEquals("Job canceled because job class no longer exists.", status.getResult());
verify(jobCurator).merge(eq(status));
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class UnpauseJobTest method unPauseTest.
@Test
public void unPauseTest() throws JobExecutionException, PinsetterException {
JobDetail jd = newJob(KingpinJob.class).withIdentity("Kayfabe", "Deluxe").build();
JobStatus js = new JobStatus(jd, true);
List<JobStatus> jl = new ArrayList<>();
jl.add(js);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(jl);
when(jobCurator.findWaitingJobs()).thenReturn(query);
unpauseJob.execute(ctx);
try {
verify(pk, atLeastOnce()).addTrigger(js);
} catch (SchedulerException e) {
fail("Should not throw an exception");
}
}
use of org.candlepin.model.CandlepinQuery 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.model.CandlepinQuery 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.model.CandlepinQuery in project candlepin by candlepin.
the class JobResourceTest method verifyInput.
@Test
public void verifyInput() {
List<JobStatus> statuses = new ArrayList<>();
JobStatus status = new JobStatus();
statuses.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(statuses);
when(jobCurator.findByOwnerKey(any(String.class))).thenReturn(query);
when(jobCurator.findByConsumerUuid(any(String.class))).thenReturn(query);
when(jobCurator.findByPrincipalName(any(String.class))).thenReturn(query);
when(query.transform(any(ElementTransformer.class))).thenReturn(query);
assertFalse(expectException("owner", "uuid", "pname"));
assertFalse(expectException("owner", null, "pname"));
assertFalse(expectException("owner", "uuid", null));
assertFalse(expectException(null, "uuid", "pname"));
assertTrue(expectException("owner", null, null));
assertTrue(expectException("owner", "", null));
assertTrue(expectException(null, "uuid", null));
assertTrue(expectException("", "uuid", null));
assertTrue(expectException(null, null, "pname"));
assertTrue(expectException(null, "", "pname"));
}
Aggregations