use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ComplianceRulesTest method entIsCompliantWhenSocketsAreCovered.
@Test
public void entIsCompliantWhenSocketsAreCovered() {
Consumer c = mockConsumer(PRODUCT_1);
c.setFact("cpu.cpu_socket(s)", "4");
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);
assertTrue(compliance.isEntitlementCompliant(c, ent, new Date()));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ComplianceRulesTest method mockEntitlement.
private Entitlement mockEntitlement(Consumer consumer, Product product, Date start, Date end, Product... providedProducts) {
Set<Product> ppset = new HashSet<>();
for (Product pp : providedProducts) {
ppset.add(pp);
}
Pool pool = new Pool(owner, product, ppset, new Long(1000), start, end, "1000", "1000", "1000");
pool.setId("pool_" + TestUtil.randomInt());
pool.setUpdated(new Date());
pool.setCreated(new Date());
when(productCurator.getPoolProvidedProductsCached(pool.getId())).thenReturn(pool.getProvidedProducts());
Entitlement e = new Entitlement(pool, consumer, owner, 1);
e.setId("ent_" + TestUtil.randomInt());
e.setUpdated(new Date());
e.setCreated(new Date());
return e;
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ComplianceRulesTest method instanceBasedPhysicalStackedGreen.
@Test
public void instanceBasedPhysicalStackedGreen() {
Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
List<Entitlement> ents = new LinkedList<>();
ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
ents.add(mockInstanceEntitlement(c, STACK_ID_1, "2", TestUtil.createProduct("Awesome Product"), PRODUCT_1, PRODUCT_2));
ents.get(0).setQuantity(6);
ents.get(1).setQuantity(2);
mockEntCurator(c, ents);
ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
assertEquals(ComplianceStatus.GREEN, status.getStatus());
assertEquals(0, status.getNonCompliantProducts().size());
assertEquals(0, status.getPartiallyCompliantProducts().size());
assertEquals(2, status.getCompliantProducts().size());
assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ComplianceRulesTest method testMultiArchitectureMatch.
@Test
public void testMultiArchitectureMatch() {
Consumer c = mockConsumer(PRODUCT_1, PRODUCT_2);
c.setFact("uname.machine", "x86_64");
List<Entitlement> ents = new LinkedList<>();
ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_1));
ents.get(0).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "PPC64,x86_64");
ents.add(mockEntitlement(c, TestUtil.createProduct("Awesome Product"), PRODUCT_2));
ents.get(1).getPool().getProduct().setAttribute(Product.Attributes.ARCHITECTURE, "x86_64");
mockEntCurator(c, ents);
ComplianceStatus status = compliance.getStatus(c, TestUtil.createDate(2011, 8, 30));
// Our one entitlement should not cover both of these:
assertEquals(2, status.getCompliantProducts().size());
assertEquals(0, status.getNonCompliantProducts().size());
assertEquals(0, status.getPartiallyCompliantProducts().size());
assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_2.getId()));
assertTrue(status.getCompliantProducts().keySet().contains(PRODUCT_1.getId()));
assertEquals("valid", status.getStatus());
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class ComplianceRulesTest method mockNonStackedHostRestrictedEntitlement.
private Entitlement mockNonStackedHostRestrictedEntitlement(Consumer consumer, String stackId, Product product, Product... providedProducts) {
Entitlement ent = this.mockEntitlement(consumer, product, providedProducts);
Pool pool = ent.getPool();
pool.setAttribute(Pool.Attributes.REQUIRES_HOST, "SOMEUUID");
pool.getProduct().setAttribute(Product.Attributes.SOCKETS, "2");
pool.getProduct().setAttribute(Product.Attributes.VCPU, "1");
return ent;
}
Aggregations