Search in sources :

Example 21 with ActivationKey

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

the class ActivationKeyResourceTest method testReaddingProductIDs.

@Test(expected = BadRequestException.class)
public void testReaddingProductIDs() {
    ActivationKey key = new ActivationKey();
    Owner owner = createOwner();
    Product product = this.createProduct(owner);
    key.setOwner(owner);
    key.setName("dd");
    key = activationKeyCurator.create(key);
    assertNotNull(key.getId());
    activationKeyResource.addProductIdToKey(key.getId(), product.getId());
    assertEquals(1, key.getProducts().size());
    activationKeyResource.addProductIdToKey(key.getId(), product.getId());
// ^ Kaboom.
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 22 with ActivationKey

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

the class ActivationKeyResourceTest method testReaddingPools.

@Test(expected = BadRequestException.class)
public void testReaddingPools() {
    ActivationKey key = new ActivationKey();
    Product product = this.createProduct(owner);
    Pool pool = createPool(owner, product, 10L, new Date(), new Date());
    key.setOwner(owner);
    key.setName("dd");
    key = activationKeyCurator.create(key);
    assertNotNull(key.getId());
    activationKeyResource.addPoolToKey(key.getId(), pool.getId(), 1L);
    assertTrue(key.getPools().size() == 1);
    activationKeyResource.addPoolToKey(key.getId(), pool.getId(), 1L);
// ^ Kaboom.
}
Also used : Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Date(java.util.Date) Test(org.junit.Test)

Example 23 with ActivationKey

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

the class ActivationKeyResourceTest method testCreateReadDelete.

@Test(expected = BadRequestException.class)
public void testCreateReadDelete() {
    ActivationKey key = new ActivationKey();
    key.setOwner(owner);
    key.setName("dd");
    key.setServiceLevel("level1");
    key.setReleaseVer(new Release("release1"));
    activationKeyCurator.create(key);
    assertNotNull(key.getId());
    ActivationKeyDTO output = activationKeyResource.getActivationKey(key.getId());
    assertNotNull(output);
    output.setName("JarJarBinks");
    output.setServiceLevel("level2");
    output.setReleaseVersion("release2");
    activationKeyResource.updateActivationKey(key.getId(), output);
    output = activationKeyResource.getActivationKey(key.getId());
    assertEquals("JarJarBinks", output.getName());
    assertEquals("level2", output.getServiceLevel());
    assertEquals("release2", output.getReleaseVersion());
    activationKeyResource.deleteActivationKey(key.getId());
    output = activationKeyResource.getActivationKey(key.getId());
    assertNull(output);
}
Also used : ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Release(org.candlepin.model.Release) Test(org.junit.Test)

Example 24 with ActivationKey

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

Example 25 with ActivationKey

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

the class ConsumerResourceCreationTest method registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner.

@Test
public void registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner() {
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    ConsumerTypeDTO ctypeDTO = this.modelTranslator.translate(ctype, ConsumerTypeDTO.class);
    this.mockConsumerType(ctype);
    // Disable autobind for the owner.
    owner.setAutobindDisabled(true);
    // Create a key that has autobind disabled.
    ActivationKey key = new ActivationKey("autobind-disabled-key", owner);
    key.setAutoAttach(true);
    when(activationKeyCurator.lookupForOwner(key.getName(), owner)).thenReturn(key);
    // No auth should be required for registering with keys:
    Principal p = new NoAuthPrincipal();
    ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, ctypeDTO);
    resource.create(consumer, p, null, owner.getKey(), key.getName(), true);
}
Also used : NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ConsumerType(org.candlepin.model.ConsumerType) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) TrustedUserPrincipal(org.candlepin.auth.TrustedUserPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) NoAuthPrincipal(org.candlepin.auth.NoAuthPrincipal) 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