Manually bind plugin guice modules in gerrit Guice universe
Short circuit the plugin loading phase from the unit tests by passing
the module names from the manifest file.
This allows us to avoid building and deploying the plugin JAR from
within build tool chain.
To use the simplified plugin bootstrap tests, plugin test class must
be inherited from the LightweightPluginDaemonTest class and must be
annotated with @TestPlugin annotation:
@TestPlugin(
name = "cookbook",
sysModule = "com.googlesource.gerrit.plugins.cookbook.Module",
httpModule = "com.googlesource.gerrit.plugins.cookbook.HttpModule",
sshModule = "com.googlesource.gerrit.plugins.cookbook.SshModule"
)
public class CookbookIT extends LightweightPluginDaemonTest {
@Test
public void revisionTest() throws Exception {
createChange();
RestResponse response =
adminRestSession.post("/changes/1/revisions/1/cookbook~hello-revision");
assertThat(response.getEntityContent())
.contains("Hello admin from change 1, patch set 1!");
}
}
Inspired-By: Dave Borowitz <dborowitz@google.com>
Change-Id: I689bb71413ecfbbf99f72730b0d2617bf526d9dd
This commit is contained in:
committed by
David Ostrovsky
parent
9c6306532b
commit
8df8af2572
@@ -0,0 +1,64 @@
|
||||
// Copyright (C) 2016 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;
|
||||
|
||||
import com.google.gerrit.server.PluginUser;
|
||||
import com.google.gerrit.server.plugins.PluginGuiceEnvironment;
|
||||
import com.google.gerrit.server.plugins.TestServerPlugin;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class LightweightPluginDaemonTest extends AbstractDaemonTest {
|
||||
@Inject
|
||||
private PluginGuiceEnvironment env;
|
||||
|
||||
@Inject
|
||||
private PluginUser.Factory pluginUserFactory;
|
||||
|
||||
private TestServerPlugin plugin;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestPlugin testPlugin = getTestPlugin(getClass());
|
||||
String name = testPlugin.name();
|
||||
plugin = new TestServerPlugin(name,
|
||||
canonicalWebUrl.get() + "plugins/" + name,
|
||||
pluginUserFactory.create(name),
|
||||
getClass().getClassLoader(),
|
||||
testPlugin.sysModule(),
|
||||
testPlugin.httpModule(),
|
||||
testPlugin.sshModule());
|
||||
|
||||
plugin.start(env);
|
||||
env.onStartPlugin(plugin);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
plugin.stop(env);
|
||||
env.onStopPlugin(plugin);
|
||||
}
|
||||
|
||||
private static TestPlugin getTestPlugin(Class<?> clazz) {
|
||||
for (; clazz != null; clazz = clazz.getSuperclass()) {
|
||||
if (clazz.getAnnotation(TestPlugin.class) != null) {
|
||||
return clazz.getAnnotation(TestPlugin.class);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("TestPlugin annotation missing");
|
||||
}
|
||||
}
|
||||
@@ -104,12 +104,11 @@ public abstract class PluginDaemonTest extends AbstractDaemonTest {
|
||||
if (subPath.endsWith("plugins")) {
|
||||
pluginsIdx = idx;
|
||||
}
|
||||
if (subPath.endsWith(BAZELOUT)) {
|
||||
if (subPath.endsWith(BAZELOUT) || subPath.endsWith(ECLIPSE)) {
|
||||
bazel = true;
|
||||
buckOutIdx = idx;
|
||||
}
|
||||
// TODO(davido): Fix Bazel plugin test from Eclipse
|
||||
if (subPath.endsWith(BUCKOUT) || subPath.endsWith(ECLIPSE)) {
|
||||
if (subPath.endsWith(BUCKOUT)) {
|
||||
buckOutIdx = idx;
|
||||
}
|
||||
idx++;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2016 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;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({TYPE})
|
||||
@Retention(RUNTIME)
|
||||
public @interface TestPlugin {
|
||||
String name();
|
||||
|
||||
String sysModule() default "";
|
||||
String httpModule() default "";
|
||||
String sshModule() default "";
|
||||
}
|
||||
Reference in New Issue
Block a user