@Test(expected = WebServerServiceException.class) public void testExecuteInstallScriptFailsSecureCopy() { WebServer mockWebServer = mock(WebServer.class); when(mockWebServer.getName()).thenReturn("web-server-name"); when(mockWebServer.getHost()).thenReturn("web-server-host"); when(Config.mockBinaryDistributionControlService.checkFileExists(anyString(), anyString())).thenReturn(new CommandOutput(new ExecReturnCode(1), "File does not exist to force create directory", "")); when(Config.mockBinaryDistributionControlService.createDirectory(anyString(), anyString())).thenReturn(new CommandOutput(new ExecReturnCode(0), "Successfully created directory", "")); when(Config.mockBinaryDistributionControlService.secureCopyFile(anyString(), anyString(), anyString())).thenReturn(new CommandOutput(new ExecReturnCode(1), "", "Failed secure copy")); RemoteCommandReturnInfo startResult = webServerCommandFactory.executeCommand(mockWebServer, WebServerControlOperation.INSTALL_SERVICE); assertEquals(0, startResult.retCode); verify(Config.mockRemoteCommandExecutorService, never()).executeCommand(any(RemoteExecCommand.class)); verify(Config.mockBinaryDistributionControlService, never()).changeFileMode(anyString(), anyString(), anyString(), anyString()); }
public RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation) throws ApplicationServiceException { if (commands.containsKey(operation.getExternalValue())) { return commands.get(operation.getExternalValue()).apply(webserver); } throw new WebServerServiceException("WebServerCommand not found: " + operation.getExternalValue()); }
WebServerCommandFactory { public RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation) throws ApplicationServiceException { if (commands.containsKey(operation.getExternalValue())) { return commands.get(operation.getExternalValue()).apply(webserver); } throw new WebServerServiceException("WebServerCommand not found: " + operation.getExternalValue()); } }
WebServerCommandFactory { public RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation) throws ApplicationServiceException { if (commands.containsKey(operation.getExternalValue())) { return commands.get(operation.getExternalValue()).apply(webserver); } throw new WebServerServiceException("WebServerCommand not found: " + operation.getExternalValue()); }  }
WebServerCommandFactory { public RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation) throws ApplicationServiceException { if (commands.containsKey(operation.getExternalValue())) { return commands.get(operation.getExternalValue()).apply(webserver); } throw new WebServerServiceException("WebServerCommand not found: " + operation.getExternalValue()); }  RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation); @PostConstruct void initWebServerCommands(); }
WebServerCommandFactory { public RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation) throws ApplicationServiceException { if (commands.containsKey(operation.getExternalValue())) { return commands.get(operation.getExternalValue()).apply(webserver); } throw new WebServerServiceException("WebServerCommand not found: " + operation.getExternalValue()); }  RemoteCommandReturnInfo executeCommand(WebServer webserver, WebServerControlOperation operation); @PostConstruct void initWebServerCommands();  }