Search in sources :

Example 41 with ActivationKey

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);
}
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 42 with ActivationKey

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);
}
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 43 with ActivationKey

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));
}
Also used : ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 44 with ActivationKey

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);
}
Also used : SubResource(org.candlepin.auth.SubResource) Access(org.candlepin.auth.Access) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Before(org.junit.Before)

Example 45 with ActivationKey

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;
}
Also used : ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) HashSet(java.util.HashSet)

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