Search in sources :

Example 11 with ValidationError

use of org.candlepin.policy.ValidationError in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementShouldNotAllowConsumptionFromRequiresHostPools.

@Test
public void preEntitlementShouldNotAllowConsumptionFromRequiresHostPools() {
    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.REQUIRES_HOST, "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());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 12 with ValidationError

use of org.candlepin.policy.ValidationError in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementNoCoreCapableBindError.

@Test
public void preEntitlementNoCoreCapableBindError() {
    // 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<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.CORES, "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.cores.unsupported.by.consumer", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with ValidationError

use of org.candlepin.policy.ValidationError in project candlepin by candlepin.

the class EntitlerTest method fakeOutResult.

private ValidationResult fakeOutResult(String msg) {
    ValidationResult result = new ValidationResult();
    ValidationError err = new ValidationError(msg);
    result.addError(err);
    return result;
}
Also used : ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult)

Example 14 with ValidationError

use of org.candlepin.policy.ValidationError in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementShouldNotAllowOverConsumptionOfEntitlements.

@Test
public void preEntitlementShouldNotAllowOverConsumptionOfEntitlements() {
    Consumer c = this.createMockConsumer(true);
    Product prod = TestUtil.createProduct();
    Pool p = TestUtil.createPool(prod);
    p.setQuantity(5L);
    ValidationResult results = enforcer.preEntitlement(c, p, 10);
    assertNotNull(results);
    assertEquals(1, results.getErrors().size());
    ValidationError error = results.getErrors().get(0);
    assertEquals("rulefailed.no.entitlements.available", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 15 with ValidationError

use of org.candlepin.policy.ValidationError in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementNoDerivedProductCapabilityProducesErrorOnBestPools.

@Test
public void preEntitlementNoDerivedProductCapabilityProducesErrorOnBestPools() {
    Consumer c = this.createMockConsumer(true);
    c.setCapabilities(new HashSet<>());
    Product prod = TestUtil.createProduct();
    Product derived = TestUtil.createProduct("sub-prod-id");
    Pool p = TestUtil.createPool(prod);
    p.setDerivedProduct(derived);
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertEquals(1, results.getErrors().size());
    assertTrue(results.getWarnings().isEmpty());
    ValidationError error = results.getErrors().get(0);
    assertEquals("rulefailed.derivedproduct.unsupported.by.consumer", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationError (org.candlepin.policy.ValidationError)15 Pool (org.candlepin.model.Pool)14 ValidationResult (org.candlepin.policy.ValidationResult)13 Consumer (org.candlepin.model.Consumer)11 Product (org.candlepin.model.Product)11 Test (org.junit.Test)11 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 ConsumerCapability (org.candlepin.model.ConsumerCapability)3 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Entitlement (org.candlepin.model.Entitlement)2 PoolQuantity (org.candlepin.model.PoolQuantity)2 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)1