Search in sources :

Example 41 with LabelDefinitionInput

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

the class SetLabelIT method setCopyValues.

@Test
public void setCopyValues() throws Exception {
    configLabel("foo", LabelFunction.NO_OP);
    assertThat(gApi.projects().name(project.get()).label("foo").get().copyValues).isNull();
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.copyValues = ImmutableList.of((short) -1, (short) 1);
    LabelDefinitionInfo updatedLabel = gApi.projects().name(project.get()).label("foo").update(input);
    assertThat(updatedLabel.copyValues).containsExactly((short) -1, (short) 1).inOrder();
    assertThat(gApi.projects().name(project.get()).label("foo").get().copyValues).containsExactly((short) -1, (short) 1).inOrder();
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 42 with LabelDefinitionInput

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

the class SetLabelIT method updateValues.

@Test
public void updateValues() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    // Positive values can be specified as '<value>' or '+<value>'.
    input.values = ImmutableMap.of("2", "Looks Very Good", "+1", "Looks Good", "0", "Don't Know", "-1", "Looks Bad", "-2", "Looks Very Bad");
    LabelDefinitionInfo updatedLabel = gApi.projects().name(allProjects.get()).label(LabelId.CODE_REVIEW).update(input);
    assertThat(updatedLabel.values).containsExactly("+2", "Looks Very Good", "+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad", "-2", "Looks Very Bad");
    assertThat(gApi.projects().name(allProjects.get()).label(LabelId.CODE_REVIEW).get().values).containsExactly("+2", "Looks Very Good", "+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad", "-2", "Looks Very Bad");
}
Also used : LabelDefinitionInfo(com.google.gerrit.extensions.common.LabelDefinitionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 43 with LabelDefinitionInput

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

the class SetLabelIT method anonymous.

@Test
public void anonymous() throws Exception {
    requestScopeOperations.setApiUserAnonymous();
    AuthException thrown = assertThrows(AuthException.class, () -> gApi.projects().name(allProjects.get()).label(LabelId.CODE_REVIEW).update(new LabelDefinitionInput()));
    assertThat(thrown).hasMessageThat().contains("Authentication required");
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 44 with LabelDefinitionInput

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

the class CreateLabelIT method commitMessageIsTrimmed.

@Test
public void commitMessageIsTrimmed() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    input.commitMessage = " Add Foo Label ";
    gApi.projects().name(project.get()).label("Foo").create(input);
    assertThat(projectOperations.project(project).getHead(RefNames.REFS_CONFIG).getShortMessage()).isEqualTo("Add Foo Label");
}
Also used : LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 45 with LabelDefinitionInput

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

the class CreateLabelIT method withCommitMessage.

@Test
public void withCommitMessage() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    input.commitMessage = "Add Foo Label";
    gApi.projects().name(project.get()).label("Foo").create(input);
    assertThat(projectOperations.project(project).getHead(RefNames.REFS_CONFIG).getShortMessage()).isEqualTo(input.commitMessage);
}
Also used : LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) 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