Search in sources :

Example 66 with ConsumerType

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

the class PreEntitlementRulesTest method missingConsumerArchitectureShouldNotGenerateWarningForNonSystem.

@Test
public void missingConsumerArchitectureShouldNotGenerateWarningForNonSystem() {
    String nonSystemType = "somethingElse";
    Product product = TestUtil.createProduct(productId, "A product for testing");
    product.setAttribute(Product.Attributes.ARCHITECTURE, "x86_64");
    product.setAttribute(Pool.Attributes.REQUIRES_CONSUMER_TYPE, nonSystemType);
    Pool pool = TestUtil.createPool(owner, product);
    pool.setId("fakeid" + TestUtil.randomInt());
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(nonSystemType));
    consumer.setType(ctype);
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 67 with ConsumerType

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

the class ConsumerTypeResourceTest method testCreateType.

@Test
public void testCreateType() {
    String label = "test_label";
    ConsumerType existing = this.consumerTypeCurator.lookupByLabel(label);
    // Verify it doesn't exist already
    assertNull(existing);
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setLabel(label);
    dto.setManifest(true);
    // Create the type with our DTO
    ConsumerTypeDTO output = this.consumerTypeResource.create(dto);
    assertNotNull(output);
    assertEquals(dto.getLabel(), output.getLabel());
    assertEquals(dto.isManifest(), output.isManifest());
    // Flush & clear DB state
    this.consumerTypeCurator.flush();
    this.consumerTypeCurator.clear();
    // Ensure the type actually hit the DB
    existing = this.consumerTypeCurator.lookupByLabel(label);
    assertNotNull(existing);
    assertEquals(dto.getLabel(), existing.getLabel());
    assertEquals(dto.isManifest(), existing.isManifest());
}
Also used : ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 68 with ConsumerType

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

the class ConsumerTypeResourceTest method testUpdateTypeUpdatesLabelButNotManifest.

@Test
public void testUpdateTypeUpdatesLabelButNotManifest() {
    String label = "updated_label";
    boolean manifest = this.testType.isManifest();
    ConsumerTypeDTO dto = new ConsumerTypeDTO();
    dto.setId(this.testType.getId());
    dto.setLabel(label);
    // Update the type with our DTO
    ConsumerTypeDTO output = this.consumerTypeResource.update(dto);
    assertNotNull(output);
    assertEquals(dto.getLabel(), output.getLabel());
    assertEquals(manifest, output.isManifest());
    // Flush & clear DB state
    this.consumerTypeCurator.flush();
    this.consumerTypeCurator.clear();
    // Ensure the update actually hit the DB
    ConsumerType existing = this.consumerTypeCurator.lookupByLabel(label);
    assertNotNull(existing);
    assertEquals(dto.getLabel(), existing.getLabel());
    assertEquals(manifest, existing.isManifest());
}
Also used : ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 69 with ConsumerType

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

the class EntitlementResourceTest method migrateEntitlementSameOwnerFail.

@Test(expected = BadRequestException.class)
public void migrateEntitlementSameOwnerFail() {
    ConsumerType ct = TestUtil.createConsumerType();
    ct.setManifest(true);
    this.mockConsumerType(ct);
    Entitlement e = TestUtil.createEntitlement();
    Owner owner2 = new Owner("admin2");
    owner.setId(TestUtil.randomString());
    owner2.setId(TestUtil.randomString());
    Consumer sourceConsumer = new Consumer("source-consumer", "bill", owner, ct);
    Consumer destConsumer = new Consumer("destination-consumer", "bill", owner2, ct);
    e.setConsumer(sourceConsumer);
    e.setQuantity(25);
    when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
    when(consumerCurator.verifyAndLookupConsumer(eq(destConsumer.getUuid()))).thenReturn(destConsumer);
    entResource.migrateEntitlement(e.getId(), destConsumer.getUuid(), 15);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 70 with ConsumerType

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

the class EntitlementResourceTest method migrateEntitlementDestinationConsumerFail.

@Test(expected = BadRequestException.class)
public void migrateEntitlementDestinationConsumerFail() {
    ConsumerType ct = TestUtil.createConsumerType();
    ct.setManifest(true);
    this.mockConsumerType(ct);
    Entitlement e = TestUtil.createEntitlement();
    Consumer sourceConsumer = new Consumer("source-consumer", "bill", owner, ct);
    e.setConsumer(sourceConsumer);
    e.setQuantity(25);
    when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    entResource.migrateEntitlement(e.getId(), consumer.getUuid(), 15);
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) 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