Search in sources :

Example 1 with ContentOverride

use of org.candlepin.model.ContentOverride in project candlepin by candlepin.

the class ContentOverrideValidatorTest method testValidateCollectionBothInvalid.

@Test
public void testValidateCollectionBothInvalid() {
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    List<ContentOverride> overrides = new LinkedList<>();
    overrides.add(new ContentOverride("label", "baseurl", "value"));
    overrides.add(new ContentOverride("other label", "name", "other value"));
    try {
        validator.validate(overrides);
        fail("Expected exception \"BadRequestException\" was not thrown.");
    } catch (BadRequestException bre) {
        assertTrue(bre.getMessage().matches("^Not allowed to override values for: (?:baseurl, name|name, baseurl)"));
    }
}
Also used : BadRequestException(org.candlepin.common.exceptions.BadRequestException) ContentOverride(org.candlepin.model.ContentOverride) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with ContentOverride

use of org.candlepin.model.ContentOverride in project candlepin by candlepin.

the class ContentOverrideResource method addContentOverrides.

/**
 * Adds a Content Override to a Principal
 *
 * @param info context to get the parent id
 * @param entries overrides to add or update
 *
 * @return a list of ContentOverride objects
 * @httpcode 404
 * @httpcode 200
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@SecurityHole
public List<T> addContentOverrides(@Context UriInfo info, @Context Principal principal, List<ContentOverride> entries) {
    String parentId = info.getPathParameters().getFirst(this.getParentPath());
    Parent parent = this.verifyAndGetParent(parentId, principal, Access.ALL);
    contentOverrideValidator.validate(entries);
    for (ContentOverride entry : entries) {
        contentOverrideCurator.addOrUpdate(parent, entry);
    }
    return contentOverrideCurator.getList(parent);
}
Also used : ContentOverride(org.candlepin.model.ContentOverride) SecurityHole(org.candlepin.common.auth.SecurityHole) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) Transactional(com.google.inject.persist.Transactional)

Example 3 with ContentOverride

use of org.candlepin.model.ContentOverride in project candlepin by candlepin.

the class ContentOverrideResource method deleteContentOverrides.

/**
 * Removes a Content Override from a Principal
 *
 * @param info context to get the parent id
 * @param entries overrides to remove to remove
 *
 * @return a list of ContentOverride objects
 * @httpcode 404
 * @httpcode 200
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Transactional
@SecurityHole
public List<T> deleteContentOverrides(@Context UriInfo info, @Context Principal principal, List<ContentOverride> entries) {
    String parentId = info.getPathParameters().getFirst(this.getParentPath());
    Parent parent = this.verifyAndGetParent(parentId, principal, Access.ALL);
    if (entries.size() == 0) {
        contentOverrideCurator.removeByParent(parent);
    } else {
        for (ContentOverride entry : entries) {
            String label = entry.getContentLabel();
            if (StringUtils.isBlank(label)) {
                contentOverrideCurator.removeByParent(parent);
            } else {
                String name = entry.getName();
                if (StringUtils.isBlank(name)) {
                    contentOverrideCurator.removeByContentLabel(parent, entry.getContentLabel());
                } else {
                    contentOverrideCurator.removeByName(parent, entry.getContentLabel(), name);
                }
            }
        }
    }
    return contentOverrideCurator.getList(parent);
}
Also used : ContentOverride(org.candlepin.model.ContentOverride) DELETE(javax.ws.rs.DELETE) SecurityHole(org.candlepin.common.auth.SecurityHole) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Transactional(com.google.inject.persist.Transactional)

Example 4 with ContentOverride

use of org.candlepin.model.ContentOverride in project candlepin by candlepin.

the class ActivationKeyContentOverrideResourceTest method testActivationKeyAddOverrides.

@Test
public void testActivationKeyAddOverrides() {
    ActivationKeyContentOverride override = new ActivationKeyContentOverride(key, "somelabel", "test", "test");
    ActivationKeyContentOverride otherOverride = new ActivationKeyContentOverride(key, "somelabel1", "test", "test");
    List<ContentOverride> toAdd = new LinkedList<>();
    toAdd.add(override);
    toAdd.add(otherOverride);
    akcor.addContentOverrides(context, principal, toAdd);
    verify(activationKeyContentOverrideCurator, Mockito.times(1)).addOrUpdate(eq(key), eq(override));
    verify(activationKeyContentOverrideCurator, Mockito.times(1)).addOrUpdate(eq(key), eq(otherOverride));
}
Also used : ContentOverride(org.candlepin.model.ContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) LinkedList(java.util.LinkedList) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Example 5 with ContentOverride

use of org.candlepin.model.ContentOverride in project candlepin by candlepin.

the class ActivationKeyContentOverrideResourceTest method testActivationKeyOverrideValidationIsRun.

@Test
public void testActivationKeyOverrideValidationIsRun() {
    List<ContentOverride> newOverrides = new LinkedList<>();
    newOverrides.add(new ActivationKeyContentOverride(key, "x", "baseurl", "x"));
    akcor.addContentOverrides(context, principal, newOverrides);
    verify(contentOverrideValidator, Mockito.times(1)).validate(eq(newOverrides));
}
Also used : ContentOverride(org.candlepin.model.ContentOverride) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) LinkedList(java.util.LinkedList) ActivationKeyContentOverride(org.candlepin.model.activationkeys.ActivationKeyContentOverride) Test(org.junit.Test)

Aggregations

ContentOverride (org.candlepin.model.ContentOverride)8 LinkedList (java.util.LinkedList)6 Test (org.junit.Test)6 ActivationKeyContentOverride (org.candlepin.model.activationkeys.ActivationKeyContentOverride)3 Transactional (com.google.inject.persist.Transactional)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 SecurityHole (org.candlepin.common.auth.SecurityHole)2 DELETE (javax.ws.rs.DELETE)1 PUT (javax.ws.rs.PUT)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 ConsumerContentOverride (org.candlepin.model.ConsumerContentOverride)1