use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolRulesTest method standaloneVirtLimitSubCreateDerived.
@Test
public void standaloneVirtLimitSubCreateDerived() {
when(configMock.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
Subscription s = createVirtLimitSubWithDerivedProducts("virtLimitProduct", "derivedProd", 10, 10);
Pool p = TestUtil.copyFromSub(s);
when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
p.setId("mockVirtLimitSubCreateDerived");
when(productCurator.getPoolDerivedProvidedProductsCached(p)).thenReturn(p.getDerivedProvidedProducts());
List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
// Should be virt_only pool for unmapped guests:
assertEquals(2, pools.size());
Pool physicalPool = pools.get(0);
assertEquals(0, physicalPool.getAttributes().size());
assertFalse(physicalPool.getProduct().hasAttribute(DERIVED_ATTR));
Pool unmappedVirtPool = pools.get(1);
assert ("true".equals(unmappedVirtPool.getAttributeValue(Product.Attributes.VIRT_ONLY)));
assert ("true".equals(unmappedVirtPool.getAttributeValue(Pool.Attributes.UNMAPPED_GUESTS_ONLY)));
assertEquals("derivedProd", unmappedVirtPool.getProductId());
assertProvidedProductsForSub(s.getDerivedProvidedProducts(), unmappedVirtPool.getProvidedProducts());
assertProvidedProducts(new HashSet<>(), unmappedVirtPool.getDerivedProvidedProducts());
assertTrue(unmappedVirtPool.getProduct().hasAttribute(DERIVED_ATTR));
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class OwnerProductResourceTest method testDeleteProductWithSubscriptions.
@Test(expected = BadRequestException.class)
public void testDeleteProductWithSubscriptions() {
OwnerCurator oc = mock(OwnerCurator.class);
OwnerProductCurator opc = mock(OwnerProductCurator.class);
ProductCurator pc = mock(ProductCurator.class);
I18n i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
OwnerProductResource pr = new OwnerProductResource(config, i18n, oc, null, opc, null, pc, null, this.modelTranslator);
Owner o = mock(Owner.class);
Product p = mock(Product.class);
when(oc.lookupByKey(eq("owner"))).thenReturn(o);
when(opc.getProductById(eq(o), eq("10"))).thenReturn(p);
Set<Subscription> subs = new HashSet<>();
Subscription s = mock(Subscription.class);
subs.add(s);
when(pc.productHasSubscriptions(eq(o), eq(p))).thenReturn(true);
pr.deleteProduct("owner", "10");
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class EntitlementRulesTestFixture method createVirtLimitSub.
protected Subscription createVirtLimitSub(String productId, int quantity, String virtLimit) {
Product product = TestUtil.createProduct(productId, productId);
product.setAttribute(Product.Attributes.VIRT_LIMIT, virtLimit);
when(ownerProductCuratorMock.getProductById(owner, productId)).thenReturn(product);
Subscription s = TestUtil.createSubscription(owner, product);
s.setQuantity(new Long(quantity));
s.setId("subId");
return s;
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitAltersBonusPoolQuantity.
@Test
@SuppressWarnings("unchecked")
public void hostedVirtLimitAltersBonusPoolQuantity() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
Subscription s = createVirtLimitSub("virtLimitProduct", 10, "10");
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
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);
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(physicalPool.getSubscriptionId()))).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, 1));
List<Pool> physicalPools = new ArrayList<>();
physicalPools.add(physicalPool);
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
Set<String> subscriptionIds = captor.getValue();
assertEquals(1, subscriptionIds.size());
assertEquals("subId", subscriptionIds.iterator().next());
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(-10L));
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(10L));
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitWithHostLimitedCreatesBonusPoolsOnBind.
/*
* Bonus pools in hosted mode for products with the host_limited attribute
* are created during binding.
*/
@Test
public void hostedVirtLimitWithHostLimitedCreatesBonusPoolsOnBind() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
Subscription s = createVirtLimitSub("virtLimitProduct", 10, "unlimited");
s.getProduct().setAttribute(Product.Attributes.HOST_LIMITED, "true");
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");
assertEquals(new Long(10), physicalPool.getQuantity());
assertEquals(0, physicalPool.getAttributes().size());
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).createPools(any(List.class));
}
Aggregations