public static SoapMockResponse generateSoapMockResponse(){ final SoapXPathExpression soapXPathExpression1 = new SoapXPathExpression(); final SoapXPathExpression soapXPathExpression2 = new SoapXPathExpression(); soapXPathExpression1.setExpression("//Request/Name[text()='Input1']"); soapXPathExpression2.setExpression("//Request/Name[text()='Input2']"); final SoapMockResponse soapMockResponse = new SoapMockResponse(); soapMockResponse.setName("Soap mock response name"); soapMockResponse.setBody("Soap mock response body"); soapMockResponse.setId("SOAP MOCK RESPONSE"); soapMockResponse.setXpathExpression("//Request/Name[text()='Input1']"); soapMockResponse.setXpathExpressions(Arrays.asList(soapXPathExpression1, soapXPathExpression2)); soapMockResponse.setStatus(SoapMockResponseStatus.ENABLED); return soapMockResponse; } }
for (SoapMockResponse testedMockResponse : mockResponses) { for(SoapXPathExpression xPathExpression : testedMockResponse.getXpathExpressions()){ if (XPathUtility.isValidXPathExpr(request.getBody(), xPathExpression.getExpression())) { mockResponse = testedMockResponse; break;
@Test public void testMockedXpathMatch(){ // Input final HttpServletRequest httpServletRequest = getMockedHttpServletRequest(REQUEST_BODY); final HttpServletResponse httpServletResponse = getHttpServletResponse(); final SoapXPathExpression xPathExpression = new SoapXPathExpression(); xPathExpression.setExpression("//ServiceName/value[text()='Input']"); final SoapOperation soapOperation = getSoapOperation(); soapOperation.getMockResponses().get(0).getXpathExpressions().add(xPathExpression); soapOperation.setResponseStrategy(SoapResponseStrategy.XPATH_INPUT); final IdentifySoapOperationOutput identifySoapOperationOutput = IdentifySoapOperationOutput.builder() .projectId(PROJECT_ID) .portId(SOAP_PORT_ID) .operationId(SOAP_OPERATION_ID) .operation(soapOperation) .build(); when(serviceProcessor.process(any(IdentifySoapOperationInput.class))).thenReturn(identifySoapOperationOutput); when(httpServletRequest.getRequestURI()).thenReturn(CONTEXT + SLASH + MOCK + SLASH + SOAP + SLASH + PROJECT + SLASH + PROJECT_ID + SLASH + SOAP_PORT_ID); final ResponseEntity responseEntity = soapServiceController.postMethod(PROJECT_ID, httpServletRequest, httpServletResponse); Assert.assertEquals(RESPONSE_BODY, responseEntity.getBody()); Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); Assert.assertEquals(true, responseEntity.getHeaders().containsKey(CONTENT_TYPE_HEADER)); Assert.assertEquals(true, responseEntity.getHeaders().containsKey(ACCEPT_HEADER)); Assert.assertEquals(APPLICATION_XML, responseEntity.getHeaders().get(CONTENT_TYPE_HEADER).get(0)); Assert.assertEquals(APPLICATION_XML, responseEntity.getHeaders().get(ACCEPT_HEADER).get(0)); }
final SoapXPathExpression xPathExpression = new SoapXPathExpression(); xPathExpression.setExpression(mockResponse.getXpathExpression()); mockResponse.getXpathExpressions().add(xPathExpression); mockResponse.setXpathExpression(null);