@Test public void flashAttribute() { this.builder.flashAttr("foo", "bar"); MockHttpServletRequest request = this.builder.buildRequest(this.servletContext); FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null); assertNotNull(flashMap); assertEquals("bar", flashMap.get("foo")); }
@Test public void getPerson() throws Exception { this.mockMvc.perform(get("/persons/Joe").flashAttr("message", "success!")) .andExpect(status().isOk()) .andExpect(forwardedUrl("persons/index")) .andExpect(model().size(2)) .andExpect(model().attribute("person", new Person("Joe"))) .andExpect(model().attribute("message", "success!")) .andExpect(flash().attributeCount(0)); }
/** * Set flash attributes. * @param flashAttributes the flash attributes */ public MockHttpServletRequestBuilder flashAttrs(Map<String, Object> flashAttributes) { Assert.notEmpty(flashAttributes, "'flashAttributes' must not be empty"); for (String name : flashAttributes.keySet()) { flashAttr(name, flashAttributes.get(name)); } return this; }
@Test public void testUpdateEndpoint() throws Exception { final String projectId = "projectId"; final UpdateRestApplicationsEndpointCommand command = new UpdateRestApplicationsEndpointCommand(); command.setForwardedEndpoint("http://localhost:8080/web"); command.setRestApplications(ImmutableList.of()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + APPLICATION + SLASH + "update/confirm") .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/rest/project/" + projectId)); Mockito.verify(serviceProcessor, Mockito.times(1)) .process(Mockito.any(UpdateRestApplicationsForwardedEndpointInput.class)); } }
@Test public void testUpdateEndpoint() throws Exception { final String projectId = "projectId"; final String applicationId = "applicationId"; final UpdateRestResourcesEndpointCommand command = new UpdateRestResourcesEndpointCommand(); command.setForwardedEndpoint("http://localhost:8080/web"); command.setRestResources(ImmutableList.of()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + APPLICATION + SLASH + applicationId + SLASH + RESOURCE + SLASH + "update/confirm") .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/rest/project/" + projectId + "/application/" + applicationId)); Mockito.verify(serviceProcessor, Mockito.times(1)).process(Mockito.any(UpdateRestResourcesForwardedEndpointInput.class)); }
@Test public void testUpdateEndpoint() throws Exception { final String projectId = "projectId"; final String portId = "portId"; final UpdateSoapOperationsEndpointCommand command = new UpdateSoapOperationsEndpointCommand(); command.setSoapOperations(ImmutableList.of()); command.setForwardedEndpoint("http://localhost:8080/web"); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + PORT + SLASH + portId + SLASH + OPERATION + SLASH + "update/confirm") .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/soap/project/" + projectId + "/port/" + portId)); Mockito.verify(serviceProcessor, Mockito.times(1)) .process(Mockito.any(UpdateSoapOperationsForwardedEndpointInput.class)); }
@Test public void testUpdateEndpoint() throws Exception { final String projectId = "projectId"; final String applicationId = "applicationId"; final String resourceId = "resourceId"; final UpdateRestMethodsEndpointCommand command = new UpdateRestMethodsEndpointCommand(); command.setForwardedEndpoint("http://localhost:8080/web"); command.setRestMethods(ImmutableList.of()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + APPLICATION + SLASH + applicationId + SLASH + RESOURCE + SLASH + resourceId + SLASH + METHOD + SLASH + "update/confirm") .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/rest/project/" + projectId + "/application/" + applicationId + "/resource/" + resourceId)); Mockito.verify(serviceProcessor, Mockito.times(1)).process(Mockito.any(UpdateRestMethodsForwardedEndpointInput.class)); }
@Test public void testUpdatePortEndpoint() throws Exception { final UpdateSoapPortsEndpointCommand command = new UpdateSoapPortsEndpointCommand(); final SoapProject soapProject = SoapProjectGenerator.generateSoapProject(); final SoapPort soapPort = SoapPortGenerator.generateSoapPort(); final List<SoapPort> soapPorts = new ArrayList<SoapPort>(); soapPorts.add(soapPort); command.setSoapPorts(soapPorts); command.setForwardedEndpoint("/new/endpoint"); when(serviceProcessor.process(any(Input.class))).thenReturn(UpdateSoapPortOutput.builder() .port(soapPort) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + soapProject.getId() + SLASH + PORT + SLASH + UPDATE + SLASH + CONFIRM) .flashAttr("command", command); 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 projectFunctionalityUpdate() throws Exception { final String projectId = "projectId"; final String[] soapPortIds = {"soapPort1", "soapPort2"}; final SoapPortModifierCommand command = new SoapPortModifierCommand(); command.setSoapPortIds(soapPortIds); command.setSoapPortStatus("MOCKED"); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH) .param("action", "update").flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.model().size(1)) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/soap/project/" + projectId)); Mockito.verify(serviceProcessor, Mockito.times(2)).process(Mockito.any(UpdateSoapPortsStatusInput.class)); }
@Test public void projectFunctionalityUpdate() throws Exception { final String projectId = "projectId"; final String[] restApplicationIds = {"restApplication1", "restApplication2"}; final RestApplicationModifierCommand command = new RestApplicationModifierCommand(); command.setRestApplicationIds(restApplicationIds); command.setRestMethodStatus("MOCKED"); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH) .param("action", "update").flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.model().size(1)) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/rest/project/" + projectId)); Mockito.verify(serviceProcessor, Mockito.times(2)).process(Mockito.any(UpdateRestApplicationsStatusInput.class)); }
@Test public void testConfirmDeletationOfMultpleProjects() throws Exception { final DeleteRestApplicationsCommand command = new DeleteRestApplicationsCommand(); final RestProject restProject = RestProjectGenerator.generateRestProject(); final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); final List<RestApplication> restApplications = new ArrayList<RestApplication>(); restApplications.add(restApplication); command.setRestApplications(restApplications); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + restProject.getId() + SLASH + APPLICATION + SLASH + DELETE + SLASH + CONFIRM) .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void projectFunctionalityUpdate() throws Exception { final String projectId = "projectId"; final String applicationId = "applicationId"; final String[] restResources = {"restApplication1", "restApplication2"}; final RestResourceModifierCommand command = new RestResourceModifierCommand(); command.setRestResourceIds(restResources); command.setRestMethodStatus("MOCKED"); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + APPLICATION + SLASH + applicationId) .param("action", "update").flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.model().size(1)) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/rest/project/" + projectId + "/application/" + applicationId)); Mockito.verify(serviceProcessor, Mockito.times(2)).process(Mockito.any(ReadRestResourceInput.class)); }
@Test public void testConfirmDeletationOfMultpleProjects() throws Exception { final DeleteSoapPortsCommand command = new DeleteSoapPortsCommand(); final SoapProject soapProject = SoapProjectGenerator.generateSoapProject(); final SoapPort soapPort = SoapPortGenerator.generateSoapPort(); final List<SoapPort> soapPorts = new ArrayList<SoapPort>(); soapPorts.add(soapPort); command.setSoapPorts(soapPorts); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + soapProject.getId() + SLASH + PORT + SLASH + DELETE + SLASH + CONFIRM) .flashAttr("command", command); 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 testConfirmDeletationOfMultipleMockResponses() throws Exception { final SoapProject project = SoapProjectGenerator.generateSoapProject(); final SoapPort application = SoapPortGenerator.generateSoapPort(); final SoapOperation soapOperation = SoapOperationGenerator.generateSoapOperation(); final SoapMockResponse soapMockResponse = SoapMockResponseGenerator.generateSoapMockResponse(); final DeleteSoapMockResponsesCommand deleteSoapMockResponsesCommand = new DeleteSoapMockResponsesCommand(); deleteSoapMockResponsesCommand.setSoapMockResponses(new ArrayList<SoapMockResponse>()); deleteSoapMockResponsesCommand.getSoapMockResponses().add(soapMockResponse); when(serviceProcessor.process(any(DeleteSoapMockResponseInput.class))).thenReturn(DeleteSoapMockResponseOutput.builder().build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + project.getId() + SLASH + PORT + SLASH + application.getId() + SLASH + OPERATION + SLASH + soapOperation.getId() + SLASH + RESPONSE + SLASH + DELETE + SLASH + CONFIRM) .flashAttr("command", deleteSoapMockResponsesCommand); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); } }
@Test public void testConfirmDeletationOfMultipleMockResponses() 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(); final DeleteRestMockResponsesCommand command = new DeleteRestMockResponsesCommand(); command.setRestMockResponses(new ArrayList<RestMockResponse>()); command.getRestMockResponses().add(restMockResponse); when(serviceProcessor.process(any(DeleteRestMockResponsesInput.class))).thenReturn(DeleteRestMockResponsesOutput.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 + restMethod.getId() + SLASH + RESPONSE + SLASH + DELETE + SLASH + CONFIRM) .flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); } }
@Test public void testUpdateMockResponse() throws Exception { final SoapProject project = SoapProjectGenerator.generateSoapProject(); final SoapPort application = SoapPortGenerator.generateSoapPort(); final SoapOperation soapOperation = SoapOperationGenerator.generateSoapOperation(); final SoapMockResponse soapMockResponse = SoapMockResponseGenerator.generateSoapMockResponse(); when(serviceProcessor.process(any(UpdateSoapMockResponseInput.class))).thenReturn(UpdateSoapMockResponseOutput.builder() .mockResponse(soapMockResponse) .build()); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + project.getId() + SLASH + PORT + SLASH + application.getId() + SLASH + OPERATION + SLASH + soapOperation.getId() + SLASH + RESPONSE + SLASH + soapMockResponse.getId() + SLASH + UPDATE) .flashAttr("soapMockResponse", soapMockResponse); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)); }
@Test public void testServiceFunctionalityUpdate() throws Exception { final String projectId = "projectId"; final String portId = "portId"; final String[] soapOperationIds = {"Operation1", "Operation2"}; final SoapOperationModifierCommand command = new SoapOperationModifierCommand(); command.setSoapOperationIds(soapOperationIds); command.setSoapOperationStatus("MOCKED"); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL + PROJECT + SLASH + projectId + SLASH + PORT + SLASH + portId) .param("action", "update").flashAttr("command", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().is3xxRedirection()) .andExpect(MockMvcResultMatchers.model().size(1)) .andExpect(MockMvcResultMatchers.redirectedUrl("/web/soap/project/" + projectId + "/port/" + portId)); Mockito.verify(serviceProcessor, Mockito.times(2)).process(Mockito.isA(UpdateSoapOperationsStatusInput.class)); }
@Test public void testConfirmDeletationOfMultpleProjects() throws Exception { final String[] projects = {"Project"}; final String[] types = {"SOAP"}; final DeleteProjectsCommand command = new DeleteProjectsCommand(); command.setProjectIds(projects); command.setTypeUrls(types); final MockHttpServletRequestBuilder message = MockMvcRequestBuilders.post(SERVICE_URL_DELETE_MULTIPLE).flashAttr("deleteProjectsCommand", command); mockMvc.perform(message) .andExpect(MockMvcResultMatchers.status().isFound()) .andExpect(MockMvcResultMatchers.model().size(1)) .andExpect(MockMvcResultMatchers.redirectedUrl("/web")); }