Search in sources :

Example 46 with ValidationResult

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

the class PreEntitlementRulesTest method x86ArchitectureProvidesI686.

@Test
public void x86ArchitectureProvidesI686() {
    Pool pool = setupArchTest("arch", "x86", "uname.machine", "i686");
    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 47 with ValidationResult

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

the class PreEntitlementRulesTest method missingConsumerArchitectureShouldGenerateWarning.

@Test
public void missingConsumerArchitectureShouldGenerateWarning() {
    Pool pool = setupArchTest("arch", "x86_64", "uname.machine", "x86_64");
    // Get rid of the facts that setupTest set.
    consumer.setFacts(new HashMap<>());
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertTrue(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 48 with ValidationResult

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

the class PreEntitlementRulesTest method missingConsumerArchitectureShouldNotGenerateWarningForNonSystem.

@Test
public void missingConsumerArchitectureShouldNotGenerateWarningForNonSystem() {
    String nonSystemType = "somethingElse";
    Product product = TestUtil.createProduct(productId, "A product for testing");
    product.setAttribute(Product.Attributes.ARCHITECTURE, "x86_64");
    product.setAttribute(Pool.Attributes.REQUIRES_CONSUMER_TYPE, nonSystemType);
    Pool pool = TestUtil.createPool(owner, product);
    pool.setId("fakeid" + TestUtil.randomInt());
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(nonSystemType));
    consumer.setType(ctype);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 49 with ValidationResult

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

the class PreEntitlementRulesTest method consumerHavingMoreRamThanProductGeneratesWarning.

@Test
public void consumerHavingMoreRamThanProductGeneratesWarning() {
    Pool pool = setupArchTest("ram", "2", "memory.memtotal", "4000000");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertTrue(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 50 with ValidationResult

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

the class EntitlementRules method update.

@Override
public ValidationResult update(Consumer consumer, Entitlement entitlement, Integer change) {
    ValidationResult result = new ValidationResult();
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (!ctype.isManifest() && !ctype.isType(ConsumerTypeEnum.SHARE)) {
        Pool pool = entitlement.getPool();
        // multi ent check
        if (!"yes".equalsIgnoreCase(pool.getProductAttributeValue(Pool.Attributes.MULTI_ENTITLEMENT)) && entitlement.getQuantity() + change > 1) {
            result.addError(new ValidationError(EntitlementRulesTranslator.PoolErrorKeys.MULTI_ENTITLEMENT_UNSUPPORTED));
        }
        if (!consumer.isGuest()) {
            String multiplier = pool.getProductAttributeValue(Product.Attributes.INSTANCE_MULTIPLIER);
            if (multiplier != null) {
                int instanceMultiplier = Integer.parseInt(multiplier);
                // quantity should be divisible by multiplier
                if ((entitlement.getQuantity() + change) % instanceMultiplier != 0) {
                    result.addError(new ValidationError(EntitlementRulesTranslator.PoolErrorKeys.QUANTITY_MISMATCH));
                }
            }
        }
    }
    finishValidation(result, entitlement.getPool(), change);
    return result;
}
Also used : Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) ConsumerType(org.candlepin.model.ConsumerType)

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