Search in sources :

Example 1 with ActivationKey

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

the class ConsumerBindUtilTest method registerFailWithKeyServiceLevelNotExist.

@Test(expected = BadRequestException.class)
public void registerFailWithKeyServiceLevelNotExist() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    key1.setServiceLevel("I don't exist");
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    doThrow(new BadRequestException("exception")).when(serviceLevelValidator).validate(eq(owner.getId()), eq(key1.getServiceLevel()));
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
Also used : Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 2 with ActivationKey

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

the class ConsumerBindUtilTest method registerWithKeyWithInstalledProductsAutoAttach.

@Test
public void registerWithKeyWithInstalledProductsAutoAttach() throws Exception {
    Product prod = TestUtil.createProduct();
    String[] prodIds = new String[] { prod.getId() };
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    key1.setAutoAttach(true);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    Set<ConsumerInstalledProduct> cips = new HashSet<>();
    ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod);
    cips.add(cip);
    consumer.setInstalledProducts(cips);
    AutobindData ad = new AutobindData(consumer, owner).forProducts(prodIds);
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
    verify(entitler).bindByProducts(eq(ad));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) AutobindData(org.candlepin.resource.dto.AutobindData) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ActivationKey

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

the class ConsumerBindUtilTest method registerFailWithNoGoodKeyPool.

@Test(expected = BadRequestException.class)
public void registerFailWithNoGoodKeyPool() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    Product prod1 = TestUtil.createProduct();
    Pool ghost = TestUtil.createPool(owner, prod1, 5);
    ghost.setId("ghost-pool");
    key1.addPool(ghost, 10L);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    when(entitler.bindByPoolQuantity(eq(consumer), eq(ghost.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 4 with ActivationKey

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

the class ConsumerBindUtilTest method registerWithKeyWithInstalledProductsPlusAutoAttach.

@Test
public void registerWithKeyWithInstalledProductsPlusAutoAttach() throws Exception {
    // installed product
    Product prod1 = TestUtil.createProduct();
    // key product
    Product prod2 = TestUtil.createProduct();
    String[] prodIds = new String[] { prod1.getId(), prod2.getId() };
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    keys.add(key1);
    key1.addProduct(prod2);
    key1.setAutoAttach(true);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    Set<ConsumerInstalledProduct> cips = new HashSet<>();
    ConsumerInstalledProduct cip = new ConsumerInstalledProduct(consumer, prod1);
    cips.add(cip);
    consumer.setInstalledProducts(cips);
    AutobindData ad = new AutobindData(consumer, owner).forProducts(prodIds);
    consumerBindUtil.handleActivationKeys(consumer, keys, false);
    verify(entitler).bindByProducts(eq(ad));
}
Also used : Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) AutobindData(org.candlepin.resource.dto.AutobindData) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ActivationKey

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

the class ConsumerBindUtilTest method registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled.

@Test
public void registerPassWhenAutobindDisabledForOwnerAndKeyHasAutobindEnabled() throws Exception {
    List<ActivationKey> keys = new ArrayList<>();
    ActivationKey key1 = new ActivationKey("key1", owner);
    key1.setAutoAttach(true);
    keys.add(key1);
    Product prod1 = TestUtil.createProduct();
    Pool pool1 = TestUtil.createPool(owner, prod1, 5);
    pool1.setId("pool1");
    key1.addPool(pool1, 10L);
    Consumer consumer = new Consumer("sys.example.com", null, null, system);
    when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
    consumerBindUtil.handleActivationKeys(consumer, keys, true);
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) 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