Search in sources :

Example 41 with Product

use of org.candlepin.model.Product in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method mockEntitlement.

private Entitlement mockEntitlement(Owner owner, Consumer consumer, Product product, DateRange range, Product... providedProducts) {
    Set<Product> provided = new HashSet<>();
    for (Product pp : providedProducts) {
        provided.add(pp);
    }
    final Pool p = new Pool(owner, product, provided, new Long(1000), range.getStartDate(), range.getEndDate(), "1000", "1000", "1000");
    p.setId("" + lastPoolId++);
    Entitlement e = new Entitlement(p, consumer, owner, 1);
    when(poolCurator.provides(p, product.getId())).thenReturn(true);
    for (Product pp : providedProducts) {
        when(poolCurator.provides(p, pp.getId())).thenReturn(true);
    }
    Random gen = new Random();
    int id = gen.nextInt(Integer.MAX_VALUE);
    e.setId(String.valueOf(id));
    return e;
}
Also used : Random(java.util.Random) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Example 42 with Product

use of org.candlepin.model.Product in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method validRangeEndDateSetToFirstDateOfLosingValidStatus.

@Test
public void validRangeEndDateSetToFirstDateOfLosingValidStatus() {
    Date now = new Date();
    Owner owner = TestUtil.createOwner();
    Product product = TestUtil.createProduct("p1", "product1");
    Consumer consumer = this.mockConsumer(owner, product);
    consumer.setCreated(now);
    DateRange range1 = this.rangeRelativeToDate(now, -4, 4);
    DateRange range2 = this.rangeRelativeToDate(now, -2, 10);
    DateRange range3 = this.rangeRelativeToDate(now, -3, -1);
    DateRange range4 = this.rangeRelativeToDate(range1.getEndDate(), 0, 10);
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range1, product));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range2, product));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range3, product));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", product, 1, range4, product));
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(range3.getStartDate(), cip.getStartDate());
    assertEquals(range2.getEndDate(), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 43 with Product

use of org.candlepin.model.Product in project candlepin by candlepin.

the class OwnerResourceTest method removePoolsForExpiredUpdate.

@Test
public void removePoolsForExpiredUpdate() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "3");
    prod = productCurator.merge(prod);
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setUpstreamPoolId("upstream-" + pool.getId());
    pool.setSubscriptionSubKey("master");
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    poolDto = ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> pools = poolCurator.listByOwner(owner).list();
    assertEquals(2, pools.size());
    poolDto.setStartDate(new Date(System.currentTimeMillis() - 5 * 24 * 60 * 60 * 1000));
    poolDto.setEndDate(new Date(System.currentTimeMillis() - 3 * 24 * 60 * 60 * 1000));
    ownerResource.updatePool(owner.getKey(), poolDto);
    pools = poolCurator.listByOwner(owner).list();
    assertEquals(0, pools.size());
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Date(java.util.Date) Test(org.junit.Test)

Example 44 with Product

use of org.candlepin.model.Product in project candlepin by candlepin.

the class OwnerResourceTest method createBonusPool.

@Test
public void createBonusPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "2");
    productCurator.merge(prod);
    Pool pool = TestUtil.createPool(owner, prod);
    pool.setUpstreamPoolId("upstream-" + pool.getId());
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    PoolDTO poolDto = this.modelTranslator.translate(pool, PoolDTO.class);
    ownerResource.createPool(owner.getKey(), poolDto);
    List<Pool> pools = poolCurator.listByOwner(owner).list();
    assertEquals(2, pools.size());
    assertTrue(pools.get(0).getSubscriptionSubKey().startsWith("master") || pools.get(1).getSubscriptionSubKey().startsWith("master"));
    assertTrue(pools.get(0).getSubscriptionSubKey().equals("derived") || pools.get(1).getSubscriptionSubKey().equals("derived"));
}
Also used : Product(org.candlepin.model.Product) PoolDTO(org.candlepin.dto.api.v1.PoolDTO) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 45 with Product

use of org.candlepin.model.Product in project candlepin by candlepin.

the class OwnerResourceTest method testRefreshPoolsWithRemovedSubscriptions.

@Test
public void testRefreshPoolsWithRemovedSubscriptions() {
    Product prod = this.createProduct(owner);
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
    sub.setId(Util.generateDbUUID());
    sub.setQuantity(2000L);
    sub.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub.setModified(TestUtil.createDate(2010, 2, 12));
    // This line is only present as a result of a (temporary?) fix for BZ 1452694. Once a
    // better fix has been implemented, the upstream pool ID can be removed.
    sub.setUpstreamPoolId("upstream_pool_id");
    subscriptions.add(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    List<Pool> pools = poolCurator.listByOwnerAndProduct(owner, prod.getId());
    assertEquals(1, pools.size());
    Pool newPool = pools.get(0);
    String poolId = newPool.getId();
    // Now delete the subscription:
    subscriptions.remove(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    assertNull("Pool not having subscription should have been deleted", poolCurator.find(poolId));
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Aggregations

Product (org.candlepin.model.Product)407 Test (org.junit.Test)281 Pool (org.candlepin.model.Pool)216 Owner (org.candlepin.model.Owner)153 Consumer (org.candlepin.model.Consumer)112 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)108 HashSet (java.util.HashSet)84 Date (java.util.Date)74 ArrayList (java.util.ArrayList)69 Entitlement (org.candlepin.model.Entitlement)67 LinkedList (java.util.LinkedList)66 HashMap (java.util.HashMap)65 Subscription (org.candlepin.model.dto.Subscription)47 Content (org.candlepin.model.Content)40 ValidationResult (org.candlepin.policy.ValidationResult)38 SourceSubscription (org.candlepin.model.SourceSubscription)36 Matchers.anyString (org.mockito.Matchers.anyString)31 List (java.util.List)29 PoolQuantity (org.candlepin.model.PoolQuantity)29 DateRange (org.candlepin.policy.js.compliance.DateRange)27