@Test public void testReceiveCommandResult() throws Exception { mockExecuteRequest(); PowerMockito.doReturn(false).when(wsManRemoteShellServiceSpy, EXECUTION_IS_TIMED_OUT_METHOD, anyLong(), anyInt()); PowerMockito.mockStatic(WSManUtils.class); Mockito.when(WSManUtils.isSpecificResponseAction(RESPONSE_BODY, RECEIVE_RESPONSE_ACTION)).thenReturn(true); Mockito.when(WSManUtils.commandExecutionIsDone(RESPONSE_BODY)).thenReturn(true); PowerMockito.doReturn(resultMock).when(wsManRemoteShellServiceSpy, PROCESS_COMMAND_EXECUTION_RESPONSE_METHOD, any(String.class)); Map<String, String> result = Whitebox.invokeMethod(wsManRemoteShellServiceSpy, RECEIVE_COMMAND_RESULT_METHOD, csHttpClientMock, httpClientInputsMock, SHELL_UUID, COMMAND_UUID, wsManRequestInputs); assertEquals(resultMock, result); verifyStatic(); WSManUtils.isSpecificResponseAction(RESPONSE_BODY, RECEIVE_RESPONSE_ACTION); WSManUtils.commandExecutionIsDone(RESPONSE_BODY); PowerMockito.verifyPrivate(wsManRemoteShellServiceSpy).invoke(PROCESS_COMMAND_EXECUTION_RESPONSE_METHOD, any(String.class)); }
private Map<String, String> receiveCommandResult(HttpClientService csHttpClient, HttpClientInputs httpClientInputs, String shellId, String commandId, WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, URISyntaxException, TransformerException, TimeoutException, XPathExpressionException, SAXException, ParserConfigurationException, InterruptedException { String documentStr = ResourceLoader.loadAsString(RECEIVE_REQUEST_XML); documentStr = createReceiveRequestBody(documentStr, httpClientInputs.getUrl(), shellId, commandId, String.valueOf(wsManRequestInputs.getMaxEnvelopeSize()), wsManRequestInputs.getWinrmLocale(), String.valueOf(wsManRequestInputs.getOperationTimeout())); Map<String, String> receiveResult; while (true) { receiveResult = executeRequestWithBody(csHttpClient, httpClientInputs, documentStr); if (executionIsTimedOut(commandExecutionStartTime, wsManRequestInputs.getOperationTimeout())) { throw new TimeoutException(EXECUTION_TIMED_OUT); } else if (WSManUtils.isSpecificResponseAction(receiveResult.get(RETURN_RESULT), RECEIVE_RESPONSE_ACTION) && WSManUtils.commandExecutionIsDone(receiveResult.get(RETURN_RESULT))) { return processCommandExecutionResponse(receiveResult); } else if (WSManUtils.isFaultResponse(receiveResult.get(RETURN_RESULT))) { throw new RuntimeException(WSManUtils.getResponseFault(receiveResult.get(RETURN_RESULT))); } try { Thread.sleep(200); } catch (InterruptedException e) { throw e; } } }
WSManRemoteShellService { private Map<String, String> receiveCommandResult(HttpClientService csHttpClient, HttpClientInputs httpClientInputs, String shellId, String commandId, WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, URISyntaxException, TransformerException, TimeoutException, XPathExpressionException, SAXException, ParserConfigurationException, InterruptedException { String documentStr = ResourceLoader.loadAsString(RECEIVE_REQUEST_XML); documentStr = createReceiveRequestBody(documentStr, httpClientInputs.getUrl(), shellId, commandId, String.valueOf(wsManRequestInputs.getMaxEnvelopeSize()), wsManRequestInputs.getWinrmLocale(), String.valueOf(wsManRequestInputs.getOperationTimeout())); Map<String, String> receiveResult; while (true) { receiveResult = executeRequestWithBody(csHttpClient, httpClientInputs, documentStr); if (executionIsTimedOut(commandExecutionStartTime, wsManRequestInputs.getOperationTimeout())) { throw new TimeoutException(EXECUTION_TIMED_OUT); } else if (WSManUtils.isSpecificResponseAction(receiveResult.get(RETURN_RESULT), RECEIVE_RESPONSE_ACTION) && WSManUtils.commandExecutionIsDone(receiveResult.get(RETURN_RESULT))) { return processCommandExecutionResponse(receiveResult); } else if (WSManUtils.isFaultResponse(receiveResult.get(RETURN_RESULT))) { throw new RuntimeException(WSManUtils.getResponseFault(receiveResult.get(RETURN_RESULT))); } try { Thread.sleep(200); } catch (InterruptedException e) { throw e; } } } }
WSManRemoteShellService { private Map<String, String> receiveCommandResult(HttpClientService csHttpClient, HttpClientInputs httpClientInputs, String shellId, String commandId, WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, URISyntaxException, TransformerException, TimeoutException, XPathExpressionException, SAXException, ParserConfigurationException, InterruptedException { String documentStr = ResourceLoader.loadAsString(RECEIVE_REQUEST_XML); documentStr = createReceiveRequestBody(documentStr, httpClientInputs.getUrl(), shellId, commandId, String.valueOf(wsManRequestInputs.getMaxEnvelopeSize()), wsManRequestInputs.getWinrmLocale(), String.valueOf(wsManRequestInputs.getOperationTimeout())); Map<String, String> receiveResult; while (true) { receiveResult = executeRequestWithBody(csHttpClient, httpClientInputs, documentStr); if (executionIsTimedOut(commandExecutionStartTime, wsManRequestInputs.getOperationTimeout())) { throw new TimeoutException(EXECUTION_TIMED_OUT); } else if (WSManUtils.isSpecificResponseAction(receiveResult.get(RETURN_RESULT), RECEIVE_RESPONSE_ACTION) && WSManUtils.commandExecutionIsDone(receiveResult.get(RETURN_RESULT))) { return processCommandExecutionResponse(receiveResult); } else if (WSManUtils.isFaultResponse(receiveResult.get(RETURN_RESULT))) { throw new RuntimeException(WSManUtils.getResponseFault(receiveResult.get(RETURN_RESULT))); } try { Thread.sleep(200); } catch (InterruptedException e) { throw e; } } } WSManRemoteShellService();  WSManRemoteShellService(PSEdition psEdition); }
WSManRemoteShellService { private Map<String, String> receiveCommandResult(HttpClientService csHttpClient, HttpClientInputs httpClientInputs, String shellId, String commandId, WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, URISyntaxException, TransformerException, TimeoutException, XPathExpressionException, SAXException, ParserConfigurationException, InterruptedException { String documentStr = ResourceLoader.loadAsString(RECEIVE_REQUEST_XML); documentStr = createReceiveRequestBody(documentStr, httpClientInputs.getUrl(), shellId, commandId, String.valueOf(wsManRequestInputs.getMaxEnvelopeSize()), wsManRequestInputs.getWinrmLocale(), String.valueOf(wsManRequestInputs.getOperationTimeout())); Map<String, String> receiveResult; while (true) { receiveResult = executeRequestWithBody(csHttpClient, httpClientInputs, documentStr); if (executionIsTimedOut(commandExecutionStartTime, wsManRequestInputs.getOperationTimeout())) { throw new TimeoutException(EXECUTION_TIMED_OUT); } else if (WSManUtils.isSpecificResponseAction(receiveResult.get(RETURN_RESULT), RECEIVE_RESPONSE_ACTION) && WSManUtils.commandExecutionIsDone(receiveResult.get(RETURN_RESULT))) { return processCommandExecutionResponse(receiveResult); } else if (WSManUtils.isFaultResponse(receiveResult.get(RETURN_RESULT))) { throw new RuntimeException(WSManUtils.getResponseFault(receiveResult.get(RETURN_RESULT))); } try { Thread.sleep(200); } catch (InterruptedException e) { throw e; } } } WSManRemoteShellService();  WSManRemoteShellService(PSEdition psEdition); Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs); }
WSManRemoteShellService { private Map<String, String> receiveCommandResult(HttpClientService csHttpClient, HttpClientInputs httpClientInputs, String shellId, String commandId, WSManRequestInputs wsManRequestInputs) throws RuntimeException, IOException, URISyntaxException, TransformerException, TimeoutException, XPathExpressionException, SAXException, ParserConfigurationException, InterruptedException { String documentStr = ResourceLoader.loadAsString(RECEIVE_REQUEST_XML); documentStr = createReceiveRequestBody(documentStr, httpClientInputs.getUrl(), shellId, commandId, String.valueOf(wsManRequestInputs.getMaxEnvelopeSize()), wsManRequestInputs.getWinrmLocale(), String.valueOf(wsManRequestInputs.getOperationTimeout())); Map<String, String> receiveResult; while (true) { receiveResult = executeRequestWithBody(csHttpClient, httpClientInputs, documentStr); if (executionIsTimedOut(commandExecutionStartTime, wsManRequestInputs.getOperationTimeout())) { throw new TimeoutException(EXECUTION_TIMED_OUT); } else if (WSManUtils.isSpecificResponseAction(receiveResult.get(RETURN_RESULT), RECEIVE_RESPONSE_ACTION) && WSManUtils.commandExecutionIsDone(receiveResult.get(RETURN_RESULT))) { return processCommandExecutionResponse(receiveResult); } else if (WSManUtils.isFaultResponse(receiveResult.get(RETURN_RESULT))) { throw new RuntimeException(WSManUtils.getResponseFault(receiveResult.get(RETURN_RESULT))); } try { Thread.sleep(200); } catch (InterruptedException e) { throw e; } } } WSManRemoteShellService();  WSManRemoteShellService(PSEdition psEdition); Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs);  }