@Test public void testMockedXpathDefaultResponse(){ // Input final HttpServletRequest httpServletRequest = getMockedHttpServletRequest(REQUEST_BODY); final HttpServletResponse httpServletResponse = getHttpServletResponse(); final SoapOperation soapOperation = getSoapOperation(); soapOperation.setDefaultResponseName("Mocked response"); soapOperation.setDefaultMockResponseId("MockResponseId"); 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)); }
@Test public void testProcessWithDefaultXPathResponse(){ final SoapOperation operation = SoapOperationGenerator.generateSoapOperation(); final SoapMockResponse mockResponse = SoapMockResponseGenerator.generateSoapMockResponse(); final String projectId = "SOAP PROJECT"; final String portId = "SOAP PORT"; operation.setDefaultMockResponseId(mockResponse.getId()); final ReadSoapOperationInput input = ReadSoapOperationInput.builder() .projectId(projectId) .portId(portId) .operationId(operation.getId()) .build(); final ServiceTask<ReadSoapOperationInput> serviceTask = new ServiceTask<ReadSoapOperationInput>(input); Mockito.when(operationRepository.findOne(operation.getId())).thenReturn(operation); Mockito.when(mockResponseRepository.findWithOperationId(operation.getId())).thenReturn(Arrays.asList(mockResponse)); final ServiceResult<ReadSoapOperationOutput> result = service.process(serviceTask); Mockito.verify(operationRepository, Mockito.times(1)).findOne(operation.getId()); Mockito.verify(mockResponseRepository, Mockito.times(1)).findWithOperationId(operation.getId()); Assert.assertNotNull(result.getOutput()); Assert.assertEquals(operation, result.getOutput().getOperation()); Assert.assertEquals(mockResponse.getName(), operation.getDefaultResponseName()); }
operation.setDefaultMockResponseId(operation.getDefaultXPathMockResponseId()); operation.setDefaultXPathMockResponseId(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<UpdateSoapOperationOutput> process(final ServiceTask<UpdateSoapOperationInput> serviceTask) { final UpdateSoapOperationInput input = serviceTask.getInput(); final SoapOperation updated = input.getOperation(); final SoapOperation soapOperation = this.operationRepository.findOne(input.getOperationId()); soapOperation.setStatus(updated.getStatus()); soapOperation.setForwardedEndpoint(updated.getForwardedEndpoint()); soapOperation.setResponseStrategy(updated.getResponseStrategy()); soapOperation.setSimulateNetworkDelay(updated.getSimulateNetworkDelay()); soapOperation.setNetworkDelay(updated.getNetworkDelay()); soapOperation.setDefaultMockResponseId(updated.getDefaultMockResponseId()); soapOperation.setMockOnFailure(updated.getMockOnFailure()); soapOperation.setIdentifyStrategy(updated.getIdentifyStrategy()); final SoapOperation updatedSoapOperation = this.operationRepository.update(input.getOperationId(), soapOperation); return createServiceResult(UpdateSoapOperationOutput.builder() .operation(updatedSoapOperation) .build()); } }