Scaffolding of the healthcheck API and build

Define the overall structure of the health check API,
with its return code and expected payload.

Add the overall Bazel build and acceptance tests.

Change-Id: Ifc25fcfa97c1fb4824e472349b8ae435e0f9551b
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..b73a92e
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,36 @@
+load(
+    "//tools/bzl:plugin.bzl",
+    "PLUGIN_DEPS",
+    "PLUGIN_TEST_DEPS",
+    "gerrit_plugin",
+)
+load("//tools/bzl:junit.bzl", "junit_tests")
+
+gerrit_plugin(
+    name = "healthcheck",
+    srcs = glob(["src/main/java/**/*.java"]),
+    manifest_entries = [
+        "Gerrit-PluginName: healthcheck",
+        "Gerrit-SysModule: com.googlesource.gerrit.plugins.healthcheck.Module",
+        "Gerrit-HttpModule: com.googlesource.gerrit.plugins.healthcheck.HttpModule",
+    ],
+    resources = glob(["src/main/resources/**/*"]),
+)
+
+junit_tests(
+    name = "healthcheck_tests",
+    srcs = glob(["src/test/java/**/*.java"]),
+    resources = glob(["src/test/resources/**/*"]),
+    deps = [
+        ":healthcheck__plugin_test_deps",
+    ],
+)
+
+java_library(
+    name = "healthcheck__plugin_test_deps",
+    testonly = 1,
+    visibility = ["//visibility:public"],
+    exports = PLUGIN_DEPS + PLUGIN_TEST_DEPS + [
+        ":healthcheck__plugin",
+    ],
+)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckStatusEndpoint.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckStatusEndpoint.java
new file mode 100644
index 0000000..4479c66
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckStatusEndpoint.java
@@ -0,0 +1,32 @@
+// Copyright (C) 2019 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.googlesource.gerrit.plugins.healthcheck;
+
+import com.google.gerrit.extensions.restapi.AuthException;
+import com.google.gerrit.extensions.restapi.BadRequestException;
+import com.google.gerrit.extensions.restapi.ResourceConflictException;
+import com.google.gerrit.extensions.restapi.RestReadView;
+import com.google.gerrit.server.config.ConfigResource;
+import com.google.inject.Singleton;
+
+@Singleton
+public class HealthCheckStatusEndpoint implements RestReadView<ConfigResource> {
+
+  @Override
+  public Object apply(ConfigResource resource)
+      throws AuthException, BadRequestException, ResourceConflictException, Exception {
+    return "{}";
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/healthcheck/Module.java b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/Module.java
new file mode 100644
index 0000000..91ad431
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/healthcheck/Module.java
@@ -0,0 +1,35 @@
+// Copyright (C) 2019 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.googlesource.gerrit.plugins.healthcheck;
+
+import static com.google.gerrit.server.config.ConfigResource.CONFIG_KIND;
+
+import com.google.gerrit.extensions.restapi.RestApiModule;
+import com.google.inject.AbstractModule;
+
+public class Module extends AbstractModule {
+
+  @Override
+  protected void configure() {
+    install(
+        new RestApiModule() {
+
+          @Override
+          protected void configure() {
+            get(CONFIG_KIND, "status").to(HealthCheckStatusEndpoint.class);
+          }
+        });
+  }
+}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckTest.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckTest.java
new file mode 100644
index 0000000..f239f5d
--- /dev/null
+++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/HealthCheckTest.java
@@ -0,0 +1,45 @@
+// Copyright (C) 2019 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.googlesource.gerrit.plugins.healthcheck;
+
+import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
+import com.google.gerrit.acceptance.RestResponse;
+import com.google.gerrit.acceptance.TestPlugin;
+import java.io.IOException;
+import org.junit.Test;
+
+@TestPlugin(
+    name = "healthcheck",
+    sysModule = "com.googlesource.gerrit.plugins.healthcheck.Module",
+    httpModule = "com.googlesource.gerrit.plugins.healthcheck.HttpModule")
+public class HealthCheckTest extends LightweightPluginDaemonTest {
+
+  @Test
+  public void shouldReturnOkWhenHealthy() throws Exception {
+    getHealthCheckStatus().assertOK();
+  }
+
+  @Test
+  public void shouldReturnAJsonPayload() throws Exception {
+    assertThat(getHealthCheckStatus().getHeader(CONTENT_TYPE)).contains("application/json");
+  }
+
+  private RestResponse getHealthCheckStatus() throws IOException {
+    return adminRestSession.get("/config/server/healthcheck~status");
+  }
+}