Search in sources :

Example 1 with PluginApi

use of com.google.gerrit.extensions.api.plugins.PluginApi in project gerrit by GerritCodeReview.

the class PluginIT method pluginManagement.

@Test
@GerritConfig(name = "plugins.allowRemoteAdmin", value = "true")
public void pluginManagement() throws Exception {
    // No plugins are loaded
    assertThat(list().get()).isEmpty();
    assertThat(list().all().get()).isEmpty();
    PluginApi api;
    // Install all the plugins
    InstallPluginInput input = new InstallPluginInput();
    for (String plugin : PLUGINS) {
        input.raw = pluginContent(plugin);
        api = gApi.plugins().install(plugin, input);
        assertThat(api).isNotNull();
        PluginInfo info = api.get();
        String name = pluginName(plugin);
        assertThat(info.id).isEqualTo(name);
        assertThat(info.version).isEqualTo(pluginVersion(plugin));
        assertThat(info.apiVersion).isEqualTo(pluginApiVersion(plugin));
        assertThat(info.indexUrl).isEqualTo(String.format("plugins/%s/", name));
        assertThat(info.filename).isEqualTo(plugin);
        assertThat(info.disabled).isNull();
    }
    assertPlugins(list().get(), PLUGINS);
    // With pagination
    assertPlugins(list().start(1).limit(2).get(), PLUGINS.subList(1, 3));
    // With prefix
    assertPlugins(list().prefix("plugin-b").get(), ImmutableList.of("plugin-b.js"));
    assertPlugins(list().prefix("PLUGIN-").get(), ImmutableList.of());
    // With substring
    assertPlugins(list().substring("lugin-").get(), PLUGINS.subList(0, PLUGINS.size() - 1));
    assertPlugins(list().substring("lugin-").start(1).limit(2).get(), PLUGINS.subList(1, 3));
    // With regex
    assertPlugins(list().regex(".*in-b").get(), ImmutableList.of("plugin-b.js"));
    assertPlugins(list().regex("plugin-.*").get(), PLUGINS.subList(0, PLUGINS.size() - 1));
    assertPlugins(list().regex("plugin-.*").start(1).limit(2).get(), PLUGINS.subList(1, 3));
    // Invalid match combinations
    assertBadRequest(list().regex(".*in-b").substring("a"));
    assertBadRequest(list().regex(".*in-b").prefix("a"));
    assertBadRequest(list().substring(".*in-b").prefix("a"));
    // Disable mandatory
    mandatoryPluginsCollection.add("plugin_e");
    assertThrows(MethodNotAllowedException.class, () -> gApi.plugins().name("plugin_e").disable());
    api = gApi.plugins().name("plugin_e");
    assertThat(api.get().disabled).isNull();
    // Disable non-mandatory
    api = gApi.plugins().name("plugin-a");
    api.disable();
    api = gApi.plugins().name("plugin-a");
    assertThat(api.get().disabled).isTrue();
    assertPlugins(list().get(), PLUGINS.subList(1, PLUGINS.size()));
    assertPlugins(list().all().get(), PLUGINS);
    // Enable
    api.enable();
    api = gApi.plugins().name("plugin-a");
    assertThat(api.get().disabled).isNull();
    assertPlugins(list().get(), PLUGINS);
    // Using deprecated input
    deprecatedInput();
    // Non-admin cannot disable
    requestScopeOperations.setApiUser(user.id());
    assertThrows(AuthException.class, () -> gApi.plugins().name("plugin-a").disable());
}
Also used : InstallPluginInput(com.google.gerrit.extensions.api.plugins.InstallPluginInput) PluginInfo(com.google.gerrit.extensions.common.PluginInfo) PluginApi(com.google.gerrit.extensions.api.plugins.PluginApi) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 InstallPluginInput (com.google.gerrit.extensions.api.plugins.InstallPluginInput)1 PluginApi (com.google.gerrit.extensions.api.plugins.PluginApi)1 PluginInfo (com.google.gerrit.extensions.common.PluginInfo)1 Test (org.junit.Test)1