Search in sources :

Example 26 with AttentionSetInput

use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.

the class AttentionSetIT method reviewersAreNotAddedForNoReasonBecauseOfAnUpdate.

@Test
public void reviewersAreNotAddedForNoReasonBecauseOfAnUpdate() throws Exception {
    PushOneCommit.Result r = createChange();
    // implictly adds the user to the attention set when adding as reviewer
    change(r).addReviewer(user.email());
    change(r).attention(user.id().toString()).remove(new AttentionSetInput("removed"));
    HashtagsInput hashtagsInput = new HashtagsInput();
    hashtagsInput.add = ImmutableSet.of("tag");
    change(r).setHashtags(hashtagsInput);
    AttentionSetUpdate attentionSet = Iterables.getOnlyElement(r.getChange().attentionSet());
    assertThat(attentionSet).hasAccountIdThat().isEqualTo(user.id());
    assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.REMOVE);
    assertThat(attentionSet).hasReasonThat().isEqualTo("removed");
}
Also used : HashtagsInput(com.google.gerrit.extensions.api.changes.HashtagsInput) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with AttentionSetInput

use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.

the class AttentionSetIT method addUserWithTemplateReason.

@Test
public void addUserWithTemplateReason() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    String manualReason = "Added by " + AccountTemplateUtil.getAccountTemplate(user.id());
    int accountId = change(r).addToAttentionSet(new AttentionSetInput(admin.email(), manualReason))._accountId;
    assertThat(accountId).isEqualTo(admin.id().get());
    AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), admin.id(), AttentionSetUpdate.Operation.ADD, manualReason);
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    AttentionSetInfo attentionSetInfo = Iterables.getOnlyElement(change(r).get().attentionSet.values());
    assertThat(attentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(attentionSetInfo.reasonAccount).isEqualTo(getAccountInfo(user.id()));
    assertThat(attentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
    AttentionSetInfo getAttentionSetInfo = Iterables.getOnlyElement(getAttentionSet.apply(parseChangeResource(r.getChangeId())).value());
    assertThat(getAttentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(getAttentionSetInfo.reasonAccount).isEqualTo(getAccountInfo(user.id()));
    assertThat(getAttentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with AttentionSetInput

use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.

the class AttentionSetIT method repliesWhileAddingAsReviewerStillRemovesUser.

@Test
public void repliesWhileAddingAsReviewerStillRemovesUser() throws Exception {
    PushOneCommit.Result r = createChange();
    // implictly adds the user to the attention set when adding as reviewer
    change(r).addReviewer(user.email());
    change(r).addToAttentionSet(new AttentionSetInput(user.email(), "remove"));
    requestScopeOperations.setApiUser(user.id());
    ReviewInput reviewInput = ReviewInput.recommend();
    change(r).current().review(reviewInput);
    // reviewer removed
    AttentionSetUpdate attentionSet = Iterables.getOnlyElement(getAttentionSetUpdatesForUser(r, user));
    assertThat(attentionSet).hasAccountIdThat().isEqualTo(user.id());
    assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.REMOVE);
    assertThat(attentionSet).hasReasonThat().isEqualTo("removed on reply");
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 29 with AttentionSetInput

use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.

the class AttentionSetIT method addUserWithTemplateReasonMultipleAccounts.

@Test
public void addUserWithTemplateReasonMultipleAccounts() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    String manualReason = String.format("Added by %s with user %s", AccountTemplateUtil.getAccountTemplate(user.id()), AccountTemplateUtil.getAccountTemplate(admin.id()));
    int accountId = change(r).addToAttentionSet(new AttentionSetInput(admin.email(), manualReason))._accountId;
    assertThat(accountId).isEqualTo(admin.id().get());
    AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), admin.id(), AttentionSetUpdate.Operation.ADD, manualReason);
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    AttentionSetInfo attentionSetInfo = Iterables.getOnlyElement(change(r).get().attentionSet.values());
    assertThat(attentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(attentionSetInfo.reasonAccount).isNull();
    assertThat(attentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
    AttentionSetInfo getAttentionSetInfo = Iterables.getOnlyElement(getAttentionSet.apply(parseChangeResource(r.getChangeId())).value());
    assertThat(getAttentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(getAttentionSetInfo.reasonAccount).isNull();
    assertThat(getAttentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 30 with AttentionSetInput

use of com.google.gerrit.extensions.api.changes.AttentionSetInput in project gerrit by GerritCodeReview.

the class AttentionSetIT method removeUserWithInvalidUserInput.

@Test
public void removeUserWithInvalidUserInput() throws Exception {
    PushOneCommit.Result r = createChange();
    // implictly adds the user to the attention set when adding as reviewer
    change(r).addReviewer(user.email());
    BadRequestException exception = assertThrows(BadRequestException.class, () -> change(r).attention(user.id().toString()).remove(new AttentionSetInput("invalid user", "reason")));
    assertThat(exception.getMessage()).isEqualTo("invalid user doesn't exist or is not active on the change as an owner, " + "uploader, reviewer, or cc so they can't be added to the attention set");
    exception = assertThrows(BadRequestException.class, () -> change(r).attention(user.id().toString()).remove(new AttentionSetInput(admin.email(), "reason")));
    assertThat(exception.getMessage()).isEqualTo("The field \"user\" must be empty, or must match the user specified in the URL.");
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AttentionSetInput (com.google.gerrit.extensions.api.changes.AttentionSetInput)34 Test (org.junit.Test)34 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)32 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)31 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)21 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)7 TestAccount (com.google.gerrit.acceptance.TestAccount)5 Change (com.google.gerrit.entities.Change)3 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)3 AttentionSetInfo (com.google.gerrit.extensions.common.AttentionSetInfo)3 Account (com.google.gerrit.entities.Account)2 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)2 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)2 Result (com.google.gerrit.acceptance.PushOneCommit.Result)1 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 HashtagsInput (com.google.gerrit.extensions.api.changes.HashtagsInput)1 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)1 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1