Skip to content

Commit 6a86ba6

Browse files
Add method to systemcommandmbean interface to invoke system command without supplying CommandRunMode (#116)
Co-authored-by: santhosh <santhosh.kotha@hmcts.net>
1 parent 642f63d commit 6a86ba6

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
44
[Semantic Versioning](http://semver.org/).
55

66
[Unreleased]
7+
### Changed
8+
- Add method to SystemCommanderMBean interface to invoke system command without supplying CommandRunMode (Used by FeatureStubber class)
79

810
## [17.4.6] - 2024-06-03
911
### Changed

jmx/jmx-api/src/main/java/uk/gov/justice/services/jmx/api/mbean/SystemCommanderMBean.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@MXBean
1212
public interface SystemCommanderMBean {
1313

14+
UUID call(final String systemCommandName);
1415
UUID call(final String systemCommandName, final CommandRunMode commandRunMode);
1516
UUID callWithRuntimeId(final String systemCommandName, final UUID commandRuntimeId, final CommandRunMode commandRunMode);
1617
List<SystemCommandDetails> listCommands();

jmx/jmx-command-handling/src/main/java/uk/gov/justice/services/jmx/api/mbean/SystemCommander.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package uk.gov.justice.services.jmx.api.mbean;
22

3-
import static java.lang.String.format;
4-
import static java.util.Optional.empty;
5-
import static java.util.Optional.of;
6-
import static java.util.stream.Collectors.toList;
7-
3+
import org.slf4j.Logger;
84
import uk.gov.justice.services.jmx.api.CommandNotFoundException;
95
import uk.gov.justice.services.jmx.api.UnrunnableSystemCommandException;
106
import uk.gov.justice.services.jmx.api.command.SystemCommand;
@@ -16,13 +12,15 @@
1612
import uk.gov.justice.services.jmx.runner.AsynchronousCommandRunner;
1713
import uk.gov.justice.services.jmx.state.observers.SystemCommandStateBean;
1814

15+
import javax.inject.Inject;
1916
import java.util.List;
2017
import java.util.Optional;
2118
import java.util.UUID;
2219

23-
import javax.inject.Inject;
24-
25-
import org.slf4j.Logger;
20+
import static java.lang.String.format;
21+
import static java.util.Optional.empty;
22+
import static java.util.Optional.of;
23+
import static java.util.stream.Collectors.toList;
2624

2725
public class SystemCommander implements SystemCommanderMBean {
2826

@@ -47,6 +45,14 @@ public class SystemCommander implements SystemCommanderMBean {
4745
@Inject
4846
private Logger logger;
4947

48+
@Override
49+
public UUID call(final String systemCommandName) {
50+
logger.info(format("Received System Command '%s'", systemCommandName));
51+
logger.info(format("Running '%s' in '%s' mode", systemCommandName, CommandRunMode.FORCED));
52+
53+
return doCall(systemCommandName, empty(), CommandRunMode.FORCED);
54+
}
55+
5056
@Override
5157
public UUID call(final String systemCommandName, final CommandRunMode commandRunMode) {
5258
logger.info(format("Received System Command '%s'", systemCommandName));

jmx/jmx-command-handling/src/test/java/uk/gov/justice/services/jmx/api/mbean/SystemCommanderTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ public class SystemCommanderTest {
6868
@InjectMocks
6969
private SystemCommander systemCommander;
7070

71+
@Test
72+
public void shouldRunTheSystemCommandInForcedModeWhenCommandRunModeNotSupplied() throws Exception {
73+
74+
final UUID commandId = randomUUID();
75+
final TestCommand testCommand = new TestCommand();
76+
final Optional<UUID> commandRuntimeId = empty();
77+
78+
when(systemCommandLocator.forName(testCommand.getName())).thenReturn(of(testCommand));
79+
when(asynchronousCommandRunner.run(testCommand, commandRuntimeId)).thenReturn(commandId);
80+
81+
assertThat(systemCommander.call("TEST_COMMAND"), is(commandId));
82+
83+
final InOrder inOrder = inOrder(logger, systemCommandVerifier, asynchronousCommandRunner);
84+
85+
inOrder.verify(logger).info("Received System Command 'TEST_COMMAND'");
86+
inOrder.verify(logger).info("Running 'TEST_COMMAND' in 'FORCED' mode");
87+
inOrder.verify(systemCommandVerifier).verify(testCommand, commandRuntimeId);
88+
inOrder.verify(asynchronousCommandRunner).run(testCommand, commandRuntimeId);
89+
}
90+
7191
@Test
7292
public void shouldRunTheSystemCommandIfSupported() throws Exception {
7393

0 commit comments

Comments
 (0)