Search in sources :

Example 36 with Consumer

use of org.candlepin.model.Consumer 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 37 with Consumer

use of org.candlepin.model.Consumer 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 38 with Consumer

use of org.candlepin.model.Consumer 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 39 with Consumer

use of org.candlepin.model.Consumer 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)

Example 40 with Consumer

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

the class ConsumerBindUtilTest method registerPassWithKeyServiceLevelNotExistOtherKeysSucceed.

@Test
public void registerPassWithKeyServiceLevelNotExistOtherKeysSucceed() throws Exception {
    List<ActivationKey> keys = mockActivationKeys();
    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) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Aggregations

Consumer (org.candlepin.model.Consumer)470 Test (org.junit.Test)345 Entitlement (org.candlepin.model.Entitlement)162 Owner (org.candlepin.model.Owner)126 Pool (org.candlepin.model.Pool)114 Product (org.candlepin.model.Product)112 Date (java.util.Date)102 ConsumerType (org.candlepin.model.ConsumerType)94 LinkedList (java.util.LinkedList)73 ArrayList (java.util.ArrayList)71 HashSet (java.util.HashSet)69 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)69 HashMap (java.util.HashMap)48 ApiOperation (io.swagger.annotations.ApiOperation)43 Produces (javax.ws.rs.Produces)43 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)40 ApiResponses (io.swagger.annotations.ApiResponses)38 GuestId (org.candlepin.model.GuestId)37 Path (javax.ws.rs.Path)36 List (java.util.List)35