/** * THe method provides the functionality to parse a document and extract all the SOAP ports from the SOAP ports. * The method will also generate mocked responses if the {@code generateResponse} * @param document The document which will be parsed * @param generateResponse Boolean value determining if a response should be generated for each extracted * operation. * @return A list of SOAP ports */ private Set<SoapPort> parseDocument(final Document document, final boolean generateResponse){ final Set<Binding> bindings = BINDING_PARSER.parseBindings(document); final Set<Message> messages = MESSAGE_PARSER.parseMessages(document); final Set<Service> services = SERVICE_PARSER.parseServices(document); final Set<PortType> portTypes = PORT_TYPE_PARSER.parsePortTypes(document); final Set<Namespace> namespaces = NAMESPACE_PARSER.parseNamespaces(document); final Set<SoapPort> ports = services.stream() .map(Service::getPorts) .flatMap(Collection::stream) .map(servicePort -> createSoapPort(servicePort, bindings, portTypes, messages, namespaces)) .collect(Collectors.toSet()); if(generateResponse){ ports.stream() .map(SoapPort::getOperations) .flatMap(List::stream) .forEach(operation -> operation.getMockResponses() .add(createSoapMockResponse(operation.getDefaultBody()))); } return ports; }
public static SoapProject generateFullSoapProject(){ final SoapProject soapProject = new SoapProject(); soapProject.setId("SOAP PROJECT"); soapProject.setName("Project name"); soapProject.setDescription("Project description"); soapProject.setCreated(new Date()); soapProject.setUpdated(new Date()); soapProject.setPorts(new ArrayList<SoapPort>()); for(int portIndex = 0; portIndex < 3; portIndex++){ final SoapPort soapPort = SoapPortGenerator.generateSoapPort(); soapPort.setOperations(new ArrayList<SoapOperation>()); soapProject.getPorts().add(soapPort); for(int operationIndex = 0; operationIndex < 3; operationIndex++){ final SoapOperation soapOperation = SoapOperationGenerator.generateSoapOperation(); soapOperation.setMockResponses(new ArrayList<SoapMockResponse>()); soapPort.getOperations().add(soapOperation); for(int responseIndex = 0; responseIndex < 3; responseIndex++){ final SoapMockResponse soapMockResponse = SoapMockResponseGenerator.generateSoapMockResponse(); soapOperation.getMockResponses().add(soapMockResponse); } } } return soapProject; }
for(SoapMockResponse mockResponse : operation.getMockResponses()){ if(this.mockResponseRepository.exists(mockResponse.getId())){ throw new IllegalArgumentException("A mocked response with the following key already exists: " + mockResponse.getId());
for(SoapMockResponse mockResponse : soapOperation.getMockResponses()){ if(mockResponse.getStatus().equals(SoapMockResponseStatus.ENABLED)){ mockResponses.add(mockResponse);
@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)); }
@Test public void testProcess(){ final SoapProject soapProject = SoapProjectGenerator.generateSoapProject(); final SoapPort soapPort = SoapPortGenerator.generateSoapPort(); final SoapOperation soapOperation = SoapOperationGenerator.generateSoapOperation(); final SoapMockResponse soapMockResponse = SoapMockResponseGenerator.generateSoapMockResponse(); soapProject.getPorts().add(soapPort); soapPort.getOperations().add(soapOperation); soapOperation.getMockResponses().add(soapMockResponse); final DeleteSoapMockResponseInput input = DeleteSoapMockResponseInput.builder() .projectId(soapProject.getId()) .portId(soapPort.getId()) .operationId(soapOperation.getId()) .mockResponseId(soapMockResponse.getId()) .build(); final ServiceTask<DeleteSoapMockResponseInput> serviceTask = new ServiceTask<DeleteSoapMockResponseInput>(input); final ServiceResult<DeleteSoapMockResponseOutput> serviceResult = service.process(serviceTask); serviceResult.getOutput(); Mockito.verify(mockResponseRepository, Mockito.times(1)).delete(Mockito.anyString()); } }
soapOperation.setPortId(savedSoapPort.getId()); SoapOperation savedSoapOperation = this.operationRepository.save(soapOperation); for(SoapMockResponse soapMockResponse : soapOperation.getMockResponses()){ soapMockResponse.setOperationId(savedSoapOperation.getId()); this.mockResponseRepository.save(soapMockResponse); newSoapOperation.setPortId(existingSoapPort.getId()); SoapOperation savedSoapOperation = this.operationRepository.save(newSoapOperation); for(SoapMockResponse soapMockResponse : newSoapOperation.getMockResponses()){ soapMockResponse.setOperationId(savedSoapOperation.getId()); this.mockResponseRepository.save(soapMockResponse);
operation.getMockResponses().add(mockResponse);