use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerPassWithOneGoodKeyPool.
@Test
public void registerPassWithOneGoodKeyPool() throws Exception {
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
Product prod1 = TestUtil.createProduct();
Pool pool1 = TestUtil.createPool(owner, prod1, 5);
pool1.setId("pool1");
key1.addPool(pool1, 10L);
Product prod2 = TestUtil.createProduct();
Pool pool2 = TestUtil.createPool(owner, prod2, 5);
pool2.setId("pool2");
key1.addPool(pool2, 10L);
Product prod3 = TestUtil.createProduct();
Pool pool3 = TestUtil.createPool(owner, prod3, 5);
pool3.setId("pool3");
key1.addPool(pool3, 5L);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
when(entitler.bindByPoolQuantity(eq(consumer), eq(pool2.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerPassWithOneGoodKey.
@Test
public void registerPassWithOneGoodKey() throws Exception {
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
ActivationKey key2 = new ActivationKey("key2", owner);
keys.add(key1);
keys.add(key2);
Product prod1 = TestUtil.createProduct();
Pool pool1 = TestUtil.createPool(owner, prod1, 5);
pool1.setId("pool1");
key1.addPool(pool1, 10L);
Product prod2 = TestUtil.createProduct();
Pool pool2 = TestUtil.createPool(owner, prod2, 5);
pool2.setId("pool2");
key1.addPool(pool2, 10L);
Product prod3 = TestUtil.createProduct();
Pool pool3 = TestUtil.createPool(owner, prod3, 5);
pool3.setId("pool3");
key2.addPool(pool3, 5L);
Consumer consumer = new Consumer("sys.example.com", null, null, system);
when(entitler.bindByPoolQuantity(eq(consumer), eq(pool1.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
when(entitler.bindByPoolQuantity(eq(consumer), eq(pool2.getId()), eq(10))).thenThrow(new ForbiddenException("fail"));
consumerBindUtil.handleActivationKeys(consumer, keys, false);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ConsumerBindUtilTest method registerWithKeyWithPoolAndInstalledProductsAutoAttach.
@Test
public void registerWithKeyWithPoolAndInstalledProductsAutoAttach() throws Exception {
Product prod = TestUtil.createProduct();
String[] prodIds = new String[] { prod.getId() };
Pool pool = TestUtil.createPool(owner, prod);
pool.setId("id-string");
List<String> poolIds = new ArrayList<>();
poolIds.add(pool.getId());
List<ActivationKey> keys = new ArrayList<>();
ActivationKey key1 = new ActivationKey("key1", owner);
keys.add(key1);
key1.addPool(pool, 0L);
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).withPools(poolIds).forProducts(prodIds);
consumerBindUtil.handleActivationKeys(consumer, keys, false);
verify(entitler).bindByProducts(eq(ad));
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyContentOverrideResourceTest method setUp.
@Before
public void setUp() throws URISyntaxException {
key = new ActivationKey("actkey", owner);
key.setId("keyid");
MultivaluedMap<String, String> mvm = new MultivaluedMapImpl<>();
mvm.add("activation_key_id", key.getId());
when(context.getPathParameters()).thenReturn(mvm);
akcor = new ActivationKeyContentOverrideResource(activationKeyContentOverrideCurator, akc, contentOverrideValidator, i18n);
when(akc.verifyAndLookupKey(eq(key.getId()))).thenReturn(key);
when(principal.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(true);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class TestUtil method createActivationKey.
public static ActivationKey createActivationKey(Owner owner, List<Pool> pools) {
ActivationKey key = new ActivationKey();
key.setOwner(owner);
key.setName("A Test Key");
key.setServiceLevel("TestLevel");
key.setDescription("A test description for the test key.");
if (pools != null) {
Set<ActivationKeyPool> akPools = new HashSet<>();
for (Pool p : pools) {
akPools.add(new ActivationKeyPool(key, p, (long) 1));
}
key.setPools(akPools);
}
return key;
}
Aggregations