Merge "Add acceptance test for plugin URL bindings"
This commit is contained in:
commit
b2c77a09ad
java/com/google/gerrit/acceptance
javatests/com/google/gerrit/acceptance/rest/binding
@ -1587,19 +1587,27 @@ public abstract class AbstractDaemonTest {
|
||||
|
||||
protected AutoCloseable installPlugin(String pluginName, Class<? extends Module> sysModuleClass)
|
||||
throws Exception {
|
||||
checkArgument(
|
||||
(sysModuleClass.getModifiers() & Modifier.STATIC) != 0,
|
||||
"module must be static: %s",
|
||||
sysModuleClass.getName());
|
||||
return installPlugin(pluginName, sysModuleClass, null, null);
|
||||
}
|
||||
|
||||
protected AutoCloseable installPlugin(
|
||||
String pluginName,
|
||||
@Nullable Class<? extends Module> sysModuleClass,
|
||||
@Nullable Class<? extends Module> httpModuleClass,
|
||||
@Nullable Class<? extends Module> sshModuleClass)
|
||||
throws Exception {
|
||||
checkStatic(sysModuleClass);
|
||||
checkStatic(httpModuleClass);
|
||||
checkStatic(sshModuleClass);
|
||||
TestServerPlugin plugin =
|
||||
new TestServerPlugin(
|
||||
pluginName,
|
||||
"http://example.com/" + pluginName,
|
||||
pluginUserFactory.create(pluginName),
|
||||
getClass().getClassLoader(),
|
||||
sysModuleClass.getName(),
|
||||
null,
|
||||
null,
|
||||
sysModuleClass != null ? sysModuleClass.getName() : null,
|
||||
httpModuleClass != null ? httpModuleClass.getName() : null,
|
||||
sshModuleClass != null ? sshModuleClass.getName() : null,
|
||||
sitePaths.data_dir.resolve(pluginName));
|
||||
plugin.start(pluginGuiceEnvironment);
|
||||
pluginGuiceEnvironment.onStartPlugin(plugin);
|
||||
@ -1608,4 +1616,13 @@ public abstract class AbstractDaemonTest {
|
||||
pluginGuiceEnvironment.onStopPlugin(plugin);
|
||||
};
|
||||
}
|
||||
|
||||
private static void checkStatic(@Nullable Class<? extends Module> moduleClass) {
|
||||
if (moduleClass != null) {
|
||||
checkArgument(
|
||||
(moduleClass.getModifiers() & Modifier.STATIC) != 0,
|
||||
"module must be static: %s",
|
||||
moduleClass.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
75
javatests/com/google/gerrit/acceptance/rest/binding/PluginProvidedRestApiBindingsIT.java
Normal file
75
javatests/com/google/gerrit/acceptance/rest/binding/PluginProvidedRestApiBindingsIT.java
Normal file
@ -0,0 +1,75 @@
|
||||
// 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.google.gerrit.acceptance.rest.binding;
|
||||
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.rest.util.RestApiCallHelper;
|
||||
import com.google.gerrit.acceptance.rest.util.RestCall;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for checking plugin-provided REST API bindings.
|
||||
*
|
||||
* <p>These tests only verify that the plugin-provided REST endpoints are correctly bound, they do
|
||||
* not test the functionality of the plugin REST endpoints.
|
||||
*/
|
||||
public class PluginProvidedRestApiBindingsIT extends AbstractDaemonTest {
|
||||
|
||||
/**
|
||||
* Plugin REST endpoints bound by {@link MyPluginModule} with Guice serlvet definitions.
|
||||
*
|
||||
* <p>Each URL contains a placeholder for the plugin identifier.
|
||||
*
|
||||
* <p>Currently does not include any resource or documentation URLs, since those would require
|
||||
* installing a plugin from a jar, which is trickier than just defining a module in this file.
|
||||
*/
|
||||
private static final ImmutableList<RestCall> SERVER_TOP_LEVEL_PLUGIN_ENDPOINTS =
|
||||
ImmutableList.of(RestCall.get("/plugins/%s/hello"));
|
||||
|
||||
static class MyPluginModule extends ServletModule {
|
||||
@Override
|
||||
public void configureServlets() {
|
||||
serve("/hello").with(HelloServlet.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
static class HelloServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
|
||||
res.setStatus(SC_OK);
|
||||
res.getWriter().println("Hello world");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverPluginTopLevelEndpoints() throws Exception {
|
||||
String pluginName = "my-plugin";
|
||||
try (AutoCloseable ignored = installPlugin(pluginName, null, MyPluginModule.class, null)) {
|
||||
RestApiCallHelper.execute(adminRestSession, SERVER_TOP_LEVEL_PLUGIN_ENDPOINTS, pluginName);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,12 +27,12 @@ import com.google.gerrit.extensions.restapi.RawInput;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for checking the bindings of the plugins REST API.
|
||||
* Tests for checking the remote administration bindings of the plugins REST API.
|
||||
*
|
||||
* <p>These tests only verify that the plugin REST endpoints are correctly bound, they do no test
|
||||
* the functionality of the plugin REST endpoints.
|
||||
*/
|
||||
public class PluginsRestApiBindingsIT extends AbstractDaemonTest {
|
||||
public class PluginsRemoteAdminRestApiBindingsIT extends AbstractDaemonTest {
|
||||
/**
|
||||
* Plugin REST endpoints to be tested, each URL contains a placeholder for the plugin identifier.
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user