Add integration test for Check Code Owner capability

This increases the test coverage for CheckCodeOwnerCapability from 80%
to 100%. More importantly now all functions are covered.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ic52fafc5d5a944a51430bfc84d08d3a505b4c41d
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD b/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD
index 82f4772..8593c50 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD
@@ -18,6 +18,7 @@
         "//plugins/code-owners/java/com/google/gerrit/plugins/codeowners/acceptance/testsuite",
         "//plugins/code-owners/java/com/google/gerrit/plugins/codeowners/api",
         "//plugins/code-owners/java/com/google/gerrit/plugins/codeowners/backend",
+        "//plugins/code-owners/java/com/google/gerrit/plugins/codeowners/restapi",
         "//plugins/code-owners/java/com/google/gerrit/plugins/codeowners/testing",
         "//plugins/code-owners/java/com/google/gerrit/plugins/codeowners/util",
     ],
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/CheckCodeOwnerCapabilityRestIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/CheckCodeOwnerCapabilityRestIT.java
new file mode 100644
index 0000000..b546baa
--- /dev/null
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/CheckCodeOwnerCapabilityRestIT.java
@@ -0,0 +1,63 @@
+// Copyright (C) 2021 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.plugins.codeowners.acceptance.restapi;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability;
+import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
+
+import com.google.gerrit.acceptance.RestResponse;
+import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
+import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersIT;
+import com.google.gerrit.plugins.codeowners.restapi.CheckCodeOwnerCapability;
+import com.google.gerrit.server.restapi.config.ListCapabilities.CapabilityInfo;
+import com.google.gson.reflect.TypeToken;
+import com.google.inject.Inject;
+import java.util.Map;
+import org.junit.Test;
+
+/**
+ * Acceptance test for {@link
+ * com.google.gerrit.plugins.codeowners.restapi.CheckCodeOwnerCapability}.
+ */
+public class CheckCodeOwnerCapabilityRestIT extends AbstractCodeOwnersIT {
+  @Inject private ProjectOperations projectOperations;
+
+  @Test
+  public void listCapabilities() throws Exception {
+    RestResponse r = adminRestSession.get("/config/server/capabilities");
+    r.assertOK();
+    Map<String, CapabilityInfo> capabilities =
+        newGson()
+            .fromJson(r.getReader(), new TypeToken<Map<String, CapabilityInfo>>() {}.getType());
+    CapabilityInfo capabilityInfo = capabilities.get("code-owners-" + CheckCodeOwnerCapability.ID);
+    assertThat(capabilityInfo.id).isEqualTo("code-owners-" + CheckCodeOwnerCapability.ID);
+    assertThat(capabilityInfo.name).isEqualTo("Check Code Owner");
+  }
+
+  @Test
+  public void getAccountCapabilities() throws Exception {
+    projectOperations
+        .allProjectsForUpdate()
+        .add(allowCapability("code-owners-" + CheckCodeOwnerCapability.ID).group(REGISTERED_USERS))
+        .update();
+
+    RestResponse r = adminRestSession.get("/accounts/self/capabilities");
+    r.assertOK();
+    Map<String, Object> capabilities =
+        newGson().fromJson(r.getReader(), new TypeToken<Map<String, Object>>() {}.getType());
+    assertThat(capabilities).containsEntry("code-owners-" + CheckCodeOwnerCapability.ID, true);
+  }
+}