submitted_together: Add a dummy change for not visible changes

Currently the submitted_together REST API call returns a 500 when a draft
change that is not visible to the querying account is included in the
change set and doesn't include changes that are not visible to the user.

Solve both cases by adding a dummy change that informs the user of change
not visible by them.

The 500s in the case of drafts were a result of I88c1cf41b4b691d048f2429cb85a64c9441701a5,
which made SubmitTypeRecord#getSubmitType throw an OrmException in case
of a draft. Removing the exception there is safe now, as all callers check
for it again.

Change-Id: I8702e5d0ca7772b335fd5129943301e2a9e00955
This commit is contained in:
Stefan Beller
2016-06-13 12:04:54 -07:00
parent e57733d8c7
commit e73ebe2dc4
12 changed files with 305 additions and 53 deletions

View File

@@ -37,6 +37,7 @@ import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.api.projects.ProjectInput;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.SubmittedTogetherOption;
import com.google.gerrit.extensions.common.ActionInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.EditInfo;
@@ -105,6 +106,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@@ -722,13 +724,20 @@ public abstract class AbstractDaemonTest {
protected void assertSubmittedTogether(String chId, String... expected)
throws Exception {
List<ChangeInfo> actual = gApi.changes().id(chId).submittedTogether();
EnumSet<SubmittedTogetherOption> o = EnumSet.noneOf(
SubmittedTogetherOption.class);
assertSubmittedTogether(chId, o, expected);
}
protected void assertSubmittedTogether(String chId,
EnumSet<SubmittedTogetherOption> o, String... expected) throws Exception {
List<ChangeInfo> actual = gApi.changes().id(chId).submittedTogether(o);
assertThat(actual).hasSize(expected.length);
assertThat(Iterables.transform(actual,
new Function<ChangeInfo, String>() {
@Override
public String apply(ChangeInfo input) {
return input.changeId;
return input.changeId != null ? input.changeId : input.subject;
}
})).containsExactly((Object[])expected).inOrder();
}