Search in sources :

Example 1 with ActivationKeyDTO

use of org.candlepin.dto.api.v1.ActivationKeyDTO in project candlepin by candlepin.

the class OwnerResourceTest method testActivationKeyRequiresName.

@Test(expected = BadRequestException.class)
public void testActivationKeyRequiresName() {
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    Owner o = new Owner();
    o.setKey("owner-key");
    OwnerResource ownerres = new OwnerResource(oc, pc, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    when(oc.lookupByKey(anyString())).thenReturn(o);
    ActivationKeyDTO key = new ActivationKeyDTO();
    key = ownerres.createActivationKey(owner.getKey(), key);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) Owner(org.candlepin.model.Owner) ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) ProductCurator(org.candlepin.model.ProductCurator) Test(org.junit.Test)

Example 2 with ActivationKeyDTO

use of org.candlepin.dto.api.v1.ActivationKeyDTO 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 3 with ActivationKeyDTO

use of org.candlepin.dto.api.v1.ActivationKeyDTO 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 4 with ActivationKeyDTO

use of org.candlepin.dto.api.v1.ActivationKeyDTO in project candlepin by candlepin.

the class OwnerResourceTest method testSearchActivationsKeysByName.

@Test
public void testSearchActivationsKeysByName() {
    ActivationKeyDTO key = new ActivationKeyDTO();
    key.setName("dd");
    key.setReleaseVersion("release1");
    key = ownerResource.createActivationKey(owner.getKey(), key);
    assertNotNull(key.getId());
    assertEquals(key.getOwner().getId(), owner.getId());
    assertEquals(key.getReleaseVersion(), "release1");
    key = new ActivationKeyDTO();
    key.setName("blah");
    key.setReleaseVersion("release2");
    key = ownerResource.createActivationKey(owner.getKey(), key);
    assertNotNull(key.getId());
    assertEquals(key.getOwner().getId(), owner.getId());
    assertEquals(key.getReleaseVersion(), "release2");
    CandlepinQuery<ActivationKeyDTO> result = ownerResource.ownerActivationKeys(owner.getKey(), "dd");
    assertNotNull(result);
    List<ActivationKeyDTO> keys = result.list();
    assertEquals(1, keys.size());
    result = ownerResource.ownerActivationKeys(owner.getKey(), null);
    assertNotNull(result);
    keys = result.list();
    assertEquals(2, keys.size());
}
Also used : ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) Test(org.junit.Test)

Example 5 with ActivationKeyDTO

use of org.candlepin.dto.api.v1.ActivationKeyDTO in project candlepin by candlepin.

the class OwnerResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO. This method will not set the
 * ID field.
 *
 * @param entity
 *  The entity instance to populate
 *
 * @param dto
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
protected void populateEntity(ActivationKey entity, ActivationKeyDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the activation key model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the activation key dto is null");
    }
    if (dto.getName() != null) {
        entity.setName(dto.getName());
    }
    if (dto.getDescription() != null) {
        entity.setDescription(dto.getDescription());
    }
    if (dto.getServiceLevel() != null) {
        entity.setServiceLevel(dto.getServiceLevel());
    }
    if (dto.getOwner() != null) {
        entity.setOwner(lookupOwnerFromDto(dto.getOwner()));
    }
    if (dto.getServiceLevel() != null) {
        if (dto.getServiceLevel().isEmpty()) {
            entity.setServiceLevel(null);
        } else {
            entity.setServiceLevel(dto.getServiceLevel());
        }
    }
    if (dto.getContentOverrides() != null) {
        if (dto.getContentOverrides().isEmpty()) {
            entity.setContentOverrides(new HashSet<>());
        } else {
            for (ActivationKeyDTO.ActivationKeyContentOverrideDTO overrideDTO : dto.getContentOverrides()) {
                if (overrideDTO != null) {
                    entity.addContentOverride(new ActivationKeyContentOverride(entity, overrideDTO.getContentLabel(), overrideDTO.getName(), overrideDTO.getValue()));
                }
            }
        }
    }
    if (dto.getReleaseVersion() != null) {
        entity.setReleaseVer(new Release(dto.getReleaseVersion()));
    }
    if (dto.getPools() != null) {
        if (dto.getPools().isEmpty()) {
            entity.setPools(new HashSet<>());
        } else {
            for (ActivationKeyDTO.ActivationKeyPoolDTO poolDTO : dto.getPools()) {
                if (poolDTO != null) {
                    Pool pool = findPool(poolDTO.getPoolId());
                    entity.addPool(pool, poolDTO.getQuantity());
                }
            }
        }
    }
    if (dto.getProductIds() != null) {
        if (dto.getProductIds().isEmpty()) {
            entity.setProducts(new HashSet<>());
        } else {
            for (String productId : dto.getProductIds()) {
                if (productId != null) {
                    Product product = findProduct(entity.getOwner(), productId);
                    entity.addProduct(product);
                }
            }
        }
    }
}
Also used : ActivationKeyDTO(org.candlepin.dto.api.v1.ActivationKeyDTO) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Release(org.candlepin.model.Release) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride)

Aggregations

ActivationKeyDTO (org.candlepin.dto.api.v1.ActivationKeyDTO)8 Test (org.junit.Test)7 Owner (org.candlepin.model.Owner)3 OwnerCurator (org.candlepin.model.OwnerCurator)3 ProductCurator (org.candlepin.model.ProductCurator)3 Release (org.candlepin.model.Release)3 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)3 OwnerDTO (org.candlepin.dto.api.v1.OwnerDTO)1 Pool (org.candlepin.model.Pool)1 Product (org.candlepin.model.Product)1 ActivationKeyContentOverride (org.candlepin.model.activationkeys.ActivationKeyContentOverride)1 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)1