Search in sources :

Example 76 with ValidationResult

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

the class PreEntitlementRulesTest method bindWithQuantityNoMultiEntitleBatch.

@Test
public void bindWithQuantityNoMultiEntitleBatch() {
    Product product = TestUtil.createProduct(productId, "A product for testing");
    Pool pool = createPool(owner, product);
    pool.setId("TaylorSwift");
    pool.setQuantity(new Long(100));
    Pool pool2 = createPool(owner, product);
    pool2.setId("SwiftTaylor");
    pool2.setQuantity(new Long(100));
    Map<String, ValidationResult> results = enforcer.preEntitlement(consumer, createPoolQuantities(100, pool, pool2), CallerType.UNKNOWN);
    assertEquals(2, results.size());
    for (ValidationResult result : results.values()) {
        assertFalse(result.isSuccessful());
        assertTrue(result.hasErrors());
        assertEquals(1, result.getErrors().size());
        assertTrue(result.getErrors().get(0).getResourceKey().contains("multi-entitlement"));
    }
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 77 with ValidationResult

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

the class PreEntitlementRulesTest method testZeroConsumerSocketsShouldNotGenerateWarning.

@Test
public void testZeroConsumerSocketsShouldNotGenerateWarning() {
    // there was a bug in an IT adapter where a null socket count was being
    // set to zero. As a hotfix, we do not generate a warning when socket
    // count is zero.
    Pool pool = setupArchTest("sockets", "0", "cpu.cpu_socket(s)", "2");
    // Get rid of the facts that setupTest set.
    consumer.setFacts(new HashMap<>());
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 78 with ValidationResult

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

the class PreEntitlementRulesTest method testCommaSplitArchesExtraSpaces.

@Test
public void testCommaSplitArchesExtraSpaces() {
    Pool pool = setupArchTest("arch", "x86_64,  z80 ", "uname.machine", "x86_64");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 79 with ValidationResult

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

the class PreEntitlementRulesTest method consumerHavingLessRamThanProductShouldNotGenerateWarning.

@Test
public void consumerHavingLessRamThanProductShouldNotGenerateWarning() {
    // Fact specified in kb
    Pool pool = setupArchTest("ram", "4", "memory.memtotal", "2000000");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 80 with ValidationResult

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

the class PreEntitlementRulesTest method hypervisorForSystemNotGenerateError.

@Test
public void hypervisorForSystemNotGenerateError() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.HYPERVISOR));
    Pool pool = setupProductWithConsumerTypeAttribute(ConsumerTypeEnum.SYSTEM);
    consumer.setType(ctype);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (org.candlepin.policy.ValidationResult)116 Pool (org.candlepin.model.Pool)111 Test (org.junit.Test)105 Product (org.candlepin.model.Product)38 Consumer (org.candlepin.model.Consumer)36 ConsumerType (org.candlepin.model.ConsumerType)22 HashSet (java.util.HashSet)19 Entitlement (org.candlepin.model.Entitlement)15 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)14 ValidationError (org.candlepin.policy.ValidationError)13 ArrayList (java.util.ArrayList)11 LinkedList (java.util.LinkedList)11 ConsumerCapability (org.candlepin.model.ConsumerCapability)11 Date (java.util.Date)10 HashMap (java.util.HashMap)9 Matchers.anyString (org.mockito.Matchers.anyString)9 List (java.util.List)8 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)8 PreUnbindHelper (org.candlepin.policy.js.entitlement.PreUnbindHelper)8 PoolQuantity (org.candlepin.model.PoolQuantity)7