Search in sources :

Example 6 with ActivationKeyCurator

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

the class OwnerResourceTest method testActivationKeyNameUnique.

@Test(expected = BadRequestException.class)
public void testActivationKeyNameUnique() {
    ActivationKeyDTO ak = mock(ActivationKeyDTO.class);
    ActivationKey akOld = mock(ActivationKey.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Owner o = mock(Owner.class);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    when(ak.getName()).thenReturn("testKey");
    when(akc.lookupForOwner(eq("testKey"), eq(o))).thenReturn(akOld);
    when(oc.lookupByKey(eq("testOwner"))).thenReturn(o);
    OwnerResource ownerres = new OwnerResource(oc, pc, akc, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, contentOverrideValidator, null, null, null, null, null, null, this.modelTranslator);
    ownerres.createActivationKey("testOwner", ak);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ProductCurator(org.candlepin.model.ProductCurator) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 7 with ActivationKeyCurator

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

the class ConsumerResourceTest method testCreatePersonConsumerWithActivationKey.

@Test(expected = BadRequestException.class)
public void testCreatePersonConsumerWithActivationKey() {
    ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.PERSON));
    ConsumerTypeDTO ctypeDto = this.translator.translate(ctype, ConsumerTypeDTO.class);
    Owner owner = this.createOwner();
    Consumer consumer = this.createConsumer(owner, ctype);
    ConsumerDTO consumerDto = this.translator.translate(consumer, ConsumerDTO.class);
    ActivationKey ak = mock(ActivationKey.class);
    NoAuthPrincipal nap = mock(NoAuthPrincipal.class);
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    ConsumerContentOverrideCurator ccoc = mock(ConsumerContentOverrideCurator.class);
    when(ak.getId()).thenReturn("testKey");
    when(akc.lookupForOwner(eq(owner.getKey()), eq(owner))).thenReturn(ak);
    ConsumerResource cr = new ConsumerResource(null, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, akc, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
    cr.create(consumerDto, nap, null, owner.getKey(), "testKey", true);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerContentOverrideCurator(org.candlepin.model.ConsumerContentOverrideCurator) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) Test(org.junit.Test)

Example 8 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithDiffHostReqPools.

@Test
public void testActivationKeyWithDiffHostReqPools() {
    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, "host2");
    ak.addPool(p2, 1L);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool1"))).thenReturn(p1);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool1", 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 9 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithNegPoolQuantity.

@Test(expected = BadRequestException.class)
public void testActivationKeyWithNegPoolQuantity() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    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", -3L);
}
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 10 with ActivationKeyCurator

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

the class ActivationKeyResourceTest method testActivationKeyWithNonPersonConsumerType.

@Test
public void testActivationKeyWithNonPersonConsumerType() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    p.getProduct().setAttribute(Pool.Attributes.REQUIRES_CONSUMER_TYPE, "candlepin");
    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);
    assertNotNull(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)

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