String body = bodyEntry.getValue(); RestMockResponse restMockResponse = generateResponse(httpStatusCode, response); restMockResponse.setName(restMockResponse.getName() + " (" + contentType + ")"); restMockResponse.setBody(body);
final String projectId = this.applicationRepository.getProjectId(applicationId); final SearchResult searchResult = new SearchResult(); searchResult.setTitle(mockResponse.getName()); searchResult.setLink(REST + SLASH + PROJECT + SLASH + projectId + SLASH + APPLICATION + SLASH + applicationId
restMockResponse.setName(String.format("%s %s", copyOfLabel, restMockResponse.getName())); serviceProcessor.process(CreateRestMockResponseInput.builder() .projectId(restProjectId)
response.setMockResponseName(mockResponse.getName()); response.setHttpStatusCode(mockResponse.getHttpStatusCode()); response.setHttpHeaders(mockResponse.getHttpHeaders());
@Test public void testSearch() { restMockResponseMongoRepository.save(createrestMockResponse("aaXYZbb")); restMockResponseMongoRepository.save(createrestMockResponse("aaXYZ")); restMockResponseMongoRepository.save(createrestMockResponse("aaxyz")); restMockResponseMongoRepository.save(createrestMockResponse("xyz")); restMockResponseMongoRepository.save(createrestMockResponse("aaefg")); SearchQuery query = new SearchQuery(); query.setQuery("xyz"); List<RestMockResponse> searchResults = restMockResponseMongoRepository.search(query); assertThat(searchResults).hasSize(4); assertThat(searchResults).noneMatch(it -> it.getName().equals("aaefg")); }
for(RestMockResponse mockResponse : mockResponses){ if(mockResponse.getId().equals(restMethod.getDefaultMockResponseId())){ restMethod.setDefaultResponseName(mockResponse.getName()); defaultQueryMockResponseId = true; break;
.filter(method -> method.getName().equals("successful operation (application/xml)")) .findFirst() .get(); Assert.assertEquals("successful operation (application/xml)", response200Xml.getName()); Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<Mock><name>${RANDOM_STRING()}</name><id>${RANDOM_LONG()}</id><createdBy>${RANDOM_STRING()}</createdBy>" + .filter(method -> method.getName().equals("successful operation (application/json)")) .findFirst() .get(); Assert.assertEquals("successful operation (application/json)", response200Json.getName()); Assert.assertEquals("{\"name\":\"${RANDOM_STRING()}\",\"id\":\"${RANDOM_LONG()}\"," + "\"createdBy\":\"${RANDOM_STRING()}\",\"mockStatus\":\"${RANDOM_INTEGER()}\"}", .filter(method -> method.getName().equals("Invalid mock id supplied")) .findFirst() .get(); Assert.assertEquals("Invalid mock id supplied", invalidMockResponse.getName()); Assert.assertNull(invalidMockResponse.getBody()); .filter(method -> method.getName().equals("Mock not found")) .findFirst() .get(); Assert.assertEquals("Mock not found", notFoundResponse.getName()); Assert.assertNull(notFoundResponse.getBody());
/** * 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<UpdateRestMockResponseOutput> process(final ServiceTask<UpdateRestMockResponseInput> serviceTask) { final UpdateRestMockResponseInput input = serviceTask.getInput(); final RestMockResponse existing = this.mockResponseRepository.findOne(input.getRestMockResponseId()); final RestMockResponse updatedRestMockResponse = input.getRestMockResponse(); existing.setName(updatedRestMockResponse.getName()); existing.setBody(updatedRestMockResponse.getBody()); existing.setHttpStatusCode(updatedRestMockResponse.getHttpStatusCode()); existing.setHttpHeaders(updatedRestMockResponse.getHttpHeaders()); existing.setStatus(updatedRestMockResponse.getStatus()); existing.setUsingExpressions(updatedRestMockResponse.isUsingExpressions()); existing.setParameterQueries(updatedRestMockResponse.getParameterQueries()); existing.setXpathExpressions(updatedRestMockResponse.getXpathExpressions()); existing.setJsonPathExpressions(updatedRestMockResponse.getJsonPathExpressions()); this.mockResponseRepository.update(input.getRestMockResponseId(), existing); return createServiceResult(UpdateRestMockResponseOutput.builder() .updatedRestMockResponse(updatedRestMockResponse) .build()); } }
Assert.assertEquals(1, restMethod.getMockResponses().size()); RestMockResponse restMockResponse = restMethod.getMockResponses().get(0); Assert.assertEquals(AUTO_GENERATED_MOCK_RESPONSE_DEFAULT_NAME, restMockResponse.getName()); Assert.assertEquals(Integer.valueOf(DEFAULT_RESPONSE_CODE), restMockResponse.getHttpStatusCode()); Assert.assertEquals(RestMockResponseStatus.ENABLED, restMockResponse.getStatus());