Search in sources :

Example 71 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ComplianceStatusHasherTest method ensureDifferentHashWhenConsumerEntitlementChanges.

@Test
public void ensureDifferentHashWhenConsumerEntitlementChanges() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Entitlement ent = consumer.getEntitlements().iterator().next();
    String id = ent.getId();
    Integer quantity = ent.getQuantity();
    // Check the ID
    ent.setId("somethhing_differerent");
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    ent.setId(id);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    // Check the quantity
    ent.setQuantity(112);
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    ent.setQuantity(quantity);
    assertEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 72 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ComplianceStatusHasherTest method ensureDifferentHashWhenPartiallyCompliantProductsChange.

@Test
public void ensureDifferentHashWhenPartiallyCompliantProductsChange() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Entitlement ent = createEntitlement(Calendar.getInstance(), owner, consumer, "test-ent");
    HashSet<Entitlement> ents = new HashSet<>();
    ents.add(ent);
    testStatus.getPartiallyCompliantProducts().put(ent.getPool().getProductId(), ents);
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ComplianceStatusHasherTest method ensureDifferentHashWhenPartialStacksChange.

@Test
public void ensureDifferentHashWhenPartialStacksChange() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Entitlement ent = createEntitlement(Calendar.getInstance(), owner, consumer, "test-ent");
    HashSet<Entitlement> ents = new HashSet<>();
    ents.add(ent);
    testStatus.getPartialStacks().put("p-stack-2", ents);
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 74 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ComplianceStatusHasherTest method ensureDifferentHashWhenCompliantProductCountChanges.

@Test
public void ensureDifferentHashWhenCompliantProductCountChanges() {
    Consumer consumer = createConsumer(owner);
    ComplianceStatus testStatus = createInitialStatus(consumer);
    assertEquals(initialHash, generateHash(testStatus, consumer));
    Set<Entitlement> ents = testStatus.getCompliantProducts().remove("p3");
    assertFalse(testStatus.getCompliantProducts().containsKey("p3"));
    assertNotEquals(initialHash, generateHash(testStatus, consumer));
    testStatus.getCompliantProducts().put("p3", ents);
    assertEquals(initialHash, generateHash(testStatus, consumer));
}
Also used : Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 75 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class HostedVirtLimitEntitlementRulesTest method noBonusPoolsForHostedNonDistributorBinds.

/*
     * Bonus pools should not be created when we are in a hosted scenario without
     * distributor binds.
     */
@Test
public void noBonusPoolsForHostedNonDistributorBinds() {
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
    Subscription s = createVirtLimitSub("virtLimitProduct", 10, "unlimited");
    Pool p = TestUtil.copyFromSub(s);
    when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(2, pools.size());
    Pool physicalPool = pools.get(0);
    physicalPool.setId("physical");
    Pool virtBonusPool = pools.get(1);
    virtBonusPool.setId("virt");
    assertEquals(new Long(10), physicalPool.getQuantity());
    assertEquals(0, physicalPool.getAttributes().size());
    // Quantity on bonus pool should be -1:
    assertEquals(new Long(-1), virtBonusPool.getQuantity());
    assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
    assertEquals("unlimited", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
    Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(physicalPool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    verify(poolManagerMock, never()).createPool(any(Pool.class));
    verify(poolManagerMock, never()).updatePoolQuantity(any(Pool.class), anyInt());
    enforcer.postUnbind(consumer, poolManagerMock, e);
    verify(poolManagerMock, never()).updatePoolQuantity(any(Pool.class), anyInt());
    verify(poolManagerMock, never()).setPoolQuantity(any(Pool.class), anyLong());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) Matchers.anyLong(org.mockito.Matchers.anyLong) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15