@PreAuthorize("hasAuthority('READER') or hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{restProjectId}/application/{restApplicationId}/resource/{restResourceId}/method/{restMethodId}/create/response", method = RequestMethod.GET) public ModelAndView displayCreatePage(@PathVariable final String restProjectId, @PathVariable final String restApplicationId, @PathVariable final String restResourceId, @PathVariable final String restMethodId) { final ReadRestMethodOutput output = serviceProcessor.process(ReadRestMethodInput.builder() .restProjectId(restProjectId) .restApplicationId(restApplicationId) .restResourceId(restResourceId) .restMethodId(restMethodId).build()); final ReadRestResourceQueryParametersOutput resourceQueryParameters = serviceProcessor.process(ReadRestResourceQueryParametersInput.builder() .projectId(restProjectId) .applicationId(restApplicationId) .resourceId(restResourceId) .build()); final RestMockResponse mockResponse = new RestMockResponse(); mockResponse.setBody(output.getRestMethod().getDefaultBody()); mockResponse.setHttpStatusCode(DEFAULT_HTTP_STATUS_CODE); final ModelAndView model = createPartialModelAndView(PAGE); model.addObject(REST_PROJECT_ID, restProjectId); model.addObject(REST_APPLICATION_ID, restApplicationId); model.addObject(REST_RESOURCE_ID, restResourceId); model.addObject(REST_METHOD_ID, restMethodId); model.addObject(REST_MOCK_RESPONSE, mockResponse); model.addObject(REST_MOCK_RESPONSE_STATUSES, RestMockResponseStatus.values()); model.addObject(REST_QUERY_PARAMETERS, resourceQueryParameters.getQueries()); return model; }
@Test public void testProcess(){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); Mockito.when(methodRepository.save(Mockito.any(RestMethod.class))).thenReturn(restMethod); final CreateRestMethodInput input = CreateRestMethodInput.builder() .projectId(restProject.getId()) .applicationId(restApplication.getId()) .resourceId(restResource.getId()) .method(restMethod) .build(); final ServiceTask<CreateRestMethodInput> serviceTask = new ServiceTask<CreateRestMethodInput>(input); final ServiceResult<CreateRestMethodOutput> serviceResult = service.process(serviceTask); final CreateRestMethodOutput createRestApplicationOutput = serviceResult.getOutput(); final RestMethod returnedRestMethod = createRestApplicationOutput.getCreatedRestMethod(); Assert.assertEquals(restMethod.getName(), returnedRestMethod.getName()); Assert.assertEquals(restMethod.getHttpMethod(), returnedRestMethod.getHttpMethod()); Assert.assertEquals(restMethod.getDefaultBody(), returnedRestMethod.getDefaultBody()); Assert.assertEquals(restMethod.getForwardedEndpoint(), returnedRestMethod.getForwardedEndpoint()); Assert.assertEquals(restMethod.getStatus(), returnedRestMethod.getStatus()); Assert.assertEquals(restMethod.getMockResponses(), returnedRestMethod.getMockResponses()); Assert.assertEquals(restMethod.getResponseStrategy(), returnedRestMethod.getResponseStrategy()); }
@Test public void testProcessWithoutStatus(){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); restMethod.setStatus(null); Mockito.when(methodRepository.save(Mockito.any(RestMethod.class))).thenReturn(restMethod); final CreateRestMethodInput input = CreateRestMethodInput.builder() .projectId(restProject.getId()) .applicationId(restApplication.getId()) .resourceId(restResource.getId()) .method(restMethod) .build(); final ServiceTask<CreateRestMethodInput> serviceTask = new ServiceTask<CreateRestMethodInput>(input); final ServiceResult<CreateRestMethodOutput> serviceResult = service.process(serviceTask); final CreateRestMethodOutput createRestApplicationOutput = serviceResult.getOutput(); final RestMethod returnedRestMethod = createRestApplicationOutput.getCreatedRestMethod(); Assert.assertEquals(restMethod.getName(), returnedRestMethod.getName()); Assert.assertEquals(restMethod.getHttpMethod(), returnedRestMethod.getHttpMethod()); Assert.assertEquals(restMethod.getDefaultBody(), returnedRestMethod.getDefaultBody()); Assert.assertEquals(restMethod.getForwardedEndpoint(), returnedRestMethod.getForwardedEndpoint()); Assert.assertEquals(restMethod.getStatus(), RestMethodStatus.MOCKED); Assert.assertEquals(restMethod.getMockResponses(), returnedRestMethod.getMockResponses()); Assert.assertEquals(restMethod.getResponseStrategy(), returnedRestMethod.getResponseStrategy()); }
@Test public void testProcessWithoutResponseStrategy(){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); restMethod.setResponseStrategy(null); Mockito.when(methodRepository.save(Mockito.any(RestMethod.class))).thenReturn(restMethod); final CreateRestMethodInput input = CreateRestMethodInput.builder() .projectId(restProject.getId()) .applicationId(restApplication.getId()) .resourceId(restResource.getId()) .method(restMethod) .build(); final ServiceTask<CreateRestMethodInput> serviceTask = new ServiceTask<CreateRestMethodInput>(input); final ServiceResult<CreateRestMethodOutput> serviceResult = service.process(serviceTask); final CreateRestMethodOutput createRestApplicationOutput = serviceResult.getOutput(); final RestMethod returnedRestMethod = createRestApplicationOutput.getCreatedRestMethod(); Assert.assertEquals(restMethod.getName(), returnedRestMethod.getName()); Assert.assertEquals(restMethod.getHttpMethod(), returnedRestMethod.getHttpMethod()); Assert.assertEquals(restMethod.getDefaultBody(), returnedRestMethod.getDefaultBody()); Assert.assertEquals(restMethod.getForwardedEndpoint(), returnedRestMethod.getForwardedEndpoint()); Assert.assertEquals(restMethod.getStatus(), returnedRestMethod.getStatus()); Assert.assertEquals(restMethod.getMockResponses(), returnedRestMethod.getMockResponses()); Assert.assertEquals(restMethod.getResponseStrategy(), RestResponseStrategy.RANDOM); }
Assert.assertEquals(0L, getAllMockServicesMethod.getNetworkDelay()); Assert.assertFalse(getAllMockServicesMethod.getSimulateNetworkDelay()); Assert.assertNull(getAllMockServicesMethod.getDefaultBody()); Assert.assertNull(getAllMockServicesMethod.getId()); Assert.assertNull(getAllMockServicesMethod.getResourceId()); Assert.assertEquals(0L, createMockMethod.getNetworkDelay()); Assert.assertFalse(createMockMethod.getSimulateNetworkDelay()); Assert.assertNull(createMockMethod.getDefaultBody()); Assert.assertNull(createMockMethod.getId()); Assert.assertNull(createMockMethod.getResourceId()); Assert.assertEquals(0L, headMockMethod.getNetworkDelay()); Assert.assertFalse(headMockMethod.getSimulateNetworkDelay()); Assert.assertNull(headMockMethod.getDefaultBody()); Assert.assertNull(headMockMethod.getId()); Assert.assertNull(headMockMethod.getResourceId()); Assert.assertEquals(0L, optionsMockMethod.getNetworkDelay()); Assert.assertFalse(optionsMockMethod.getSimulateNetworkDelay()); Assert.assertNull(optionsMockMethod.getDefaultBody()); Assert.assertNull(optionsMockMethod.getId()); Assert.assertNull(optionsMockMethod.getResourceId()); Assert.assertEquals(0L, getMockByIdMethod.getNetworkDelay()); Assert.assertFalse(getMockByIdMethod.getSimulateNetworkDelay()); Assert.assertNull(getMockByIdMethod.getDefaultBody()); Assert.assertNull(getMockByIdMethod.getId()); Assert.assertNull(getMockByIdMethod.getResourceId());
Assert.assertNull(restMethod.getInvokeAddress()); Assert.assertNull(restMethod.getForwardedEndpoint()); Assert.assertNull(restMethod.getDefaultBody());