Merge changes Ie9229923,Ibe1cd165
* changes: Change API: Add convenience get() and info() methods ChangeJson: Fix reviewed property initialization
This commit is contained in:
@@ -16,7 +16,6 @@ package com.google.gerrit.acceptance.rest.change;
|
|||||||
|
|
||||||
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
|
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
|
||||||
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
||||||
import static com.google.gerrit.extensions.common.ListChangesOption.MESSAGES;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
@@ -29,7 +28,6 @@ import com.google.gerrit.extensions.api.GerritApi;
|
|||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||||
import com.google.gerrit.extensions.common.ListChangesOption;
|
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@@ -45,7 +43,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class ChangeMessagesIT extends AbstractDaemonTest {
|
public class ChangeMessagesIT extends AbstractDaemonTest {
|
||||||
@@ -90,8 +87,7 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
|||||||
IOException, RestApiException {
|
IOException, RestApiException {
|
||||||
String changeId = createChange();
|
String changeId = createChange();
|
||||||
postMessage(changeId, "Some nits need to be fixed.");
|
postMessage(changeId, "Some nits need to be fixed.");
|
||||||
ChangeInfo c = getChange("p~master~" + changeId,
|
ChangeInfo c = getChange("p~master~" + changeId);
|
||||||
EnumSet.noneOf(ListChangesOption.class));
|
|
||||||
assertNull(c.messages);
|
assertNull(c.messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +95,7 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
|||||||
public void defaultMessage() throws GitAPIException, IOException,
|
public void defaultMessage() throws GitAPIException, IOException,
|
||||||
RestApiException {
|
RestApiException {
|
||||||
String changeId = createChange();
|
String changeId = createChange();
|
||||||
ChangeInfo c = getChange("p~master~" + changeId, EnumSet.of(MESSAGES));
|
ChangeInfo c = getChangeAll("p~master~" + changeId);
|
||||||
assertNotNull(c.messages);
|
assertNotNull(c.messages);
|
||||||
assertEquals(1, c.messages.size());
|
assertEquals(1, c.messages.size());
|
||||||
assertEquals("Uploaded patch set 1.", c.messages.iterator().next().message);
|
assertEquals("Uploaded patch set 1.", c.messages.iterator().next().message);
|
||||||
@@ -113,7 +109,7 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
|||||||
postMessage(changeId, firstMessage);
|
postMessage(changeId, firstMessage);
|
||||||
String secondMessage = "I like this feature.";
|
String secondMessage = "I like this feature.";
|
||||||
postMessage(changeId, secondMessage);
|
postMessage(changeId, secondMessage);
|
||||||
ChangeInfo c = getChange("p~master~" + changeId, EnumSet.of(MESSAGES));
|
ChangeInfo c = getChangeAll("p~master~" + changeId);
|
||||||
assertNotNull(c.messages);
|
assertNotNull(c.messages);
|
||||||
assertEquals(3, c.messages.size());
|
assertEquals(3, c.messages.size());
|
||||||
Iterator<ChangeMessageInfo> it = c.messages.iterator();
|
Iterator<ChangeMessageInfo> it = c.messages.iterator();
|
||||||
@@ -139,8 +135,13 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
|||||||
.consume();
|
.consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChangeInfo getChange(String triplet, EnumSet<ListChangesOption> s)
|
private ChangeInfo getChange(String triplet)
|
||||||
throws RestApiException {
|
throws RestApiException {
|
||||||
return gApi.changes().id(triplet).get(s);
|
return gApi.changes().id(triplet).info();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChangeInfo getChangeAll(String triplet)
|
||||||
|
throws RestApiException {
|
||||||
|
return gApi.changes().id(triplet).get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,4 +40,9 @@ public interface ChangeApi {
|
|||||||
void addReviewer(String in) throws RestApiException;
|
void addReviewer(String in) throws RestApiException;
|
||||||
|
|
||||||
ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException;
|
ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException;
|
||||||
|
|
||||||
|
/** {@code get} with {@link ListChangesOption} set to ALL. */
|
||||||
|
ChangeInfo get() throws RestApiException;
|
||||||
|
/** {@code get} with {@link ListChangesOption} set to NONE. */
|
||||||
|
ChangeInfo info() throws RestApiException;
|
||||||
}
|
}
|
||||||
|
@@ -170,4 +170,14 @@ class ChangeApiImpl implements ChangeApi {
|
|||||||
throw new RestApiException("Cannot retrieve change", e);
|
throw new RestApiException("Cannot retrieve change", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChangeInfo get() throws RestApiException {
|
||||||
|
return get(EnumSet.allOf(ListChangesOption.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChangeInfo info() throws RestApiException {
|
||||||
|
return get(EnumSet.noneOf(ListChangesOption.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -118,9 +118,11 @@ class ChangeInfoMapper {
|
|||||||
lo.value = li.value;
|
lo.value = li.value;
|
||||||
lo.optional = li.optional;
|
lo.optional = li.optional;
|
||||||
lo.values = li.values;
|
lo.values = li.values;
|
||||||
lo.all = Lists.newArrayListWithExpectedSize(li.all.size());
|
if (li.all != null) {
|
||||||
for (ChangeJson.ApprovalInfo ai : li.all) {
|
lo.all = Lists.newArrayListWithExpectedSize(li.all.size());
|
||||||
lo.all.add(fromApprovalInfo(ai));
|
for (ChangeJson.ApprovalInfo ai : li.all) {
|
||||||
|
lo.all.add(fromApprovalInfo(ai));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
r.put(e.getKey(), lo);
|
r.put(e.getKey(), lo);
|
||||||
}
|
}
|
||||||
@@ -141,6 +143,9 @@ class ChangeInfoMapper {
|
|||||||
|
|
||||||
private static AccountInfo fromAcountInfo(
|
private static AccountInfo fromAcountInfo(
|
||||||
com.google.gerrit.server.account.AccountInfo i) {
|
com.google.gerrit.server.account.AccountInfo i) {
|
||||||
|
if (i == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
AccountInfo ai = new AccountInfo();
|
AccountInfo ai = new AccountInfo();
|
||||||
fromAccount(i, ai);
|
fromAccount(i, ai);
|
||||||
return ai;
|
return ai;
|
||||||
|
@@ -227,6 +227,9 @@ public class ChangeJson {
|
|||||||
private ChangeInfo format(ChangeData cd, Optional<PatchSet.Id> limitToPsId)
|
private ChangeInfo format(ChangeData cd, Optional<PatchSet.Id> limitToPsId)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
|
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
|
||||||
|
if (has(REVIEWED)) {
|
||||||
|
ensureReviewedLoaded(Collections.singleton(cd));
|
||||||
|
}
|
||||||
ChangeInfo res = toChangeInfo(cd, limitToPsId);
|
ChangeInfo res = toChangeInfo(cd, limitToPsId);
|
||||||
accountLoader.fill();
|
accountLoader.fill();
|
||||||
return res;
|
return res;
|
||||||
|
Reference in New Issue
Block a user