Search in sources :

Example 21 with ValidationResult

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

the class ManifestEntitlementRulesTest method preEntitlementNoInstanceCapableListWarn.

@Test
public void preEntitlementNoInstanceCapableListWarn() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "2");
    Pool p = TestUtil.createPool(prod);
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.LIST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    ValidationWarning warning = results.getWarnings().get(0);
    assertEquals("rulewarning.instance.unsupported.by.consumer", warning.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationWarning(org.candlepin.policy.ValidationWarning) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with ValidationResult

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

the class ManifestEntitlementRulesTest method preEntitlementNoDerivedProductCapabilityProducesWarningOnList.

@Test
public void preEntitlementNoDerivedProductCapabilityProducesWarningOnList() {
    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.LIST_POOLS);
    assertNotNull(results);
    assertEquals(1, results.getWarnings().size());
    assertTrue(results.getErrors().isEmpty());
    ValidationWarning warning = results.getWarnings().get(0);
    assertEquals("rulewarning.derivedproduct.unsupported.by.consumer", warning.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationWarning(org.candlepin.policy.ValidationWarning) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 23 with ValidationResult

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

the class ManifestEntitlementRulesTest method preEntitlementShouldNotAllowListOfRequiresHostPools.

@Test
public void preEntitlementShouldNotAllowListOfRequiresHostPools() {
    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.LIST_POOLS);
    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 24 with ValidationResult

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

the class PreEntitlementRulesTest method unmappedGuestFuturePoolDate.

@Test
public void unmappedGuestFuturePoolDate() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    Date fourHoursFromNow = new Date(new Date().getTime() + 4L * 60L * 60L * 1000L);
    Pool pool = setupUnmappedGuestPool();
    pool.setStartDate(fourHoursFromNow);
    Consumer consumer = new Consumer("test newborn consumer", "test user", owner, ctype);
    consumer.setFact("virt.is_guest", "true");
    consumer.setCreated(new Date());
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1, CallerType.BIND);
    assertTrue(result.hasErrors());
    assertEquals(1, result.getErrors().size());
    assertEquals("virt.guest.cannot.bind.future.unmapped.guest.pool", result.getErrors().get(0).getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Date(java.util.Date) Test(org.junit.Test)

Example 25 with ValidationResult

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

the class PreEntitlementRulesTest method virtOnlyNonHostReqPool.

@Test
public void virtOnlyNonHostReqPool() {
    Pool pool = setupVirtOnlyPool();
    consumer.setFact("virt.is_guest", "true");
    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)

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