Add support for plugin-owned capabilities
Plugin contributed SSH commands and UiActions can now be annotated with plugin-owned capabilities. Capability scope was introduced to differentiate between plugin-owned capabilities and core capabilities. Per default the scope of @RequiresCapability annotation is CapabilityScope.CONTEXT, i. e. when @RequiresCapability is used within a plugin the scope of the capability is assumed to be that plugin. If @RequiresCapability is used within the core Gerrit Code Review server (and thus is outside of a plugin) the scope is the core server and will use the GlobalCapability known to Gerrit Code Review server. If a plugin needs to use a core capability name (e.g. "administrateServer") this can be specified by setting scope = CapabilityScope.CORE: @RequiresCapability(value="administrateServer", scope=CapabilityScope.CORE) Change-Id: I82f7a6fef2a47613a1fd9c7474ff568db3ca84a2
This commit is contained in:
@@ -19,21 +19,55 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.Exports;
|
||||
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.server.config.ListCapabilities.CapabilityInfo;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListCapabilitiesTest {
|
||||
private Injector injector;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
AbstractModule mod = new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
DynamicMap.mapOf(binder(), CapabilityDefinition.class);
|
||||
bind(CapabilityDefinition.class)
|
||||
.annotatedWith(Exports.named("printHello"))
|
||||
.toInstance(new CapabilityDefinition() {
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Print Hello";
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
injector = Guice.createInjector(mod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() throws Exception {
|
||||
Map<String, CapabilityInfo> m =
|
||||
new ListCapabilities().apply(new ConfigResource());
|
||||
injector.getInstance(ListCapabilities.class)
|
||||
.apply(new ConfigResource());
|
||||
for (String id : GlobalCapability.getAllNames()) {
|
||||
assertTrue("contains " + id, m.containsKey(id));
|
||||
assertEquals(id, m.get(id).id);
|
||||
assertNotNull(id + " has name", m.get(id).name);
|
||||
}
|
||||
|
||||
String pluginCapability = "gerrit-printHello";
|
||||
assertTrue("contains " + pluginCapability, m.containsKey(pluginCapability));
|
||||
assertEquals(pluginCapability, m.get(pluginCapability).id);
|
||||
assertEquals("Print Hello", m.get(pluginCapability).name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user