use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class QueryChangesIT method hasOperandAliasQuery.
@Test
@SuppressWarnings("unchecked")
@GerritConfig(name = "has-operand-alias.change.unaddressedaliastest", value = "unresolved")
public void hasOperandAliasQuery() throws Exception {
String cId1 = createChange().getChangeId();
String cId2 = createChange().getChangeId();
int numericId1 = gApi.changes().id(cId1).get()._number;
int numericId2 = gApi.changes().id(cId2).get()._number;
ReviewInput input = new ReviewInput();
ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
comment.line = 1;
comment.message = "comment";
comment.unresolved = true;
input.comments = ImmutableMap.of(Patch.COMMIT_MSG, ImmutableList.of(comment));
gApi.changes().id(cId2).current().review(input);
QueryChanges queryChanges = queryChangesProvider.get();
queryChanges.addQuery("is:open repo:" + project.get());
queryChanges.addQuery("has:unaddressedaliastest repo:" + project.get());
List<List<ChangeInfo>> result = (List<List<ChangeInfo>>) queryChanges.apply(TopLevelResource.INSTANCE).value();
assertThat(result).hasSize(2);
assertThat(result.get(0)).hasSize(2);
assertThat(result.get(1)).hasSize(1);
List<Integer> firstResultIds = ImmutableList.of(result.get(0).get(0)._number, result.get(0).get(1)._number);
assertThat(firstResultIds).containsExactly(numericId1, numericId2);
assertThat(result.get(1).get(0)._number).isEqualTo(numericId2);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class RevertIT method cantCreateRevertSubmissionWithoutReadPermission.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void cantCreateRevertSubmissionWithoutReadPermission() throws Exception {
String secondProject = "secondProject";
projectOperations.newProject().name(secondProject).create();
TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
String topic = "topic";
String change1 = createChange(testRepo, "master", "first change", "a.txt", "message", topic).getChangeId();
String change2 = createChange(secondRepo, "master", "second change", "b.txt", "message", topic).getChangeId();
gApi.changes().id(change1).current().review(ReviewInput.approve());
gApi.changes().id(change2).current().review(ReviewInput.approve());
gApi.changes().id(change1).current().submit();
// revoke read permissions for the first repository.
projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/master").group(REGISTERED_USERS)).update();
// assert that if first repository has no read permissions, it will fail.
ResourceNotFoundException resourceNotFoundException = assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(change1).revertSubmission());
assertThat(resourceNotFoundException).hasMessageThat().isEqualTo("Not found: " + change1);
// assert that if the first repository has no READ permissions and a change from another
// repository is trying to revert the submission, it will fail.
AuthException authException = assertThrows(AuthException.class, () -> gApi.changes().id(change2).revertSubmission());
assertThat(authException).hasMessageThat().isEqualTo("read not permitted");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class AbandonIT method abandonInactiveOpenChanges.
@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
public void abandonInactiveOpenChanges() throws Exception {
// create 2 changes which will be abandoned ...
int id1 = createChange().getChange().getId().get();
int id2 = createChange().getChange().getId().get();
// ... because they are older than 1 week
TestTimeUtil.incrementClock(7 * 24, HOURS);
// create 1 new change that will not be abandoned
ChangeData cd = createChange().getChange();
int id3 = cd.getId().get();
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3);
assertThat(query("is:abandoned")).isEmpty();
abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
assertThat(toChangeNumbers(query("is:open"))).containsExactly(id3);
assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id1, id2);
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method suggestReviewersTooManyQueryTerms.
@Test
@GerritConfig(name = "index.maxTerms", value = "10")
public void suggestReviewersTooManyQueryTerms() throws Exception {
String changeId = createChange().getChangeId();
// Do a query which doesn't exceed index.maxTerms succeeds (add only 9 terms, since on
// 'inactive:1' term is implicitly added) and assert that a result is returned
StringBuilder query = new StringBuilder();
for (int i = 1; i <= 9; i++) {
query.append(name("u")).append(" ");
}
assertThat(suggestReviewers(changeId, query.toString())).isNotEmpty();
// Do a query which exceed index.maxTerms succeeds (10 terms plus 'inactive:1' term which is
// implicitly added).
query.append(name("u"));
BadRequestException exception = assertThrows(BadRequestException.class, () -> suggestReviewers(changeId, query.toString()));
assertThat(exception).hasMessageThat().isEqualTo("too many terms in query");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method confirmationIsNeverRequestedForAccounts.
@Test
@GerritConfig(name = "addreviewer.maxAllowed", value = "1")
@GerritConfig(name = "addreviewer.maxWithoutConfirmation", value = "1")
public void confirmationIsNeverRequestedForAccounts() throws Exception {
user("individual 0", "Test0 Last0");
user("individual 1", "Test1 Last1");
String changeId = createChange().getChangeId();
List<SuggestedReviewerInfo> reviewers;
SuggestedReviewerInfo reviewer;
// Individual account suggestions have count of 1 and no confirm.
reviewers = suggestReviewers(changeId, "test", 10);
assertThat(reviewers).hasSize(2);
reviewer = reviewers.get(0);
assertThat(reviewer.count).isEqualTo(1);
assertThat(reviewer.confirm).isNull();
}
Aggregations