Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  Forwarder tests: Replace null event json with valid one
  Add .apt_generated directory to .gitignore
  Update mockito-core to 2.24.0
  RestForwarderServletModuleIT: Add a cache wildcard endpoint test
  RestForwarderServletModule: Add missing wildcard to event endpoint

Change-Id: I60e2399e9ac00cf56f54c7e5d17544bfadea87d6
diff --git a/.gitignore b/.gitignore
index 912f8a6..0f6afe5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/.apt_generated/
 /.classpath
 /.project
 /.settings/
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index d6f303f..232314b 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -9,8 +9,8 @@
 
     maven_jar(
         name = "mockito",
-        artifact = "org.mockito:mockito-core:2.23.4",
-        sha1 = "a35b6f8ffcfa786771eac7d7d903429e790fdf3f",
+        artifact = "org.mockito:mockito-core:2.24.0",
+        sha1 = "969a7bcb6f16e076904336ebc7ca171d412cc1f9",
         deps = [
             "@byte-buddy//jar",
             "@byte-buddy-agent//jar",
@@ -18,18 +18,18 @@
         ],
     )
 
-    BYTE_BUDDY_VERSION = "1.9.3"
+    BYTE_BUDDY_VERSION = "1.9.7"
 
     maven_jar(
         name = "byte-buddy",
         artifact = "net.bytebuddy:byte-buddy:" + BYTE_BUDDY_VERSION,
-        sha1 = "f32e510b239620852fc9a2387fac41fd053d6a4d",
+        sha1 = "8fea78fea6449e1738b675cb155ce8422661e237",
     )
 
     maven_jar(
         name = "byte-buddy-agent",
         artifact = "net.bytebuddy:byte-buddy-agent:" + BYTE_BUDDY_VERSION,
-        sha1 = "f5b78c16cf4060664d80b6ca32d80dca4bd3d264",
+        sha1 = "8e7d1b599f4943851ffea125fd9780e572727fc0",
     )
 
     maven_jar(
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java
index 9752e1a..43795e0 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModule.java
@@ -22,7 +22,7 @@
     serveRegex("/index/account/\\d+$").with(IndexAccountRestApiServlet.class);
     serveRegex("/index/change/.*$").with(IndexChangeRestApiServlet.class);
     serveRegex("/index/group/\\w+$").with(IndexGroupRestApiServlet.class);
-    serve("/event").with(EventRestApiServlet.class);
+    serve("/event/*").with(EventRestApiServlet.class);
     serve("/cache/project_list/*").with(ProjectListApiServlet.class);
     serve("/cache/*").with(CacheRestApiServlet.class);
   }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java
index dbf6342..02b4a47 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java
@@ -28,7 +28,7 @@
 
   private EventListener listenerMock;
   private ForwardedAwareEventBroker broker;
-  private Event event = new Event(null) {};
+  private Event event = new TestEvent();
 
   @Before
   public void setUp() {
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/TestEvent.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/TestEvent.java
new file mode 100644
index 0000000..f2f22cd
--- /dev/null
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/TestEvent.java
@@ -0,0 +1,33 @@
+// 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.ericsson.gerrit.plugins.highavailability.forwarder;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.server.events.Event;
+import org.junit.Test;
+
+public class TestEvent extends Event {
+  private static final String TYPE = "test-event";
+
+  public TestEvent() {
+    super(TYPE);
+  }
+
+  @Test
+  public void typeSet() {
+    assertThat(getType()).isEqualTo(TYPE);
+  }
+}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModuleIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModuleIT.java
new file mode 100644
index 0000000..0092902
--- /dev/null
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderServletModuleIT.java
@@ -0,0 +1,59 @@
+// 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.ericsson.gerrit.plugins.highavailability.forwarder.rest;
+
+import com.ericsson.gerrit.plugins.highavailability.forwarder.TestEvent;
+import com.google.common.base.Joiner;
+import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
+import com.google.gerrit.acceptance.NoHttpd;
+import com.google.gerrit.acceptance.TestPlugin;
+import com.google.gerrit.acceptance.UseLocalDisk;
+import com.google.gerrit.server.events.Event;
+import javax.servlet.http.HttpServletResponse;
+import org.junit.Test;
+
+@NoHttpd
+@TestPlugin(
+    name = "high-availability",
+    sysModule = "com.ericsson.gerrit.plugins.highavailability.Module",
+    httpModule = "com.ericsson.gerrit.plugins.highavailability.HttpModule")
+public class RestForwarderServletModuleIT extends LightweightPluginDaemonTest {
+
+  private final Event event = new TestEvent();
+  private final String endpointPrefix = "/plugins/high-availability";
+  private final String eventEndpointSuffix = "event";
+
+  @Test
+  @UseLocalDisk
+  public void serveTypedEventEndpoint() throws Exception {
+    adminRestSession
+        .post(Joiner.on("/").join(endpointPrefix, eventEndpointSuffix, event.type), event)
+        .assertStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+  }
+
+  @Test
+  @UseLocalDisk
+  public void doNotServeStraightEventEndpoint() throws Exception {
+    adminRestSession
+        .post(Joiner.on("/").join(endpointPrefix, eventEndpointSuffix), event)
+        .assertMethodNotAllowed();
+  }
+
+  @Test
+  @UseLocalDisk
+  public void doNotServeStraightCacheEndpoint() throws Exception {
+    adminRestSession.post(Joiner.on("/").join(endpointPrefix, "cache")).assertMethodNotAllowed();
+  }
+}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
index c5b52a0..d516d09 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
@@ -25,6 +25,7 @@
 import com.ericsson.gerrit.plugins.highavailability.Configuration;
 import com.ericsson.gerrit.plugins.highavailability.cache.Constants;
 import com.ericsson.gerrit.plugins.highavailability.forwarder.IndexEvent;
+import com.ericsson.gerrit.plugins.highavailability.forwarder.TestEvent;
 import com.ericsson.gerrit.plugins.highavailability.forwarder.rest.HttpResponseHandler.HttpResult;
 import com.ericsson.gerrit.plugins.highavailability.peers.PeerInfo;
 import com.google.common.base.Joiner;
@@ -75,7 +76,7 @@
       Joiner.on("/").join(URL, PLUGINS, PLUGIN_NAME, "index/group", UUID);
 
   // Event
-  private static Event event = new Event("test-event") {};
+  private static Event event = new TestEvent();
   private static final String EVENT_ENDPOINT =
       Joiner.on("/").join(URL, PLUGINS, PLUGIN_NAME, "event", event.type);