Search in sources :

Example 16 with Consumer

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

the class CalculatedAttributesUtilTest method testCalculatedAttributesPresent.

@Test
public void testCalculatedAttributesPresent() {
    for (PoolComplianceType type : PoolComplianceType.values()) {
        when(mockPool.getComplianceType()).thenReturn(type);
        Date date = new Date();
        Map<String, String> attrs = attrUtil.buildCalculatedAttributes(mockPool, date);
        assertTrue(attrs.containsKey("compliance_type"));
    }
    SuggestedQuantity suggested = new SuggestedQuantity();
    suggested.setSuggested(1L);
    suggested.setIncrement(1L);
    Map<String, SuggestedQuantity> suggestedMap = new HashMap<>();
    suggestedMap.put(pool1.getId(), suggested);
    when(quantityRules.getSuggestedQuantities(any(List.class), any(Consumer.class), any(Date.class))).thenReturn(suggestedMap);
    Date date = new Date();
    attrUtil.setQuantityAttributes(pool1, consumer, date);
    assertTrue(pool1.getCalculatedAttributes().containsKey("suggested_quantity"));
    assertTrue(pool1.getCalculatedAttributes().containsKey("quantity_increment"));
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) SuggestedQuantity(org.candlepin.policy.js.quantity.SuggestedQuantity) List(java.util.List) Date(java.util.Date) PoolComplianceType(org.candlepin.model.Pool.PoolComplianceType) Test(org.junit.Test)

Example 17 with Consumer

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

the class CalculatedAttributesUtilTest method testQuantityIncrement.

@Test
public void testQuantityIncrement() {
    Product product2 = TestUtil.createProduct("blah", "blah");
    product2.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "12");
    productCurator.create(product2);
    Pool pool2 = createPool(owner1, product2, 500L, TestUtil.createDate(2000, 1, 1), TestUtil.createDate(3000, 1, 1));
    SuggestedQuantity suggested = new SuggestedQuantity();
    suggested.setSuggested(1L);
    suggested.setIncrement(12L);
    Map<String, SuggestedQuantity> suggestedMap = new HashMap<>();
    suggestedMap.put(pool2.getId(), suggested);
    when(quantityRules.getSuggestedQuantities(any(List.class), any(Consumer.class), any(Date.class))).thenReturn(suggestedMap);
    Date date = new Date();
    attrUtil.setQuantityAttributes(pool2, consumer, date);
    assertEquals("1", pool2.getCalculatedAttributes().get("suggested_quantity"));
    assertEquals("12", pool2.getCalculatedAttributes().get("quantity_increment"));
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) SuggestedQuantity(org.candlepin.policy.js.quantity.SuggestedQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Consumer

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

the class InstalledProductStatusCalculatorTest method validRangeIsNullWhenOnlyExpiredEntitlementExists.

@Test
public void validRangeIsNullWhenOnlyExpiredEntitlementExists() {
    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, -2);
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(null, cip.getStartDate());
    assertEquals(null, 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 19 with Consumer

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

the class InstalledProductStatusCalculatorTest method validRangeWithMultipleWhereFutureEntitlementOverlaps.

@Test
public void validRangeWithMultipleWhereFutureEntitlementOverlaps() {
    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, 2);
    DateRange range2 = this.rangeRelativeToDate(now, 2, 4);
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range2, product));
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(range1.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 20 with Consumer

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

the class InstalledProductStatusCalculatorTest method validRangeConsidersInvalidGapBetweenNonStackedEntitlement.

@Test
public void validRangeConsidersInvalidGapBetweenNonStackedEntitlement() {
    Date now = new Date();
    Owner owner = TestUtil.createOwner();
    Product product = TestUtil.createProduct("p1", "product1");
    Product stacked = TestUtil.createProduct("p1_stack", "product1-stacked");
    Consumer consumer = this.mockConsumer(owner, product);
    consumer.setCreated(now);
    DateRange range1 = this.rangeRelativeToDate(now, -4, -2);
    DateRange range2 = this.rangeRelativeToDate(now, -3, 2);
    DateRange range3 = this.rangeRelativeToDate(now, -1, 4);
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
    consumer.addEntitlement(this.mockStackedEntitlement(owner, consumer, "stack_id_1", stacked, 1, range2, product));
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range3, 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(range3.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)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35