List of usage examples for org.springframework.web.servlet.mvc.support RedirectAttributesModelMap RedirectAttributesModelMap
public RedirectAttributesModelMap()
From source file:com.trenako.web.controllers.ControllerMessageTests.java
@Test public void shouldAppendItselfToRedirectAttributes() { RedirectAttributes redirectAtts = new RedirectAttributesModelMap(); ControllerMessage msg = ControllerMessage.info("info message", 1, "arg2"); msg.appendToRedirect(redirectAtts);//from w w w . ja v a 2 s .com Map<String, ?> flashMap = redirectAtts.getFlashAttributes(); assertTrue("Map don't contain the message", flashMap.containsKey("message")); assertEquals("message{type: info, message: info message, args: [1, arg2]}", flashMap.get("message").toString()); }
From source file:com.mtt.myapp.home.controller.HomeControllerTest.java
@Test public void testErrorPage() { String viewName = homeController.error404(new ModelMap()); assertThat(viewName).startsWith("redirect:/doError"); MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletRequest req = new MockHttpServletRequest(); RedirectAttributesModelMap model = new RedirectAttributesModelMap(); viewName = homeController.second(getTestUser(), model, res, req); assertThat(viewName).isEqualTo("index"); }
From source file:org.ngrinder.home.controller.HomeControllerTest.java
@Test public void testErrorPage() { String viewName = homeController.error404(new ModelMap()); assertThat(viewName, startsWith("redirect:/doError")); MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletRequest req = new MockHttpServletRequest(); RedirectAttributesModelMap model = new RedirectAttributesModelMap(); viewName = homeController.second(getTestUser(), model, res, req); assertThat(viewName, is("index")); }
From source file:alfio.controller.ReservationFlowIntegrationTest.java
private String payOffline(String eventName, String reservationIdentifier) { PaymentForm paymentForm = new PaymentForm(); paymentForm.setPaymentMethod(PaymentProxy.OFFLINE); paymentForm.setEmail("test@test.com"); paymentForm.setBillingAddress("my billing address"); paymentForm.setFirstName("full"); paymentForm.setLastName("name"); paymentForm.setTermAndConditionsAccepted(true); paymentForm.setPostponeAssignment(true); BindingResult bindingResult = new BeanPropertyBindingResult(paymentForm, "paymentForm"); Model model = new BindingAwareModelMap(); MockHttpServletRequest request = new MockHttpServletRequest(); RedirectAttributes redirectAttributes = new RedirectAttributesModelMap(); return reservationController.handleReservation(eventName, reservationIdentifier, paymentForm, bindingResult, model, request, Locale.ENGLISH, redirectAttributes); }
From source file:alfio.controller.ReservationFlowIntegrationTest.java
private String reserveTicket(String eventName) { ReservationForm reservationForm = new ReservationForm(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); ServletWebRequest servletWebRequest = new ServletWebRequest(request); BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation"); Model model = new BindingAwareModelMap(); RedirectAttributes redirectAttributes = new RedirectAttributesModelMap(); TicketReservationModification ticketReservation = new TicketReservationModification(); ticketReservation.setAmount(1);//from w w w. ja v a 2s.c o m ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream() .findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new)); reservationForm.setReservation(Collections.singletonList(ticketReservation)); return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH); }
From source file:org.ngrinder.script.controller.FileEntryControllerTest.java
@SuppressWarnings("unchecked") @Test/*from ww w . jav a 2 s. c om*/ public void testSaveAndGet() { ModelMap model = new ModelMap(); String path = "test1-path"; scriptController.addFolder(getTestUser(), "", path, model); // create scriptController.createForm(getTestUser(), path, "test.com", "new_file.py", "jython", false, null, new RedirectAttributesModelMap(), model); FileEntry script = (FileEntry) model.get("file"); script.setContent(script.getContent() + "#test comment"); scriptController.save(getTestUser(), script, null, "", false, model); scriptController.validate(getTestUser(), script, "test.com"); // save and get model.clear(); scriptController.getOne(getTestUser(), script.getPath(), -1L, model); FileEntry newScript = (FileEntry) model.get("file"); assertThat(newScript.getFileName(), is(script.getFileName())); assertThat(newScript.getContent(), is(script.getContent())); // List<Long> versionList = newScript.getRevisions(); // reversion list is not implemented yet. // assertThat(versionList.size(), is(2)); model.clear(); scriptController.search(getTestUser(), "test", model); model.clear(); scriptController.delete(getTestUser(), path, "new_file.py"); scriptController.getAll(getTestUser(), path, model); List<FileEntry> scriptList = (List<FileEntry>) model.get("files"); assertThat(scriptList.size(), is(0)); }
From source file:org.ngrinder.script.controller.FileEntryControllerTest.java
@SuppressWarnings("unchecked") @Test//w w w .java2s. c om public void testCreateFolderSaveAndGet() { ModelMap model = new ModelMap(); String path = "test2-path"; // add folder scriptController.addFolder(getTestUser(), "", path, model); // create scriptController.createForm(getTestUser(), path, "test.com", "file-for-search.py", "jython", false, null, new RedirectAttributesModelMap(), model); FileEntry script = (FileEntry) model.get("file"); scriptController.save(getTestUser(), script, null, "", false, model); // save another script model.clear(); script.setPath(script.getPath().replace("file-for-search", "new-file-for-search")); scriptController.save(getTestUser(), script, null, "", false, model); // save and get model.clear(); scriptController.getOne(getTestUser(), script.getPath(), -1L, model); model.clear(); scriptController.search(getTestUser(), "file-for-search", model); Collection<FileEntry> searchResult = (Collection<FileEntry>) model.get("files"); assertThat(searchResult.size(), is(2)); model.clear(); // delete both files scriptController.delete(getTestUser(), path, "file-for-search.py,new-file-for-search.py"); scriptController.getAll(getTestUser(), path, model); List<FileEntry> scriptList = (List<FileEntry>) model.get("files"); assertThat(scriptList.size(), is(0)); }
From source file:org.ngrinder.script.controller.FileEntryControllerTest.java
@Test public void testDownload() { ModelMap model = new ModelMap(); String path = "download-path"; String fileName = "download_file.py"; scriptController.addFolder(getTestUser(), "", path, model); RedirectAttributesModelMap attrMap = new RedirectAttributesModelMap(); scriptController.createForm(getTestUser(), path, "test.com", fileName, "jython", false, null, attrMap, model);// w ww. jav a2s. com FileEntry script = (FileEntry) model.get("file"); script.setContent(script.getContent() + "#test comment"); scriptController.save(getTestUser(), script, null, "", false, model); scriptController.createForm(getTestUser(), path, "", fileName, "", false, null, attrMap, model); MockHttpServletResponse response = new MockHttpServletResponse(); path = path + "/" + fileName; scriptController.download(getTestUser(), path, response); }