Line data Source code
1 : // Copyright (C) 2016 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.acceptance; 16 : 17 : import com.google.gerrit.server.PluginUser; 18 : import com.google.gerrit.server.plugins.PluginGuiceEnvironment; 19 : import com.google.gerrit.server.plugins.TestServerPlugin; 20 : import com.google.inject.Inject; 21 : import org.junit.After; 22 : import org.junit.Before; 23 : import org.junit.Rule; 24 : import org.junit.rules.TemporaryFolder; 25 : 26 5 : public class LightweightPluginDaemonTest extends AbstractDaemonTest { 27 : @Inject private PluginGuiceEnvironment env; 28 : 29 : @Inject private PluginUser.Factory pluginUserFactory; 30 : 31 5 : @Rule public TemporaryFolder tempDataDir = new TemporaryFolder(); 32 : 33 : protected TestServerPlugin plugin; 34 : 35 : @Before 36 : public void setUpTestPlugin() throws Exception { 37 5 : TestPlugin testPlugin = getTestPlugin(getClass()); 38 5 : String name = testPlugin.name(); 39 5 : plugin = 40 : new TestServerPlugin( 41 : name, 42 5 : canonicalWebUrl.get() + "plugins/" + name, 43 5 : pluginUserFactory.create(name), 44 5 : getClass().getClassLoader(), 45 5 : testPlugin.sysModule(), 46 5 : testPlugin.httpModule(), 47 5 : testPlugin.sshModule(), 48 5 : tempDataDir.getRoot().toPath()); 49 : 50 5 : plugin.start(env); 51 5 : env.onStartPlugin(plugin); 52 5 : } 53 : 54 : @After 55 : public void tearDownTestPlugin() { 56 5 : if (plugin != null) { 57 : // plugin will be null if the plugin test requires ssh, but the command 58 : // line flag says we are running tests without ssh as the assume() 59 : // statement in AbstractDaemonTest will prevent the execution of setUp() 60 : // in this class 61 5 : plugin.stop(env); 62 5 : env.onStopPlugin(plugin); 63 : } 64 5 : } 65 : 66 : private static TestPlugin getTestPlugin(Class<?> clazz) { 67 5 : for (; clazz != null; clazz = clazz.getSuperclass()) { 68 5 : if (clazz.getAnnotation(TestPlugin.class) != null) { 69 5 : return clazz.getAnnotation(TestPlugin.class); 70 : } 71 : } 72 0 : throw new IllegalStateException("TestPlugin annotation missing"); 73 : } 74 : }