Search in sources :

Example 91 with Product

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

the class PoolManagerTest method refreshPoolsCleanupPoolThatLostVirtLimit.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void refreshPoolsCleanupPoolThatLostVirtLimit() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Owner owner = getOwner();
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    Subscription s = TestUtil.createSubscription(owner, product);
    s.setId("01923");
    subscriptions.add(s);
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    p.setMarkedForDelete(true);
    p.setOwner(owner);
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    List<PoolUpdate> updates = new LinkedList();
    PoolUpdate u = new PoolUpdate(p);
    u.setQuantityChanged(true);
    u.setOrderChanged(true);
    updates.add(u);
    ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
    when(poolRulesMock.updatePools(argPool.capture(), eq(pools), eq(s.getQuantity()), any(Map.class))).thenReturn(updates);
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProducts(owner, product);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    verify(poolRulesMock).createAndEnrichPools(argPool.capture(), any(List.class));
    TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(s), argPool.getValue());
}
Also used : Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) PoolUpdate(org.candlepin.policy.js.pool.PoolUpdate) LinkedList(java.util.LinkedList) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 92 with Product

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

the class PoolManagerTest method testRefreshPoolsSortsStackDerivedPools.

@SuppressWarnings("rawtypes")
@Test
public void testRefreshPoolsSortsStackDerivedPools() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    // Pool has no subscription ID:
    Product product = TestUtil.createProduct();
    Pool p = TestUtil.createPool(product);
    p.setSourceStack(new SourceStack(new Consumer(), "a"));
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    ArgumentCaptor<List> poolCaptor = ArgumentCaptor.forClass(List.class);
    verify(this.poolRulesMock).updatePools(poolCaptor.capture(), any(Map.class));
    assertEquals(1, poolCaptor.getValue().size());
    assertEquals(p, poolCaptor.getValue().get(0));
}
Also used : Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Consumer(org.candlepin.model.Consumer) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 93 with Product

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

the class PoolManagerTest method testCreatePoolForSubscription.

@Test
public void testCreatePoolForSubscription() {
    Product product = TestUtil.createProduct();
    Subscription s = TestUtil.createSubscription(getOwner(), product);
    List<Pool> newPools = new LinkedList<>();
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    newPools.add(p);
    when(poolRulesMock.createAndEnrichPools(eq(s), any(List.class))).thenReturn(newPools);
    this.manager.createAndEnrichPools(s);
    verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
}
Also used : SourceSubscription(org.candlepin.model.SourceSubscription) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 94 with Product

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

the class PoolManagerTest method expiredEntitlementEvent.

@Test
public void expiredEntitlementEvent() {
    Date now = new Date();
    Product p = TestUtil.createProduct();
    p.setAttribute(Product.Attributes.HOST_LIMITED, "true");
    p.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
    Consumer guest = TestUtil.createConsumer(owner);
    guest.setFact("virt.is_guest", "true");
    guest.addInstalledProduct(new ConsumerInstalledProduct(p));
    Pool pool = TestUtil.createPool(owner, p);
    pool.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
    pool.setAttribute(Pool.Attributes.VIRT_ONLY, "true");
    pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    pool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "false");
    pool.setAttribute(Product.Attributes.VIRT_LIMIT, "0");
    pool.setStartDate(new Date(now.getTime() - (1000 * 60 * 60 * 24 * 2)));
    Entitlement ent = TestUtil.createEntitlement(owner, guest, pool, null);
    ent.setEndDateOverride(new Date(now.getTime() - (1000 * 60 * 60 * 24 * 1)));
    ent.setId("test-ent-id");
    ent.setQuantity(1);
    Set<Entitlement> entitlements = new HashSet<>();
    entitlements.add(ent);
    pool.setEntitlements(entitlements);
    Event event = new Event();
    event.setConsumerUuid(guest.getUuid());
    event.setOwnerId(owner.getId());
    event.setTarget(Target.ENTITLEMENT);
    event.setType(Type.EXPIRED);
    when(eventFactory.entitlementExpired(eq(ent))).thenReturn(event);
    when(mockPoolCurator.lockAndLoad(eq(pool))).thenReturn(pool);
    manager.revokeEntitlement(ent);
    String message = event.getMessageText();
    assertNotNull(message);
    message = message.split(": ")[1];
    assertEquals(message, i18n.tr("Unmapped guest entitlement expired without establishing a host/guest mapping."));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 95 with Product

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

the class PoolManagerTest method testEntitlebyProductRetry.

@Test
public void testEntitlebyProductRetry() throws Exception {
    Product product = TestUtil.createProduct();
    List<Pool> pools = new ArrayList<>();
    Pool pool1 = TestUtil.createPool(product);
    pool1.setId("poolId1");
    pools.add(pool1);
    Pool pool2 = TestUtil.createPool(product);
    pool2.setId("poolId2");
    pools.add(pool2);
    Date now = new Date();
    Map<String, ValidationResult> resultMap = new HashMap<>();
    ValidationResult result = mock(ValidationResult.class);
    resultMap.put("poolId1", result);
    resultMap.put("poolId2", result);
    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);
    List<Pool> poolList = Arrays.asList(pool1);
    when(mockQuery.iterator()).thenReturn(poolList.listIterator()).thenReturn(poolList.listIterator()).thenReturn(poolList.listIterator()).thenReturn(poolList.listIterator());
    when(enforcerMock.preEntitlement(any(Consumer.class), anyCollectionOf(PoolQuantity.class), any(CallerType.class))).thenReturn(resultMap);
    when(result.isSuccessful()).thenReturn(false);
    List<ValidationError> errors = new ArrayList<>();
    errors.add(new ValidationError("rulefailed.no.entitlements.available"));
    when(result.getErrors()).thenReturn(errors);
    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);
    AutobindData data = AutobindData.create(TestUtil.createConsumer(owner), owner).forProducts(new String[] { product.getUuid() }).on(now);
    doNothing().when(mockPoolCurator).flush();
    try {
        List<Entitlement> e = manager.entitleByProducts(data);
        fail();
    } catch (EntitlementRefusedException e) {
        assertNotNull(e);
        verify(autobindRules, times(4)).selectBestPools(any(Consumer.class), any(String[].class), any(List.class), any(ComplianceStatus.class), any(String.class), any(Set.class), eq(false));
    }
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) 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) 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) ValidationError(org.candlepin.policy.ValidationError) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Date(java.util.Date) Entitlement(org.candlepin.model.Entitlement) 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