Search in sources :

Example 31 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by spring-projects.

the class ViewNameMethodReturnValueHandlerTests method returnViewRedirectWithCustomRedirectPattern.

@Test
public void returnViewRedirectWithCustomRedirectPattern() throws Exception {
    ModelMap redirectModel = new RedirectAttributesModelMap();
    this.mavContainer.setRedirectModel(redirectModel);
    this.handler.setRedirectPatterns("myRedirect:*");
    this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
    assertThat(this.mavContainer.getViewName()).isEqualTo("redirect:testView");
    assertThat(this.mavContainer.getModel()).isSameAs(redirectModel);
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.jupiter.api.Test)

Example 32 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project Sermant by huaweicloud.

the class FileEntryControllerTest method testSaveAndGet.

@SuppressWarnings("unchecked")
@Test
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));
}
Also used : ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) FileEntry(org.ngrinder.script.model.FileEntry) List(java.util.List) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) AbstractNGrinderTransactionalTest(org.ngrinder.AbstractNGrinderTransactionalTest) Test(org.junit.Test)

Example 33 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project alf.io by alfio-event.

the class ReservationFlowIntegrationTest method reserveTicket.

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);
    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);
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) BindingAwareModelMap(org.springframework.validation.support.BindingAwareModelMap) ReservationForm(alfio.controller.form.ReservationForm) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) TicketReservationModification(alfio.model.modification.TicketReservationModification)

Example 34 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project alf.io by alfio-event.

the class ReservationFlowIntegrationTest method payOffline.

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);
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) PaymentForm(alfio.controller.form.PaymentForm) Model(org.springframework.ui.Model) BindingAwareModelMap(org.springframework.validation.support.BindingAwareModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)

Example 35 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.

the class RegistrationControllerTest method verifyEmailTest.

@Test
public void verifyEmailTest() throws UnsupportedEncodingException {
    String orcid = "0000-0000-0000-0000";
    String email = "user_1@test.orcid.org";
    SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
    String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
    when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenReturn(email);
    when(emailManagerReadOnlyMock.emailExists(email)).thenReturn(true);
    when(emailManagerReadOnlyMock.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(emailManager.verifyEmail(email, orcid)).thenReturn(true);
    when(emailManagerReadOnlyMock.isPrimaryEmail(orcid, email)).thenReturn(true);
    when(emailManagerReadOnlyMock.isPrimaryEmailVerified(orcid)).thenReturn(true);
    RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
    ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
    assertNotNull(mav);
    assertEquals("redirect:/my-orcid", mav.getViewName());
    assertTrue(ra.getFlashAttributes().containsKey("emailVerified"));
    assertTrue((Boolean) ra.getFlashAttributes().get("emailVerified"));
    assertFalse(ra.getFlashAttributes().containsKey("primaryEmailUnverified"));
    verify(emailManager, times(1)).verifyEmail(email, orcid);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)64 ModelMap (org.springframework.ui.ModelMap)44 Test (org.junit.jupiter.api.Test)33 ModelAndView (org.springframework.web.servlet.ModelAndView)25 Test (org.junit.Test)24 RedirectView (org.springframework.web.servlet.view.RedirectView)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 BindingResult (org.springframework.validation.BindingResult)6 DBUnitTest (org.orcid.test.DBUnitTest)5 MethodParameter (org.springframework.core.MethodParameter)5 DataBinder (org.springframework.validation.DataBinder)5 TodoDTO (net.petrikainulainen.spring.testmvc.todo.dto.TodoDTO)4 AbstractNGrinderTransactionalTest (org.ngrinder.AbstractNGrinderTransactionalTest)4 FileEntry (org.ngrinder.script.model.FileEntry)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 TodoNotFoundException (net.petrikainulainen.spring.testmvc.todo.exception.TodoNotFoundException)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Model (org.springframework.ui.Model)2