use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class ComplianceOp method preProcess.
/**
* Computes the compliance status implemented in java script.
* does not compute the hash or apply the status.
* requires only the consumer to be locked.
* @param context
*/
@Override
public boolean preProcess(BindContext context) {
Consumer consumer = context.getLockedConsumer();
Map<String, Entitlement> entitlementMap = context.getEntitlementMap();
Map<String, PoolQuantity> poolQuantityMap = context.getPoolQuantities();
for (Map.Entry<String, Entitlement> entry : entitlementMap.entrySet()) {
PoolQuantity pq = poolQuantityMap.get(entry.getKey());
entry.getValue().setPool(pq.getPool());
}
status = complianceRules.getStatus(consumer, entitlementMap.values(), null, false, false, false, false);
for (Map.Entry<String, Entitlement> entry : entitlementMap.entrySet()) {
PoolQuantity pq = poolQuantityMap.get(entry.getKey());
entry.getValue().setPool(null);
}
return true;
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class EntitlementCertificateGeneratorTest method testGenerateEntitlementCertificate.
@Test
public void testGenerateEntitlementCertificate() throws GeneralSecurityException, IOException {
this.ecGenerator = new EntitlementCertificateGenerator(this.mockEntCertCurator, this.mockEntCertAdapter, this.mockEntitlementCurator, this.mockPoolCurator, this.mockEventSink, this.mockEventFactory, this.mockProductCurator);
Consumer consumer = mock(Consumer.class);
Pool pool = mock(Pool.class);
Product product = mock(Product.class);
when(pool.getId()).thenReturn("Swift");
when(pool.getProduct()).thenReturn(product);
Entitlement entitlement = mock(Entitlement.class);
when(entitlement.getConsumer()).thenReturn(consumer);
Map<String, Product> expectedProducts = new HashMap<>();
expectedProducts.put("Swift", product);
Map<String, Entitlement> expected = new HashMap<>();
expected.put("Swift", entitlement);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put("Swift", new PoolQuantity(pool, 0));
ecGenerator.generateEntitlementCertificate(pool, entitlement);
verify(mockEntCertAdapter).generateEntitlementCerts(eq(consumer), eq(poolQuantityMap), eq(expected), eq(expectedProducts), eq(true));
}
use of org.candlepin.model.PoolQuantity 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));
}
}
use of org.candlepin.model.PoolQuantity 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);
}
use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method noBonusPoolsForHostedNonDistributorBinds.
/*
* Bonus pools should not be created when we are in a hosted scenario without
* distributor binds.
*/
@Test
public void noBonusPoolsForHostedNonDistributorBinds() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
Subscription s = createVirtLimitSub("virtLimitProduct", 10, "unlimited");
Pool p = TestUtil.copyFromSub(s);
when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
assertEquals(2, pools.size());
Pool physicalPool = pools.get(0);
physicalPool.setId("physical");
Pool virtBonusPool = pools.get(1);
virtBonusPool.setId("virt");
assertEquals(new Long(10), physicalPool.getQuantity());
assertEquals(0, physicalPool.getAttributes().size());
// Quantity on bonus pool should be -1:
assertEquals(new Long(-1), virtBonusPool.getQuantity());
assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
assertEquals("unlimited", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(physicalPool.getId(), e);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
verify(poolManagerMock, never()).createPool(any(Pool.class));
verify(poolManagerMock, never()).updatePoolQuantity(any(Pool.class), anyInt());
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock, never()).updatePoolQuantity(any(Pool.class), anyInt());
verify(poolManagerMock, never()).setPoolQuantity(any(Pool.class), anyLong());
}
Aggregations