Search in sources :

Example 61 with ActivationKey

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

the class ActivationKeyResourceTest method testActivationKeyWithNegPoolQuantity.

@Test(expected = BadRequestException.class)
public void testActivationKeyWithNegPoolQuantity() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.setQuantity(10L);
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool", -3L);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 62 with ActivationKey

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

the class ActivationKeyResourceTest method testActivationKeyWithNonPersonConsumerType.

@Test
public void testActivationKeyWithNonPersonConsumerType() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.getProduct().setAttribute(Pool.Attributes.REQUIRES_CONSUMER_TYPE, "candlepin");
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    assertNotNull(akr.addPoolToKey("testKey", "testPool", 1L));
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 63 with ActivationKey

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

the class ActivationKeyResourceTest method testActivationKeyWithUnlimitedPool.

@Test
public void testActivationKeyWithUnlimitedPool() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    p.setQuantity(-1L);
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool", 15L);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 64 with ActivationKey

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

the class ActivationKeyResourceTest method testUpdateTooLongRelease.

@Test(expected = BadRequestException.class)
public void testUpdateTooLongRelease() {
    ActivationKey key = new ActivationKey();
    OwnerDTO ownerDto = new OwnerDTO();
    key.setOwner(owner);
    key.setName("dd");
    key.setServiceLevel("level1");
    key.setReleaseVer(new Release("release1"));
    activationKeyCurator.create(key);
    ActivationKeyDTO update = new ActivationKeyDTO();
    update.setOwner(ownerDto);
    update.setName("dd");
    update.setServiceLevel("level1");
    update.setReleaseVersion(TestUtil.getStringOfSize(256));
    activationKeyResource.updateActivationKey(key.getId(), update);
}
Also used : ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Release(org.candlepin.model.Release) Test(org.junit.Test)

Example 65 with ActivationKey

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

the class ActivationKeyResourceTest method testAddingRemovingPools.

@Test
public void testAddingRemovingPools() {
    ActivationKey key = new ActivationKey();
    Product product = this.createProduct(owner);
    Pool pool = createPool(owner, product, 10L, new Date(), new Date());
    key.setOwner(owner);
    key.setName("dd");
    key = activationKeyCurator.create(key);
    assertNotNull(key.getId());
    activationKeyResource.addPoolToKey(key.getId(), pool.getId(), 1L);
    assertTrue(key.getPools().size() == 1);
    activationKeyResource.removePoolFromKey(key.getId(), pool.getId());
    assertTrue(key.getPools().size() == 0);
}
Also used : Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Date(java.util.Date) 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