Search in sources :

Example 16 with BatchLabelInput

use of com.google.gerrit.extensions.common.BatchLabelInput in project gerrit by GerritCodeReview.

the class PostLabelsIT method updateLabels.

@Test
public void updateLabels() throws Exception {
    configLabel("Foo", LabelFunction.NO_OP);
    configLabel("Bar", LabelFunction.NO_OP);
    LabelDefinitionInput fooUpdate = new LabelDefinitionInput();
    fooUpdate.function = LabelFunction.MAX_WITH_BLOCK.getFunctionName();
    LabelDefinitionInput barUpdate = new LabelDefinitionInput();
    barUpdate.name = "Baz";
    BatchLabelInput input = new BatchLabelInput();
    input.update = ImmutableMap.of("Foo", fooUpdate, "Bar", barUpdate);
    gApi.projects().name(project.get()).labels(input);
    assertThat(gApi.projects().name(project.get()).label("Foo").get().function).isEqualTo(fooUpdate.function);
    assertThat(gApi.projects().name(project.get()).label("Baz").get()).isNotNull();
    assertThrows(ResourceNotFoundException.class, () -> gApi.projects().name(project.get()).label("Bar").get());
}
Also used : 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 17 with BatchLabelInput

use of com.google.gerrit.extensions.common.BatchLabelInput in project gerrit by GerritCodeReview.

the class PostLabelsIT method cannotCreateTwoLabelsWithTheSameName.

@Test
public void cannotCreateTwoLabelsWithTheSameName() throws Exception {
    LabelDefinitionInput fooInput = new LabelDefinitionInput();
    fooInput.name = "Foo";
    fooInput.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    BatchLabelInput input = new BatchLabelInput();
    input.create = ImmutableList.of(fooInput, fooInput);
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.projects().name(project.get()).labels(input));
    assertThat(thrown).hasMessageThat().contains("label Foo already exists");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) 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 18 with BatchLabelInput

use of com.google.gerrit.extensions.common.BatchLabelInput in project gerrit by GerritCodeReview.

the class PostLabelsIT method defaultCommitMessage.

@Test
public void defaultCommitMessage() throws Exception {
    BatchLabelInput input = new BatchLabelInput();
    input.delete = ImmutableList.of(LabelId.CODE_REVIEW);
    gApi.projects().name(allProjects.get()).labels(input);
    assertThat(projectOperations.project(allProjects).getHead(RefNames.REFS_CONFIG).getShortMessage()).isEqualTo("Update labels");
}
Also used : BatchLabelInput(com.google.gerrit.extensions.common.BatchLabelInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 19 with BatchLabelInput

use of com.google.gerrit.extensions.common.BatchLabelInput in project gerrit by GerritCodeReview.

the class PostLabelsIT method withCommitMessage.

@Test
public void withCommitMessage() throws Exception {
    BatchLabelInput input = new BatchLabelInput();
    input.commitMessage = "Batch Update Labels";
    input.delete = ImmutableList.of(LabelId.CODE_REVIEW);
    gApi.projects().name(allProjects.get()).labels(input);
    assertThat(projectOperations.project(allProjects).getHead(RefNames.REFS_CONFIG).getShortMessage()).isEqualTo(input.commitMessage);
}
Also used : BatchLabelInput(com.google.gerrit.extensions.common.BatchLabelInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 20 with BatchLabelInput

use of com.google.gerrit.extensions.common.BatchLabelInput in project gerrit by GerritCodeReview.

the class PostLabelsIT method updateNonExistingLabel.

@Test
public void updateNonExistingLabel() throws Exception {
    BatchLabelInput input = new BatchLabelInput();
    input.update = ImmutableMap.of("Foo", new LabelDefinitionInput());
    UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.projects().name(allProjects.get()).labels(input));
    assertThat(thrown).hasMessageThat().contains("label Foo not found");
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) BatchLabelInput(com.google.gerrit.extensions.common.BatchLabelInput) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BatchLabelInput (com.google.gerrit.extensions.common.BatchLabelInput)27 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)26 Test (org.junit.Test)26 LabelDefinitionInput (com.google.gerrit.extensions.common.LabelDefinitionInput)17 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 LabelDefinitionInfo (com.google.gerrit.extensions.common.LabelDefinitionInfo)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 LabelType (com.google.gerrit.entities.LabelType)1 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)1 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)1 Map (java.util.Map)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1