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");
}
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));
}
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());
}
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;
}
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;
}
Aggregations