Search in sources :

Example 51 with BadRequestException

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");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) BatchLabelInput(com.google.gerrit.extensions.common.BatchLabelInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 52 with BadRequestException

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);
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 53 with BadRequestException

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");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 54 with BadRequestException

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");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 55 with BadRequestException

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);
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)310 Test (org.junit.Test)154 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)146 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)56 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)51 AuthException (com.google.gerrit.extensions.restapi.AuthException)46 Repository (org.eclipse.jgit.lib.Repository)30 IdString (com.google.gerrit.extensions.restapi.IdString)29 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)29 LabelDefinitionInput (com.google.gerrit.extensions.common.LabelDefinitionInput)28 ArrayList (java.util.ArrayList)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)27 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)27 IOException (java.io.IOException)25 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)22 ObjectId (org.eclipse.jgit.lib.ObjectId)20 Map (java.util.Map)19 Change (com.google.gerrit.entities.Change)18