use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method batchHostedVirtLimitAltersBonusPoolQuantity.
@Test
public void batchHostedVirtLimitAltersBonusPoolQuantity() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
Subscription s = createVirtLimitSub("virtLimitProduct", 10, "10");
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 virt limit * sub quantity:
assertEquals(new Long(100), virtBonusPool.getQuantity());
assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
assertEquals("10", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
Subscription s2 = createVirtLimitSub("virtLimitProduct2", 10, "10");
s2.setId("subId2");
Pool p2 = TestUtil.copyFromSub(s2);
when(poolManagerMock.isManaged(eq(p2))).thenReturn(true);
List<Pool> pools2 = poolRules.createAndEnrichPools(p2, new LinkedList<>());
assertEquals(2, pools.size());
Pool physicalPool2 = pools2.get(0);
physicalPool2.setId("physical2");
Pool virtBonusPool2 = pools2.get(1);
virtBonusPool2.setId("virt2");
assertEquals(new Long(10), physicalPool2.getQuantity());
assertEquals(0, physicalPool2.getAttributes().size());
// Quantity on bonus pool should be virt limit * sub quantity:
assertEquals(new Long(100), virtBonusPool2.getQuantity());
assertEquals("true", virtBonusPool2.getAttributeValue(Product.Attributes.VIRT_ONLY));
assertEquals("10", virtBonusPool2.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
Entitlement e2 = new Entitlement(physicalPool2, consumer, owner, 1);
List<Pool> poolList = new ArrayList<>();
poolList.add(virtBonusPool);
List<Pool> poolList2 = new ArrayList<>();
poolList.add(virtBonusPool2);
ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
when(poolManagerMock.lookupBySubscriptionIds(anyString(), captor.capture())).thenReturn(poolList);
when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq(physicalPool.getSubscriptionId()))).thenReturn(poolList);
when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq(physicalPool2.getSubscriptionId()))).thenReturn(poolList2);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(physicalPool.getId(), e);
entitlements.put(physicalPool2.getId(), e2);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
poolQuantityMap.put(physicalPool2.getId(), new PoolQuantity(physicalPool2, 1));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
@SuppressWarnings("unchecked") Set<String> subscriptionIds = captor.getValue();
assertEquals(2, subscriptionIds.size());
assertThat(subscriptionIds, hasItems("subId", "subId2"));
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(-10L));
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool2), eq(-10L));
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(10L));
enforcer.postUnbind(consumer, poolManagerMock, e2);
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool2), eq(10L));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method exportAllPhysicalZeroBonusPoolQuantity.
@Test
public void exportAllPhysicalZeroBonusPoolQuantity() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
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, 10);
physicalPool.setConsumed(10L);
physicalPool.setExported(10L);
List<Pool> poolList = new ArrayList<>();
poolList.add(virtBonusPool);
ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
when(poolManagerMock.lookupBySubscriptionIds(anyString(), captor.capture())).thenReturn(poolList);
when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq("subId"))).thenReturn(poolList);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(physicalPool.getId(), e);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 10));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
@SuppressWarnings("unchecked") Set<String> subscriptionIds = captor.getValue();
assertEquals(1, subscriptionIds.size());
assertEquals("subId", subscriptionIds.iterator().next());
verify(poolManagerMock).setPoolQuantity(eq(virtBonusPool), eq(0L));
virtBonusPool.setQuantity(0L);
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock).setPoolQuantity(eq(virtBonusPool), eq(-1L));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitDoesNotAlterQuantitiesForHostLimited.
@Test
public void hostedVirtLimitDoesNotAlterQuantitiesForHostLimited() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
Pool virtBonusPool = setupVirtLimitPool();
virtBonusPool.setQuantity(100L);
virtBonusPool.setAttribute(Product.Attributes.HOST_LIMITED, "true");
virtBonusPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
virtBonusPool.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
virtBonusPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
Entitlement e = new Entitlement(virtBonusPool, consumer, owner, 1);
List<Pool> poolList = new ArrayList<>();
poolList.add(virtBonusPool);
when(poolManagerMock.lookupBySubscriptionId(eq(virtBonusPool.getOwner()), eq(virtBonusPool.getSubscriptionId()))).thenReturn(poolList);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(virtBonusPool.getId(), e);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(virtBonusPool.getId(), new PoolQuantity(virtBonusPool, 1));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
verify(poolManagerMock, never()).updatePoolQuantity(eq(virtBonusPool), eq(-10L));
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock, never()).updatePoolQuantity(eq(virtBonusPool), eq(10L));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method hostedParentConsumerPostCreatesNoPool.
@Test
public void hostedParentConsumerPostCreatesNoPool() {
Pool pool = setupVirtLimitPool();
List<Pool> pools = new ArrayList<>();
pools.add(pool);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(pool.getId(), new Entitlement(pool, consumer, owner, 1));
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(pool.getId(), new PoolQuantity(pool, 1));
PoolManager poolManager = mock(PoolManager.class);
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
enforcer.postEntitlement(poolManager, consumer, owner, entitlements, null, false, poolQuantityMap);
verify(poolManager, never()).createPools(any(List.class));
}
use of org.candlepin.model.Entitlement in project candlepin by candlepin.
the class PostEntitlementRulesTest method virtLimitSubPool.
@Test
public void virtLimitSubPool() {
Pool pool = setupVirtLimitPool();
pool.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
Entitlement e = new Entitlement(pool, consumer, owner, 5);
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));
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(1, pools.size());
assertEquals(10L, pools.get(0).getQuantity().longValue());
}
Aggregations