Search in sources :

Example 46 with Subscription

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

Example 47 with Subscription

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

Example 48 with Subscription

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));
}
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) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 49 with Subscription

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));
}
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) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 50 with Subscription

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);
}
Also used : Owner(org.candlepin.model.Owner) ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) ArrayList(java.util.ArrayList) Subscription(org.candlepin.model.dto.Subscription) ConsumerType(org.candlepin.model.ConsumerType) Before(org.junit.Before)

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