/** * Count the method statuses for {@link RestApplication} * @param restApplication The application which statuses will be counted * @return The result of the status count */ protected Map<RestMethodStatus, Integer> getRestMethodStatusCount(final RestApplication restApplication){ Preconditions.checkNotNull(restApplication, "The REST application cannot be null"); final Map<RestMethodStatus, Integer> statuses = new HashMap<RestMethodStatus, Integer>(); for(RestMethodStatus restMethodStatus : RestMethodStatus.values()){ statuses.put(restMethodStatus, 0); } final List<String> resourceIds = this.resourceRepository.findIdsWithApplicationId(restApplication.getId()); for(String resourceId : resourceIds){ final List<RestMethod> methods = this.methodRepository.findWithResourceId(resourceId); for(RestMethod restMethod : methods){ RestMethodStatus restMethodStatus = restMethod.getStatus(); statuses.put(restMethodStatus, statuses.get(restMethodStatus)+1); } } return statuses; }
@PreAuthorize("hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{projectId}/create/application", method = RequestMethod.POST) public ModelAndView createProject(@PathVariable final String projectId, @ModelAttribute final RestApplication restApplication) { final CreateRestApplicationOutput output = serviceProcessor.process(CreateRestApplicationInput.builder() .projectId(projectId) .application(restApplication) .build()); return redirect("/rest/project/" + projectId + "/application/" + output.getSavedRestApplication().getId()); }
/** * 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<DeleteRestApplicationsOutput> process(final ServiceTask<DeleteRestApplicationsInput> serviceTask) { final DeleteRestApplicationsInput input = serviceTask.getInput(); for(RestApplication restApplication : input.getRestApplications()){ this.deleteApplication(restApplication.getId()); } return createServiceResult(DeleteRestApplicationsOutput.builder().build()); } }
@Test public void testDeleteMethodConfirm() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); when(serviceProcessor.process(any(DeleteRestMockResponseInput.class))).thenReturn(DeleteRestMockResponsesOutput.builder().build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + DELETE + SLASH + CONFIRM); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(0)); }
@Test public void testUpdateConfirmPortWithValidId() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); when(serviceProcessor.process(any(UpdateRestApplicationInput.class))).thenReturn(UpdateRestApplicationOutput.builder() .updatedRestApplication(restApplication) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + UPDATE, restApplication); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testConfirmDeletationOfMultipleMethods() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final DeleteRestResourcesCommand command = new DeleteRestResourcesCommand(); command.setRestResources(new ArrayList<RestResource>()); command.getRestResources().add(restResource); when(serviceProcessor.process(any(DeleteRestMethodInput.class))).thenReturn(DeleteRestMethodOutput.builder().build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + DELETE + SLASH + CONFIRM) .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); } }
@Test public void testPostCreateMethod() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); when(serviceProcessor.process(any(CreateRestResourceInput.class))).thenReturn(CreateRestResourceOutput .builder().savedRestApplication(restResource) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + CREATE_RESOURCE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testUpdateRestResource() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); when(serviceProcessor.process(any(UpdateRestResourceInput.class))).thenReturn(UpdateRestResourceOutput.builder().updatedRestResource(restResource).build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + UPDATE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testConfirmDeletationOfMultipleMethods() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); final DeleteRestMethodsCommand command = new DeleteRestMethodsCommand(); command.setRestMethods(new ArrayList<RestMethod>()); command.getRestMethods().add(restMethod); when(serviceProcessor.process(any(DeleteRestMethodInput.class))).thenReturn(DeleteRestMethodOutput.builder().build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + METHOD + SLASH + DELETE + SLASH + CONFIRM) .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); } }
@Test public void testDeleteMethodConfirm() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); when(serviceProcessor.process(any(DeleteRestMockResponseInput.class))).thenReturn(DeleteRestMockResponsesOutput.builder().build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + METHOD + SLASH + restMethod.getId() + SLASH + DELETE + SLASH + CONFIRM); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(0)); }
@Test public void testPostCreateMethod() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); when(serviceProcessor.process(any(CreateRestMethodInput.class))).thenReturn(CreateRestMethodOutput.builder() .createdRestMethod(restMethod) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + CREATE_METHOD); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testUpdateRestMethod() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); when(serviceProcessor.process(any(UpdateRestResourceInput.class))).thenReturn(UpdateRestResourceOutput.builder() .updatedRestResource(restResource) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + METHOD + SLASH + restMethod.getId() + SLASH + UPDATE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testDeleteMockResponseConfirm() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); final RestMockResponse restMockResponse = RestMockResponseGenerator.generateRestMockResponse(); when(serviceProcessor.process(any(DeleteRestMockResponseInput.class))).thenReturn(DeleteRestMockResponsesOutput.builder().build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + METHOD + SLASH + restMethod.getId() + SLASH + RESPONSE + SLASH + restMockResponse.getId() + SLASH + DELETE + SLASH + CONFIRM); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(0)); }
@Test public void testPostCreateResponse() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); final RestMockResponse restMockResponse = RestMockResponseGenerator.generateRestMockResponse(); when(serviceProcessor.process(any(CreateRestMockResponseInput.class))).thenReturn(CreateRestMockResponseOutput.builder() .restMockResponse(restMockResponse) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + METHOD + SLASH + restMethod.getId() + SLASH + CREATE_RESPONSE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testUpdateMockResponse() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final RestResource restResource = RestResourceGenerator.generateRestResource(); final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); final RestMockResponse restMockResponse = RestMockResponseGenerator.generateRestMockResponse(); when(serviceProcessor.process(any(UpdateRestMockResponseInput.class))).thenReturn(UpdateRestMockResponseOutput.builder() .updatedRestMockResponse(restMockResponse) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + RESOURCE + SLASH + restResource.getId() + SLASH + METHOD + SLASH + restMethod.getId() + SLASH + RESPONSE + SLASH + restMockResponse.getId() + SLASH + UPDATE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testCreateMethod() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); when(serviceProcessor.process(any(ReadRestApplicationInput.class))).thenReturn(ReadRestApplicationOutput.builder() .restApplication(restApplication).build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + CREATE_RESOURCE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().size(3 + GLOBAL_VIEW_MODEL_COUNT)) .andExpect(MockMvcResultMatchers.forwardedUrl(INDEX)) .andExpect(MockMvcResultMatchers.model().attribute(PARTIAL, PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(REST_PROJECT_ID, restProject.getId())) .andExpect(MockMvcResultMatchers.model().attribute(REST_APPLICATION_ID, restApplication.getId())) .andExpect(MockMvcResultMatchers.model().attributeExists(REST_RESOURCE)); }
@Test public void testDeleteConfirmApplicationWithValidId() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + DELETE + SLASH + CONFIRM); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(0)); }
@Test public void testDeleteApplicationWithValidId() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); when(serviceProcessor.process(any(ReadRestApplicationInput.class))).thenReturn(ReadRestApplicationOutput.builder() .restApplication(restApplication) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + DELETE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().size(2 + GLOBAL_VIEW_MODEL_COUNT)) .andExpect(MockMvcResultMatchers.forwardedUrl(INDEX)) .andExpect(MockMvcResultMatchers.model().attribute(PARTIAL, PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(REST_PROJECT_ID, restProject.getId())) .andExpect(MockMvcResultMatchers.model().attribute(REST_APPLICATION, restApplication)); }
@Test public void testUpdatePortWithValidId() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); when(serviceProcessor.process(any(ReadRestApplicationInput.class))).thenReturn(ReadRestApplicationOutput.builder() .restApplication(restApplication ).build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId() + SLASH + UPDATE); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().size(2 + GLOBAL_VIEW_MODEL_COUNT)) .andExpect(MockMvcResultMatchers.forwardedUrl(INDEX)) .andExpect(MockMvcResultMatchers.model().attribute(PARTIAL, PAGE)) .andExpect(MockMvcResultMatchers.model().attribute(REST_PROJECT_ID, restProject.getId())) .andExpect(MockMvcResultMatchers.model().attribute(REST_APPLICATION, restApplication)); }
@Test public void getRestApplication() throws Exception { final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); when(serviceProcessor.process(any(ReadRestApplicationInput.class))).thenReturn(ReadRestApplicationOutput.builder() .restApplication(restApplication) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.get(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + restApplication.getId()); 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(REST_PROJECT_ID, restProject.getId())) .andExpect(MockMvcResultMatchers.model().attribute(REST_APPLICATION, restApplication)); }