Add Java API for change edits and use it in tests
For some reason, a Java API for change edits didn't exist previously even though a detailed REST API has been available. Because of that, tests needed to use internal classes when they interacted with change edits. Using internal classes is fragile and impedes refactorings. That's why we should avoid it. If possible, the structure and behavior of the tests is kept. Some of them might and should be improved but that's beyond the scope of this change. Some of the tests are adapted a bit because the internal classes allow change edits to be created for previous patch sets which isn't possible when using the REST API (and hence the Java API). As modifications to the mentioned internal classes are necessary to properly implement the 'Apply fix' feature of robot comments, it is crucial that none of the tests use the internal classes directly. In addition, the tests which will be added for the 'Apply fix' feature will also need to modify and query change edits, which will be much easier with the Java API. Change-Id: I6b455541d1bc1b7a05b5f0507911181b0451829a
This commit is contained in:
@@ -69,7 +69,6 @@ import com.google.gerrit.server.change.ChangeInserter;
|
||||
import com.google.gerrit.server.change.ChangeTriplet;
|
||||
import com.google.gerrit.server.change.PatchSetInserter;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.edit.ChangeEditModifier;
|
||||
import com.google.gerrit.server.git.BatchUpdate;
|
||||
import com.google.gerrit.server.git.validators.CommitValidators;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
@@ -138,7 +137,6 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
@Inject protected ChangeQueryBuilder queryBuilder;
|
||||
@Inject protected GerritApi gApi;
|
||||
@Inject protected IdentifiedUser.GenericFactory userFactory;
|
||||
@Inject protected ChangeEditModifier changeEditModifier;
|
||||
@Inject protected ChangeIndexCollection indexes;
|
||||
@Inject protected ChangeIndexer indexer;
|
||||
@Inject protected IndexConfig indexConfig;
|
||||
@@ -1581,25 +1579,27 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
Account.Id user2 = createAccount("user2");
|
||||
TestRepository<Repo> repo = createProject("repo");
|
||||
Change change1 = insert(repo, newChange(repo));
|
||||
ChangeNotes notes1 =
|
||||
notesFactory.create(db, change1.getProject(), change1.getId());
|
||||
PatchSet ps1 = psUtil.get(db, notes1, change1.currentPatchSetId());
|
||||
String changeId1 = change1.getKey().get();
|
||||
Change change2 = insert(repo, newChange(repo));
|
||||
ChangeNotes notes2 =
|
||||
notesFactory.create(db, change2.getProject(), change2.getId());
|
||||
PatchSet ps2 = psUtil.get(db, notes2, change2.currentPatchSetId());
|
||||
String changeId2 = change2.getKey().get();
|
||||
|
||||
requestContext.setContext(newRequestContext(user1));
|
||||
assertQuery("has:edit");
|
||||
assertThat(changeEditModifier.createEdit(change1, ps1))
|
||||
.isEqualTo(RefUpdate.Result.NEW);
|
||||
assertThat(changeEditModifier.createEdit(change2, ps2))
|
||||
.isEqualTo(RefUpdate.Result.NEW);
|
||||
gApi.changes()
|
||||
.id(changeId1)
|
||||
.edit()
|
||||
.create();
|
||||
gApi.changes()
|
||||
.id(changeId2)
|
||||
.edit()
|
||||
.create();
|
||||
|
||||
requestContext.setContext(newRequestContext(user2));
|
||||
assertQuery("has:edit");
|
||||
assertThat(changeEditModifier.createEdit(change2, ps2))
|
||||
.isEqualTo(RefUpdate.Result.NEW);
|
||||
gApi.changes()
|
||||
.id(changeId2)
|
||||
.edit()
|
||||
.create();
|
||||
|
||||
requestContext.setContext(newRequestContext(user1));
|
||||
assertQuery("has:edit", change2, change1);
|
||||
@@ -1698,13 +1698,16 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
Project.NameKey project = new Project.NameKey("repo");
|
||||
TestRepository<Repo> repo = createProject(project.get());
|
||||
Change change = insert(repo, newChange(repo));
|
||||
String changeId = change.getKey().get();
|
||||
ChangeNotes notes =
|
||||
notesFactory.create(db, change.getProject(), change.getId());
|
||||
PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId());
|
||||
|
||||
requestContext.setContext(newRequestContext(user));
|
||||
assertThat(changeEditModifier.createEdit(change, ps))
|
||||
.isEqualTo(RefUpdate.Result.NEW);
|
||||
gApi.changes()
|
||||
.id(changeId)
|
||||
.edit()
|
||||
.create();
|
||||
assertQuery("has:edit", change);
|
||||
assertThat(indexer.reindexIfStale(project, change.getId()).get()).isFalse();
|
||||
|
||||
@@ -1734,17 +1737,17 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
|
||||
Change change = insert(repo, newChangeForCommit(repo, commit));
|
||||
Change.Id id = change.getId();
|
||||
int c = id.get();
|
||||
ChangeNotes notes =
|
||||
notesFactory.create(db, change.getProject(), change.getId());
|
||||
PatchSet ps = psUtil.get(db, notes, change.currentPatchSetId());
|
||||
String changeId = change.getKey().get();
|
||||
requestContext.setContext(newRequestContext(user));
|
||||
|
||||
// Ensure one of each type of supported ref is present for the change. If
|
||||
// any more refs are added, update this test to reflect them.
|
||||
|
||||
// Edit
|
||||
assertThat(changeEditModifier.createEdit(change, ps))
|
||||
.isEqualTo(RefUpdate.Result.NEW);
|
||||
gApi.changes()
|
||||
.id(changeId)
|
||||
.edit()
|
||||
.create();
|
||||
|
||||
// Star
|
||||
gApi.accounts()
|
||||
|
||||
Reference in New Issue
Block a user