Search in sources :

Example 46 with CandlepinQuery

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

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");
}
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)

Example 48 with CandlepinQuery

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()));
}
Also used : Consumer(org.candlepin.model.Consumer) CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 49 with CandlepinQuery

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()));
}
Also used : Consumer(org.candlepin.model.Consumer) CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 50 with CandlepinQuery

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));
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) JobExecutionContext(org.quartz.JobExecutionContext) CandlepinQuery(org.candlepin.model.CandlepinQuery) CandlepinPoolManager(org.candlepin.controller.CandlepinPoolManager) 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