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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations