@Test public void testRunCommand() throws Exception { PowerMockito.doReturn(SHELL_UUID).when(wsManRemoteShellServiceSpy, CREATE_SHELL_METHOD, any(HttpClientService.class), any(HttpClientInputs.class), any(WSManRequestInputs.class)); PowerMockito.doReturn(COMMAND_UUID).when(wsManRemoteShellServiceSpy, EXECUTE_COMMAND_METHOD, any(HttpClientService.class), any(HttpClientInputs.class), any(String.class), any(WSManRequestInputs.class), any(String.class)); PowerMockito.doReturn(resultMock).when(wsManRemoteShellServiceSpy, RECEIVE_COMMAND_RESULT_METHOD, any(HttpClientService.class), any(HttpClientInputs.class), any(String.class), any(String.class), any(WSManRequestInputs.class)); PowerMockito.doNothing().when(wsManRemoteShellServiceSpy, DELETE_SHELL_METHOD, any(HttpClientService.class), any(HttpClientInputs.class), any(String.class), any(WSManRequestInputs.class)); PowerMockito.whenNew(HttpClientService.class).withNoArguments().thenReturn(csHttpClientMock); PowerMockito.whenNew(HttpClientInputs.class).withNoArguments().thenReturn(httpClientInputsMock); PowerMockito.mockStatic(WSManUtils.class); PowerMockito.doNothing().when(WSManUtils.class); WSManUtils.validateUUID(SHELL_UUID, SHELL_ID); WSManUtils.validateUUID(COMMAND_UUID, COMMAND_ID); Map<String, String> result = wsManRemoteShellServiceSpy.runCommand(wsManRequestInputs); PowerMockito.verifyNew(HttpClientService.class).withNoArguments(); PowerMockito.verifyNew(HttpClientInputs.class).withNoArguments(); verifyStatic(); WSManUtils.validateUUID(SHELL_UUID, SHELL_ID); WSManUtils.validateUUID(COMMAND_UUID, COMMAND_ID); assertEquals(resultMock, result); }
public Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, InterruptedException, ParserConfigurationException, TransformerException, XPathExpressionException, TimeoutException, URISyntaxException, SAXException { HttpClientService csHttpClient = new HttpClientService(); HttpClientInputs httpClientInputs = new HttpClientInputs(); URL url = buildURL(wsManRequestInputs, WSMAN_RESOURCE_URI); httpClientInputs = setCommonHttpInputs(httpClientInputs, url, wsManRequestInputs); String shellId = createShell(csHttpClient, httpClientInputs, wsManRequestInputs); WSManUtils.validateUUID(shellId, SHELL_ID); String commandStr = WSManUtils.constructCommand(wsManRequestInputs, this.psEdition); String commandId = executeCommand(csHttpClient, httpClientInputs, shellId, wsManRequestInputs, commandStr); WSManUtils.validateUUID(commandId, COMMAND_ID); Map<String, String> scriptResults = receiveCommandResult(csHttpClient, httpClientInputs, shellId, commandId, wsManRequestInputs); deleteShell(csHttpClient, httpClientInputs, shellId, wsManRequestInputs); return scriptResults; }
WSManRemoteShellService { public Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, InterruptedException, ParserConfigurationException, TransformerException, XPathExpressionException, TimeoutException, URISyntaxException, SAXException { HttpClientService csHttpClient = new HttpClientService(); HttpClientInputs httpClientInputs = new HttpClientInputs(); URL url = buildURL(wsManRequestInputs, WSMAN_RESOURCE_URI); httpClientInputs = setCommonHttpInputs(httpClientInputs, url, wsManRequestInputs); String shellId = createShell(csHttpClient, httpClientInputs, wsManRequestInputs); WSManUtils.validateUUID(shellId, SHELL_ID); String commandStr = WSManUtils.constructCommand(wsManRequestInputs, this.psEdition); String commandId = executeCommand(csHttpClient, httpClientInputs, shellId, wsManRequestInputs, commandStr); WSManUtils.validateUUID(commandId, COMMAND_ID); Map<String, String> scriptResults = receiveCommandResult(csHttpClient, httpClientInputs, shellId, commandId, wsManRequestInputs); deleteShell(csHttpClient, httpClientInputs, shellId, wsManRequestInputs); return scriptResults; } }
WSManRemoteShellService { public Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, InterruptedException, ParserConfigurationException, TransformerException, XPathExpressionException, TimeoutException, URISyntaxException, SAXException { HttpClientService csHttpClient = new HttpClientService(); HttpClientInputs httpClientInputs = new HttpClientInputs(); URL url = buildURL(wsManRequestInputs, WSMAN_RESOURCE_URI); httpClientInputs = setCommonHttpInputs(httpClientInputs, url, wsManRequestInputs); String shellId = createShell(csHttpClient, httpClientInputs, wsManRequestInputs); WSManUtils.validateUUID(shellId, SHELL_ID); String commandStr = WSManUtils.constructCommand(wsManRequestInputs, this.psEdition); String commandId = executeCommand(csHttpClient, httpClientInputs, shellId, wsManRequestInputs, commandStr); WSManUtils.validateUUID(commandId, COMMAND_ID); Map<String, String> scriptResults = receiveCommandResult(csHttpClient, httpClientInputs, shellId, commandId, wsManRequestInputs); deleteShell(csHttpClient, httpClientInputs, shellId, wsManRequestInputs); return scriptResults; } WSManRemoteShellService();  WSManRemoteShellService(PSEdition psEdition); }
WSManRemoteShellService { public Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, InterruptedException, ParserConfigurationException, TransformerException, XPathExpressionException, TimeoutException, URISyntaxException, SAXException { HttpClientService csHttpClient = new HttpClientService(); HttpClientInputs httpClientInputs = new HttpClientInputs(); URL url = buildURL(wsManRequestInputs, WSMAN_RESOURCE_URI); httpClientInputs = setCommonHttpInputs(httpClientInputs, url, wsManRequestInputs); String shellId = createShell(csHttpClient, httpClientInputs, wsManRequestInputs); WSManUtils.validateUUID(shellId, SHELL_ID); String commandStr = WSManUtils.constructCommand(wsManRequestInputs, this.psEdition); String commandId = executeCommand(csHttpClient, httpClientInputs, shellId, wsManRequestInputs, commandStr); WSManUtils.validateUUID(commandId, COMMAND_ID); Map<String, String> scriptResults = receiveCommandResult(csHttpClient, httpClientInputs, shellId, commandId, wsManRequestInputs); deleteShell(csHttpClient, httpClientInputs, shellId, wsManRequestInputs); return scriptResults; } WSManRemoteShellService();  WSManRemoteShellService(PSEdition psEdition); Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs); }
WSManRemoteShellService { public Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, InterruptedException, ParserConfigurationException, TransformerException, XPathExpressionException, TimeoutException, URISyntaxException, SAXException { HttpClientService csHttpClient = new HttpClientService(); HttpClientInputs httpClientInputs = new HttpClientInputs(); URL url = buildURL(wsManRequestInputs, WSMAN_RESOURCE_URI); httpClientInputs = setCommonHttpInputs(httpClientInputs, url, wsManRequestInputs); String shellId = createShell(csHttpClient, httpClientInputs, wsManRequestInputs); WSManUtils.validateUUID(shellId, SHELL_ID); String commandStr = WSManUtils.constructCommand(wsManRequestInputs, this.psEdition); String commandId = executeCommand(csHttpClient, httpClientInputs, shellId, wsManRequestInputs, commandStr); WSManUtils.validateUUID(commandId, COMMAND_ID); Map<String, String> scriptResults = receiveCommandResult(csHttpClient, httpClientInputs, shellId, commandId, wsManRequestInputs); deleteShell(csHttpClient, httpClientInputs, shellId, wsManRequestInputs); return scriptResults; } WSManRemoteShellService();  WSManRemoteShellService(PSEdition psEdition); Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs);  }