use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolRulesStackDerivedTest method createStackedVirtSub.
private Subscription createStackedVirtSub(Owner owner, Product product, Date start, Date end) {
Subscription s = TestUtil.createSubscription(owner, TestUtil.createProduct());
s.setStartDate(start);
s.setEndDate(end);
s.setProduct(product.toDTO());
s.setContractNumber(Integer.toString(TestUtil.randomInt()));
s.setOrderNumber(Integer.toString(TestUtil.randomInt()));
s.setAccountNumber(Integer.toString(TestUtil.randomInt()));
return s;
}
use of org.candlepin.model.dto.Subscription 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());
}
use of org.candlepin.model.dto.Subscription 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.dto.Subscription 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.dto.Subscription in project candlepin by candlepin.
the class ConsumerResourceVirtEntitlementTest method setUp.
@Before
public void setUp() {
List<Subscription> subscriptions = new ArrayList<>();
subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
manifestType = consumerTypeCurator.create(new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN));
systemType = consumerTypeCurator.create(new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM));
owner = ownerCurator.create(new Owner("test-owner"));
ownerCurator.create(owner);
manifestConsumer = TestUtil.createConsumer(manifestType, owner);
consumerCurator.create(manifestConsumer);
systemConsumer = TestUtil.createConsumer(systemType, owner);
consumerCurator.create(systemConsumer);
// create a physical pool with numeric virt_limit
productLimit = TestUtil.createProduct();
productLimit.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
productLimit.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
productLimit = this.createProduct(productLimit, owner);
Subscription limitSub = TestUtil.createSubscription(owner, productLimit, new HashSet<>());
limitSub.setId(Util.generateDbUUID());
limitSub.setQuantity(10L);
limitSub.setStartDate(TestUtil.createDate(2010, 1, 1));
limitSub.setEndDate(TestUtil.createDate(2020, 1, 1));
limitSub.setModified(TestUtil.createDate(2000, 1, 1));
subscriptions.add(limitSub);
limitPools = poolManager.createAndEnrichPools(limitSub);
// create a physical pool with unlimited virt_limit
productUnlimit = TestUtil.createProduct();
productUnlimit.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
productUnlimit.setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
productUnlimit = this.createProduct(productUnlimit, owner);
Subscription unlimitSub = TestUtil.createSubscription(owner, productUnlimit, new HashSet<>());
unlimitSub.setId(Util.generateDbUUID());
unlimitSub.setQuantity(10L);
unlimitSub.setStartDate(TestUtil.createDate(2010, 1, 1));
unlimitSub.setEndDate(TestUtil.createDate(2020, 1, 1));
unlimitSub.setModified(TestUtil.createDate(2000, 1, 1));
subscriptions.add(unlimitSub);
unlimitPools = poolManager.createAndEnrichPools(unlimitSub);
}
Aggregations