Introduce top-menu APIs
Expose the ability to invoke the list of top-menu items provided by plugins through the GerritApi. Main use-case is enabling the automation of tests that need to verify the top-menu items configuration. Change-Id: Ic2f5b6c9dc07e9695a75f07372d11c5e6d731761
This commit is contained in:
committed by
David Pursehouse
parent
b9368021a3
commit
a95b8da931
@@ -20,6 +20,8 @@ import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.ServerInfo;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.webui.TopMenu;
|
||||
import java.util.List;
|
||||
|
||||
public interface Server {
|
||||
/** @return Version of server. */
|
||||
@@ -41,6 +43,8 @@ public interface Server {
|
||||
|
||||
ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException;
|
||||
|
||||
List<TopMenu.MenuEntry> topMenus() throws RestApiException;
|
||||
|
||||
/**
|
||||
* A default implementation which allows source compatibility when adding new methods to the
|
||||
* interface.
|
||||
@@ -93,5 +97,10 @@ public interface Server {
|
||||
public ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TopMenu.MenuEntry> topMenus() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,18 +25,21 @@ import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.ServerInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.webui.TopMenu;
|
||||
import com.google.gerrit.server.config.ConfigResource;
|
||||
import com.google.gerrit.server.restapi.config.CheckConsistency;
|
||||
import com.google.gerrit.server.restapi.config.GetDiffPreferences;
|
||||
import com.google.gerrit.server.restapi.config.GetEditPreferences;
|
||||
import com.google.gerrit.server.restapi.config.GetPreferences;
|
||||
import com.google.gerrit.server.restapi.config.GetServerInfo;
|
||||
import com.google.gerrit.server.restapi.config.ListTopMenus;
|
||||
import com.google.gerrit.server.restapi.config.SetDiffPreferences;
|
||||
import com.google.gerrit.server.restapi.config.SetEditPreferences;
|
||||
import com.google.gerrit.server.restapi.config.SetPreferences;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
@Singleton
|
||||
public class ServerImpl implements Server {
|
||||
@@ -48,6 +51,7 @@ public class ServerImpl implements Server {
|
||||
private final SetEditPreferences setEditPreferences;
|
||||
private final GetServerInfo getServerInfo;
|
||||
private final Provider<CheckConsistency> checkConsistency;
|
||||
private final ListTopMenus listTopMenus;
|
||||
|
||||
@Inject
|
||||
ServerImpl(
|
||||
@@ -58,7 +62,8 @@ public class ServerImpl implements Server {
|
||||
GetEditPreferences getEditPreferences,
|
||||
SetEditPreferences setEditPreferences,
|
||||
GetServerInfo getServerInfo,
|
||||
Provider<CheckConsistency> checkConsistency) {
|
||||
Provider<CheckConsistency> checkConsistency,
|
||||
ListTopMenus listTopMenus) {
|
||||
this.getPreferences = getPreferences;
|
||||
this.setPreferences = setPreferences;
|
||||
this.getDiffPreferences = getDiffPreferences;
|
||||
@@ -67,6 +72,7 @@ public class ServerImpl implements Server {
|
||||
this.setEditPreferences = setEditPreferences;
|
||||
this.getServerInfo = getServerInfo;
|
||||
this.checkConsistency = checkConsistency;
|
||||
this.listTopMenus = listTopMenus;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,4 +154,9 @@ public class ServerImpl implements Server {
|
||||
throw asRestApiException("Cannot check consistency", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TopMenu.MenuEntry> topMenus() {
|
||||
return listTopMenus.apply(new ConfigResource()).value();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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.api.config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.acceptance.LightweightPluginDaemonTest;
|
||||
import com.google.gerrit.acceptance.TestPlugin;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.webui.TopMenu;
|
||||
import com.google.gerrit.extensions.webui.TopMenu.MenuEntry;
|
||||
import com.google.inject.AbstractModule;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
@TestPlugin(
|
||||
name = "test-topmenus",
|
||||
sysModule = "com.google.gerrit.acceptance.api.config.TopMenusIT$Module")
|
||||
public class TopMenusIT extends LightweightPluginDaemonTest {
|
||||
|
||||
static final TopMenu.MenuEntry TEST_MENU_ENTRY =
|
||||
new TopMenu.MenuEntry("MyMenu", Collections.emptyList());
|
||||
|
||||
public static class Module extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
DynamicSet.bind(binder(), TopMenu.class).to(TopMenuTest.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TopMenuTest implements TopMenu {
|
||||
|
||||
@Override
|
||||
public List<MenuEntry> getEntries() {
|
||||
return Arrays.asList(TEST_MENU_ENTRY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void topMenuShouldReturnOneEntry() throws RestApiException {
|
||||
List<MenuEntry> topMenuItems = gApi.config().server().topMenus();
|
||||
assertThat(topMenuItems).containsExactly(TEST_MENU_ENTRY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user