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