Search in sources :

Example 11 with ActivationKeyContentOverride

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

the class ActivationKeyContentOverrideCuratorTest method testCreateOverride.

@Test
public void testCreateOverride() {
    ActivationKeyContentOverride override = new ActivationKeyContentOverride(key, "test-repo", "gpgcheck", "1");
    assertEquals(override, this.activationKeyContentOverrideCurator.create(override));
}
Also used : ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Example 12 with ActivationKeyContentOverride

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

the class ActivationKeyContentOverrideResourceTest method testActivationKeyGetOverrides.

@Test
public void testActivationKeyGetOverrides() {
    List<ActivationKeyContentOverride> overrides = new LinkedList<>();
    ActivationKeyContentOverride override = new ActivationKeyContentOverride(key, "label", "name", "value");
    overrides.add(override);
    when(activationKeyContentOverrideCurator.getList(eq(key))).thenReturn(overrides);
    List<ActivationKeyContentOverride> res = akcor.getContentOverrideList(context, principal);
    assertEquals(overrides, res);
}
Also used : LinkedList(java.util.LinkedList) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Example 13 with ActivationKeyContentOverride

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

Example 14 with ActivationKeyContentOverride

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

the class ActivationKeyContentOverrideCuratorTest method testAddOrUpdateUpdatesValue.

@Test
public void testAddOrUpdateUpdatesValue() {
    ActivationKeyContentOverride cco1 = new ActivationKeyContentOverride(key, "test-content1", "name1", "value");
    activationKeyContentOverrideCurator.create(cco1);
    ActivationKeyContentOverride cco2 = new ActivationKeyContentOverride(key, "test-content1", "name1", "value2");
    activationKeyContentOverrideCurator.addOrUpdate(key, cco2);
    List<ActivationKeyContentOverride> ccoList = activationKeyContentOverrideCurator.listAll().list();
    assertEquals(1, ccoList.size());
    assertEquals("value2", ccoList.get(0).getValue());
}
Also used : ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Example 15 with ActivationKeyContentOverride

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

the class ActivationKeyContentOverrideCuratorTest method normalCreateAndUpdate.

@Test
public void normalCreateAndUpdate() {
    ActivationKeyContentOverride cco = new ActivationKeyContentOverride(key, "test-content", "name", "value");
    activationKeyContentOverrideCurator.create(cco);
    cco.setValue("value-update");
    activationKeyContentOverrideCurator.merge(cco);
    ActivationKeyContentOverride cco2 = activationKeyContentOverrideCurator.retrieve(key, "test-content", "name");
    assert (cco2 != null);
    assertEquals("value-update", cco2.getValue());
}
Also used : ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Aggregations

ActivationKeyContentOverride (org.candlepin.model.activationkeys.ActivationKeyContentOverride)26 Test (org.junit.Test)22 LinkedList (java.util.LinkedList)4 ContentOverride (org.candlepin.model.ContentOverride)3 Product (org.candlepin.model.Product)3 Release (org.candlepin.model.Release)3 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)2 ActivationKeyDTO (org.candlepin.dto.api.v1.ActivationKeyDTO)1 ConsumerContentOverride (org.candlepin.model.ConsumerContentOverride)1 Owner (org.candlepin.model.Owner)1 Pool (org.candlepin.model.Pool)1 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)1