Search in sources :

Example 66 with ValidationResult

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

the class PreEntitlementRulesTest method matchingNumberOfSocketsShouldNotGenerateWarningBatch.

@Test
public void matchingNumberOfSocketsShouldNotGenerateWarningBatch() {
    Pool pool = setupArchTest("sockets", "2", "cpu.cpu_socket(s)", "2");
    Pool pool2 = setupArchTest("sockets", "2", "cpu.cpu_socket(s)", "2");
    Map<String, ValidationResult> results = enforcer.preEntitlement(consumer, createPoolQuantities(1, pool, pool2), CallerType.UNKNOWN);
    assertEquals(2, results.size());
    for (ValidationResult result : results.values()) {
        assertFalse(result.hasErrors());
        assertFalse(result.hasWarnings());
    }
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 67 with ValidationResult

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

the class PreEntitlementRulesTest method mappedGuest.

@Test
public void mappedGuest() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    Consumer parent = new Consumer("test parent consumer", "test user", owner, ctype);
    Consumer newborn = new Consumer("test newborn consumer", "test user", owner, ctype);
    newborn.setCreated(new java.util.Date());
    Pool pool = setupUnmappedGuestPool();
    String guestId = "virtguestuuid";
    newborn.setFact("virt.is_guest", "true");
    newborn.setFact("virt.uuid", guestId);
    when(consumerCurator.getHost(newborn, owner.getId())).thenReturn(parent);
    ValidationResult result = enforcer.preEntitlement(newborn, pool, 1);
    assertTrue(result.hasErrors());
    assertEquals(1, result.getErrors().size());
    assertEquals("virt.guest.cannot.use.unmapped.guest.pool.has.host", result.getErrors().get(0).getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Date(java.util.Date) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 68 with ValidationResult

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

the class PreEntitlementRulesTest method physOnlyPoolGuestNoHostIsPhysical.

@Test
public void physOnlyPoolGuestNoHostIsPhysical() {
    Pool pool = setupPhysOnlyPool();
    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 69 with ValidationResult

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

the class PreEntitlementRulesTest method virtOnlyPoolGuestHostDoesNotMatch.

@Test
public void virtOnlyPoolGuestHostDoesNotMatch() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    // Parent consumer of our guest:
    Consumer parent = new Consumer("test parent consumer", "test user", owner, ctype);
    // 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(parent);
    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 70 with ValidationResult

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

the class PreEntitlementRulesTest method architectureMatches.

@Test
public void architectureMatches() {
    Pool pool = setupArchTest("arch", "x86_64", "uname.machine", "x86_64");
    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