public static SoapPort generateSoapPort(){ final SoapPort soapPort = new SoapPort(); soapPort.setId("SOAP PORT"); soapPort.setName("Soap port name"); soapPort.setUri("UrlPath"); soapPort.setOperations(new ArrayList<SoapOperation>()); return soapPort; }
if(this.portRepository.exists(port.getId())){ throw new IllegalArgumentException("A port with the following key already exists: " + port.getId()); for(SoapOperation operation : port.getOperations()){ if(this.operationRepository.exists(operation.getId())){ throw new IllegalArgumentException("An operation with the following key already exists: " + operation.getId());
@Test public void testProcess(){ final String projectId = "ProjectId"; final SoapPort port = SoapPortGenerator.generateSoapPort(); final UpdateSoapPortInput input = UpdateSoapPortInput.builder() .projectId(projectId) .portId(port.getId()) .port(port) .build(); final ServiceTask<UpdateSoapPortInput> serviceTask = new ServiceTask<UpdateSoapPortInput>(input); Mockito.when(soapPortRepository.findOne(port.getId())).thenReturn(port); Mockito.when(soapPortRepository.update(Mockito.anyString(), Mockito.any(SoapPort.class))).thenReturn(port); final ServiceResult<UpdateSoapPortOutput> result = service.process(serviceTask); final UpdateSoapPortOutput output = result.getOutput(); final SoapPort returnedSoapPort = output.getPort(); Mockito.verify(soapPortRepository, Mockito.times(1)).findOne(port.getId()); Mockito.verify(soapPortRepository, Mockito.times(1)).update(port.getId(), port); Assert.assertEquals(port.getId(), returnedSoapPort.getId()); Assert.assertEquals(port.getName(), returnedSoapPort.getName()); Assert.assertEquals(port.getUri(), returnedSoapPort.getUri()); Assert.assertEquals(port.getProjectId(), returnedSoapPort.getProjectId()); } }
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; }
/** * Returns an port that matches the incoming parameters (soapProjectId and soapPortId) * @param soapProjectId The id of the project which the port belongs to * @param soapPortId The id of the port that should be returned * @param request The incoming servlet request. Used to extract the address used to invoke the SOAP operation * @return Returns an port that matches the incoming parameters (projectId and soapPortId) */ @PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{soapProjectId}/port/{soapPortId}", method = RequestMethod.GET) public ModelAndView getSoapPort(@PathVariable final String soapProjectId, @PathVariable final String soapPortId, final ServletRequest request) { final ReadSoapPortOutput readSoapPortOutput = serviceProcessor.process(ReadSoapPortInput.builder() .projectId(soapProjectId) .portId(soapPortId) .build()); final SoapPort soapPort = readSoapPortOutput.getPort(); final String protocol = getProtocol(request); final String invokeAddress = getSoapInvokeAddress(protocol, request.getServerPort(), soapProjectId, soapPort.getUri()); soapPort.setInvokeAddress(invokeAddress); final ModelAndView model = createPartialModelAndView(PAGE); model.addObject(SOAP_PROJECT_ID,soapProjectId); model.addObject(SOAP_PORT,soapPort); model.addObject(SOAP_OPERATION_STATUSES, getSoapOperationStatuses()); model.addObject(SOAP_OPERATION_MODIFIER_COMMAND, new SoapOperationModifierCommand()); return model; }
SoapPort port = new SoapPort(); port.setName(portV1.getName()); port.setUri(portV1.getUri()); port.setId(portV1.getId()); port.setProjectId(project.getId()); project.getPorts().add(port); operation.setSimulateNetworkDelay(operationV1.getSimulateNetworkDelay()); operation.setNetworkDelay(operationV1.getNetworkDelay()); operation.setPortId(port.getId()); port.getOperations().add(operation);
protected SoapProject deleteProject(final String projectId){ final List<SoapPort> ports = this.portRepository.findWithProjectId(projectId); final List<SoapResource> resources = this.resourceRepository.findWithProjectId(projectId); ports.forEach(port -> this.deletePort(port.getId())); resources.forEach(resource -> this.deleteResource(resource.getId())); return this.repository.delete(projectId); }
newSoapPort.setProjectId(soapProjectId); SoapPort existingSoapPort = this.portRepository.findWithName(soapProjectId, newSoapPort.getName()); for(SoapOperation soapOperation : newSoapPort.getOperations()){ soapOperation.setPortId(savedSoapPort.getId()); SoapOperation savedSoapOperation = this.operationRepository.save(soapOperation); for(SoapMockResponse soapMockResponse : soapOperation.getMockResponses()){ for(SoapOperation newSoapOperation : newSoapPort.getOperations()){ SoapOperation existingSoapOperation = this.operationRepository.findWithName(existingSoapPort.getId(), newSoapOperation.getName()); this.operationRepository.update(existingSoapOperation.getId(), existingSoapOperation); } else { newSoapOperation.setPortId(existingSoapPort.getId()); SoapOperation savedSoapOperation = this.operationRepository.save(newSoapOperation); for(SoapMockResponse soapMockResponse : newSoapOperation.getMockResponses()){
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()); }
searchResult.setTitle(port.getName()); searchResult.setLink(SOAP + SLASH + PROJECT + SLASH + port.getProjectId() + SLASH + PORT + SLASH + port.getId()); searchResult.setDescription(SOAP_TYPE + COMMA + portType); searchResults.add(searchResult);
@Test public void getSoapPort() throws Exception { final SoapProject soapProject = SoapProjectGenerator.generateSoapProject(); final SoapPort soapPort = SoapPortGenerator.generateSoapPort(); final SoapOperation soapOperation = SoapOperationGenerator.generateSoapOperation(); final List<SoapOperation> operations = new ArrayList<SoapOperation>(); operations.add(soapOperation); soapPort.setOperations(operations); when(serviceProcessor.process(any(ReadSoapPortInput.class))).thenReturn(ReadSoapPortOutput.builder() .port(soapPort) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + soapProject.getId() + SLASH + PORT + SLASH + soapPort.getId() + SLASH); ResultActions result = 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, PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_PORT, soapPort)); SoapPort soapPortResponse = (SoapPort) result.andReturn().getModelAndView().getModel().get(SOAP_PORT); }
/** * 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<UpdateSoapPortOutput> process(final ServiceTask<UpdateSoapPortInput> serviceTask) { final UpdateSoapPortInput input = serviceTask.getInput(); final SoapPort updated = input.getSoapPort(); final SoapPort soapPort = this.portRepository.findOne(input.getPortId()); soapPort.setUri(updated.getUri()); final SoapPort updatedSoapPort = this.portRepository.update(input.getPortId(), soapPort); return createServiceResult(UpdateSoapPortOutput.builder() .port(updatedSoapPort) .build()); } }
@Test public void testDefaultPage() throws Exception { final SoapProject soapProject = SoapProjectGenerator.generateSoapProject(); final SoapPort soapPort = SoapPortGenerator.generateSoapPort(); final SoapOperation soapOperation = SoapOperationGenerator.generateSoapOperation(); when(serviceProcessor.process(isA(ReadSoapPortInput.class))).thenReturn(ReadSoapPortOutput.builder() .port(soapPort) .build()); when(serviceProcessor.process(isA(ReadSoapOperationInput.class))).thenReturn(ReadSoapOperationOutput.builder() .operation(soapOperation) .build()); when(serviceProcessor.process(isA(ReadSoapEventsByOperationIdInput.class))).thenReturn(ReadSoapEventsByOperationIdOutput.builder() .soapEvents(new ArrayList<SoapEvent>()) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + soapProject.getId() + SLASH + PORT + SLASH + soapPort.getId() + SLASH + OPERATION + SLASH + soapOperation.getId() + SLASH); ResultActions result = mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().size(6 + GLOBAL_VIEW_MODEL_COUNT)) .andExpect(MockMvcResultMatchers.forwardedUrl(INDEX)) .andExpect(MockMvcResultMatchers.model().attribute(PARTIAL, PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_PROJECT_ID, soapProject.getId())) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_PORT_ID, soapPort.getId())) .andExpect(MockMvcResultMatchers.model().attribute(SOAP_OPERATION, soapOperation)); SoapOperation SoapOperationResponse = (SoapOperation) result.andReturn().getModelAndView().getModel().get(SOAP_OPERATION); String hostAddress = serviceController.getHostAddress(); Assert.assertEquals(HTTP + hostAddress + COLON + DEFAULT_PORT + CONTEXT + SLASH + MOCK + SLASH + SOAP + SLASH + PROJECT + SLASH + soapProject.getId() + SLASH + soapPort.getUri(), soapOperation.getInvokeAddress()); }
/** * 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<ReadSoapProjectOutput> process(final ServiceTask<ReadSoapProjectInput> serviceTask) { final ReadSoapProjectInput input = serviceTask.getInput(); final SoapProject soapProject = find(input.getProjectId()); final List<SoapResource> resources = this.resourceRepository.findWithProjectId(input.getProjectId()); final List<SoapPort> ports = this.portRepository.findWithProjectId(input.getProjectId()); soapProject.setResources(resources); soapProject.setPorts(ports); for(final SoapPort soapPort : soapProject.getPorts()){ final List<SoapOperation> operations = this.operationRepository.findWithPortId(soapPort.getId()); final Map<SoapOperationStatus, Integer> soapOperationStatusCount = getSoapOperationStatusCount(operations); soapPort.setStatusCount(soapOperationStatusCount); } return createServiceResult(ReadSoapProjectOutput.builder() .project(soapProject) .build()); }
/** * 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<ReadSoapPortOutput> process(final ServiceTask<ReadSoapPortInput> serviceTask) { final ReadSoapPortInput input = serviceTask.getInput(); final SoapPort soapPort = this.portRepository.findOne(input.getPortId()); final List<SoapOperation> operations = this.operationRepository.findWithPortId(input.getPortId()); soapPort.setOperations(operations); return createServiceResult(ReadSoapPortOutput.builder() .port(soapPort) .build()); } }
final String invokeAddress = getSoapInvokeAddress(protocol, request.getServerPort(), soapProjectId, soapPort.getUri()); soapOperation.setInvokeAddress(invokeAddress);
/** * 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<UpdateSoapPortsForwardedEndpointOutput> process(final ServiceTask<UpdateSoapPortsForwardedEndpointInput> serviceTask) { final UpdateSoapPortsForwardedEndpointInput input = serviceTask.getInput(); input.getPorts().stream() .map(soapPort -> this.operationRepository.findWithPortId(soapPort.getId())) .flatMap(List::stream) .forEach(operation -> { operation.setForwardedEndpoint(input.getForwardedEndpoint()); this.operationRepository.update(operation.getId(), operation); }); return createServiceResult(UpdateSoapPortsForwardedEndpointOutput.builder().build()); } }
.collect(Collectors.toList()); final SoapPort soapPort = new SoapPort(); soapPort.setName(servicePort.getName()); soapPort.setOperations(operations); soapPort.setUri(servicePort.getName()); return soapPort;