Search in sources :

Example 96 with Product

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

the class PoolManagerTest method testEntitleWithADate.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testEntitleWithADate() throws Exception {
    Product product = TestUtil.createProduct();
    List<Pool> pools = new ArrayList<>();
    Pool pool1 = TestUtil.createPool(product);
    pools.add(pool1);
    Pool pool2 = TestUtil.createPool(product);
    pools.add(pool2);
    Date now = new Date();
    ValidationResult result = mock(ValidationResult.class);
    Page page = mock(Page.class);
    when(page.getPageData()).thenReturn(pools);
    when(mockPoolCurator.listAvailableEntitlementPools(any(Consumer.class), any(String.class), any(String.class), any(String.class), eq(now), any(PoolFilterBuilder.class), any(PageRequest.class), anyBoolean(), anyBoolean(), anyBoolean(), any(Date.class))).thenReturn(page);
    CandlepinQuery mockQuery = mock(CandlepinQuery.class);
    when(mockPoolCurator.listAllByIds(any(List.class))).thenReturn(mockQuery);
    when(mockQuery.iterator()).thenReturn(Arrays.asList(pool1).listIterator());
    when(enforcerMock.preEntitlement(any(Consumer.class), any(Pool.class), anyInt(), any(CallerType.class))).thenReturn(result);
    when(result.isSuccessful()).thenReturn(true);
    List<PoolQuantity> bestPools = new ArrayList<>();
    bestPools.add(new PoolQuantity(pool1, 1));
    when(autobindRules.selectBestPools(any(Consumer.class), any(String[].class), any(List.class), any(ComplianceStatus.class), any(String.class), any(Set.class), eq(false))).thenReturn(bestPools);
    ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
    Consumer consumer = TestUtil.createConsumer(ctype, owner);
    AutobindData data = AutobindData.create(consumer, owner).forProducts(new String[] { product.getUuid() }).on(now);
    doNothing().when(mockPoolCurator).flush();
    doNothing().when(mockPoolCurator).clear();
    List<Entitlement> e = manager.entitleByProducts(data);
    assertNotNull(e);
    assertEquals(e.size(), 1);
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashSet(java.util.HashSet) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Page(org.candlepin.common.paging.Page) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) CallerType(org.candlepin.policy.js.entitlement.Enforcer.CallerType) ValidationResult(org.candlepin.policy.ValidationResult) Date(java.util.Date) PageRequest(org.candlepin.common.paging.PageRequest) Consumer(org.candlepin.model.Consumer) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) AutobindData(org.candlepin.resource.dto.AutobindData) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 97 with Product

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

the class PoolManagerTest method derivedProvidedProductsCopiedOntoMasterPoolWhenCreatingNewPool.

@Test
public void derivedProvidedProductsCopiedOntoMasterPoolWhenCreatingNewPool() {
    Product product = TestUtil.createProduct();
    Product subProduct = TestUtil.createProduct();
    Product subProvidedProduct = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setDerivedProduct(subProduct.toDTO());
    Set<ProductData> subProvided = new HashSet<>();
    subProvided.add(subProvidedProduct.toDTO());
    sub.setDerivedProvidedProducts(subProvided);
    this.mockProducts(owner, product, subProduct, subProvidedProduct);
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Pool> pools = pRules.createAndEnrichPools(sub);
    assertEquals(1, pools.size());
    Pool resultPool = pools.get(0);
    assertEquals(1, resultPool.getDerivedProvidedProducts().size());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with Product

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

the class PoolManagerTest method mockProducts.

private void mockProducts(Owner owner, Product... products) {
    Map<String, Product> productMap = new HashMap<>();
    for (Product product : products) {
        productMap.put(product.getId(), product);
    }
    this.mockProducts(owner, productMap);
}
Also used : HashMap(java.util.HashMap) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString)

Example 99 with Product

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

the class PoolManagerTest method subProductAttributesCopiedOntoPoolWhenCreatingNewPool.

@Test
public void subProductAttributesCopiedOntoPoolWhenCreatingNewPool() {
    Product product = TestUtil.createProduct();
    Product subProduct = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setDerivedProduct(subProduct.toDTO());
    String testAttributeKey = "multi-entitlement";
    String expectedAttributeValue = "yes";
    subProduct.setAttribute(testAttributeKey, expectedAttributeValue);
    this.mockProducts(owner, product, subProduct);
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Pool> pools = pRules.createAndEnrichPools(sub);
    assertEquals(1, pools.size());
    Pool resultPool = pools.get(0);
    assertNotNull(resultPool.getDerivedProduct());
    assertTrue(resultPool.getDerivedProduct().hasAttribute(testAttributeKey));
    assertEquals(expectedAttributeValue, resultPool.getDerivedProduct().getAttributeValue(testAttributeKey));
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Example 100 with Product

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

the class PoolManagerTest method subProductIdCopiedOntoPoolWhenCreatingNewPool.

@Test
public void subProductIdCopiedOntoPoolWhenCreatingNewPool() {
    Product product = TestUtil.createProduct();
    Product subProduct = TestUtil.createProduct();
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setDerivedProduct(subProduct.toDTO());
    this.mockProducts(owner, product, subProduct);
    PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
    List<Pool> pools = pRules.createAndEnrichPools(sub);
    assertEquals(1, pools.size());
    Pool resultPool = pools.get(0);
    assertEquals(subProduct, resultPool.getDerivedProduct());
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) 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