Search in sources :

Example 1 with LegacySubmitRequirementInfo

use of com.google.gerrit.extensions.common.LegacySubmitRequirementInfo in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRecords.

@Test
public void submitRecords() throws Exception {
    PushOneCommit.Result r = createChange();
    TestSubmitRule testSubmitRule = new TestSubmitRule();
    try (Registration registration = extensionRegistry.newRegistration().add(testSubmitRule)) {
        String changeId = r.getChangeId();
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRecords).hasSize(2);
        // Check the default submit record for the code-review label
        SubmitRecordInfo codeReviewRecord = Iterables.get(change.submitRecords, 0);
        assertThat(codeReviewRecord.ruleName).isEqualTo("gerrit~DefaultSubmitRule");
        assertThat(codeReviewRecord.status).isEqualTo(SubmitRecordInfo.Status.NOT_READY);
        assertThat(codeReviewRecord.labels).hasSize(1);
        SubmitRecordInfo.Label label = Iterables.getOnlyElement(codeReviewRecord.labels);
        assertThat(label.label).isEqualTo("Code-Review");
        assertThat(label.status).isEqualTo(SubmitRecordInfo.Label.Status.NEED);
        assertThat(label.appliedBy).isNull();
        // Check the custom test record created by the TestSubmitRule
        SubmitRecordInfo testRecord = Iterables.get(change.submitRecords, 1);
        assertThat(testRecord.ruleName).isEqualTo("testSubmitRule");
        assertThat(testRecord.status).isEqualTo(SubmitRecordInfo.Status.OK);
        assertThat(testRecord.requirements).containsExactly(new LegacySubmitRequirementInfo("OK", "fallback text", "type"));
        assertThat(testRecord.labels).hasSize(1);
        SubmitRecordInfo.Label testLabel = Iterables.getOnlyElement(testRecord.labels);
        assertThat(testLabel.label).isEqualTo("label");
        assertThat(testLabel.status).isEqualTo(SubmitRecordInfo.Label.Status.OK);
        assertThat(testLabel.appliedBy).isNull();
        voteLabel(changeId, "Code-Review", 2);
        // Code review record is satisfied after voting +2
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRecords).hasSize(2);
        codeReviewRecord = Iterables.get(change.submitRecords, 0);
        assertThat(codeReviewRecord.ruleName).isEqualTo("gerrit~DefaultSubmitRule");
        assertThat(codeReviewRecord.status).isEqualTo(SubmitRecordInfo.Status.OK);
        assertThat(codeReviewRecord.labels).hasSize(1);
        label = Iterables.getOnlyElement(codeReviewRecord.labels);
        assertThat(label.label).isEqualTo("Code-Review");
        assertThat(label.status).isEqualTo(SubmitRecordInfo.Label.Status.OK);
        assertThat(label.appliedBy._accountId).isEqualTo(admin.id().get());
    }
}
Also used : LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 LegacySubmitRequirementInfo (com.google.gerrit.extensions.common.LegacySubmitRequirementInfo)1 SubmitRecordInfo (com.google.gerrit.extensions.common.SubmitRecordInfo)1 Test (org.junit.Test)1