} else if (soapOperation.getResponseStrategy().equals(SoapResponseStrategy.XPATH_INPUT)) { for (SoapMockResponse testedMockResponse : mockResponses) { for(SoapXPathExpression xPathExpression : testedMockResponse.getXpathExpressions()){ if (XPathUtility.isValidXPathExpr(request.getBody(), xPathExpression.getExpression())) { mockResponse = testedMockResponse;
Assert.assertEquals(mockResponse.getStatus(), returnedSoapMockResponse.getStatus()); Assert.assertEquals(mockResponse.isUsingExpressions(), returnedSoapMockResponse.isUsingExpressions()); Assert.assertEquals(mockResponse.getXpathExpressions(), returnedSoapMockResponse.getXpathExpressions());
@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);
/** * The process message is responsible for processing an incoming serviceTask and generate * a response based on the incoming serviceTask input * @param serviceTask The serviceTask that will be processed by the service * @return A result based on the processed incoming serviceTask * @see ServiceTask * @see ServiceResult */ @Override public ServiceResult<UpdateSoapMockResponseOutput> process(final ServiceTask<UpdateSoapMockResponseInput> serviceTask) { final UpdateSoapMockResponseInput input = serviceTask.getInput(); final SoapMockResponse updated = input.getMockResponse(); final SoapMockResponse mockResponse = this.mockResponseRepository.findOne(input.getMockResponseId()); mockResponse.setName(updated.getName()); mockResponse.setBody(updated.getBody()); mockResponse.setHttpStatusCode(updated.getHttpStatusCode()); mockResponse.setStatus(updated.getStatus()); mockResponse.setHttpHeaders(updated.getHttpHeaders()); mockResponse.setUsingExpressions(updated.isUsingExpressions()); mockResponse.setXpathExpressions(updated.getXpathExpressions()); final SoapMockResponse updatedSoapMockResponse = mockResponseRepository.update(input.getMockResponseId(), mockResponse); return createServiceResult(UpdateSoapMockResponseOutput.builder() .mockResponse(updatedSoapMockResponse) .build()); } }