use of org.candlepin.model.CandlepinQuery 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());
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class JobResourceTest method emptyStringIsAlsoValid.
@Test
public void emptyStringIsAlsoValid() {
List<JobStatus> statuses = new ArrayList<>();
JobStatus status = new JobStatus();
statuses.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(statuses);
when(jobCurator.findByPrincipalName(eq("foo"))).thenReturn(query);
when(query.transform(any(ElementTransformer.class))).thenReturn(query);
jobResource.getStatuses(null, "", "foo");
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ComplianceRulesTest method entIsCompliantIfSocketsNotSetOnEntPool.
@Test
public void entIsCompliantIfSocketsNotSetOnEntPool() {
Consumer c = mockConsumer(PRODUCT_1);
c.setFact("cpu.cpu_socket(s)", "2");
Entitlement ent = mockEntitlement(c, PRODUCT_1);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(Arrays.asList(ent));
when(entCurator.listByConsumerAndDate(eq(c), any(Date.class))).thenReturn(cqmock);
assertTrue(compliance.isEntitlementCompliant(c, ent, new Date()));
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ComplianceRulesTest method entIsNotCompliantWhenSocketsAreNotCovered.
@Test
public void entIsNotCompliantWhenSocketsAreNotCovered() {
Consumer c = mockConsumer(PRODUCT_1);
c.setFact("cpu.cpu_socket(s)", "8");
Entitlement ent = mockEntitlement(c, PRODUCT_1);
ent.getPool().getProduct().setAttribute(Product.Attributes.SOCKETS, "4");
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(Arrays.asList(ent));
when(entCurator.listByConsumerAndDate(eq(c), any(Date.class))).thenReturn(cqmock);
assertFalse(compliance.isEntitlementCompliant(c, ent, new Date()));
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class RegenEntitlementCertsJobTest method execute.
@Test
public void execute() throws Exception {
// prep
CandlepinPoolManager pm = mock(CandlepinPoolManager.class);
JobExecutionContext jec = mock(JobExecutionContext.class);
OwnerCurator oc = mock(OwnerCurator.class);
JobDetail detail = mock(JobDetail.class);
JobDataMap jdm = mock(JobDataMap.class);
String ownerId = "foo_owner";
String prodId = "bar_prod";
boolean lazyRegen = true;
Owner owner = new Owner(ownerId);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(Arrays.asList(owner));
when(oc.listAll()).thenReturn(cqmock);
when(jdm.getString(eq(RegenProductEntitlementCertsJob.PROD_ID))).thenReturn(prodId);
when(jdm.getBoolean(eq(RegenProductEntitlementCertsJob.LAZY_REGEN))).thenReturn(lazyRegen);
when(detail.getJobDataMap()).thenReturn(jdm);
when(jec.getJobDetail()).thenReturn(detail);
// test
RegenProductEntitlementCertsJob recj = new RegenProductEntitlementCertsJob(pm, oc);
injector.injectMembers(recj);
recj.execute(jec);
// verification
verify(pm).regenerateCertificatesOf(eq(owner), eq(prodId), eq(lazyRegen));
}
Aggregations