AbstractDaemonTest: Simplify helpers for getting changes
There were two versions, getChange using HTTP and get using the extension API. Standardize on the extension API, which works even on @NoHttpd tests. Update callers to use get() or info() as appropriate. Remove the version that passes a specific user, as it was unused. Callers can work around this with setApiUser, or we can always add back a helper to call setApiUser and unset it after the get call. Change-Id: Idbbea5f54b4e5098235b2bfd681a2d29e413c81e
This commit is contained in:
@@ -14,15 +14,14 @@
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
|
||||
import static com.google.gerrit.acceptance.GitUtil.initSsh;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static com.google.gerrit.server.project.Util.block;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Chars;
|
||||
import com.google.gerrit.acceptance.AcceptanceTestRequestScope.Context;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
@@ -60,7 +59,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
@@ -77,7 +75,6 @@ import org.junit.runners.model.Statement;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -328,19 +325,6 @@ public abstract class AbstractDaemonTest {
|
||||
return push.to(ref);
|
||||
}
|
||||
|
||||
protected ChangeInfo getChange(String changeId, ListChangesOption... options)
|
||||
throws IOException {
|
||||
return getChange(adminSession, changeId, options);
|
||||
}
|
||||
|
||||
protected ChangeInfo getChange(RestSession session, String changeId,
|
||||
ListChangesOption... options) throws IOException {
|
||||
String q = options.length > 0 ? "?o=" + Joiner.on("&o=").join(options) : "";
|
||||
RestResponse r = session.get("/changes/" + changeId + q);
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
|
||||
return newGson().fromJson(r.getReader(), ChangeInfo.class);
|
||||
}
|
||||
|
||||
protected ChangeInfo info(String id)
|
||||
throws RestApiException {
|
||||
return gApi.changes().id(id).info();
|
||||
@@ -358,9 +342,8 @@ public abstract class AbstractDaemonTest {
|
||||
|
||||
protected ChangeInfo get(String id, ListChangesOption... options)
|
||||
throws RestApiException {
|
||||
EnumSet<ListChangesOption> s = EnumSet.noneOf(ListChangesOption.class);
|
||||
s.addAll(Arrays.asList(options));
|
||||
return gApi.changes().id(id).get(s);
|
||||
return gApi.changes().id(id).get(
|
||||
Sets.newEnumSet(Arrays.asList(options), ListChangesOption.class));
|
||||
}
|
||||
|
||||
protected List<ChangeInfo> query(String q) throws RestApiException {
|
||||
|
||||
@@ -55,11 +55,11 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
gApi.accounts()
|
||||
.self()
|
||||
.starChange(triplet);
|
||||
assertThat(getChange(triplet).starred).isTrue();
|
||||
assertThat(info(triplet).starred).isTrue();
|
||||
gApi.accounts()
|
||||
.self()
|
||||
.unstarChange(triplet);
|
||||
assertThat(getChange(triplet).starred).isNull();
|
||||
assertThat(info(triplet).starred).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -245,8 +245,8 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
protected void assertCurrentRevision(String changeId, int expectedNum,
|
||||
ObjectId expectedId) throws IOException {
|
||||
ChangeInfo c = getChange(changeId, CURRENT_REVISION);
|
||||
ObjectId expectedId) throws Exception {
|
||||
ChangeInfo c = get(changeId, CURRENT_REVISION);
|
||||
assertThat(c.currentRevision).isEqualTo(expectedId.name());
|
||||
assertThat(c.revisions.get(expectedId.name())._number).isEqualTo(expectedNum);
|
||||
Repository repo =
|
||||
@@ -261,8 +261,8 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertApproved(String changeId) throws IOException {
|
||||
ChangeInfo c = getChange(changeId, DETAILED_LABELS);
|
||||
protected void assertApproved(String changeId) throws Exception {
|
||||
ChangeInfo c = get(changeId, DETAILED_LABELS);
|
||||
LabelInfo cr = c.labels.get("Code-Review");
|
||||
assertThat(cr.all).hasSize(1);
|
||||
assertThat(cr.all.get(0).value).isEqualTo(2);
|
||||
|
||||
Reference in New Issue
Block a user