diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d8758..b8e2b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to ## [Unreleased] +## [2.3.0] - 2019-11-07 +### Changed +- Update to framework 6.3.0 +- All commands are now called using their String command name to allow for new commands to be +added without needing to update the dependency on framework + ## [2.2.4] - 2019-10-31 ### Changed - Update to framework 6.2.3 diff --git a/pom.xml b/pom.xml index c223b99..cbe6aed 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ framework-jmx-command-client 4.1.0 - 6.2.3 + 6.3.0 2.4.0 diff --git a/runSystemCommand.sh b/runSystemCommand.sh index d404ec2..1e9ff00 100755 --- a/runSystemCommand.sh +++ b/runSystemCommand.sh @@ -11,7 +11,7 @@ # ################################################ -FRAMEWORK_JMX_COMMAND_CLIENT_VERSION=2.2.2-SNAPSHOT +FRAMEWORK_JMX_COMMAND_CLIENT_VERSION=2.3.1-SNAPSHOT CONTEXT_NAME="people" USER_NAME="admin" PASSWORD="admin" diff --git a/src/main/java/uk/gov/justice/framework/command/client/CommandExecutor.java b/src/main/java/uk/gov/justice/framework/command/client/CommandExecutor.java index f37182f..dc2e3ae 100644 --- a/src/main/java/uk/gov/justice/framework/command/client/CommandExecutor.java +++ b/src/main/java/uk/gov/justice/framework/command/client/CommandExecutor.java @@ -3,11 +3,10 @@ import uk.gov.justice.framework.command.client.io.CommandPrinter; import uk.gov.justice.framework.command.client.io.ToConsolePrinter; import uk.gov.justice.framework.command.client.jmx.SystemCommandInvoker; -import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters; import java.util.List; -import java.util.Optional; import javax.inject.Inject; @@ -18,32 +17,19 @@ public class CommandExecutor { @Inject private SystemCommandInvoker systemCommandInvoker; - @Inject - private CommandLocator commandLocator; - - @Inject - private ToConsolePrinter toConsolePrinter; - @Inject private CommandPrinter commandPrinter; public void executeCommand( final CommandLine commandLine, final JmxParameters jmxParameters, - final List systemCommands) { + final List systemCommandDetails) { if (commandLine.hasOption("list")) { - commandPrinter.printSystemCommands(systemCommands); + commandPrinter.printSystemCommands(systemCommandDetails); } else { final String commandName = commandLine.getOptionValue("command"); - final Optional command = commandLocator.lookupCommand(commandName, systemCommands); - - if (command.isPresent()) { - systemCommandInvoker.runSystemCommand(command.get(), jmxParameters); - } else { - toConsolePrinter.printf("No command found with name '%s'", commandName); - commandPrinter.printSystemCommands(systemCommands); - } + systemCommandInvoker.runSystemCommand(commandName, jmxParameters); } } } diff --git a/src/main/java/uk/gov/justice/framework/command/client/CommandLocator.java b/src/main/java/uk/gov/justice/framework/command/client/CommandLocator.java deleted file mode 100644 index 3568d77..0000000 --- a/src/main/java/uk/gov/justice/framework/command/client/CommandLocator.java +++ /dev/null @@ -1,17 +0,0 @@ -package uk.gov.justice.framework.command.client; - -import uk.gov.justice.services.jmx.api.command.SystemCommand; - -import java.util.List; -import java.util.Optional; - -public class CommandLocator { - - - public Optional lookupCommand(final String commandName, final List systemCommands) { - - return systemCommands.stream() - .filter(systemCommand -> systemCommand.getName().equals(commandName)) - .findFirst(); - } -} diff --git a/src/main/java/uk/gov/justice/framework/command/client/MainApplication.java b/src/main/java/uk/gov/justice/framework/command/client/MainApplication.java index af22fc3..8687200 100644 --- a/src/main/java/uk/gov/justice/framework/command/client/MainApplication.java +++ b/src/main/java/uk/gov/justice/framework/command/client/MainApplication.java @@ -6,6 +6,7 @@ import uk.gov.justice.framework.command.client.jmx.ListCommandsInvoker; import uk.gov.justice.framework.command.client.startup.CommandLineArgumentParser; import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters; import java.util.List; @@ -51,7 +52,7 @@ public ReturnCode run(final String[] args) { try { - final Optional> systemCommandsOptional = listCommandsInvoker.listSystemCommands(jmxParameters); + final Optional> systemCommandsOptional = listCommandsInvoker.listSystemCommands(jmxParameters); systemCommandsOptional.ifPresent(systemCommands -> commandExecutor.executeCommand(commandLine, jmxParameters, systemCommands)); } catch (final RuntimeException e) { diff --git a/src/main/java/uk/gov/justice/framework/command/client/io/CommandPrinter.java b/src/main/java/uk/gov/justice/framework/command/client/io/CommandPrinter.java index 39edcde..d28a56b 100644 --- a/src/main/java/uk/gov/justice/framework/command/client/io/CommandPrinter.java +++ b/src/main/java/uk/gov/justice/framework/command/client/io/CommandPrinter.java @@ -1,6 +1,6 @@ package uk.gov.justice.framework.command.client.io; -import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import java.util.List; @@ -11,19 +11,19 @@ public class CommandPrinter { @Inject private ToConsolePrinter toConsolePrinter; - public void printSystemCommands(final List commands) { + public void printSystemCommands(final List systemCommandDetails) { - if (commands.isEmpty()) { + if (systemCommandDetails.isEmpty()) { toConsolePrinter.println("This instance of wildfly does not support any system commands"); } - toConsolePrinter.printf("This instance of wildfly supports the following %d commands:", commands.size()); - commands.forEach(this::printCommand); + toConsolePrinter.printf("This instance of wildfly supports the following %d commands:", systemCommandDetails.size()); + systemCommandDetails.forEach(this::printCommand); } - private void printCommand(final SystemCommand systemCommand) { + private void printCommand(final SystemCommandDetails systemCommandDetails) { - final String commandName = systemCommand.getName() + ":"; - toConsolePrinter.printf("\t- %-20s%s", commandName, systemCommand.getDescription()); + final String commandName = systemCommandDetails.getName() + ":"; + toConsolePrinter.printf("\t- %-20s%s", commandName, systemCommandDetails.getDescription()); } } diff --git a/src/main/java/uk/gov/justice/framework/command/client/jmx/CommandPoller.java b/src/main/java/uk/gov/justice/framework/command/client/jmx/CommandPoller.java index 2e36327..c1ad186 100644 --- a/src/main/java/uk/gov/justice/framework/command/client/jmx/CommandPoller.java +++ b/src/main/java/uk/gov/justice/framework/command/client/jmx/CommandPoller.java @@ -28,7 +28,7 @@ public class CommandPoller { @Inject private ToConsolePrinter toConsolePrinter; - public void runUntilComplete(final SystemCommanderMBean systemCommanderMBean, final UUID commandId, final SystemCommand systemCommand) { + public void runUntilComplete(final SystemCommanderMBean systemCommanderMBean, final UUID commandId, final String commandName) { final ZonedDateTime startTime = clock.now(); @@ -39,7 +39,7 @@ public void runUntilComplete(final SystemCommanderMBean systemCommanderMBean, fi if (count % 10 == 0) { final long seconds = between(startTime, clock.now()).getSeconds(); - toConsolePrinter.println(format("%s running for %d seconds", systemCommand.getName(), seconds)); + toConsolePrinter.println(format("%s running for %d seconds", commandName, seconds)); } } } diff --git a/src/main/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvoker.java b/src/main/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvoker.java index 5b1428e..e0c24a3 100644 --- a/src/main/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvoker.java +++ b/src/main/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvoker.java @@ -4,6 +4,7 @@ import uk.gov.justice.framework.command.client.io.ToConsolePrinter; import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean; import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient; import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory; @@ -24,7 +25,7 @@ public class ListCommandsInvoker { @Inject private ToConsolePrinter toConsolePrinter; - public Optional> listSystemCommands(final JmxParameters jmxParameters) { + public Optional> listSystemCommands(final JmxParameters jmxParameters) { final String contextName = jmxParameters.getContextName(); diff --git a/src/main/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvoker.java b/src/main/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvoker.java index ef3c8b1..471d77b 100644 --- a/src/main/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvoker.java +++ b/src/main/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvoker.java @@ -26,9 +26,8 @@ public class SystemCommandInvoker { @Inject private ToConsolePrinter toConsolePrinter; - public void runSystemCommand(final SystemCommand systemCommand, final JmxParameters jmxParameters) { + public void runSystemCommand(final String commandName, final JmxParameters jmxParameters) { - final String commandName = systemCommand.getName(); final String contextName = jmxParameters.getContextName(); toConsolePrinter.printf("Running system command '%s'", commandName); @@ -41,9 +40,9 @@ public void runSystemCommand(final SystemCommand systemCommand, final JmxParamet toConsolePrinter.printf("Connected to %s context", contextName); final SystemCommanderMBean systemCommanderMBean = systemCommanderClient.getRemote(contextName); - final UUID commandId = systemCommanderMBean.call(systemCommand); + final UUID commandId = systemCommanderMBean.call(commandName); toConsolePrinter.printf("System command '%s' with id '%s' successfully sent to %s", commandName, commandId, contextName); - commandPoller.runUntilComplete(systemCommanderMBean, commandId, systemCommand); + commandPoller.runUntilComplete(systemCommanderMBean, commandId, commandName); } catch (final UnrunnableSystemCommandException e) { toConsolePrinter.printf("The command '%s' is not supported on this %s context", commandName, contextName); diff --git a/src/test/java/uk/gov/justice/framework/command/client/CommandExecutorTest.java b/src/test/java/uk/gov/justice/framework/command/client/CommandExecutorTest.java index 977b02e..0927258 100644 --- a/src/test/java/uk/gov/justice/framework/command/client/CommandExecutorTest.java +++ b/src/test/java/uk/gov/justice/framework/command/client/CommandExecutorTest.java @@ -12,6 +12,7 @@ import uk.gov.justice.framework.command.client.io.ToConsolePrinter; import uk.gov.justice.framework.command.client.jmx.SystemCommandInvoker; import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters; import java.util.List; @@ -30,9 +31,6 @@ public class CommandExecutorTest { @Mock private SystemCommandInvoker systemCommandInvoker; - @Mock - private CommandLocator commandLocator; - @Mock private ToConsolePrinter toConsolePrinter; @@ -47,54 +45,30 @@ public void shouldLookupSystemCommandByNameAndExecute() throws Exception { final String commandName = "CATCHUP"; - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); + final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class); + final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class); final CommandLine commandLine = mock(CommandLine.class); final JmxParameters jmxParameters = mock(JmxParameters.class); - final List systemCommands = asList(systemCommand_1, systemCommand_2); + final List systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2); when(commandLine.hasOption("list")).thenReturn(false); when(commandLine.getOptionValue("command")).thenReturn(commandName); - when(commandLocator.lookupCommand(commandName, systemCommands)).thenReturn(of(systemCommand_2)); commandExecutor.executeCommand(commandLine, jmxParameters, systemCommands); - verify(systemCommandInvoker).runSystemCommand(systemCommand_2, jmxParameters); - } - - @Test - public void shouldPrintErrorAndListOfSystemCommandsIfTheNoCommandFound() throws Exception { - - final String commandName = "CATCHUP"; - - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); - - final CommandLine commandLine = mock(CommandLine.class); - final JmxParameters jmxParameters = mock(JmxParameters.class); - final List systemCommands = asList(systemCommand_1, systemCommand_2); - - when(commandLine.hasOption("list")).thenReturn(false); - when(commandLine.getOptionValue("command")).thenReturn(commandName); - when(commandLocator.lookupCommand(commandName, systemCommands)).thenReturn(empty()); - - commandExecutor.executeCommand(commandLine, jmxParameters, systemCommands); - - verify(toConsolePrinter).printf("No command found with name '%s'", commandName); - verify(commandPrinter).printSystemCommands(systemCommands); - verifyZeroInteractions(systemCommandInvoker); + verify(systemCommandInvoker).runSystemCommand(commandName, jmxParameters); } @Test public void shouldListSystemCommandsIfCommandLineOptionIsList() throws Exception { - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); + final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class); + final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class); final CommandLine commandLine = mock(CommandLine.class); final JmxParameters jmxParameters = mock(JmxParameters.class); - final List systemCommands = asList(systemCommand_1, systemCommand_2); + final List systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2); when(commandLine.hasOption("list")).thenReturn(true); diff --git a/src/test/java/uk/gov/justice/framework/command/client/CommandLocatorTest.java b/src/test/java/uk/gov/justice/framework/command/client/CommandLocatorTest.java deleted file mode 100644 index afbe262..0000000 --- a/src/test/java/uk/gov/justice/framework/command/client/CommandLocatorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package uk.gov.justice.framework.command.client; - -import static java.util.Arrays.asList; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import uk.gov.justice.services.jmx.api.command.SystemCommand; - -import java.util.List; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class CommandLocatorTest { - - - @InjectMocks - private CommandLocator commandLocator; - - @SuppressWarnings("OptionalGetWithoutIsPresent") - @Test - public void shouldFindTheCorrectCommandByName() throws Exception { - - final String commandName_1 = "commandName_1"; - final String commandName_2 = "commandName_2"; - final String commandName_3 = "commandName_3"; - final String commandName_4 = "commandName_4"; - - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); - final SystemCommand systemCommand_3 = mock(SystemCommand.class); - final SystemCommand systemCommand_4 = mock(SystemCommand.class); - - final List systemCommands = asList(systemCommand_1, systemCommand_2, systemCommand_3, systemCommand_4); - - when(systemCommand_1.getName()).thenReturn(commandName_1); - when(systemCommand_2.getName()).thenReturn(commandName_2); - when(systemCommand_3.getName()).thenReturn(commandName_3); - when(systemCommand_4.getName()).thenReturn(commandName_4); - - - assertThat(commandLocator.lookupCommand(commandName_1, systemCommands).get(), is(systemCommand_1)); - assertThat(commandLocator.lookupCommand(commandName_2, systemCommands).get(), is(systemCommand_2)); - assertThat(commandLocator.lookupCommand(commandName_3, systemCommands).get(), is(systemCommand_3)); - assertThat(commandLocator.lookupCommand(commandName_4, systemCommands).get(), is(systemCommand_4)); - } - - @Test - public void shouldReturnEmptyIfTheCommandIsNotFound() throws Exception { - - final String commandName_1 = "commandName_1"; - final String commandName_2 = "commandName_2"; - final String commandName_3 = "commandName_3"; - final String commandName_4 = "commandName_4"; - - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); - final SystemCommand systemCommand_3 = mock(SystemCommand.class); - final SystemCommand systemCommand_4 = mock(SystemCommand.class); - - final List systemCommands = asList(systemCommand_1, systemCommand_2, systemCommand_3, systemCommand_4); - - when(systemCommand_1.getName()).thenReturn(commandName_1); - when(systemCommand_2.getName()).thenReturn(commandName_2); - when(systemCommand_3.getName()).thenReturn(commandName_3); - when(systemCommand_4.getName()).thenReturn(commandName_4); - - - assertThat(commandLocator.lookupCommand("some other command name", systemCommands).isPresent(), is(false)); - } -} diff --git a/src/test/java/uk/gov/justice/framework/command/client/MainApplicationTest.java b/src/test/java/uk/gov/justice/framework/command/client/MainApplicationTest.java index e9df931..f4d4787 100644 --- a/src/test/java/uk/gov/justice/framework/command/client/MainApplicationTest.java +++ b/src/test/java/uk/gov/justice/framework/command/client/MainApplicationTest.java @@ -16,6 +16,7 @@ import uk.gov.justice.framework.command.client.jmx.ListCommandsInvoker; import uk.gov.justice.framework.command.client.startup.CommandLineArgumentParser; import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import uk.gov.justice.services.jmx.system.command.client.connection.JmxParameters; import java.util.List; @@ -65,10 +66,10 @@ public void shouldLookupTheCorrectCommandAndInvokeIt() throws Exception { final JmxParameters jmxParameters = mock(JmxParameters.class); final CommandLine commandLine = mock(CommandLine.class); - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); + final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class); + final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class); - final List systemCommands = asList(systemCommand_1, systemCommand_2); + final List systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2); when(commandLineArgumentParser.parse(args)).thenReturn(of(commandLine)); when(jmxParametersFactory.createFrom(commandLine)).thenReturn(jmxParameters); diff --git a/src/test/java/uk/gov/justice/framework/command/client/io/CommandPrinterTest.java b/src/test/java/uk/gov/justice/framework/command/client/io/CommandPrinterTest.java index 399f377..9eed76f 100644 --- a/src/test/java/uk/gov/justice/framework/command/client/io/CommandPrinterTest.java +++ b/src/test/java/uk/gov/justice/framework/command/client/io/CommandPrinterTest.java @@ -9,6 +9,7 @@ import static org.mockito.Mockito.when; import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import java.util.List; @@ -36,15 +37,15 @@ public void shouldGetTheListOfAllCommandsAndPrintThem() throws Exception { final String description_1 = "description_1"; final String description_2 = "description_2"; - final SystemCommand systemCommand_1 = mock(SystemCommand.class); - final SystemCommand systemCommand_2 = mock(SystemCommand.class); + final SystemCommandDetails systemCommandDetails_1 = mock(SystemCommandDetails.class); + final SystemCommandDetails systemCommandDetails_2 = mock(SystemCommandDetails.class); - final List systemCommands = asList(systemCommand_1, systemCommand_2); + final List systemCommands = asList(systemCommandDetails_1, systemCommandDetails_2); - when(systemCommand_1.getName()).thenReturn(commandName_1); - when(systemCommand_1.getDescription()).thenReturn(description_1); - when(systemCommand_2.getName()).thenReturn(commandName_2); - when(systemCommand_2.getDescription()).thenReturn(description_2); + when(systemCommandDetails_1.getName()).thenReturn(commandName_1); + when(systemCommandDetails_1.getDescription()).thenReturn(description_1); + when(systemCommandDetails_2.getName()).thenReturn(commandName_2); + when(systemCommandDetails_2.getDescription()).thenReturn(description_2); commandPrinter.printSystemCommands(systemCommands); diff --git a/src/test/java/uk/gov/justice/framework/command/client/jmx/CommandPollerTest.java b/src/test/java/uk/gov/justice/framework/command/client/jmx/CommandPollerTest.java index 3b711b1..6f8828e 100644 --- a/src/test/java/uk/gov/justice/framework/command/client/jmx/CommandPollerTest.java +++ b/src/test/java/uk/gov/justice/framework/command/client/jmx/CommandPollerTest.java @@ -9,8 +9,6 @@ import uk.gov.justice.framework.command.client.io.ToConsolePrinter; import uk.gov.justice.framework.command.client.util.Sleeper; import uk.gov.justice.framework.command.client.util.UtcClock; -import uk.gov.justice.services.jmx.api.command.EventCatchupCommand; -import uk.gov.justice.services.jmx.api.command.SystemCommand; import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean; import java.time.ZonedDateTime; @@ -44,7 +42,7 @@ public class CommandPollerTest { public void shouldCheckCommandUntilComplete() throws Exception { final UUID commandId = UUID.randomUUID(); - final SystemCommand systemCommand = new EventCatchupCommand(); + final String commandName = "CATCHUP"; final ZonedDateTime startTime = new UtcClock().now(); @@ -53,7 +51,7 @@ public void shouldCheckCommandUntilComplete() throws Exception { when(clock.now()).thenReturn(startTime); when(commandChecker.commandComplete(systemCommanderMBean, commandId, startTime)).thenReturn(false, false, true); - commandPoller.runUntilComplete(systemCommanderMBean, commandId, systemCommand); + commandPoller.runUntilComplete(systemCommanderMBean, commandId, commandName); verify(sleeper, times(2)).sleepFor(1_000); verifyZeroInteractions(toConsolePrinter); @@ -63,7 +61,7 @@ public void shouldCheckCommandUntilComplete() throws Exception { public void shouldLogProgressEveryTenthCall() throws Exception { final UUID commandId = UUID.randomUUID(); - final SystemCommand systemCommand = new EventCatchupCommand(); + final String commandName = "CATCHUP"; final ZonedDateTime startTime = new UtcClock().now(); final ZonedDateTime now = startTime.plusSeconds(10); @@ -73,7 +71,7 @@ public void shouldLogProgressEveryTenthCall() throws Exception { when(clock.now()).thenReturn(startTime, now); when(commandChecker.commandComplete(systemCommanderMBean, commandId, startTime)).thenReturn(false, false, false, false, false, false, false, false, false, false, true); - commandPoller.runUntilComplete(systemCommanderMBean, commandId, systemCommand); + commandPoller.runUntilComplete(systemCommanderMBean, commandId, commandName); verify(sleeper, times(10)).sleepFor(1_000); verify(toConsolePrinter).println("CATCHUP running for 10 seconds"); diff --git a/src/test/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvokerTest.java b/src/test/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvokerTest.java index 89e5a6c..3641b9d 100644 --- a/src/test/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvokerTest.java +++ b/src/test/java/uk/gov/justice/framework/command/client/jmx/ListCommandsInvokerTest.java @@ -10,7 +10,7 @@ import static org.mockito.Mockito.when; import uk.gov.justice.framework.command.client.io.ToConsolePrinter; -import uk.gov.justice.services.jmx.api.command.SystemCommand; +import uk.gov.justice.services.jmx.api.command.SystemCommandDetails; import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean; import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient; import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory; @@ -45,7 +45,7 @@ public void shouldMakeAJmxCallToRetrieveTheListOfCommands() throws Exception { final String host = "localhost"; final int port = 92834; - final List systemCommands = singletonList(mock(SystemCommand.class)); + final List systemCommandDetails = singletonList(mock(SystemCommandDetails.class)); final JmxParameters jmxParameters = mock(JmxParameters.class); final SystemCommanderClient systemCommanderClient = mock(SystemCommanderClient.class); @@ -57,9 +57,9 @@ public void shouldMakeAJmxCallToRetrieveTheListOfCommands() throws Exception { when(jmxParameters.getCredentials()).thenReturn(empty()); when(systemCommanderClientFactory.create(jmxParameters)).thenReturn(systemCommanderClient); when(systemCommanderClient.getRemote(contextName)).thenReturn(commanderMBean); - when(commanderMBean.listCommands()).thenReturn(systemCommands); + when(commanderMBean.listCommands()).thenReturn(systemCommandDetails); - assertThat(listCommandsInvoker.listSystemCommands(jmxParameters), is(of(systemCommands))); + assertThat(listCommandsInvoker.listSystemCommands(jmxParameters), is(of(systemCommandDetails))); final InOrder inOrder = inOrder( toConsolePrinter, @@ -80,7 +80,7 @@ public void shouldLogIfUsingCredentials() throws Exception { final int port = 92834; final String username = "Fred"; - final List systemCommands = singletonList(mock(SystemCommand.class)); + final List systemCommandDetails = singletonList(mock(SystemCommandDetails.class)); final Credentials credentials = mock(Credentials.class); final JmxParameters jmxParameters = mock(JmxParameters.class); @@ -94,9 +94,9 @@ public void shouldLogIfUsingCredentials() throws Exception { when(credentials.getUsername()).thenReturn(username); when(systemCommanderClientFactory.create(jmxParameters)).thenReturn(systemCommanderClient); when(systemCommanderClient.getRemote(contextName)).thenReturn(commanderMBean); - when(commanderMBean.listCommands()).thenReturn(systemCommands); + when(commanderMBean.listCommands()).thenReturn(systemCommandDetails); - assertThat(listCommandsInvoker.listSystemCommands(jmxParameters), is(of(systemCommands))); + assertThat(listCommandsInvoker.listSystemCommands(jmxParameters), is(of(systemCommandDetails))); final InOrder inOrder = inOrder( toConsolePrinter, diff --git a/src/test/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvokerTest.java b/src/test/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvokerTest.java index 1b7ad6f..c017d74 100644 --- a/src/test/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvokerTest.java +++ b/src/test/java/uk/gov/justice/framework/command/client/jmx/SystemCommandInvokerTest.java @@ -11,8 +11,6 @@ import uk.gov.justice.framework.command.client.io.ToConsolePrinter; import uk.gov.justice.services.jmx.api.SystemCommandInvocationFailedException; import uk.gov.justice.services.jmx.api.UnrunnableSystemCommandException; -import uk.gov.justice.services.jmx.api.command.PingCommand; -import uk.gov.justice.services.jmx.api.command.SystemCommand; import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean; import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClient; import uk.gov.justice.services.jmx.system.command.client.SystemCommanderClientFactory; @@ -52,7 +50,6 @@ public void shouldMakeJmxCallToRetrieveTheListOfCommands() throws Exception { final String commandName = "SOME_COMMAND"; final UUID commandId = randomUUID(); - final SystemCommand systemCommand = mock(SystemCommand.class); final JmxParameters jmxParameters = mock(JmxParameters.class); final SystemCommanderClient systemCommanderClient = mock(SystemCommanderClient.class); final SystemCommanderMBean systemCommanderMBean = mock(SystemCommanderMBean.class); @@ -63,10 +60,9 @@ public void shouldMakeJmxCallToRetrieveTheListOfCommands() throws Exception { when(jmxParameters.getCredentials()).thenReturn(empty()); when(systemCommanderClientFactory.create(jmxParameters)).thenReturn(systemCommanderClient); when(systemCommanderClient.getRemote(contextName)).thenReturn(systemCommanderMBean); - when(systemCommanderMBean.call(systemCommand)).thenReturn(commandId); - when(systemCommand.getName()).thenReturn(commandName); + when(systemCommanderMBean.call(commandName)).thenReturn(commandId); - systemCommandInvoker.runSystemCommand(systemCommand, jmxParameters); + systemCommandInvoker.runSystemCommand(commandName, jmxParameters); final InOrder inOrder = inOrder( toConsolePrinter, @@ -80,9 +76,9 @@ public void shouldMakeJmxCallToRetrieveTheListOfCommands() throws Exception { inOrder.verify(systemCommanderClientFactory).create(jmxParameters); inOrder.verify(toConsolePrinter).printf("Connected to %s context", contextName); inOrder.verify(systemCommanderClient).getRemote(contextName); - inOrder.verify(systemCommanderMBean).call(systemCommand); + inOrder.verify(systemCommanderMBean).call(commandName); inOrder.verify(toConsolePrinter).printf("System command '%s' with id '%s' successfully sent to %s", commandName, commandId, contextName); - inOrder.verify(commandPoller).runUntilComplete(systemCommanderMBean, commandId, systemCommand); + inOrder.verify(commandPoller).runUntilComplete(systemCommanderMBean, commandId, commandName); } @Test @@ -96,7 +92,6 @@ public void shouldLogIfUsingCredentials() throws Exception { final UUID commandId = randomUUID(); final Credentials credentials = mock(Credentials.class); - final SystemCommand systemCommand = mock(SystemCommand.class); final JmxParameters jmxParameters = mock(JmxParameters.class); final SystemCommanderClient systemCommanderClient = mock(SystemCommanderClient.class); final SystemCommanderMBean systemCommanderMBean = mock(SystemCommanderMBean.class); @@ -108,10 +103,9 @@ public void shouldLogIfUsingCredentials() throws Exception { when(credentials.getUsername()).thenReturn(username); when(systemCommanderClientFactory.create(jmxParameters)).thenReturn(systemCommanderClient); when(systemCommanderClient.getRemote(contextName)).thenReturn(systemCommanderMBean); - when(systemCommanderMBean.call(systemCommand)).thenReturn(commandId); - when(systemCommand.getName()).thenReturn(commandName); + when(systemCommanderMBean.call(commandName)).thenReturn(commandId); - systemCommandInvoker.runSystemCommand(systemCommand, jmxParameters); + systemCommandInvoker.runSystemCommand(commandName, jmxParameters); final InOrder inOrder = inOrder( toConsolePrinter, @@ -126,9 +120,9 @@ public void shouldLogIfUsingCredentials() throws Exception { inOrder.verify(systemCommanderClientFactory).create(jmxParameters); inOrder.verify(toConsolePrinter).printf("Connected to %s context", contextName); inOrder.verify(systemCommanderClient).getRemote(contextName); - inOrder.verify(systemCommanderMBean).call(systemCommand); + inOrder.verify(systemCommanderMBean).call(commandName); inOrder.verify(toConsolePrinter).printf("System command '%s' with id '%s' successfully sent to %s", commandName, commandId, contextName); - inOrder.verify(commandPoller).runUntilComplete(systemCommanderMBean, commandId, systemCommand); + inOrder.verify(commandPoller).runUntilComplete(systemCommanderMBean, commandId, commandName); } @Test(expected = UnrunnableSystemCommandException.class) @@ -138,8 +132,7 @@ public void shouldLogIfTheCommandIsUnsupported() throws Exception { final String host = "localhost"; final int port = 92834; final String username = "Fred"; - final SystemCommand systemCommand = new PingCommand(); - final String commandName = systemCommand.getName(); + final String commandName = "PING"; final UnrunnableSystemCommandException unrunnableSystemCommandException = new UnrunnableSystemCommandException("Ooops"); @@ -155,9 +148,9 @@ public void shouldLogIfTheCommandIsUnsupported() throws Exception { when(credentials.getUsername()).thenReturn(username); when(systemCommanderClientFactory.create(jmxParameters)).thenReturn(systemCommanderClient); when(systemCommanderClient.getRemote(contextName)).thenReturn(systemCommanderMBean); - doThrow(unrunnableSystemCommandException).when(systemCommanderMBean).call(systemCommand); + doThrow(unrunnableSystemCommandException).when(systemCommanderMBean).call(commandName); - systemCommandInvoker.runSystemCommand(systemCommand, jmxParameters); + systemCommandInvoker.runSystemCommand(commandName, jmxParameters); final InOrder inOrder = inOrder( toConsolePrinter, @@ -180,8 +173,7 @@ public void shouldLogAndPrintTheServerStackTraceIfTheCommandFails() throws Excep final String username = "Fred"; final String serverStackTrace = "the stack trace from the server"; final String errorMessage = "Ooops"; - final SystemCommand systemCommand = new PingCommand(); - final String commandName = systemCommand.getName(); + final String commandName = "PING"; final SystemCommandInvocationFailedException systemCommandInvocationFailedException = new SystemCommandInvocationFailedException(errorMessage, serverStackTrace); @@ -197,9 +189,9 @@ public void shouldLogAndPrintTheServerStackTraceIfTheCommandFails() throws Excep when(credentials.getUsername()).thenReturn(username); when(systemCommanderClientFactory.create(jmxParameters)).thenReturn(systemCommanderClient); when(systemCommanderClient.getRemote(contextName)).thenReturn(systemCommanderMBean); - doThrow(systemCommandInvocationFailedException).when(systemCommanderMBean).call(systemCommand); + doThrow(systemCommandInvocationFailedException).when(systemCommanderMBean).call(commandName); - systemCommandInvoker.runSystemCommand(systemCommand, jmxParameters); + systemCommandInvoker.runSystemCommand(commandName, jmxParameters); final InOrder inOrder = inOrder( toConsolePrinter, @@ -209,7 +201,7 @@ public void shouldLogAndPrintTheServerStackTraceIfTheCommandFails() throws Excep inOrder.verify(toConsolePrinter).printf("Connecting to %s context at '%s' on port %d", contextName, host, port); inOrder.verify(toConsolePrinter).printf("Connecting with credentials for user '%s'", username); inOrder.verify(toConsolePrinter).printf("Connected to %s context", contextName); - inOrder.verify(toConsolePrinter).printf("The command '%s' failed: %s", errorMessage, systemCommand.getName()); + inOrder.verify(toConsolePrinter).printf("The command '%s' failed: %s", errorMessage, commandName); inOrder.verify(toConsolePrinter).println(serverStackTrace); } }