Search in sources :

Example 36 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class OwnerProductCuratorTest method testUpdateOwnerProductReferences.

@Test
public void testUpdateOwnerProductReferences() {
    Owner owner = this.createOwner();
    Product original = this.createProduct();
    Product updated = this.createProduct();
    this.createOwnerProductMapping(owner, original);
    ActivationKey key = TestUtil.createActivationKey(owner, null);
    key.setProducts(Util.asSet(original));
    Pool pool1 = TestUtil.createPool(owner, original);
    Pool pool2 = TestUtil.createPool(owner);
    pool2.addProvidedProduct(original);
    Pool pool3 = TestUtil.createPool(owner);
    pool3.setDerivedProduct(original);
    Pool pool4 = TestUtil.createPool(owner);
    pool4.setDerivedProvidedProducts(Arrays.asList(original));
    this.activationKeyCurator.create(key);
    this.poolCurator.create(pool1);
    this.productCurator.create(pool2.getProduct());
    this.poolCurator.create(pool2);
    this.productCurator.create(pool3.getProduct());
    this.poolCurator.create(pool3);
    this.productCurator.create(pool4.getProduct());
    this.poolCurator.create(pool4);
    assertTrue(this.isProductMappedToOwner(original, owner));
    assertFalse(this.isProductMappedToOwner(updated, owner));
    Map<String, String> uuidMap = new HashMap<>();
    uuidMap.put(original.getUuid(), updated.getUuid());
    this.ownerProductCurator.updateOwnerProductReferences(owner, uuidMap);
    assertFalse(this.isProductMappedToOwner(original, owner));
    assertTrue(this.isProductMappedToOwner(updated, owner));
    this.activationKeyCurator.refresh(key);
    Collection<Product> products = key.getProducts();
    assertEquals(1, products.size());
    assertEquals(updated.getUuid(), products.iterator().next().getUuid());
    this.poolCurator.refresh(pool1);
    assertEquals(updated.getUuid(), pool1.getProduct().getUuid());
    this.poolCurator.refresh(pool2);
    assertNotEquals(updated.getUuid(), pool2.getProduct().getUuid());
    products = pool2.getProvidedProducts();
    assertEquals(1, products.size());
    assertEquals(updated.getUuid(), products.iterator().next().getUuid());
    this.poolCurator.refresh(pool3);
    assertNotEquals(updated.getUuid(), pool3.getProduct().getUuid());
    assertEquals(updated.getUuid(), pool3.getDerivedProduct().getUuid());
    this.poolCurator.refresh(pool4);
    assertNotEquals(updated.getUuid(), pool4.getProduct().getUuid());
    products = pool4.getDerivedProvidedProducts();
    assertEquals(1, products.size());
    assertEquals(updated.getUuid(), products.iterator().next().getUuid());
}
Also used : HashMap(java.util.HashMap) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 37 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyTest method testCreate.

@Test
public void testCreate() {
    ActivationKey key = createActivationKey(owner);
    activationKeyCurator.create(key);
    assertNotNull(key.getId());
    assertNotNull(key.getName());
    assertNotNull(key.getServiceLevel());
    assertNotNull(key.getDescription());
    assertEquals(owner, key.getOwner());
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 38 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyTest method testActivationKeyHasPool.

@Test
public void testActivationKeyHasPool() {
    ActivationKey key = this.createActivationKey(this.owner);
    Product prod = TestUtil.createProduct();
    productCurator.create(prod);
    Pool pool = createPool(this.owner, prod, 12L, new Date(), new Date(System.currentTimeMillis() + (365 * 24 * 60 * 60 * 1000)));
    assertTrue(!key.hasPool(pool));
    key.addPool(pool, 1L);
    assertTrue(key.hasPool(pool));
    key.removePool(pool);
    assertTrue(!key.hasPool(pool));
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Date(java.util.Date) Test(org.junit.Test)

Example 39 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyTest method testOwnerRelationship.

@Test
public void testOwnerRelationship() {
    ActivationKey key = createActivationKey(owner);
    activationKeyCurator.create(key);
    ownerCurator.refresh(owner);
    assertNotNull(owner.getActivationKeys());
    assertTrue("The count of keys should be 1", owner.getActivationKeys().size() == 1);
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 40 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ConsumerResourceTest method testCreatePersonConsumerWithActivationKey.

@Test(expected = BadRequestException.class)
public void testCreatePersonConsumerWithActivationKey() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Owner owner = this.createOwner();
    Consumer consumer = this.createConsumer(owner, ctype);
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    ActivationKey ak = mock(ActivationKey.class);
    NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);
    when(ak.getId()).thenReturn("testKey");
    when(akc.lookupForOwner(eq(owner.getKey()), eq(owner))).thenReturn(ak);
    ConsumerResource cr = new ConsumerResource(null, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, akc, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.create(consumerDto, nap, null, owner.getKey(), "testKey", true);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerContentOverrideCurator(org.candlepin.model.ConsumerContentOverrideCurator) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Aggregations

ActivationKey (org.candlepin.model.activationkeys.ActivationKey)76 Test (org.junit.Test)55 Pool (org.candlepin.model.Pool)38 Product (org.candlepin.model.Product)16 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)15 ArrayList (java.util.ArrayList)14 ValidationResult (org.candlepin.policy.ValidationResult)14 Consumer (org.candlepin.model.Consumer)13 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)13 PoolManager (org.candlepin.controller.PoolManager)11 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)10 Owner (org.candlepin.model.Owner)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 BadRequestException (org.candlepin.common.exceptions.BadRequestException)9 Date (java.util.Date)8 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)8 HashSet (java.util.HashSet)6