Search in sources :

Example 26 with CandlepinQuery

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));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Field(java.lang.reflect.Field) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) Test(org.junit.Test)

Example 27 with CandlepinQuery

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");
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) Test(org.junit.Test)

Example 28 with CandlepinQuery

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());
}
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 29 with CandlepinQuery

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());
}
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 30 with CandlepinQuery

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"));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ElementTransformer(org.candlepin.util.ElementTransformer) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) Test(org.junit.Test)

Aggregations

CandlepinQuery (org.candlepin.model.CandlepinQuery)50 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)25 Date (java.util.Date)21 Consumer (org.candlepin.model.Consumer)20 Entitlement (org.candlepin.model.Entitlement)14 Owner (org.candlepin.model.Owner)14 Pool (org.candlepin.model.Pool)14 ConsumerType (org.candlepin.model.ConsumerType)12 Product (org.candlepin.model.Product)11 List (java.util.List)10 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)10 MockResultIterator (org.candlepin.test.MockResultIterator)10 LinkedList (java.util.LinkedList)9 CertificateSerial (org.candlepin.model.CertificateSerial)9 InputStream (java.io.InputStream)8 HashSet (java.util.HashSet)8 Rules (org.candlepin.model.Rules)8 Matchers.anyString (org.mockito.Matchers.anyString)8 File (java.io.File)7