Search in sources :

Example 6 with ActivationKey

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

Example 7 with ActivationKey

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

the class ConsumerBindUtilTest method mockActivationKeys.

private List<ActivationKey> mockActivationKeys() {
    ActivationKey key1 = new ActivationKey("key1", owner);
    ActivationKey key2 = new ActivationKey("key2", owner);
    ActivationKey key3 = new ActivationKey("key3", owner);
    List<ActivationKey> keys = new LinkedList<>();
    keys.add(key1);
    keys.add(key2);
    keys.add(key3);
    return keys;
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey) LinkedList(java.util.LinkedList)

Example 8 with ActivationKey

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

the class EventSinkImplTest method emptyKeyShouldEmitSuccessfully.

@Test
public void emptyKeyShouldEmitSuccessfully() throws Exception {
    ActivationKey key = TestUtil.createActivationKey(new Owner("deadbeef"), null);
    eventSinkImpl.emitActivationKeyCreated(key);
    eventSinkImpl.sendEvents();
    verify(mockClientProducer).send(any(ClientMessage.class));
}
Also used : Owner(org.candlepin.model.Owner) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 9 with ActivationKey

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

the class PoolManagerFunctionalTest method testListAllForActKeyExcludesErrors.

@Test
public void testListAllForActKeyExcludesErrors() {
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    ActivationKey ak = new ActivationKey();
    Pool akpool = new Pool();
    akpool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "true");
    ak.addPool(akpool, 1L);
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(4, results.getPageData().size());
    // Creating a pool with no entitlements available, which does not trigger
    // a rules error:
    Pool pool = createPool(o, p, 0L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    // Pool in error should not be included. Should have the same number of
    // initial pools.
    assertEquals(5, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 10 with ActivationKey

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

the class PoolCuratorTest method testActivationKeyList.

@Test
public void testActivationKeyList() {
    Date activeOn = TestUtil.createDate(2011, 2, 2);
    Pool pool = TestUtil.createPool(owner, product);
    pool.setEndDate(activeOn);
    poolCurator.create(pool);
    List<Pool> pools = new ArrayList<>();
    pools.add(pool);
    assertEquals(0, poolCurator.getActivationKeysForPool(pool).size());
    ActivationKey ak = TestUtil.createActivationKey(owner, pools);
    activationKeyCurator.create(ak);
    // test the pool and its inverse
    assertEquals(1, ak.getPools().size());
    assertEquals(1, poolCurator.getActivationKeysForPool(pool).size());
}
Also used : ArrayList(java.util.ArrayList) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Date(java.util.Date) 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