Search in sources :

Example 71 with PoolQuantity

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

the class PostEntitlementRulesTest method unlimitedVirtLimitSubPool.

@Test
public void unlimitedVirtLimitSubPool() {
    Pool pool = setupVirtLimitPool();
    pool.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
    Entitlement e = new Entitlement(pool, consumer, owner, 5);
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(pool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, 5));
    Class<List<Pool>> listClass = (Class<List<Pool>>) (Class) ArrayList.class;
    ArgumentCaptor<List<Pool>> poolsArg = ArgumentCaptor.forClass(listClass);
    when(poolManagerMock.createPools(poolsArg.capture())).thenReturn(new LinkedList<>());
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    // Pool quantity should be virt_limit:
    List<Pool> pools = poolsArg.getValue();
    assertEquals(1, pools.size());
    assertEquals(-1L, pools.get(0).getQuantity().longValue());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 72 with PoolQuantity

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

the class PostEntitlementRulesTest method noSubPoolsForGuestBinds.

// Sub-pools should not be created when guests bind:
@Test
public void noSubPoolsForGuestBinds() {
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    Pool pool = setupVirtLimitPool();
    consumer.setFact("virt.is_guest", "true");
    Entitlement e = new Entitlement(pool, consumer, owner, 1);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(pool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, 1));
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    verify(poolManagerMock, never()).createPools(any(List.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) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 73 with PoolQuantity

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

the class PostEntitlementRulesTest method noSubPoolsForDistributorBinds.

// Sub-pools should not be created when distributors bind:
@Test
public void noSubPoolsForDistributorBinds() {
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
    consumer.setType(ctype);
    Pool pool = setupVirtLimitPool();
    Entitlement e = new Entitlement(pool, consumer, owner, 1);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(pool.getId(), e);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, 1));
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    verify(poolManagerMock, never()).createPools(any(List.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) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 74 with PoolQuantity

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

the class PostEntitlementRulesTest method virtLimitSubPoolBatch.

@Test
public void virtLimitSubPoolBatch() {
    Pool pool = setupVirtLimitPool();
    pool.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
    Entitlement e = new Entitlement(pool, consumer, owner, 5);
    Pool pool2 = setupVirtLimitPool();
    pool2.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
    Entitlement e2 = new Entitlement(pool2, consumer, owner, 5);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(pool.getId(), e);
    entitlements.put(pool2.getId(), e2);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, 5));
    poolQuantityMap.put(pool2.getId(), new PoolQuantity(pool2, 5));
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    // Pool quantity should be virt_limit:
    Class<List<Pool>> listClass = (Class<List<Pool>>) (Class) ArrayList.class;
    ArgumentCaptor<List<Pool>> poolsArg = ArgumentCaptor.forClass(listClass);
    when(poolManagerMock.createPools(poolsArg.capture())).thenReturn(new LinkedList<>());
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    List<Pool> pools = poolsArg.getValue();
    assertEquals(2, pools.size());
    assertEquals(10L, pools.get(0).getQuantity().longValue());
    assertEquals(10L, pools.get(1).getQuantity().longValue());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 75 with PoolQuantity

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

the class PostEntitlementRulesTest method unlimitedVirtLimitSubPoolBatch.

@Test
public void unlimitedVirtLimitSubPoolBatch() {
    Pool pool = setupVirtLimitPool();
    pool.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
    Entitlement e = new Entitlement(pool, consumer, owner, 5);
    Pool pool2 = setupVirtLimitPool();
    pool2.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
    Entitlement e2 = new Entitlement(pool2, consumer, owner, 5);
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    Map<String, Entitlement> entitlements = new HashMap<>();
    entitlements.put(pool.getId(), e);
    entitlements.put(pool2.getId(), e2);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, 5));
    poolQuantityMap.put(pool2.getId(), new PoolQuantity(pool2, 5));
    Class<List<Pool>> listClass = (Class<List<Pool>>) (Class) ArrayList.class;
    ArgumentCaptor<List<Pool>> poolsArg = ArgumentCaptor.forClass(listClass);
    when(poolManagerMock.createPools(poolsArg.capture())).thenReturn(new LinkedList<>());
    enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
    // Pool quantity should be virt_limit:
    List<Pool> pools = poolsArg.getValue();
    assertEquals(2, pools.size());
    assertEquals(-1L, pools.get(0).getQuantity().longValue());
    assertEquals(-1L, pools.get(1).getQuantity().longValue());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

PoolQuantity (org.candlepin.model.PoolQuantity)75 Pool (org.candlepin.model.Pool)65 Test (org.junit.Test)52 Entitlement (org.candlepin.model.Entitlement)34 LinkedList (java.util.LinkedList)30 Product (org.candlepin.model.Product)28 HashMap (java.util.HashMap)27 ArrayList (java.util.ArrayList)21 Consumer (org.candlepin.model.Consumer)12 List (java.util.List)11 ConsumerType (org.candlepin.model.ConsumerType)11 Matchers.anyString (org.mockito.Matchers.anyString)11 Date (java.util.Date)8 Set (java.util.Set)8 HashSet (java.util.HashSet)7 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)7 ValidationResult (org.candlepin.policy.ValidationResult)7 Subscription (org.candlepin.model.dto.Subscription)6 Matchers.anyLong (org.mockito.Matchers.anyLong)6 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)5