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)"));
}
}
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);
}
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);
}
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));
}
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));
}
Aggregations