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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations