Add patchset retrieval to test API of changes
The returned patchset object doesn't contain many attributes yet. It's main purpose is currently to retrieve the PatchSet.Id or the commit SHA-1 of the current patchset. The introduced patchset-level in the API will also serve as basis for any actions we want to define on patchsets like the addition of comments. Change-Id: I7259099b13873ea5cedff9b5bde613a78bd02e30
This commit is contained in:
@@ -32,6 +32,7 @@ import com.google.gerrit.acceptance.testsuite.account.AccountOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.account.AccountOperationsImpl;
|
||||
import com.google.gerrit.acceptance.testsuite.change.ChangeOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.change.ChangeOperationsImpl;
|
||||
import com.google.gerrit.acceptance.testsuite.change.PerPatchsetOperationsImpl;
|
||||
import com.google.gerrit.acceptance.testsuite.group.GroupOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.group.GroupOperationsImpl;
|
||||
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||
@@ -509,6 +510,7 @@ public class GerritServer implements AutoCloseable {
|
||||
bind(ProjectOperations.class).to(ProjectOperationsImpl.class);
|
||||
bind(RequestScopeOperations.class).to(RequestScopeOperationsImpl.class);
|
||||
bind(ChangeOperations.class).to(ChangeOperationsImpl.class);
|
||||
factory(PerPatchsetOperationsImpl.Factory.class);
|
||||
factory(PushOneCommit.Factory.class);
|
||||
install(InProcessProtocol.module());
|
||||
install(new NoSshModule());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.acceptance.testsuite.change;
|
||||
|
||||
import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
|
||||
/**
|
||||
* An aggregation of operations on changes for test purposes.
|
||||
@@ -95,5 +96,20 @@ public interface ChangeOperations {
|
||||
* @return builder to create a new patchset
|
||||
*/
|
||||
TestPatchsetCreation.Builder newPatchset();
|
||||
|
||||
/**
|
||||
* Starts the fluent chain for querying or modifying a patchset. Please see the methods of
|
||||
* {@link PerPatchsetOperations} for details on possible operations.
|
||||
*
|
||||
* @return an aggregation of operations on a specific patchset
|
||||
*/
|
||||
PerPatchsetOperations patchset(PatchSet.Id patchsetId);
|
||||
|
||||
/**
|
||||
* Like {@link #patchset(PatchSet.Id)} but for the current patchset.
|
||||
*
|
||||
* @return an aggregation of operations on a specific patchset
|
||||
*/
|
||||
PerPatchsetOperations currentPatchset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class ChangeOperationsImpl implements ChangeOperations {
|
||||
private final BatchUpdate.Factory batchUpdateFactory;
|
||||
private final ProjectCache projectCache;
|
||||
private final ChangeFinder changeFinder;
|
||||
private final PerPatchsetOperationsImpl.Factory perPatchsetOperationsFactory;
|
||||
|
||||
@Inject
|
||||
public ChangeOperationsImpl(
|
||||
@@ -91,7 +92,8 @@ public class ChangeOperationsImpl implements ChangeOperations {
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
BatchUpdate.Factory batchUpdateFactory,
|
||||
ProjectCache projectCache,
|
||||
ChangeFinder changeFinder) {
|
||||
ChangeFinder changeFinder,
|
||||
PerPatchsetOperationsImpl.Factory perPatchsetOperationsFactory) {
|
||||
this.seq = seq;
|
||||
this.changeInserterFactory = changeInserterFactory;
|
||||
this.patchsetInserterFactory = patchsetInserterFactory;
|
||||
@@ -102,6 +104,7 @@ public class ChangeOperationsImpl implements ChangeOperations {
|
||||
this.batchUpdateFactory = batchUpdateFactory;
|
||||
this.projectCache = projectCache;
|
||||
this.changeFinder = changeFinder;
|
||||
this.perPatchsetOperationsFactory = perPatchsetOperationsFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -393,5 +396,17 @@ public class ChangeOperationsImpl implements ChangeOperations {
|
||||
patchSetInserter.setMessage(String.format("Uploaded patchset %d.", patchsetId.get()));
|
||||
return patchSetInserter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PerPatchsetOperations patchset(PatchSet.Id patchsetId) {
|
||||
return perPatchsetOperationsFactory.create(getChangeNotes(), patchsetId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PerPatchsetOperations currentPatchset() {
|
||||
ChangeNotes changeNotes = getChangeNotes();
|
||||
return perPatchsetOperationsFactory.create(
|
||||
changeNotes, changeNotes.getChange().currentPatchSetId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package com.google.gerrit.acceptance.testsuite.change;
|
||||
|
||||
/** An aggregation of methods on a specific patchset. */
|
||||
public interface PerPatchsetOperations {
|
||||
|
||||
/**
|
||||
* Retrieves the patchset.
|
||||
*
|
||||
* <p><strong>Note:</strong> This call will fail with an exception if the requested patchset
|
||||
* doesn't exist.
|
||||
*
|
||||
* @return the corresponding {@code TestPatchset}
|
||||
*/
|
||||
TestPatchset get();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.change;
|
||||
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
/**
|
||||
* The implementation of {@link PerPatchsetOperations}.
|
||||
*
|
||||
* <p>There is only one implementation of {@link PerPatchsetOperations}. Nevertheless, we keep the
|
||||
* separation between interface and implementation to enhance clarity.
|
||||
*/
|
||||
public class PerPatchsetOperationsImpl implements PerPatchsetOperations {
|
||||
private final ChangeNotes changeNotes;
|
||||
private final PatchSet.Id patchsetId;
|
||||
|
||||
public interface Factory {
|
||||
PerPatchsetOperationsImpl create(ChangeNotes changeNotes, PatchSet.Id patchsetId);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private PerPatchsetOperationsImpl(
|
||||
@Assisted ChangeNotes changeNotes, @Assisted PatchSet.Id patchsetId) {
|
||||
this.changeNotes = changeNotes;
|
||||
this.patchsetId = patchsetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestPatchset get() {
|
||||
PatchSet patchset = changeNotes.getPatchSets().get(patchsetId);
|
||||
return TestPatchset.builder().patchsetId(patchsetId).commitId(patchset.commitId()).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.testsuite.change;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
/** Representation of a patchset used for testing purposes. */
|
||||
@AutoValue
|
||||
public abstract class TestPatchset {
|
||||
|
||||
/** The numeric patchset ID. */
|
||||
public abstract PatchSet.Id patchsetId();
|
||||
|
||||
/** The commit SHA-1 of the patchset. */
|
||||
public abstract ObjectId commitId();
|
||||
|
||||
static Builder builder() {
|
||||
return new AutoValue_TestPatchset.Builder();
|
||||
}
|
||||
|
||||
@AutoValue.Builder
|
||||
abstract static class Builder {
|
||||
abstract Builder patchsetId(PatchSet.Id patchsetId);
|
||||
|
||||
abstract Builder commitId(ObjectId commitId);
|
||||
|
||||
abstract TestPatchset build();
|
||||
}
|
||||
}
|
||||
@@ -305,6 +305,33 @@ public class ChangeOperationsImplTest extends AbstractDaemonTest {
|
||||
assertThat(change.changeId()).isEqualTo("I0123456789012345678901234567890123456789");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentPatchsetOfExistingChangeCanBeRetrieved() throws Exception {
|
||||
Change.Id changeId = changeOperations.newChange().create();
|
||||
|
||||
TestPatchset patchset = changeOperations.change(changeId).currentPatchset().get();
|
||||
|
||||
ChangeInfo expectedChange = getChangeFromServer(changeId);
|
||||
String expectedCommitId = expectedChange.currentRevision;
|
||||
int expectedPatchsetNumber = expectedChange.revisions.get(expectedCommitId)._number;
|
||||
assertThat(patchset.commitId()).isEqualTo(ObjectId.fromString(expectedCommitId));
|
||||
assertThat(patchset.patchsetId()).isEqualTo(PatchSet.id(changeId, expectedPatchsetNumber));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void earlierPatchsetOfExistingChangeCanBeRetrieved() {
|
||||
Change.Id changeId = changeOperations.newChange().create();
|
||||
PatchSet.Id earlierPatchsetId =
|
||||
changeOperations.change(changeId).currentPatchset().get().patchsetId();
|
||||
PatchSet.Id currentPatchsetId = changeOperations.change(changeId).newPatchset().create();
|
||||
|
||||
TestPatchset earlierPatchset =
|
||||
changeOperations.change(changeId).patchset(earlierPatchsetId).get();
|
||||
|
||||
assertThat(earlierPatchset.patchsetId()).isEqualTo(earlierPatchsetId);
|
||||
assertThat(earlierPatchset.patchsetId()).isNotEqualTo(currentPatchsetId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newPatchsetCanBeCreatedWithoutSpecifyingAnyParameters() throws Exception {
|
||||
Change.Id changeId = changeOperations.newChange().create();
|
||||
|
||||
Reference in New Issue
Block a user