Merge CheckIT into ConsistencyCheckerIT

These were originally split when ConsistencyCheckerTest was not an
acceptance test. Now that it is, there's no reason to have two.

The only case that was not already tested in ConsistencyCheckIT was
that the result ChangeInfo was properly updated after fixing. Write a
simpler test for this than what we had before.

Change-Id: Ib88442cf062d032104d7a0e35d9348ba5c103246
This commit is contained in:
Dave Borowitz
2016-01-28 10:19:29 -05:00
committed by Edwin Kempin
parent 022ab1291c
commit 1c7aa94de4
2 changed files with 22 additions and 114 deletions

View File

@@ -1,114 +0,0 @@
// Copyright (C) 2014 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.api.change;
import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.extensions.api.changes.FixInput;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ProblemInfo;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.project.ChangeControl;
import com.google.inject.Inject;
import org.junit.Test;
import java.util.Collections;
import java.util.List;
@NoHttpd
public class CheckIT extends AbstractDaemonTest {
@Inject
private ChangeControl.GenericFactory changeControlFactory;
@Inject
private IdentifiedUser.GenericFactory userFactory;
@Inject
private ChangeUpdate.Factory changeUpdateFactory;
// Most types of tests belong in ConsistencyCheckerTest; these mostly just
// test paths outside of ConsistencyChecker, like API wiring.
@Test
public void currentPatchSetMissing() throws Exception {
PushOneCommit.Result r = createChange();
Change c = getChange(r);
db.patchSets().deleteKeys(Collections.singleton(c.currentPatchSetId()));
indexer.index(db, c);
List<ProblemInfo> problems = gApi.changes()
.id(r.getChangeId())
.check()
.problems;
assertThat(problems).hasSize(1);
assertThat(problems.get(0).message)
.isEqualTo("Current patch set 1 not found");
}
@Test
public void fixReturnsUpdatedValue() throws Exception {
PushOneCommit.Result r = createChange();
gApi.changes()
.id(r.getChangeId())
.revision(r.getCommit().name())
.review(ReviewInput.approve());
gApi.changes()
.id(r.getChangeId())
.revision(r.getCommit().name())
.submit();
Change c = getChange(r);
c.setStatus(Change.Status.NEW);
db.changes().update(Collections.singleton(c));
ChangeUpdate changeUpdate =
changeUpdateFactory.create(
changeControlFactory.controlFor(
c, userFactory.create(admin.id)));
changeUpdate.setStatus(Change.Status.NEW);
changeUpdate.commit();
indexer.index(db, c);
ChangeInfo info = gApi.changes()
.id(r.getChangeId())
.check();
assertThat(info.problems).hasSize(1);
assertThat(info.problems.get(0).status).isNull();
assertThat(info.status).isEqualTo(ChangeStatus.NEW);
info = gApi.changes()
.id(r.getChangeId())
.check(new FixInput());
assertThat(info.problems).hasSize(1);
assertThat(info.problems.get(0).status).isEqualTo(ProblemInfo.Status.FIXED);
assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
info = gApi.changes()
.id(r.getChangeId())
.get();
assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
}
private Change getChange(PushOneCommit.Result r) throws Exception {
return db.changes().get(new Change.Id(
gApi.changes().id(r.getChangeId()).get()._number));
}
}

View File

@@ -27,6 +27,8 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.extensions.api.changes.FixInput;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ProblemInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
@@ -390,6 +392,26 @@ public class ConsistencyCheckerIT extends AbstractDaemonTest {
assertProblems(c);
}
@Test
public void extensionApiReturnsUpdatedValueAfterFix() throws Exception {
Change c = insertChange();
RevCommit commit = testRepo.branch(c.currentPatchSetId().toRefName()).commit()
.parent(tip).create();
PatchSet ps = newPatchSet(c.currentPatchSetId(), commit, adminId);
db.patchSets().insert(singleton(ps));
testRepo.branch(c.getDest().get()).update(commit);
ChangeInfo info = gApi.changes()
.id(c.getChangeId())
.info();
assertThat(info.status).isEqualTo(ChangeStatus.NEW);
info = gApi.changes()
.id(c.getChangeId())
.check(new FixInput());
assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
}
@Test
public void expectedMergedCommitIsLatestPatchSet() throws Exception {
Change c = insertChange();