Search in sources :

Example 41 with ValidationResult

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

the class PreEntitlementRulesTest method mismatchingConsumerTypeShouldGenerateError.

@Test
public void mismatchingConsumerTypeShouldGenerateError() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    Pool pool = setupProductWithConsumerTypeAttribute(ConsumerTypeEnum.DOMAIN);
    consumer.setType(ctype);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertTrue(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 42 with ValidationResult

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

the class PreEntitlementRulesTest method testEmptyArch.

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

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

the class PreEntitlementRulesTest method missingConsumerSocketsShouldNotGenerateWarning.

@Test
public void missingConsumerSocketsShouldNotGenerateWarning() {
    // non-system consumers do not have socket counts, no warning
    // should be generated (per IT)
    Pool pool = setupArchTest("sockets", "2", "cpu.cpu_socket(s)", "2");
    // Get rid of the facts that setupTest set.
    consumer.setFacts(new HashMap<>());
    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 44 with ValidationResult

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

the class PreEntitlementRulesTest method unmappedGuestBadDate.

@Test
public void unmappedGuestBadDate() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    Pool pool = setupUnmappedGuestPool();
    Consumer tooOld = new Consumer("test newborn consumer", "test user", owner, ctype);
    tooOld.setFact("virt.is_guest", "true");
    Date twentyFiveHoursAgo = new Date(new Date().getTime() - 25L * 60L * 60L * 1000L);
    tooOld.setCreated(twentyFiveHoursAgo);
    ValidationResult result = enforcer.preEntitlement(tooOld, pool, 1);
    assertTrue(result.hasErrors());
    assertEquals(1, result.getErrors().size());
    assertEquals("virt.guest.cannot.use.unmapped.guest.pool.not.new", 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 45 with ValidationResult

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

the class PreEntitlementRulesTest method multipleArchesMatches.

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