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());
}
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());
}
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));
}
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);
}
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);
}
Aggregations