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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations