private Optional<RestMockResponse> getDefaultMockResponse(final RestMethod restMethod, final List<RestMockResponse> mockResponses){ final String defaultResponseId = restMethod.getDefaultMockResponseId(); if(defaultResponseId != null && !defaultResponseId.isEmpty()){ LOGGER.info("Use the default response"); for (RestMockResponse tmpMockResponse : mockResponses) { if(defaultResponseId.equals(tmpMockResponse.getId())){ return Optional.of(tmpMockResponse); } } LOGGER.error("Unable to find the default response"); } return Optional.empty(); }
restMethod.setMockResponses(mockResponses); if(restMethod.getDefaultMockResponseId() != null){ if(mockResponse.getId().equals(restMethod.getDefaultMockResponseId())){ restMethod.setDefaultResponseName(mockResponse.getName()); defaultQueryMockResponseId = true; restMethod.getDefaultMockResponseId());
/** * 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<UpdateRestMethodOutput> process(final ServiceTask<UpdateRestMethodInput> serviceTask) { final UpdateRestMethodInput input = serviceTask.getInput(); final RestMethod updatedRestMethod = input.getRestMethod(); final RestMethod existing = this.methodRepository.findOne(input.getRestMethodId()); existing.setName(updatedRestMethod.getName()); existing.setHttpMethod(updatedRestMethod.getHttpMethod()); existing.setResponseStrategy(updatedRestMethod.getResponseStrategy()); existing.setStatus(updatedRestMethod.getStatus()); existing.setForwardedEndpoint(updatedRestMethod.getForwardedEndpoint()); existing.setNetworkDelay(updatedRestMethod.getNetworkDelay()); existing.setSimulateNetworkDelay(updatedRestMethod.getSimulateNetworkDelay()); existing.setDefaultMockResponseId(updatedRestMethod.getDefaultMockResponseId()); this.methodRepository.update(input.getRestMethodId(), existing); return createServiceResult(UpdateRestMethodOutput.builder() .restMethod(updatedRestMethod) .build()); } }