Stop using deprecated method to create test changes
The createV1() method to create test changes has been deprecated in
favour of the new create() method. Adapt all tests to use the new
method for creating test changes.
Change-Id: Ideb86f1dbb51658f7c5be1545b60ba300dd300d4
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/SkipCodeOwnerConfigValidationPushOptionIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/SkipCodeOwnerConfigValidationPushOptionIT.java
index 50d1289..b585b23 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/SkipCodeOwnerConfigValidationPushOptionIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/SkipCodeOwnerConfigValidationPushOptionIT.java
@@ -25,8 +25,8 @@
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
import com.google.gerrit.common.Nullable;
-import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Project;
+import com.google.gerrit.extensions.api.changes.ChangeIdentifier;
import com.google.gerrit.extensions.common.ValidationOptionInfo;
import com.google.gerrit.extensions.common.ValidationOptionInfos;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersIT;
@@ -70,9 +70,9 @@
// implicitly assigned.
requestScopeOperations.setApiUser(admin.id());
- Change.Id changeId = createChangeWithCodeOwnerConfigFile(project);
+ ChangeIdentifier changeIdentifier = createChangeWithCodeOwnerConfigFile(project);
ValidationOptionInfos validationOptionsInfos =
- gApi.changes().id(project.get(), changeId.get()).getValidationOptions();
+ gApi.changes().id(changeIdentifier).getValidationOptions();
ValidationOptionInfos branchValidationOptionInfos =
gApi.projects().name(project.get()).branch("refs/heads/master").getValidationOptions();
assertThat(validationOptionsInfos.validationOptions)
@@ -101,9 +101,9 @@
.update();
requestScopeOperations.setApiUser(user.id());
- Change.Id changeId = createChangeWithCodeOwnerConfigFile(project);
+ ChangeIdentifier changeIdentifier = createChangeWithCodeOwnerConfigFile(project);
ValidationOptionInfos validationOptionsInfos =
- gApi.changes().id(project.get(), changeId.get()).getValidationOptions();
+ gApi.changes().id(changeIdentifier).getValidationOptions();
ValidationOptionInfos branchValidationOptionInfos =
gApi.projects().name(project.get()).branch("refs/heads/master").getValidationOptions();
assertThat(validationOptionsInfos.validationOptions)
@@ -128,9 +128,9 @@
// capability.
requestScopeOperations.setApiUser(user.id());
- Change.Id changeId = createChangeWithCodeOwnerConfigFile(project);
+ ChangeIdentifier changeIdentifier = createChangeWithCodeOwnerConfigFile(project);
ValidationOptionInfos validationOptionsInfos =
- gApi.changes().id(project.get(), changeId.get()).getValidationOptions();
+ gApi.changes().id(changeIdentifier).getValidationOptions();
ValidationOptionInfos branchValidationOptionInfos =
gApi.projects().name(project.get()).branch("refs/heads/master").getValidationOptions();
assertThat(validationOptionsInfos.validationOptions).isEmpty();
@@ -141,9 +141,9 @@
@Test
public void codeOwnersSkipOptionIsOmittedIfCodeOwnersFunctionalityIsDisabledForProject()
throws Exception {
- Change.Id changeId = createChangeWithCodeOwnerConfigFile(project);
+ ChangeIdentifier changeIdentifier = createChangeWithCodeOwnerConfigFile(project);
ValidationOptionInfos validationOptionsInfos =
- gApi.changes().id(project.get(), changeId.get()).getValidationOptions();
+ gApi.changes().id(changeIdentifier).getValidationOptions();
ValidationOptionInfos branchValidationOptionInfos =
gApi.projects().name(project.get()).branch("refs/heads/master").getValidationOptions();
assertThat(validationOptionsInfos.validationOptions).isEmpty();
@@ -154,9 +154,9 @@
@Test
public void codeOwnersSkipOptionIsOmittedIfCodeOwnersFunctionalityIsDisabledForBranch()
throws Exception {
- Change.Id changeId = createChangeWithCodeOwnerConfigFile(project, "master");
+ ChangeIdentifier changeIdentifier = createChangeWithCodeOwnerConfigFile(project, "master");
ValidationOptionInfos validationOptionsInfos =
- gApi.changes().id(project.get(), changeId.get()).getValidationOptions();
+ gApi.changes().id(changeIdentifier).getValidationOptions();
ValidationOptionInfos branchValidationOptionInfos =
gApi.projects().name(project.get()).branch("refs/heads/master").getValidationOptions();
assertThat(validationOptionsInfos.validationOptions).isEmpty();
@@ -166,9 +166,9 @@
@Test
public void codeOwnersSkipOptionIsOmittedIfChangeDoesNotTouchCodeOwnerConfigs() throws Exception {
requestScopeOperations.setApiUser(admin.id());
- Change.Id changeId = changeOperations.newChange().project(project).createV1();
+ ChangeIdentifier changeIdentifier = changeOperations.newChange().project(project).create();
ValidationOptionInfos validationOptionsInfos =
- gApi.changes().id(project.get(), changeId.get()).getValidationOptions();
+ gApi.changes().id(changeIdentifier).getValidationOptions();
ValidationOptionInfos branchValidationOptionInfos =
gApi.projects().name(project.get()).branch("refs/heads/master").getValidationOptions();
assertThat(validationOptionsInfos.validationOptions).isEmpty();
@@ -180,11 +180,12 @@
SkipCodeOwnerConfigValidationPushOption.DESCRIPTION)));
}
- private Change.Id createChangeWithCodeOwnerConfigFile(Project.NameKey project) throws Exception {
+ private ChangeIdentifier createChangeWithCodeOwnerConfigFile(Project.NameKey project)
+ throws Exception {
return createChangeWithCodeOwnerConfigFile(project, /* branch= */ null);
}
- private Change.Id createChangeWithCodeOwnerConfigFile(
+ private ChangeIdentifier createChangeWithCodeOwnerConfigFile(
Project.NameKey project, @Nullable String branch) throws Exception {
CodeOwnerConfig.Key codeOwnerConfigKey = CodeOwnerConfig.Key.create(project, "master", "/");
String codeOwnerConfigFile =
@@ -203,7 +204,7 @@
CodeOwnerConfig.builder(codeOwnerConfigKey, TEST_REVISION)
.addCodeOwnerSet(CodeOwnerSet.createWithoutPathExpressions(admin.email()))
.build()))
- .createV1();
+ .create();
}
private String format(CodeOwnerConfig codeOwnerConfig) throws Exception {
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java
index 05f2fe3..9b9e5f0 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java
@@ -32,7 +32,7 @@
import com.google.gerrit.acceptance.config.GerritConfig;
import com.google.gerrit.acceptance.testsuite.change.ChangeOperations;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
-import com.google.gerrit.entities.Change;
+import com.google.gerrit.extensions.api.changes.ChangeIdentifier;
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.TopLevelResource;
@@ -167,7 +167,7 @@
ImmutableList<ChangedFile> changedFilesSet =
changedFiles.getFromDiffCache(
project,
- getRevisionResource(changeId).getPatchSet().commitId(),
+ getRevisionResource(ChangeIdentifier.byChangeId(changeId)).getPatchSet().commitId(),
MergeCommitStrategy.ALL_CHANGED_FILES);
assertThat(changedFilesSet).hasSize(1);
ChangedFile changedFile = Iterables.getOnlyElement(changedFilesSet);
@@ -188,7 +188,7 @@
ImmutableList<ChangedFile> changedFilesSet =
changedFiles.getFromDiffCache(
project,
- getRevisionResource(changeId).getPatchSet().commitId(),
+ getRevisionResource(ChangeIdentifier.byChangeId(changeId)).getPatchSet().commitId(),
MergeCommitStrategy.ALL_CHANGED_FILES);
ChangedFileSubject changedFile = assertThatCollection(changedFilesSet).onlyElement();
changedFile.hasNewPath().value().isEqualTo(Path.of(newPath));
@@ -237,14 +237,14 @@
String file2 = "bar/b.txt";
// Create a base change.
- Change.Id baseChange =
+ ChangeIdentifier baseChange =
changeOperations
.newChange()
.project(project)
.branch("master")
.file(file1)
.content("base content")
- .createV1();
+ .create();
approveAndSubmit(baseChange);
// Create another branch
@@ -255,18 +255,18 @@
gApi.projects().name(project.get()).branch(branchInput.ref).create(branchInput);
// Create a change in master that touches file1.
- Change.Id changeInMaster =
+ ChangeIdentifier changeInMaster =
changeOperations
.newChange()
.project(project)
.branch("master")
.file(file1)
.content("master content")
- .createV1();
+ .create();
approveAndSubmit(changeInMaster);
// Create a change in the other branch and that touches file1 and creates file2.
- Change.Id changeInOtherBranch =
+ ChangeIdentifier changeInOtherBranch =
changeOperations
.newChange()
.project(project)
@@ -275,12 +275,12 @@
.content("other content")
.file(file2)
.content("content")
- .createV1();
+ .create();
approveAndSubmit(changeInOtherBranch);
// Create a merge change with a conflict resolution for file1 and file2 with the same content as
// in the other branch (no conflict on file2).
- Change.Id mergeChange =
+ ChangeIdentifier mergeChange =
changeOperations
.newChange()
.project(project)
@@ -293,12 +293,12 @@
.content("merged content")
.file(file2)
.content("content")
- .createV1();
+ .create();
ImmutableList<ChangedFile> changedFilesSet =
changedFiles.getFromDiffCache(
project,
- getRevisionResource(Integer.toString(mergeChange.get())).getPatchSet().commitId(),
+ getRevisionResource(mergeChange).getPatchSet().commitId(),
mergeCommitStrategy);
if (MergeCommitStrategy.ALL_CHANGED_FILES.equals(mergeCommitStrategy)) {
@@ -337,14 +337,14 @@
String file = "foo/a.txt";
// Create a base change.
- Change.Id baseChange =
+ ChangeIdentifier baseChange =
changeOperations
.newChange()
.project(project)
.branch("master")
.file(file)
.content("base content")
- .createV1();
+ .create();
approveAndSubmit(baseChange);
// Create another branch
@@ -355,14 +355,14 @@
gApi.projects().name(project.get()).branch(branchInput.ref).create(branchInput);
// Create a change in master that touches file1.
- Change.Id changeInMaster =
+ ChangeIdentifier changeInMaster =
changeOperations
.newChange()
.project(project)
.branch("master")
.file(file)
.content("master content")
- .createV1();
+ .create();
approveAndSubmit(changeInMaster);
// Create a change in the other branch and that deleted file1.
@@ -370,11 +370,11 @@
pushFactory.create(admin.newIdent(), testRepo, "Change Deleting A File", file, "");
Result r = push.rm("refs/for/master");
r.assertOkStatus();
- approveAndSubmit(r.getChange().getId());
+ approveAndSubmit(ChangeIdentifier.byNumericChangeId(r.getChange().getId().get()));
// Create a merge change with resolving the conflict on file between the edit in master and the
// deletion in the other branch by deleting the file.
- Change.Id mergeChange =
+ ChangeIdentifier mergeChange =
changeOperations
.newChange()
.project(project)
@@ -385,12 +385,12 @@
.tipOfBranch(branchName)
.file(file)
.delete()
- .createV1();
+ .create();
ImmutableList<ChangedFile> changedFilesSet =
changedFiles.getFromDiffCache(
project,
- getRevisionResource(Integer.toString(mergeChange.get())).getPatchSet().commitId(),
+ getRevisionResource(mergeChange).getPatchSet().commitId(),
mergeCommitStrategy);
ImmutableSet<String> oldPaths =
changedFilesSet.stream()
@@ -459,7 +459,7 @@
String file5 = "baz/foo.bar";
// Create a base change.
- Change.Id baseChange =
+ ChangeIdentifier baseChange =
changeOperations
.newChange()
.project(project)
@@ -470,7 +470,7 @@
.content("base content")
.file(file5)
.content("base content")
- .createV1();
+ .create();
approveAndSubmit(baseChange);
// Create another branch
@@ -481,7 +481,7 @@
gApi.projects().name(project.get()).branch(branchInput.ref).create(branchInput);
// Create a change in master that touches file1, file3 and file5
- Change.Id changeInMaster =
+ ChangeIdentifier changeInMaster =
changeOperations
.newChange()
.project(project)
@@ -492,12 +492,12 @@
.content("master content")
.file(file5)
.content("master content")
- .createV1();
+ .create();
approveAndSubmit(changeInMaster);
// Create a change in the other branch and that touches file1, file3, file5 and creates file2,
// file4.
- Change.Id changeInOtherBranch =
+ ChangeIdentifier changeInOtherBranch =
changeOperations
.newChange()
.project(project)
@@ -512,12 +512,12 @@
.content("content")
.file(file5)
.content("other content")
- .createV1();
+ .create();
approveAndSubmit(changeInOtherBranch);
// Create a merge change with a conflict resolution for file1 and file2 with the same content as
// in the other branch (no conflict on file2).
- Change.Id mergeChange =
+ ChangeIdentifier mergeChange =
changeOperations
.newChange()
.project(project)
@@ -536,12 +536,12 @@
.content("content")
.file(file5)
.content("merged content")
- .createV1();
+ .create();
ImmutableList<ChangedFile> changedFilesSet =
changedFiles.getFromDiffCache(
project,
- getRevisionResource(Integer.toString(mergeChange.get())).getPatchSet().commitId(),
+ getRevisionResource(mergeChange).getPatchSet().commitId(),
mergeCommitStrategy);
if (MergeCommitStrategy.ALL_CHANGED_FILES.equals(mergeCommitStrategy)) {
@@ -558,14 +558,14 @@
}
}
- private void approveAndSubmit(Change.Id changeId) throws Exception {
- approve(Integer.toString(changeId.get()));
- gApi.changes().id(changeId.get()).current().submit();
+ private void approveAndSubmit(ChangeIdentifier changeIdentifier) throws Exception {
+ approve(changeIdentifier.id());
+ gApi.changes().id(changeIdentifier).current().submit();
}
- private RevisionResource getRevisionResource(String changeId) throws Exception {
+ private RevisionResource getRevisionResource(ChangeIdentifier changeIdentifier) throws Exception {
ChangeResource changeResource =
- changesCollection.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(changeId));
+ changesCollection.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeIdentifier.id()));
return revisions.parse(changeResource, IdString.fromDecoded("current"));
}
}