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");
}
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()));
}
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");
}
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()));
}
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.");
}
Aggregations