use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class PostLabelsIT method cannotSetCommitMessageOnLabelDefinitionInputForCreate.
@Test
public void cannotSetCommitMessageOnLabelDefinitionInputForCreate() throws Exception {
LabelDefinitionInput labelInput = new LabelDefinitionInput();
labelInput.name = "Foo";
labelInput.commitMessage = "Create Label Foo";
BatchLabelInput input = new BatchLabelInput();
input.create = ImmutableList.of(labelInput);
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(allProjects.get()).labels(input));
assertThat(thrown).hasMessageThat().contains("commit message on label definition input not supported");
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class SetLabelIT method cannotSetUnknownFunction.
@Test
public void cannotSetUnknownFunction() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.function = "UnknownFunction";
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(allProjects.get()).label(LabelId.CODE_REVIEW).update(input));
assertThat(thrown).hasMessageThat().contains("unknown function: " + input.function);
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class SetLabelIT method setInvalidCopyCondition.
@Test
public void setInvalidCopyCondition() throws Exception {
configLabel("foo", LabelFunction.NO_OP);
assertThat(gApi.projects().name(project.get()).label("foo").get().copyCondition).isNull();
LabelDefinitionInput input = new LabelDefinitionInput();
input.copyCondition = "foo:::bar";
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(project.get()).label("foo").update(input));
assertThat(thrown).hasMessageThat().contains("unable to parse copy condition");
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class SetLabelIT method cannotSetValueWithEmptyDescription.
@Test
public void cannotSetValueWithEmptyDescription() throws Exception {
LabelDefinitionInput input = new LabelDefinitionInput();
input.values = ImmutableMap.of("+1", "");
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(allProjects.get()).label(LabelId.CODE_REVIEW).update(input));
assertThat(thrown).hasMessageThat().contains("description for value '+1' cannot be empty");
}
use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.
the class SetLabelIT method setCopyConditionPerformsGroupVisibilityCheckWhenUserInPredicateIsUsed.
@Test
public void setCopyConditionPerformsGroupVisibilityCheckWhenUserInPredicateIsUsed() throws Exception {
String administratorsUUID = gApi.groups().query("name:Administrators").get().get(0).id;
configLabel("foo", LabelFunction.NO_OP);
assertThat(gApi.projects().name(project.get()).label("foo").get().copyCondition).isNull();
LabelDefinitionInput input = new LabelDefinitionInput();
input.copyCondition = "uploaderin:" + administratorsUUID;
projectOperations.project(project).forUpdate().add(allow(Permission.OWNER).ref("refs/*").group(REGISTERED_USERS)).update();
// User can't see admin group
requestScopeOperations.setApiUser(user.id());
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(project.get()).label("foo").update(input));
assertThat(thrown).hasMessageThat().contains("Group " + administratorsUUID + " not found");
// Admin can see admin group
requestScopeOperations.setApiUser(admin.id());
LabelDefinitionInfo updatedLabel = gApi.projects().name(project.get()).label("foo").update(input);
assertThat(updatedLabel.copyCondition).isEqualTo(input.copyCondition);
}
Aggregations