public static SoapOperation generateSoapOperation(){ final SoapOperation soapOperation = new SoapOperation(); soapOperation.setId("SOAP OPERATION"); soapOperation.setName("Soap operation name"); soapOperation.setCurrentResponseSequenceIndex(1); soapOperation.setDefaultBody("Default body"); soapOperation.setForwardedEndpoint("Forwarded event"); soapOperation.setInvokeAddress("Invoke address"); soapOperation.setOriginalEndpoint("Original endpoint"); soapOperation.setHttpMethod(HttpMethod.POST); soapOperation.setStatus(SoapOperationStatus.MOCKED); soapOperation.setSoapVersion(SoapVersion.SOAP11); soapOperation.setIdentifyStrategy(SoapOperationIdentifyStrategy.ELEMENT_NAMESPACE); soapOperation.setMockResponses(new ArrayList<SoapMockResponse>()); return soapOperation; } }
for(SoapMockResponse mockResponse : soapOperation.getMockResponses()){ if(mockResponse.getStatus().equals(SoapMockResponseStatus.ENABLED)){ mockResponses.add(mockResponse); throw new SoapException("No mocked response created for operation " + soapOperation.getName()); } else if(soapOperation.getResponseStrategy().equals(SoapResponseStrategy.RANDOM)){ final Integer responseIndex = RANDOM.nextInt(mockResponses.size()); mockResponse = mockResponses.get(responseIndex); } else if(soapOperation.getResponseStrategy().equals(SoapResponseStrategy.SEQUENCE)){ Integer currentSequenceNumber = soapOperation.getCurrentResponseSequenceIndex(); if(currentSequenceNumber >= mockResponses.size()){ currentSequenceNumber = 0; .projectId(soapProjectId) .portId(soapPortId) .operationId(soapOperation.getId()) .currentResponseSequenceIndex(currentSequenceNumber + 1) .build()); } else if (soapOperation.getResponseStrategy().equals(SoapResponseStrategy.XPATH_INPUT)) { for (SoapMockResponse testedMockResponse : mockResponses) { for(SoapXPathExpression xPathExpression : testedMockResponse.getXpathExpressions()){ throw new SoapException("No mocked response created for operation " + soapOperation.getName());
private SoapOperation createSoapOperation(String portId, String name) { SoapOperation soapOperation = new SoapOperation(); soapOperation.setName(name); soapOperation.setPortId(portId); return soapOperation; }
/** * 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()); } }
SoapOperation operation = new SoapOperation(); operation.setId(operationV1.getId()); operation.setName(operationV1.getName()); operation.setResponseStrategy(operationV1.getResponseStrategy()); operation.setStatus(operationV1.getStatus()); operation.setHttpMethod(operationV1.getHttpMethod()); operation.setSoapVersion(operationV1.getSoapVersion()); operation.setDefaultBody(operationV1.getDefaultBody()); operation.setCurrentResponseSequenceIndex(operationV1.getCurrentResponseSequenceIndex()); operation.setForwardedEndpoint(operationV1.getForwardedEndpoint()); operation.setOriginalEndpoint(operationV1.getOriginalEndpoint()); operation.setDefaultXPathMockResponseId(operationV1.getDefaultXPathMockResponseId()); operation.setSimulateNetworkDelay(operationV1.getSimulateNetworkDelay()); operation.setNetworkDelay(operationV1.getNetworkDelay()); operation.setPortId(port.getId()); port.getOperations().add(operation); mockResponse.setName(mockResponseV1.getName()); mockResponse.setBody(mockResponseV1.getBody()); mockResponse.setOperationId(operation.getId()); mockResponse.setStatus(mockResponseV1.getStatus()); mockResponse.setHttpStatusCode(mockResponseV1.getHttpStatusCode()); operation.getMockResponses().add(mockResponse);
createSoapOperationIdentifier(outputMessagePart, namespaces); final SoapOperation soapOperation = new SoapOperation(); soapOperation.setOperationIdentifier(operationRequestIdentifier); soapOperation.setName(bindingOperation.getName()); soapOperation.setHttpMethod(HttpMethod.POST); soapOperation.setStatus(SoapOperationStatus.MOCKED); soapOperation.setResponseStrategy(SoapResponseStrategy.RANDOM); soapOperation.setForwardedEndpoint(address.getLocation()); soapOperation.setOriginalEndpoint(address.getLocation()); soapOperation.setSoapVersion(address.getVersion()); soapOperation.setMockResponses(new ArrayList<SoapMockResponse>()); soapOperation.setDefaultBody(generateDefaultBody(operationResponseIdentifier)); soapOperation.setCurrentResponseSequenceIndex(DEFAULT_RESPONSE_SEQUENCE_INDEX); soapOperation.setIdentifyStrategy(SoapOperationIdentifyStrategy.ELEMENT_NAMESPACE);
final SoapOperation soapOperation = new SoapOperation(); soapOperation.setCurrentResponseSequenceIndex(0); soapOperation.setForwardedEndpoint(FORWARD_ENDPOINT); soapOperation.setHttpMethod(HttpMethod.GET); soapOperation.setId(SOAP_OPERATION_ID); soapOperation.setInvokeAddress("http://localhost:8080" + CONTEXT + SLASH + MOCK + SLASH + SOAP + SLASH + PROJECT + SLASH + PROJECT_ID + SLASH + SOAP_PORT_ID); soapOperation.setName("SOAP operation name"); soapOperation.setNetworkDelay(0L); soapOperation.setResponseStrategy(SoapResponseStrategy.SEQUENCE); soapOperation.setSimulateNetworkDelay(false); soapOperation.setStatus(SoapOperationStatus.MOCKED); soapOperation.setMockResponses(Arrays.asList(soapMockResponse));
if(this.operationRepository.exists(operation.getId())){ throw new IllegalArgumentException("An operation with the following key already exists: " + operation.getId()); if(operation.getOperationIdentifier() == null){ SoapOperationIdentifier operationIdentifier = new SoapOperationIdentifier(); operationIdentifier.setName(operation.getIdentifier()); operation.setOperationIdentifier(operationIdentifier); operation.setIdentifier(null); if(operation.getIdentifyStrategy() == null){ operation.setIdentifyStrategy(SoapOperationIdentifyStrategy.ELEMENT_NAMESPACE); if(operation.getCurrentResponseSequenceIndex() == null){ operation.setCurrentResponseSequenceIndex(0); if(!Strings.isNullOrEmpty(operation.getDefaultXPathMockResponseId())){ operation.setDefaultMockResponseId(operation.getDefaultXPathMockResponseId()); operation.setDefaultXPathMockResponseId(null); operation.setCurrentResponseSequenceIndex(0); this.operationRepository.save(operation);
private SoapOperation createSoapOperation(String portId, HttpMethod method, SoapVersion soapVersion, String identifierName, String namespace) { SoapOperation soapOperation = new SoapOperation(); soapOperation.setPortId(portId); soapOperation.setHttpMethod(method); soapOperation.setSoapVersion(soapVersion); soapOperation.setIdentifyStrategy(SoapOperationIdentifyStrategy.ELEMENT_NAMESPACE); SoapOperationIdentifier soapOperationIdentifier = new SoapOperationIdentifier(); soapOperationIdentifier.setName(identifierName); soapOperationIdentifier.setNamespace(namespace); soapOperation.setOperationIdentifier(soapOperationIdentifier); return soapOperation; }
soapOperation.setPortId(savedSoapPort.getId()); SoapOperation savedSoapOperation = this.operationRepository.save(soapOperation); for(SoapMockResponse soapMockResponse : soapOperation.getMockResponses()){ soapMockResponse.setOperationId(savedSoapOperation.getId()); this.mockResponseRepository.save(soapMockResponse); this.operationRepository.findWithName(existingSoapPort.getId(), newSoapOperation.getName()); existingSoapOperation.setOriginalEndpoint(newSoapOperation.getOriginalEndpoint()); existingSoapOperation.setSoapVersion(newSoapOperation.getSoapVersion()); this.operationRepository.update(existingSoapOperation.getId(), existingSoapOperation); } else { newSoapOperation.setPortId(existingSoapPort.getId()); SoapOperation savedSoapOperation = this.operationRepository.save(newSoapOperation); for(SoapMockResponse soapMockResponse : newSoapOperation.getMockResponses()){ soapMockResponse.setOperationId(savedSoapOperation.getId()); this.mockResponseRepository.save(soapMockResponse);
.projectId(projectId) .portId(portId) .operationId(operation.getId()) .operation(operation) .build(); Mockito.when(operationRepository.findOne(operation.getId())).thenReturn(operation); Mockito.when(operationRepository.update(Mockito.anyString(), Mockito.any(SoapOperation.class))).thenReturn(operation); final SoapOperation returnedSoapOperation = output.getOperation(); Mockito.verify(operationRepository, Mockito.times(1)).findOne(operation.getId()); Mockito.verify(operationRepository, Mockito.times(1)).update(operation.getId(), operation); Assert.assertEquals(operation.getId(), returnedSoapOperation.getId()); Assert.assertEquals(operation.getName(), returnedSoapOperation.getName()); Assert.assertEquals(operation.getStatus(), returnedSoapOperation.getStatus()); Assert.assertEquals(operation.getForwardedEndpoint(), returnedSoapOperation.getForwardedEndpoint()); Assert.assertEquals(operation.getResponseStrategy(), returnedSoapOperation.getResponseStrategy()); Assert.assertEquals(operation.getSimulateNetworkDelay(), returnedSoapOperation.getSimulateNetworkDelay()); Assert.assertEquals(operation.getNetworkDelay(), returnedSoapOperation.getNetworkDelay()); Assert.assertEquals(operation.getCurrentResponseSequenceIndex(), returnedSoapOperation.getCurrentResponseSequenceIndex()); Assert.assertEquals(operation.getDefaultXPathMockResponseId(), returnedSoapOperation.getDefaultXPathMockResponseId()); Assert.assertEquals(operation.getMockOnFailure(), returnedSoapOperation.getMockOnFailure());
try { connection = HttpMessageSupport.establishConnection( soapOperation.getForwardedEndpoint(), request.getHttpMethod(), request.getBody(), if(soapOperation.getMockOnFailure()){ " to mock response upon error: " + soapOperation.getId()); return this.mockResponse(request, soapProjectId, soapPortId, soapOperation); if(SoapOperationStatus.RECORDING.equals(soapOperation.getStatus()) || SoapOperationStatus.RECORD_ONCE.equals(soapOperation.getStatus())){ final SoapMockResponse mockResponse = new SoapMockResponse(); final Date date = new Date(); .operationId(soapOperation.getId()) .mockResponse(mockResponse) .build()); if(SoapOperationStatus.RECORD_ONCE.equals(soapOperation.getStatus())){ soapOperation.setStatus(SoapOperationStatus.MOCKED); serviceProcessor.process(UpdateSoapOperationInput.builder().projectId(soapProjectId) .portId(soapPortId) .operationId(soapOperation.getId()) .operation(soapOperation) .build());
SoapResponse response = null; try { event = new SoapEvent(soapOperation.getName(), request, soapProjectId, soapPortId, soapOperation.getId()); if (SoapOperationStatus.DISABLED.equals(soapOperation.getStatus())) { throw new SoapException("The requested soap operation, " + soapOperation.getName() + ", is disabled"); } else if (SoapOperationStatus.FORWARDED.equals(soapOperation.getStatus()) || SoapOperationStatus.RECORDING.equals(soapOperation.getStatus()) || SoapOperationStatus.RECORD_ONCE.equals(soapOperation.getStatus())) { response = forwardRequest(request, soapProjectId, soapPortId, soapOperation); } else if (SoapOperationStatus.ECHO.equals(soapOperation.getStatus())) { response = echoResponse(request); } else { // Status.MOCKED if(soapOperation.getSimulateNetworkDelay() && soapOperation.getNetworkDelay() >= 0){ try { Thread.sleep(soapOperation.getNetworkDelay()); } catch (InterruptedException e) { LOGGER.error("Unable to simulate network delay", e);
protected SoapPort deletePort(final String portId){ final List<SoapOperation> operations = this.operationRepository.findWithPortId(portId); operations.forEach(operation -> this.deleteOperation(operation.getId())); return this.portRepository.delete(portId); }
private void verify(final SoapPort soapPort, final String name, final SoapVersion soapVersion){ Assert.assertEquals(name + ".Endpoint", soapPort.getName()); Assert.assertEquals(name + ".Endpoint", soapPort.getUri()); Assert.assertEquals(1, soapPort.getOperations().size()); SoapOperation soapOperation = soapPort.getOperations().get(0); Assert.assertEquals(name, soapOperation.getName()); Assert.assertEquals(SoapResponseStrategy.RANDOM, soapOperation.getResponseStrategy()); Assert.assertEquals(SoapOperationStatus.MOCKED, soapOperation.getStatus()); Assert.assertEquals(soapVersion, soapOperation.getSoapVersion()); Assert.assertEquals(HttpMethod.POST, soapOperation.getHttpMethod()); SoapOperationIdentifier operationIdentifier = soapOperation.getOperationIdentifier(); Assert.assertNotNull(operationIdentifier); Assert.assertEquals("Request", operationIdentifier.getName()); Assert.assertEquals("http://Services/ServiceExample/ServiceExample/1/Schema", operationIdentifier.getNamespace()); }
/** * 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<UpdateSoapOperationsForwardedEndpointOutput> process(final ServiceTask<UpdateSoapOperationsForwardedEndpointInput> serviceTask) { final UpdateSoapOperationsForwardedEndpointInput input = serviceTask.getInput(); input.getOperations().stream() .map(soapOperation -> this.operationRepository.findOne(soapOperation.getId())) .findFirst() .map(soapOperation -> { soapOperation.setForwardedEndpoint(input.getForwardedEndpoint()); return this.operationRepository.update(soapOperation.getId(), soapOperation); }); return createServiceResult(UpdateSoapOperationsForwardedEndpointOutput.builder().build()); } }
if(this.operationRepository.exists(operation.getId())){ throw new IllegalArgumentException("An operation with the following key already exists: " + operation.getId()); 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());
final String projectId = this.portRepository.getProjectId(operation.getPortId()); final SearchResult searchResult = new SearchResult(); searchResult.setTitle(operation.getName()); searchResult.setLink(SOAP + SLASH + PROJECT + SLASH + projectId + SLASH + PORT + SLASH + operation.getPortId() + SLASH + OPERATION + SLASH + operation.getId()); searchResult.setDescription(SOAP_TYPE + COMMA + operationType); searchResults.add(searchResult);
@Test public void testServiceFunctionalityUpdateEndpoint() throws Exception { final String projectId = "projectId"; final String portId = "portId"; final String[] soapOperationIds = {"Operation1", "Operation2"}; final SoapOperation soapOperation1 = new SoapOperation(); soapOperation1.setId("SoapOperation1"); final SoapOperation soapOperation2 = new SoapOperation(); soapOperation2.setId("SoapOperation2"); Mockito.when(serviceProcessor.process(Mockito.any(ReadSoapOperationInput.class))) .thenReturn(ReadSoapOperationOutput.builder().operation(soapOperation1).build()) .thenReturn(ReadSoapOperationOutput.builder().operation(soapOperation2).build()); final List<SoapOperation> operations = Arrays.asList(soapOperation1, soapOperation2); final SoapOperationModifierCommand command = new SoapOperationModifierCommand(); command.setSoapOperationIds(soapOperationIds); command.setSoapOperationStatus("ENABLED"); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + PORT + SLASH + portId) .param("action", "update-endpoint").flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().size(4 + GLOBAL_VIEW_MODEL_COUNT)) .andExpect(MockMvcResultMatchers.forwardedUrl(INDEX)) .andExpect(MockMvcResultMatchers.model().attribute(PARTIAL, UPDATE_SOAP_OPERATIONS_ENDPOINT_PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_PROJECT_ID, projectId)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_PORT_ID, portId)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_OPERATIONS, operations)) .andExpect(MockMvcResultMatchers.model().attributeExists(UPDATE_SOAP_OPERATIONS_ENDPOINT_COMMAND)); Mockito.verify(serviceProcessor, Mockito.times(2)).process(Mockito.isA(ReadSoapOperationInput.class)); }
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; }