Search in sources :

Example 11 with LabelDefinitionInput

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

the class PostLabelsIT method deleteAndRecreateLabel.

@Test
public void deleteAndRecreateLabel() throws Exception {
    configLabel("Foo", LabelFunction.NO_OP);
    LabelDefinitionInput fooInput = new LabelDefinitionInput();
    fooInput.name = "Foo";
    fooInput.function = LabelFunction.MAX_NO_BLOCK.getFunctionName();
    fooInput.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    BatchLabelInput input = new BatchLabelInput();
    input.delete = ImmutableList.of("Foo");
    input.create = ImmutableList.of(fooInput);
    gApi.projects().name(project.get()).labels(input);
    LabelDefinitionInfo fooLabel = gApi.projects().name(project.get()).label("Foo").get();
    assertThat(fooLabel.function).isEqualTo(fooInput.function);
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) 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 12 with LabelDefinitionInput

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

the class PostLabelsIT method cannotCreateLabelWithoutName.

@Test
public void cannotCreateLabelWithoutName() throws Exception {
    BatchLabelInput input = new BatchLabelInput();
    input.create = ImmutableList.of(new LabelDefinitionInput());
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(allProjects.get()).labels(input));
    assertThat(thrown).hasMessageThat().contains("label name is required for new label");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) BatchLabelInput(com.google.gerrit.extensions.common.BatchLabelInput) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 13 with LabelDefinitionInput

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

the class PostLabelsIT method createAndUpdateLabel.

@Test
public void createAndUpdateLabel() throws Exception {
    LabelDefinitionInput fooCreateInput = new LabelDefinitionInput();
    fooCreateInput.name = "Foo";
    fooCreateInput.function = LabelFunction.MAX_NO_BLOCK.getFunctionName();
    fooCreateInput.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    LabelDefinitionInput fooUpdateInput = new LabelDefinitionInput();
    fooUpdateInput.function = LabelFunction.ANY_WITH_BLOCK.getFunctionName();
    BatchLabelInput input = new BatchLabelInput();
    input.create = ImmutableList.of(fooCreateInput);
    input.update = ImmutableMap.of("Foo", fooUpdateInput);
    gApi.projects().name(project.get()).labels(input);
    LabelDefinitionInfo fooLabel = gApi.projects().name(project.get()).label("Foo").get();
    assertThat(fooLabel.function).isEqualTo(fooUpdateInput.function);
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) 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 14 with LabelDefinitionInput

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

the class PostLabelsIT method createLabels.

@Test
public void createLabels() throws Exception {
    LabelDefinitionInput fooInput = new LabelDefinitionInput();
    fooInput.name = "Foo";
    fooInput.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    LabelDefinitionInput barInput = new LabelDefinitionInput();
    barInput.name = "Bar";
    barInput.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    BatchLabelInput input = new BatchLabelInput();
    input.create = ImmutableList.of(fooInput, barInput);
    gApi.projects().name(allProjects.get()).labels(input);
    assertThat(gApi.projects().name(allProjects.get()).label("Foo").get()).isNotNull();
    assertThat(gApi.projects().name(allProjects.get()).label("Bar").get()).isNotNull();
}
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 15 with LabelDefinitionInput

use of com.google.gerrit.extensions.common.LabelDefinitionInput 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)

Aggregations

LabelDefinitionInput (com.google.gerrit.extensions.common.LabelDefinitionInput)132 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)129 Test (org.junit.Test)129 LabelDefinitionInfo (com.google.gerrit.extensions.common.LabelDefinitionInfo)79 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)28 BatchLabelInput (com.google.gerrit.extensions.common.BatchLabelInput)17 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)7 LabelType (com.google.gerrit.entities.LabelType)4 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)4 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 Map (java.util.Map)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1