Search in sources :

Example 61 with ValidationResult

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

the class ManifestEntitlementRulesTest method preEntitlementNoRamCapableListWarn.

@Test
public void preEntitlementNoRamCapableListWarn() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("memory.memtotal", "2000000");
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.RAM, "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.ram.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 62 with ValidationResult

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

the class PreEntitlementRulesTest method testBindForSameProductNotAllowed.

@Test
public void testBindForSameProductNotAllowed() {
    Product product = TestUtil.createProduct(productId, "A product for testing");
    Pool pool = createPool(owner, product);
    Entitlement e = new Entitlement(pool, consumer, owner, 1);
    consumer.addEntitlement(e);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertTrue(result.hasErrors());
    assertFalse(result.isSuccessful());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 63 with ValidationResult

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

the class PreEntitlementRulesTest method exceedingNumberOfSocketsShouldGenerateWarning.

@Test
public void exceedingNumberOfSocketsShouldGenerateWarning() {
    Pool pool = setupArchTest("sockets", "2", "cpu.cpu_socket(s)", "4");
    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 64 with ValidationResult

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

the class PreEntitlementRulesTest method virtOnlyPoolGuestHostMatches.

@Test
public void virtOnlyPoolGuestHostMatches() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    Consumer parent = new Consumer("test parent consumer", "test user", owner, ctype);
    Pool pool = setupHostRestrictedPool(parent);
    String guestId = "virtguestuuid";
    consumer.setFact("virt.is_guest", "true");
    consumer.setFact("virt.uuid", guestId);
    when(consumerCurator.getHost(consumer, owner.getId())).thenReturn(parent);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 65 with ValidationResult

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

the class PreEntitlementRulesTest method testListForInsufficientCores.

@Test
public void testListForInsufficientCores() {
    Product product = TestUtil.createProduct(productId, "A product for testing");
    product.setAttribute(Product.Attributes.CORES, "10");
    Pool pool = createPool(owner, product);
    consumer.setFacts(new HashMap<>());
    consumer.setFact("cpu.cpu_socket(s)", "2");
    consumer.setFact("cpu.core(s)_per_socket", "10");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertTrue(result.hasWarnings());
    assertTrue(result.isSuccessful());
    assertEquals("rulewarning.unsupported.number.of.cores", result.getWarnings().get(0).getResourceKey());
}
Also used : Product(org.candlepin.model.Product) 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