Search in sources :

Example 66 with Pool

use of org.candlepin.model.Pool 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 67 with Pool

use of org.candlepin.model.Pool 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 68 with Pool

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

the class PoolManagerTest method testCleanupExpiredPoolsReadOnlySubscriptions.

@Test
public void testCleanupExpiredPoolsReadOnlySubscriptions() {
    Pool p = createPoolWithEntitlements();
    p.setSubscriptionId("subid");
    List<Pool> pools = Arrays.asList(p);
    when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
    when(mockPoolCurator.listExpiredPools(anyInt())).thenReturn(pools);
    when(mockPoolCurator.entitlementsIn(p)).thenReturn(new ArrayList<>(p.getEntitlements()));
    Subscription sub = new Subscription();
    sub.setId(p.getSubscriptionId());
    when(mockSubAdapter.getSubscription(any(String.class))).thenReturn(sub);
    when(mockSubAdapter.isReadOnly()).thenReturn(true);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    manager.cleanupExpiredPools();
    // And the pool should be deleted:
    verify(mockPoolCurator).batchDelete(eq(pools), anySetOf(String.class));
    verify(mockSubAdapter, never()).getSubscription(any(String.class));
    verify(mockSubAdapter, never()).deleteSubscription(any(Subscription.class));
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 69 with Pool

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

the class PoolManagerTest method mockPoolsList.

private void mockPoolsList(List<Pool> pools) {
    List<Pool> floating = new LinkedList<>();
    subToPools = new HashMap<>();
    for (Pool pool : pools) {
        String subid = pool.getSubscriptionId();
        if (subid != null) {
            if (!subToPools.containsKey(subid)) {
                subToPools.put(subid, new LinkedList<>());
            }
            subToPools.get(subid).add(pool);
        } else {
            floating.add(pool);
        }
    }
    for (String subid : subToPools.keySet()) {
        CandlepinQuery cqmock = mock(CandlepinQuery.class);
        when(cqmock.list()).thenReturn(subToPools.get(subid));
        when(mockPoolCurator.getPoolsBySubscriptionId(eq(subid))).thenReturn(cqmock);
    }
    when(mockPoolCurator.getOwnersFloatingPools(any(Owner.class))).thenReturn(floating);
    when(mockPoolCurator.getPoolsFromBadSubs(any(Owner.class), any(Collection.class))).thenAnswer(new Answer<List<Pool>>() {

        @SuppressWarnings("unchecked")
        @Override
        public List<Pool> answer(InvocationOnMock iom) throws Throwable {
            Collection<String> subIds = (Collection<String>) iom.getArguments()[1];
            List<Pool> results = new LinkedList<>();
            for (Entry<String, List<Pool>> entry : PoolManagerTest.subToPools.entrySet()) {
                for (Pool pool : entry.getValue()) {
                    if (!subIds.contains(pool.getSubscriptionId())) {
                        results.add(pool);
                    }
                }
            }
            return results;
        }
    });
}
Also used : Owner(org.candlepin.model.Owner) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) Entry(java.util.Map.Entry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyCollection(org.mockito.Matchers.anyCollection) Collection(java.util.Collection) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList)

Example 70 with Pool

use of org.candlepin.model.Pool 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)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30