Search in sources :

Example 61 with ConsumerType

use of org.candlepin.model.ConsumerType 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 62 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class PreEntitlementRulesTest method unmappedGuestGoodDate.

@Test
public void unmappedGuestGoodDate() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    Pool pool = setupUnmappedGuestPool();
    Consumer newborn = new Consumer("test newborn consumer", "test user", owner, ctype);
    newborn.setFact("virt.is_guest", "true");
    newborn.setCreated(new Date());
    ValidationResult result = enforcer.preEntitlement(newborn, 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) Date(java.util.Date) Test(org.junit.Test)

Example 63 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class PreEntitlementRulesTest method devPoolConsumerDoesNotMatch.

@Test
public void devPoolConsumerDoesNotMatch() {
    // Another consumer we'll make a dev pool for:
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SYSTEM));
    Consumer otherConsumer = new Consumer("test consumer", "test user", owner, ctype);
    Pool pool = setupDevConsumerRestrictedPool(otherConsumer);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasWarnings());
    assertEquals(1, result.getErrors().size());
    assertEquals("consumer.does.not.match.pool.consumer.requirement", 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 64 with ConsumerType

use of org.candlepin.model.ConsumerType 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 65 with ConsumerType

use of org.candlepin.model.ConsumerType 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)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16