Search in sources :

Example 1 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 2 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 3 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)

Example 4 with RedirectAttributesModelMap

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

the class RegistrationControllerTest method verifyEmail_InvalidEmailTest.

@Test
public void verifyEmail_InvalidEmailTest() 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);
    // Email doesn't exists
    when(emailManagerReadOnlyMock.emailExists(email)).thenReturn(false);
    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());
    assertFalse(ra.getFlashAttributes().containsKey("emailVerified"));
    assertFalse(ra.getFlashAttributes().containsKey("primaryEmailUnverified"));
    verify(emailManager, times(0)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
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)

Example 5 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.

the class SamplesControllerTest method testRemoveFileFromSample.

@Test
public void testRemoveFileFromSample() {
    Long sampleId = 1L;
    Long fileId = 2L;
    Sample sample = new Sample();
    SequencingObject file = new SingleEndSequenceFile(new SequenceFile(Paths.get("/tmp")));
    when(sampleService.read(sampleId)).thenReturn(sample);
    when(sequencingObjectService.readSequencingObjectForSample(sample, fileId)).thenReturn(file);
    RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
    HttpServletRequest request = new MockHttpServletRequest();
    controller.removeSequencingObjectFromSample(attributes, sampleId, fileId, request, Locale.US);
    verify(sampleService).removeSequencingObjectFromSample(sample, file);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Test(org.junit.Test)

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)18 ModelAndView (org.springframework.web.servlet.ModelAndView)9 Test (org.junit.jupiter.api.Test)8 ModelMap (org.springframework.ui.ModelMap)8 Test (org.junit.Test)7 DBUnitTest (org.orcid.test.DBUnitTest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Model (org.springframework.ui.Model)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 BindingResult (org.springframework.validation.BindingResult)2 BindingAwareModelMap (org.springframework.validation.support.BindingAwareModelMap)2 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 PaymentForm (alfio.controller.form.PaymentForm)1 ReservationForm (alfio.controller.form.ReservationForm)1 TicketReservationModification (alfio.model.modification.TicketReservationModification)1 GenomeAssembly (ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1