Show that CodeOwnersSubmitRule is run twice when a Code-Owners SR is configured

Add a test to show that the CodeOwnersSubmitRule is executed twice when
a Code-Owners submit requirement is configured, once because the
CodeOwnerSubmitRule implements the SubmitRule extension point and once
because there is submit requirement configured that uses the
CodeOwnerApprovalPredicate.

CodeOwnerApprovalPredicate was added by change I391a0d7fd as part of
replacing submit rules with submit requirements, but then submit rules
were not migrated to submit requirements.

Bug: Google b/325070428
Change-Id: I07f9ed1f0dff448b5b51d9dd232184648e88652a
Signed-off-by: Edwin Kempin <ekempin@google.com>
Reviewed-on: https://gerrit-review.googlesource.com/c/plugins/code-owners/+/412200
Tested-by: Zuul <zuul-63@gerritcodereview-ci.iam.gserviceaccount.com>
Reviewed-by: Patrick Hiesel <hiesel@google.com>
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
index 2d2c8c7..618f5df 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
@@ -14,7 +14,6 @@
 
 package com.google.gerrit.plugins.codeowners.acceptance.api;
 
-import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction;
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.TruthJUnit.assume;
 import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel;
@@ -22,6 +21,7 @@
 import static com.google.gerrit.plugins.codeowners.testing.LegacySubmitRequirementInfoSubject.assertThatCollection;
 import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
 import static com.google.gerrit.testing.GerritJUnit.assertThrows;
+import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -41,6 +41,7 @@
 import com.google.gerrit.extensions.client.ChangeStatus;
 import com.google.gerrit.extensions.client.ListChangesOption;
 import com.google.gerrit.extensions.common.ChangeInfo;
+import com.google.gerrit.extensions.common.SubmitRequirementInput;
 import com.google.gerrit.extensions.restapi.ResourceConflictException;
 import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersIT;
 import com.google.gerrit.plugins.codeowners.api.CodeOwnerStatusInfo;
@@ -698,6 +699,31 @@
   }
 
   @Test
+  public void submitRuleIsInvokedTwiceWhenACodeOwnersSubmitRequirementIsConfigured()
+      throws Exception {
+    // Configure a Code-Owners submit requirement
+    SubmitRequirementInput input = new SubmitRequirementInput();
+    input.name = "Code-Owners";
+    input.submittabilityExpression = "has:approval_code-owners";
+    gApi.projects().name(project.get()).submitRequirement("Code-Owners").create(input);
+
+    // Getting change details triggers the Code-Owners submit requirement twice, once because the
+    // CodeOwnerSubmitRule implements the SubmitRule extension point and once because there is a
+    // submit requirement configured that uses the CodeOwnerApprovalPredicate.
+    PushOneCommit.Result r = createChange("Some Change", "foo.txt", "some content");
+    String changeId = r.getChangeId();
+
+    testMetricMaker.reset();
+    gApi.changes()
+        .id(changeId)
+        .get(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS);
+
+    // Submit rules are computed freshly, but only once.
+    assertThat(testMetricMaker.getCount("plugins/code-owners/count_code_owner_submit_rule_runs"))
+        .isEqualTo(2);
+  }
+
+  @Test
   public void submitRuleIsNotInvokedWhenQueryingChange() throws Exception {
     PushOneCommit.Result r = createChange("Some Change", "foo.txt", "some content");
     String changeId = r.getChangeId();