Search in sources :

Example 96 with Subscription

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));
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 97 with Subscription

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");
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) OwnerProductCurator(org.candlepin.model.OwnerProductCurator) ProductCurator(org.candlepin.model.ProductCurator) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) OwnerProductCurator(org.candlepin.model.OwnerProductCurator) I18n(org.xnap.commons.i18n.I18n) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with Subscription

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;
}
Also used : Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription)

Example 99 with Subscription

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));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyLong(org.mockito.Matchers.anyLong) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 100 with Subscription

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));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) Matchers.anyLong(org.mockito.Matchers.anyLong) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Aggregations

Subscription (org.candlepin.model.dto.Subscription)101 Test (org.junit.Test)77 Pool (org.candlepin.model.Pool)60 Product (org.candlepin.model.Product)48 SourceSubscription (org.candlepin.model.SourceSubscription)36 LinkedList (java.util.LinkedList)35 ArrayList (java.util.ArrayList)34 Owner (org.candlepin.model.Owner)33 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)18 Matchers.anyString (org.mockito.Matchers.anyString)18 Entitlement (org.candlepin.model.Entitlement)16 Date (java.util.Date)15 PoolType (org.candlepin.model.Pool.PoolType)13 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)13 List (java.util.List)11 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)11 ConsumerType (org.candlepin.model.ConsumerType)10 ProductData (org.candlepin.model.dto.ProductData)9