Search in sources :

Example 6 with QueryChanges

use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.

the class QueryChangesIT method defaultQueryWithInvalidQuotedRegEx.

@Test
public void defaultQueryWithInvalidQuotedRegEx() throws Exception {
    QueryChanges queryChanges = queryChangesProvider.get();
    queryChanges.addQuery("\"^[A\"");
    BadRequestException e = assertThrows(BadRequestException.class, () -> queryChanges.apply(TopLevelResource.INSTANCE));
    assertThat(e).hasMessageThat().isEqualTo("invalid regular expression: [A");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) QueryChanges(com.google.gerrit.server.restapi.change.QueryChanges) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with QueryChanges

use of com.google.gerrit.server.restapi.change.QueryChanges 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);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) QueryChanges(com.google.gerrit.server.restapi.change.QueryChanges) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with QueryChanges

use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.

the class QueryChangesIT method moreChangesIndicatorDoesNotWronglyCopyToUnrelatedChanges.

@Test
@SuppressWarnings("unchecked")
public void moreChangesIndicatorDoesNotWronglyCopyToUnrelatedChanges() throws Exception {
    String queryWithMoreChanges = "is:wip limit:1 repo:" + project.get();
    String queryWithNoMoreChanges = "is:open limit:10 repo:" + project.get();
    createChange().getChangeId();
    String cId2 = createChange().getChangeId();
    String cId3 = createChange().getChangeId();
    gApi.changes().id(cId2).setWorkInProgress();
    gApi.changes().id(cId3).setWorkInProgress();
    // Run the capped query first
    QueryChanges queryChanges = queryChangesProvider.get();
    queryChanges.addQuery(queryWithMoreChanges);
    queryChanges.addQuery(queryWithNoMoreChanges);
    List<List<ChangeInfo>> result = (List<List<ChangeInfo>>) queryChanges.apply(TopLevelResource.INSTANCE).value();
    assertThat(result).hasSize(2);
    assertThat(result.get(0)).hasSize(1);
    assertThat(result.get(1)).hasSize(3);
    // _moreChanges is set on the first response, but not on the second.
    assertThat(result.get(0).get(0)._moreChanges).isTrue();
    assertNoChangeHasMoreChangesSet(result.get(1));
    // Run the capped query second
    QueryChanges queryChanges2 = queryChangesProvider.get();
    queryChanges2.addQuery(queryWithNoMoreChanges);
    queryChanges2.addQuery(queryWithMoreChanges);
    List<List<ChangeInfo>> result2 = (List<List<ChangeInfo>>) queryChanges2.apply(TopLevelResource.INSTANCE).value();
    assertThat(result2).hasSize(2);
    assertThat(result2.get(0)).hasSize(3);
    assertThat(result2.get(1)).hasSize(1);
    // _moreChanges is set on the second response, but not on the first.
    assertNoChangeHasMoreChangesSet(result2.get(0));
    assertThat(result2.get(1).get(0)._moreChanges).isTrue();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) QueryChanges(com.google.gerrit.server.restapi.change.QueryChanges) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with QueryChanges

use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.

the class PluginOperatorsIT method getChangeWithIsOperator.

@Test
public void getChangeWithIsOperator() throws Exception {
    QueryChanges queryChanges = queryChangesProvider.get();
    queryChanges.addQuery("is:changeNumberEven_myplugin");
    String oddChangeId = createChange().getChangeId();
    String evenChangeId = createChange().getChangeId();
    BadRequestException exception = assertThrows(BadRequestException.class, () -> getChanges(queryChanges));
    assertThat(exception).hasMessageThat().isEqualTo("Unrecognized value: changeNumberEven_myplugin");
    try (AutoCloseable ignored = installPlugin("myplugin", IsOperatorModule.class)) {
        List<?> changes = getChanges(queryChanges);
        assertThat(changes).hasSize(1);
        ChangeInfo c = (ChangeInfo) changes.get(0);
        String outputChangeId = c.changeId;
        assertThat(outputChangeId).isEqualTo(evenChangeId);
        assertThat(outputChangeId).isNotEqualTo(oddChangeId);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) QueryChanges(com.google.gerrit.server.restapi.change.QueryChanges) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with QueryChanges

use of com.google.gerrit.server.restapi.change.QueryChanges in project gerrit by GerritCodeReview.

the class QueryChangesIT method multipleQueriesInOneRequestCanContainSameChange.

@Test
@SuppressWarnings("unchecked")
public void multipleQueriesInOneRequestCanContainSameChange() 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;
    gApi.changes().id(cId2).setWorkInProgress();
    QueryChanges queryChanges = queryChangesProvider.get();
    queryChanges.addQuery("is:open repo:" + project.get());
    queryChanges.addQuery("is:wip 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);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) QueryChanges(com.google.gerrit.server.restapi.change.QueryChanges) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

QueryChanges (com.google.gerrit.server.restapi.change.QueryChanges)15 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Test (org.junit.Test)13 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 Collectors.toList (java.util.stream.Collectors.toList)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 Account (com.google.gerrit.entities.Account)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)2 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 RestResponse (com.google.gerrit.acceptance.RestResponse)1 UseClockStep (com.google.gerrit.acceptance.UseClockStep)1 AccountOperations (com.google.gerrit.acceptance.testsuite.account.AccountOperations)1