Search in sources :

Example 6 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesStackDerivedTest method virtLimitFromFirstVirtLimitEntBatch.

@Test
public void virtLimitFromFirstVirtLimitEntBatch() {
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    stackedEnts.clear();
    Entitlement e1 = createEntFromPool(pool1);
    e1.setQuantity(4);
    stackedEnts.add(e1);
    Entitlement e2 = createEntFromPool(pool4);
    e2.setQuantity(16);
    stackedEnts.add(e2);
    Class<Set<String>> listClass = (Class<Set<String>>) (Class) HashSet.class;
    ArgumentCaptor<Set<String>> arg = ArgumentCaptor.forClass(listClass);
    when(cqmock.iterator()).thenReturn(stackedEnts.iterator());
    when(entCurMock.findByStackIds(eq(consumer), arg.capture())).thenReturn(cqmock);
    List<PoolUpdate> updates = poolRules.updatePoolsFromStack(consumer, Arrays.asList(stackDerivedPool, stackDerivedPool2), false);
    Set<String> stackIds = arg.getValue();
    assertEquals(2, stackIds.size());
    assertThat(stackIds, hasItems(STACK, STACK + "3"));
    for (PoolUpdate update : updates) {
        assertTrue(update.changed());
        assertTrue(update.getQuantityChanged());
    }
    assertEquals((Long) 2L, stackDerivedPool.getQuantity());
    assertEquals((Long) 9L, stackDerivedPool2.getQuantity());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesStackDerivedTest method mergedProductAttributes.

@Test
public void mergedProductAttributes() {
    Entitlement ent1 = createEntFromPool(pool1);
    ent1.setCreated(new Date(System.currentTimeMillis() - 86400000));
    stackedEnts.add(ent1);
    stackedEnts.add(createEntFromPool(pool3));
    PoolUpdate update = poolRules.updatePoolFromStack(stackDerivedPool, null);
    assertTrue(update.changed());
    assertTrue(update.getProductAttributesChanged());
    assertEquals(pool1.getProductAttributes(), stackDerivedPool.getProductAttributes());
}
Also used : Entitlement(org.candlepin.model.Entitlement) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Date(java.util.Date) Test(org.junit.Test)

Example 8 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate 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 9 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesTest method contractNumberChanged.

@Test
public void contractNumberChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    p.setContractNumber("123");
    // Setup a pool with a single (different) provided product:
    Pool p1 = TestUtil.clone(p);
    p1.setQuantity(2000L);
    p1.setContractNumber("ABC");
    List<Pool> existingPools = new LinkedList<>();
    existingPools.add(p1);
    List<PoolUpdate> updates = this.poolRules.updatePools(p, existingPools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertTrue(update.getOrderChanged());
    assertEquals("123", update.getPool().getContractNumber());
}
Also used : Pool(org.candlepin.model.Pool) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with PoolUpdate

use of org.candlepin.policy.js.pool.PoolUpdate in project candlepin by candlepin.

the class PoolRulesTest method brandingChanged.

@Test
public void brandingChanged() {
    Pool p = TestUtil.createPool(owner, TestUtil.createProduct());
    Pool p1 = TestUtil.clone(p);
    // Add some branding to the pool and do an update:
    Branding b1 = new Branding("8000", "OS", "Awesome OS Branded");
    Branding b2 = new Branding("8001", "OS", "Awesome OS Branded 2");
    p.getBranding().add(b1);
    p.getBranding().add(b2);
    List<Pool> existingPools = Arrays.asList(p1);
    List<PoolUpdate> updates = this.poolRules.updatePools(p, existingPools, p.getQuantity(), Collections.<String, Product>emptyMap());
    assertEquals(1, updates.size());
    PoolUpdate update = updates.get(0);
    assertFalse(update.getProductsChanged());
    assertFalse(update.getDatesChanged());
    assertFalse(update.getQuantityChanged());
    assertTrue(update.getBrandingChanged());
    assertTrue(update.changed());
    assertEquals(2, update.getPool().getBranding().size());
    assertTrue(update.getPool().getBranding().contains(b1));
    assertTrue(update.getPool().getBranding().contains(b2));
}
Also used : Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) Test(org.junit.Test)

Aggregations

PoolUpdate (org.candlepin.policy.js.pool.PoolUpdate)38 Test (org.junit.Test)35 Pool (org.candlepin.model.Pool)28 LinkedList (java.util.LinkedList)10 Product (org.candlepin.model.Product)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 EventBuilder (org.candlepin.audit.EventBuilder)4 Entitlement (org.candlepin.model.Entitlement)4 Subscription (org.candlepin.model.dto.Subscription)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 Branding (org.candlepin.model.Branding)2 Transactional (com.google.inject.persist.Transactional)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Event (org.candlepin.audit.Event)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)1