Mercurial > hg > release > thermostat-2.0
changeset 2511:00ee332a96a8
Update LogLevelCompleterService for Declarative Services
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-November/021515.html
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Fri, 04 Nov 2016 11:52:59 -0400 |
parents | 6f13c7edf6a5 |
children | da2170fe3541 |
files | launcher/src/main/java/com/redhat/thermostat/launcher/internal/Activator.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterService.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/ActivatorTest.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterServiceTest.java |
diffstat | 4 files changed, 18 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/Activator.java Thu Nov 03 18:23:07 2016 +0100 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/Activator.java Fri Nov 04 11:52:59 2016 -0400 @@ -323,9 +323,6 @@ }); pingCommandCompleterDepsTracker.open(); - LogLevelCompleterService logLevelCompleterService = new LogLevelCompleterService(); - context.registerService(CompleterService.class.getName(), logLevelCompleterService, null); - context.registerService(CompleterService.class.getName(), helpCommandCompleterService, null); context.registerService(CompleterService.class.getName(), vmIdCompleterService, null); context.registerService(CompleterService.class.getName(), agentIdCompleterService, null);
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterService.java Thu Nov 03 18:23:07 2016 +0100 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterService.java Fri Nov 04 11:52:59 2016 -0400 @@ -36,11 +36,13 @@ package com.redhat.thermostat.launcher.internal; -import com.redhat.thermostat.common.cli.AbstractCompleterService; import com.redhat.thermostat.common.cli.CliCommandOption; +import com.redhat.thermostat.common.cli.CompleterService; import com.redhat.thermostat.common.cli.StringsTabCompleter; import com.redhat.thermostat.common.cli.TabCompleter; import com.redhat.thermostat.common.utils.LoggingUtils; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Service; import java.util.ArrayList; import java.util.Collections; @@ -48,7 +50,9 @@ import java.util.Map; import java.util.Set; -public class LogLevelCompleterService extends AbstractCompleterService { +@Component(immediate = true) +@Service +public class LogLevelCompleterService implements CompleterService { public static final CliCommandOption LOG_LEVEL_OPTION = new CliCommandOption("l", "logLevel", true, "log level", false); @@ -67,8 +71,12 @@ @Override public Map<CliCommandOption, ? extends TabCompleter> getOptionCompleters() { - TabCompleter logLevelCompleter = new StringsTabCompleter(LOG_LEVELS); + return Collections.singletonMap(LOG_LEVEL_OPTION, (TabCompleter) new StringsTabCompleter(LOG_LEVELS)); + } - return Collections.singletonMap(LOG_LEVEL_OPTION, logLevelCompleter); + @Override + public Map<String, Map<CliCommandOption, ? extends TabCompleter>> getSubcommandCompleters() { + return Collections.emptyMap(); } + }
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/ActivatorTest.java Thu Nov 03 18:23:07 2016 +0100 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/ActivatorTest.java Fri Nov 04 11:52:59 2016 -0400 @@ -323,48 +323,6 @@ } @Test - public void testLogLevelCompleterServiceAvailability() throws Exception { - StubBundleContext context = new StubBundleContext(); - MultipleServiceTracker unusedTracker = mock(MultipleServiceTracker.class); - ArgumentCaptor<Action> unusedCaptor = ArgumentCaptor.forClass(Action.class); - Class<?>[] launcherDeps = new Class[] { - Keyring.class, - CommonPaths.class, - SSLConfiguration.class, - }; - whenNew(MultipleServiceTracker.class).withParameterTypes(BundleContext.class, Class[].class, Action.class).withArguments(eq(context), - eq(launcherDeps), unusedCaptor.capture()).thenReturn(unusedTracker); - - Class<?>[] shellDeps = new Class[] { - CommonPaths.class, - ConfigurationInfoSource.class, - }; - whenNew(MultipleServiceTracker.class).withParameterTypes(BundleContext.class, Class[].class, Action.class).withArguments(eq(context), - eq(shellDeps), unusedCaptor.capture()).thenReturn(unusedTracker); - Class<?>[] vmIdCompleterDeps = new Class[] { - VmInfoDAO.class, - AgentInfoDAO.class - }; - whenNew(MultipleServiceTracker.class).withParameterTypes(BundleContext.class, Class[].class, Action.class).withArguments(eq(context), - eq(vmIdCompleterDeps), unusedCaptor.capture()).thenReturn(unusedTracker); - Class<?>[] agentIdCompleterDeps = new Class[] { - AgentInfoDAO.class - }; - whenNew(MultipleServiceTracker.class).withParameterTypes(BundleContext.class, Class[].class, Action.class).withArguments(eq(context), - eq(agentIdCompleterDeps), unusedCaptor.capture()).thenReturn(unusedTracker); - Class<?>[] pingCompleterDeps = new Class[] { - AgentInfoDAO.class - }; - whenNew(MultipleServiceTracker.class).withParameterTypes(BundleContext.class, Class[].class, Action.class).withArguments(eq(context), - eq(pingCompleterDeps), unusedCaptor.capture()).thenReturn(unusedTracker); - - Activator activator = new Activator(); - activator.start(context); - - assertTrue(context.isServiceRegistered(CompleterService.class.getName(), LogLevelCompleterService.class)); - } - - @Test public void testVmIdCompleterServiceAvailability() throws Exception { StubBundleContext context = new StubBundleContext(); MultipleServiceTracker unusedTracker = mock(MultipleServiceTracker.class);
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterServiceTest.java Thu Nov 03 18:23:07 2016 +0100 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterServiceTest.java Fri Nov 04 11:52:59 2016 -0400 @@ -104,4 +104,10 @@ assertThat(completer, is(not(equalTo(null)))); } + @Test + @SuppressWarnings("unchecked") + public void testProvidesNoSubcommandCompletions() { + assertThat(service.getSubcommandCompleters().size(), is(0)); + } + }