Search in sources :

Example 86 with LabelDefinitionInput

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

the class CreateLabelIT method createWithFunction.

@Test
public void createWithFunction() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    input.function = LabelFunction.NO_OP.getFunctionName();
    LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("Foo").create(input).get();
    assertThat(createdLabel.function).isEqualTo(LabelFunction.NO_OP.getFunctionName());
}
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 87 with LabelDefinitionInput

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

the class CreateLabelIT method createWithCopyAllScoresOnTrivialRebase.

@Test
public void createWithCopyAllScoresOnTrivialRebase() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    input.copyAllScoresOnTrivialRebase = true;
    LabelDefinitionInfo createdLabel = gApi.projects().name(project.get()).label("foo").create(input).get();
    assertThat(createdLabel.copyAllScoresOnTrivialRebase).isTrue();
}
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 88 with LabelDefinitionInput

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

the class CreateLabelIT method anonymous.

@Test
public void anonymous() throws Exception {
    requestScopeOperations.setApiUserAnonymous();
    AuthException thrown = assertThrows(AuthException.class, () -> gApi.projects().name(project.get()).label("Foo-Review").create(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 89 with LabelDefinitionInput

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

the class CreateLabelIT method createCopyConditionPerformsGroupVisibilityCheckWhenUserInPredicateIsUsed.

@Test
public void createCopyConditionPerformsGroupVisibilityCheckWhenUserInPredicateIsUsed() throws Exception {
    String administratorsUUID = gApi.groups().query("name:Administrators").get().get(0).id;
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    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").create(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").create(input).get();
    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)

Example 90 with LabelDefinitionInput

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

the class CreateLabelIT method defaultCommitMessage.

@Test
public void defaultCommitMessage() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", " 0", "Don't Know", "-1", "Looks Bad");
    gApi.projects().name(project.get()).label("Foo").create(input);
    assertThat(projectOperations.project(project).getHead(RefNames.REFS_CONFIG).getShortMessage()).isEqualTo("Update label");
}
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