Search in sources :

Example 81 with ValidationResult

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

the class PreEntitlementRulesTest method userRestrictedPoolPassesPre.

@Test
public void userRestrictedPoolPassesPre() {
    Pool pool = setupUserRestrictedPool();
    consumer.setUsername("bob");
    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 82 with ValidationResult

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

the class PreEntitlementRulesTest method consumerRamIsRoundedToNearestGbAndShouldNotGenerateWarning.

@Test
public void consumerRamIsRoundedToNearestGbAndShouldNotGenerateWarning() {
    // Fact specified in kb - actual value of 2 GiB in kb.
    Pool pool = setupArchTest("ram", "2", "memory.memtotal", "2097152");
    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 83 with ValidationResult

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

the class PreEntitlementRulesTest method testListForSufficientRAM.

@Test
public void testListForSufficientRAM() {
    Product product = TestUtil.createProduct(productId, "A product for testing");
    product.setAttribute(Product.Attributes.RAM, "16");
    Pool pool = createPool(owner, product);
    consumer.setFacts(new HashMap<>());
    consumer.setFact("memory.memtotal", "16777216");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
    assertTrue(result.isSuccessful());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 84 with ValidationResult

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

the class PreEntitlementRulesTest method virtOnlyPoolGuestNoHost.

@Test
public void virtOnlyPoolGuestNoHost() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    // Another parent we'll make a virt only pool for:
    Consumer otherParent = new Consumer("test parent consumer", "test user", owner, ctype);
    Pool pool = setupHostRestrictedPool(otherParent);
    String guestId = "virtguestuuid";
    consumer.setFact("virt.is_guest", "true");
    consumer.setFact("virt.uuid", guestId);
    when(consumerCurator.getHost(consumer, owner.getId())).thenReturn(null);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasWarnings());
    assertEquals(1, result.getErrors().size());
    assertEquals("virt.guest.host.does.not.match.pool.owner", 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) Test(org.junit.Test)

Example 85 with ValidationResult

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

the class PreEntitlementRulesTest method testListForSufficientCores.

@Test
public void testListForSufficientCores() {
    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)", "1");
    consumer.setFact("cpu.core(s)_per_socket", "10");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
    assertTrue(result.isSuccessful());
}
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