use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.
the class EntitlerJobTest method respondWithValidationErrors.
@Test
public void respondWithValidationErrors() throws JobExecutionException, EntitlementRefusedException {
PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
pQs[0] = new PoolIdAndQuantity("pool10", 1);
JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
HashMap<String, ValidationResult> mapResult = new HashMap<>();
ValidationResult result = new ValidationResult();
result.addError("rulefailed.no.entitlements.available");
mapResult.put("hello", result);
when(e.bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class))).thenThrow(new EntitlementRefusedException(mapResult));
EntitlerJob job = new EntitlerJob(e, null, pC, i18n);
injector.injectMembers(job);
Pool p = new Pool();
p.setId("hello");
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(p).iterator());
when(pC.listAllByIds(anyListOf(String.class))).thenReturn(cqmock);
job.execute(ctx);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(ctx).setResult(argumentCaptor.capture());
List<PoolIdAndErrors> resultErrors = (List<PoolIdAndErrors>) argumentCaptor.getValue();
assertEquals(1, resultErrors.size());
assertEquals("hello", resultErrors.get(0).getPoolId());
assertEquals(1, resultErrors.get(0).getErrors().size());
assertEquals("No subscriptions are available from the pool with ID \"hello\".", resultErrors.get(0).getErrors().get(0));
}
use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementNoRamCapableBindError.
@Test
public void preEntitlementNoRamCapableBindError() {
// Test with sockets to make sure that they are skipped.
Consumer c = this.createMockConsumer(true);
c.setFact("memory.memtotal", "2000000");
Set<ConsumerCapability> caps = new HashSet<>();
c.setCapabilities(caps);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.RAM, "2");
Pool p = TestUtil.createPool(prod);
p.setId("poolId");
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
assertNotNull(results);
assertEquals(0, results.getWarnings().size());
ValidationError error = results.getErrors().get(0);
assertEquals("rulefailed.ram.unsupported.by.consumer", error.getResourceKey());
}
use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementSuccessRamCapable.
@Test
public void preEntitlementSuccessRamCapable() {
// Test with sockets to make sure that they are skipped.
Consumer c = this.createMockConsumer(true);
c.setFact("memory.memtotal", "2000000");
Set<ConsumerCapability> caps = new HashSet<>();
ConsumerCapability cc = new ConsumerCapability(c, "ram");
caps.add(cc);
c.setCapabilities(caps);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.RAM, "2");
Pool p = TestUtil.createPool(prod);
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
assertNotNull(results);
assertEquals(0, results.getErrors().size());
assertEquals(0, results.getWarnings().size());
}
use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementSuccessCoreCapable.
@Test
public void preEntitlementSuccessCoreCapable() {
// Test with sockets to make sure that they are skipped.
Consumer c = this.createMockConsumer(true);
c.setFact("cpu.core(s)_per_socket", "2");
Set<ConsumerCapability> caps = new HashSet<>();
ConsumerCapability cc = new ConsumerCapability(c, "cores");
caps.add(cc);
c.setCapabilities(caps);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.CORES, "2");
Pool p = TestUtil.createPool(prod);
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
assertNotNull(results);
assertEquals(0, results.getErrors().size());
assertEquals(0, results.getWarnings().size());
}
use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementShouldNotAllowConsumptionFromDerivedPools.
@Test
public void preEntitlementShouldNotAllowConsumptionFromDerivedPools() {
Consumer c = this.createMockConsumer(true);
Product prod = TestUtil.createProduct();
Pool p = TestUtil.createPool(prod);
p.setAttribute(Product.Attributes.VIRT_ONLY, "true");
p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
p.setId("poolId");
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
assertNotNull(results);
assertEquals(1, results.getErrors().size());
ValidationError error = results.getErrors().get(0);
assertEquals("pool.not.available.to.manifest.consumers", error.getResourceKey());
}
Aggregations