@Test public void testExecuteInstallScriptForAlreadyExistingScript() throws IOException { 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(0), "File exists - just run the script", "")); when(Config.mockRemoteCommandExecutorService.executeCommand(any(RemoteExecCommand.class))).thenReturn(new RemoteCommandReturnInfo(0, "Install command succeeded", "")); ResourceContent mockResourceContent = mock(ResourceContent.class); when(mockResourceContent.getMetaData()).thenReturn("{deployPath:\"/fake/deploy/path\"}"); ResourceTemplateMetaData mockResourceTemplateMetaData = mock(ResourceTemplateMetaData.class); when(mockResourceTemplateMetaData.getDeployPath()).thenReturn("/fake/deploy/path"); when(Config.mockResourceService.getResourceContent(any(ResourceIdentifier.class))).thenReturn(mockResourceContent); when(Config.mockResourceService.getMetaData(anyString())).thenReturn(mockResourceTemplateMetaData); final Media apacheHttpdMedia = new Media(); apacheHttpdMedia.setRemoteDir(Paths.get("c:/ctp")); apacheHttpdMedia.setRootDir(Paths.get("Apache24")); apacheHttpdMedia.setType(MediaType.APACHE); when(mockWebServer.getApacheHttpdMedia()).thenReturn(apacheHttpdMedia); when(Config.mockResourceContentGeneratorService.generateContent(anyString(), anyString(), any(ResourceGroup.class), anyObject(), any(ResourceGeneratorType.class))).thenReturn("C:/ctp"); RemoteCommandReturnInfo startResult = webServerCommandFactory.executeCommand(mockWebServer, WebServerControlOperation.INSTALL_SERVICE); assertEquals(0, startResult.retCode); verify(Config.mockBinaryDistributionControlService, never()).createDirectory(anyString(), anyString()); verify(Config.mockBinaryDistributionControlService, never()).secureCopyFile(anyString(), anyString(), anyString()); 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();  }