Search in sources :

Example 51 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class ProductResourceTest method testDeleteProductWithSubscriptions.

@Test(expected = BadRequestException.class)
public void testDeleteProductWithSubscriptions() {
    ProductCurator pc = mock(ProductCurator.class);
    I18n i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    ProductResource pr = new ProductResource(pc, null, null, config, i18n, this.modelTranslator);
    Owner o = mock(Owner.class);
    Product p = mock(Product.class);
    // when(pc.lookupById(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("10");
}
Also used : Owner(org.candlepin.model.Owner) ProductCurator(org.candlepin.model.ProductCurator) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) I18n(org.xnap.commons.i18n.I18n) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 52 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesInstanceTest method hostedInstanceBasedRemoved.

@Test
public void hostedInstanceBasedRemoved() {
    Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, false);
    Pool masterPool = TestUtil.copyFromSub(s);
    List<Pool> pools = poolRules.createAndEnrichPools(masterPool, new LinkedList<>());
    assertEquals(1, pools.size());
    Pool pool = pools.get(0);
    // Remove the instance multiplier attribute entirely, pool quantity should
    // revert to half of what it was. No existing entitlements need to be adjusted,
    // we will let a (future) overconsumption routine handle that.
    masterPool = TestUtil.copyFromSub(s);
    masterPool.getProduct().removeAttribute(Product.Attributes.INSTANCE_MULTIPLIER);
    List<Pool> existingPools = new LinkedList<>();
    existingPools.add(pool);
    List<PoolUpdate> updates = poolRules.updatePools(masterPool, existingPools, s.getQuantity(), TestUtil.stubChangedProducts(masterPool.getProduct()));
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getQuantityChanged());
    assertEquals(new Long(100), update.getPool().getQuantity());
    assertFalse(update.getPool().getProduct().hasAttribute(Product.Attributes.INSTANCE_MULTIPLIER));
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 53 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesInstanceTest method hostedCreateInstanceBasedPool.

@Test
public void hostedCreateInstanceBasedPool() {
    Subscription s = createInstanceBasedSub("INSTANCEPROD", 100, 2, false);
    Pool p = TestUtil.copyFromSub(s);
    List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
    assertEquals(1, pools.size());
    Pool pool = pools.get(0);
    // Quantity should be doubled:
    assertEquals(new Long(200), pool.getQuantity());
}
Also used : Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 54 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesInstanceTest method createInstanceBasedSub.

private Subscription createInstanceBasedSub(String productId, int quantity, int instanceMultiplier, boolean exported) {
    Owner owner = new Owner("Test Corporation");
    Product product = TestUtil.createProduct(productId, productId);
    product.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, Integer.toString(instanceMultiplier));
    Subscription s = TestUtil.createSubscription(owner, product);
    if (exported) {
        s.setUpstreamPoolId("SOMETHING");
    }
    s.setQuantity(new Long(quantity));
    return s;
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription)

Example 55 with Subscription

use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.

the class PoolRulesTest method createVirtLimitSubWithDerivedProducts.

private Subscription createVirtLimitSubWithDerivedProducts(String productId, String derivedProductId, int quantity, int virtLimit) {
    Product product = TestUtil.createProduct(productId, productId);
    product.setAttribute(Product.Attributes.VIRT_LIMIT, Integer.toString(virtLimit));
    when(ownerProdCuratorMock.getProductById(owner, product.getId())).thenReturn(product);
    Product derivedProd = TestUtil.createProduct(derivedProductId, derivedProductId);
    // We'll look for this to make sure it makes it to correct pools:
    derivedProd.setAttribute(DERIVED_ATTR, "nobodycares");
    when(ownerProdCuratorMock.getProductById(owner, derivedProd.getId())).thenReturn(derivedProd);
    // Create some provided products:
    Product provided1 = TestUtil.createProduct();
    when(ownerProdCuratorMock.getProductById(owner, provided1.getId())).thenReturn(provided1);
    Product provided2 = TestUtil.createProduct();
    when(ownerProdCuratorMock.getProductById(owner, provided2.getId())).thenReturn(provided2);
    // Create some derived provided products:
    Product derivedProvided1 = TestUtil.createProduct();
    when(ownerProdCuratorMock.getProductById(owner, derivedProvided1.getId())).thenReturn(derivedProvided1);
    Product derivedProvided2 = TestUtil.createProduct();
    when(ownerProdCuratorMock.getProductById(owner, derivedProvided2.getId())).thenReturn(derivedProvided2);
    Subscription s = TestUtil.createSubscription(owner, product);
    s.setQuantity(new Long(quantity));
    s.setDerivedProduct(derivedProd.toDTO());
    Set<ProductData> derivedProds = new HashSet<>();
    derivedProds.add(derivedProvided1.toDTO());
    derivedProds.add(derivedProvided2.toDTO());
    s.setDerivedProvidedProducts(derivedProds);
    return s;
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Product(org.candlepin.model.Product) Subscription(org.candlepin.model.dto.Subscription) HashSet(java.util.HashSet)

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