Search in sources :

Example 1 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithPersonConsumerType.

@Test(expected = BadRequestException.class)
public void testActivationKeyWithPersonConsumerType() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.getProduct().setAttribute(Pool.Attributes.REQUIRES_CONSUMER_TYPE, "person");
    p.setQuantity(1L);
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool", 1L);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 2 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithNonMultiPool.

@Test(expected = BadRequestException.class)
public void testActivationKeyWithNonMultiPool() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "no");
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool", 2L);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 3 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithSameHostReqPools.

@Test
public void testActivationKeyWithSameHostReqPools() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    PoolManager poolManager = mock(PoolManager.class);
    Pool p1 = genPool();
    p1.setAttribute(Pool.Attributes.REQUIRES_HOST, "host1");
    Pool p2 = genPool();
    p2.setAttribute(Pool.Attributes.REQUIRES_HOST, "host1");
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool1"))).thenReturn(p1);
    when(poolManager.find(eq("testPool2"))).thenReturn(p2);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool1", 1L);
    assertEquals(1, ak.getPools().size());
    Set<ActivationKeyPool> akPools = new HashSet<>();
    akPools.add(new ActivationKeyPool(ak, p1, 1L));
    ak.setPools(akPools);
    akr.addPoolToKey("testKey", "testPool2", 1L);
    assertEquals(2, ak.getPools().size());
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyHostReqPoolThenNonHostReq.

@Test
public void testActivationKeyHostReqPoolThenNonHostReq() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    PoolManager poolManager = mock(PoolManager.class);
    Pool p1 = genPool();
    p1.setAttribute(Pool.Attributes.REQUIRES_HOST, "host1");
    Pool p2 = genPool();
    p2.setAttribute(Pool.Attributes.REQUIRES_HOST, "");
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool1"))).thenReturn(p1);
    when(poolManager.find(eq("testPool2"))).thenReturn(p2);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool1", 1L);
    assertEquals(1, ak.getPools().size());
    ak.addPool(p1, 1L);
    akr.addPoolToKey("testKey", "testPool2", 1L);
    assertEquals(3, ak.getPools().size());
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 5 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithLargePoolQuantity.

@Test
public void testActivationKeyWithLargePoolQuantity() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    p.setQuantity(10L);
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool", 15L);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Aggregations

ActivationKey (org.candlepin.model.activationkeys.ActivationKey)12 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)12 Test (org.junit.Test)12 PoolManager (org.candlepin.controller.PoolManager)10 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)10 Pool (org.candlepin.model.Pool)10 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)10 Owner (org.candlepin.model.Owner)2 HashSet (java.util.HashSet)1 NoAuthPrincipal (org.candlepin.auth.NoAuthPrincipal)1 ActivationKeyDTO (org.candlepin.dto.api.v1.ActivationKeyDTO)1 ConsumerDTO (org.candlepin.dto.api.v1.ConsumerDTO)1 ConsumerTypeDTO (org.candlepin.dto.api.v1.ConsumerTypeDTO)1 Consumer (org.candlepin.model.Consumer)1 ConsumerContentOverrideCurator (org.candlepin.model.ConsumerContentOverrideCurator)1 ConsumerType (org.candlepin.model.ConsumerType)1 OwnerCurator (org.candlepin.model.OwnerCurator)1 ProductCurator (org.candlepin.model.ProductCurator)1