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());
}
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));
}
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));
}
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."));
}
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));
}
}
Aggregations