List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:org.orcid.frontend.web.controllers.RegistrationControllerTest.java
@Test public void testPasswordResetLinkValidLinkDirectsToSecurityQuestionScreenWhenSecurityQuestionPresent() throws Exception { HttpServletRequest servletRequest = mock(HttpServletRequest.class); RedirectAttributes redirectAttributes = mock(RedirectAttributes.class); when(encryptionManager.decryptForExternalUse(any(String.class))) .thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27"); when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())) .thenReturn(orcidWithSecurityQuestion()); ModelAndView modelAndView = registrationController.resetPasswordEmail(servletRequest, "randomString", redirectAttributes);/*ww w. ja v a2 s. c o m*/ assertEquals("password_one_time_reset_optional_security_questions", modelAndView.getViewName()); verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true); }
From source file:org.orcid.frontend.web.controllers.RegistrationControllerTest.java
@Test public void testStandAloneSecurityQuestionsView() throws Exception { RedirectAttributes redirectAttributes = mock(RedirectAttributes.class); String encryptedLink = "this is encrypted. No really, it is."; String expiredLink = "this link has expired."; when(encryptionManager.decryptForExternalUse(eq(new String(Base64.decodeBase64(encryptedLink), "UTF-8")))) .thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27"); when(encryptionManager.decryptForExternalUse(eq(new String(Base64.decodeBase64(expiredLink), "UTF-8")))) .thenReturn("email=any@orcid.org&issueDate=1970-05-29T17:04:27"); when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())) .thenReturn(orcidWithSecurityQuestion()); ModelAndView modelAndView = registrationController.buildAnswerSecurityQuestionView(encryptedLink, redirectAttributes);/*from w w w .jav a 2s . c om*/ assertEquals("answer_security_question", modelAndView.getViewName()); // assertEquals("What is your all-time favorite sports team?",modelAndView.getModel().get("securityQuestionText")); verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true); modelAndView = registrationController.buildAnswerSecurityQuestionView(expiredLink, redirectAttributes); assertEquals("redirect:/reset-password", modelAndView.getViewName()); verify(redirectAttributes, times(1)).addFlashAttribute("passwordResetLinkExpired", true); }
From source file:org.orcid.frontend.web.controllers.RegistrationControllerTest.java
@Test public void testStandaloneSecurityQuestionsRedirectsToStandalonePasswordUponSuccess() throws Exception { RedirectAttributes redirectAttributes = mock(RedirectAttributes.class); BindingResult bindingResult = mock(BindingResult.class); when(encryptionManager.decryptForExternalUse(any(String.class))) .thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27"); when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())) .thenReturn(orcidWithSecurityQuestion()); when(bindingResult.hasErrors()).thenReturn(true); ChangeSecurityQuestionForm changeSecurityQuestionForm = new ChangeSecurityQuestionForm(); changeSecurityQuestionForm.setSecurityQuestionAnswer("Not the answer"); // try submit with invalid form ModelAndView modelAndView = registrationController.submitSecurityAnswer("encrypted", changeSecurityQuestionForm, bindingResult, redirectAttributes); assertEquals("answer_security_question", modelAndView.getViewName()); assertNull(modelAndView.getModel().get("securityQuestionIncorrect")); // Now form is valid but won't match the answer on the server when(bindingResult.hasErrors()).thenReturn(false); modelAndView = registrationController.submitSecurityAnswer("encrypted", changeSecurityQuestionForm, bindingResult, redirectAttributes); assertEquals("answer_security_question", modelAndView.getViewName()); assertEquals(modelAndView.getModel().get("securityQuestionIncorrect"), true); // finally correct the form to match the server changeSecurityQuestionForm.setSecurityQuestionAnswer("Answer"); modelAndView = registrationController.submitSecurityAnswer("encrypted", changeSecurityQuestionForm, bindingResult, redirectAttributes); assertEquals("redirect:/one-time-password/encrypted", modelAndView.getViewName()); assertNull(modelAndView.getModel().get("securityQuestionIncorrect")); }
From source file:org.orcid.frontend.web.controllers.RegistrationControllerTest.java
@Test public void testSubmitStandalonePasswordResetSuccess() throws Exception { RedirectAttributes redirectAttributes = mock(RedirectAttributes.class); BindingResult bindingResult = mock(BindingResult.class); when(encryptionManager.decryptForExternalUse(any(String.class))) .thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27"); when(orcidProfileManager.retrieveOrcidProfileByEmail("any@orcid.org")) .thenReturn(orcidWithSecurityQuestion()); when(bindingResult.hasErrors()).thenReturn(true); PasswordTypeAndConfirmForm passwordTypeAndConfirmForm = new PasswordTypeAndConfirmForm(); ModelAndView failedView = registrationController.confirmPasswordOneTimeResetView(servletRequest, servletResponse, "encrypted link", passwordTypeAndConfirmForm, bindingResult, redirectAttributes); verify(orcidProfileManager, times(0)).updatePasswordInformation(orcidWithSecurityQuestion()); assertEquals("password_one_time_reset", failedView.getViewName()); // check success flow when(bindingResult.hasErrors()).thenReturn(false); when(encryptionManager.decryptForExternalUse(any(String.class))) .thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27"); when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())) .thenReturn(orcidWithSecurityQuestion()); passwordTypeAndConfirmForm = new PasswordTypeAndConfirmForm(); ModelAndView successView = registrationController.confirmPasswordOneTimeResetView(servletRequest, servletResponse, "encrypted link", passwordTypeAndConfirmForm, bindingResult, redirectAttributes); verify(orcidProfileManager, times(1)).updatePasswordInformation(orcidWithSecurityQuestion()); assertEquals("redirect:http://testserver.orcid.org/my-orcid", successView.getViewName()); }
From source file:org.orcid.frontend.web.controllers.RegistrationControllerTest.java
@Test public void testSubmitConsolidatedPasswordReset() throws Exception { RedirectAttributes redirectAttributes = mock(RedirectAttributes.class); BindingResult bindingResult = mock(BindingResult.class); OneTimeResetPasswordForm oneTimeResetPasswordForm = new OneTimeResetPasswordForm(); // check validation failure rebuilds the one time view without a // redirect//w w w.j a va2s . c om when(encryptionManager.decryptForExternalUse(any(String.class))) .thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27"); when(bindingResult.hasErrors()).thenReturn(true); ModelAndView validationFailedView = registrationController.submitPasswordReset(servletRequest, servletResponse, "encrypted string not expired", oneTimeResetPasswordForm, bindingResult, redirectAttributes); assertEquals("password_one_time_reset_optional_security_questions", validationFailedView.getViewName()); verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true); // check success flow oneTimeResetPasswordForm.setPassword(Text.valueOf("password")); when(bindingResult.hasErrors()).thenReturn(false); when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())) .thenReturn(orcidWithSecurityQuestion()); ModelAndView successView = registrationController.submitPasswordReset(servletRequest, servletResponse, "encrypted string not expired", oneTimeResetPasswordForm, bindingResult, redirectAttributes); assertEquals("redirect:http://testserver.orcid.org/my-orcid", successView.getViewName()); verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true); // finally check expiry works when(encryptionManager.decryptForExternalUse(any(String.class))) .thenReturn("email=any@orcid.org&issueDate=1970-05-29T17:04:27"); ModelAndView expiredView = registrationController.submitPasswordReset(servletRequest, servletResponse, "encrypted string that's expired", oneTimeResetPasswordForm, bindingResult, redirectAttributes); assertEquals("redirect:/reset-password", expiredView.getViewName()); verify(redirectAttributes, times(1)).addFlashAttribute("passwordResetLinkExpired", true); }
From source file:org.springframework.integration.http.inbound.HttpRequestHandlingControllerTests.java
@Test public void sendOnly() throws Exception { QueueChannel requestChannel = new QueueChannel(); HttpRequestHandlingController controller = new HttpRequestHandlingController(false); controller.setBeanFactory(mock(BeanFactory.class)); controller.setRequestChannel(requestChannel); controller.setViewName("foo"); controller.afterPropertiesSet();//from ww w .j a v a 2 s . c om controller.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContent("hello".getBytes()); //request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE //Instead do: request.addHeader("Content-Type", "text/plain"); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals("foo", modelAndView.getViewName()); assertEquals(0, modelAndView.getModel().size()); Message<?> requestMessage = requestChannel.receive(0); assertNotNull(requestMessage); assertEquals("hello", requestMessage.getPayload()); }
From source file:org.springframework.integration.http.inbound.HttpRequestHandlingControllerTests.java
@Test public void sendOnlyViewExpression() throws Exception { QueueChannel requestChannel = new QueueChannel(); HttpRequestHandlingController controller = new HttpRequestHandlingController(false); controller.setBeanFactory(mock(BeanFactory.class)); controller.setRequestChannel(requestChannel); Expression viewExpression = new SpelExpressionParser().parseExpression("'baz'"); controller.setViewExpression(viewExpression); controller.afterPropertiesSet();/*from w ww.j av a2s .c om*/ controller.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContent("hello".getBytes()); //request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE //Instead do: request.addHeader("Content-Type", "text/plain"); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals("baz", modelAndView.getViewName()); assertEquals(0, modelAndView.getModel().size()); Message<?> requestMessage = requestChannel.receive(0); assertNotNull(requestMessage); assertEquals("hello", requestMessage.getPayload()); }
From source file:org.springframework.integration.http.inbound.HttpRequestHandlingControllerTests.java
@Test public void requestReply() throws Exception { DirectChannel requestChannel = new DirectChannel(); AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override//from w w w.ja va2 s . co m protected Object handleRequestMessage(Message<?> requestMessage) { return requestMessage.getPayload().toString().toUpperCase(); } }; requestChannel.subscribe(handler); HttpRequestHandlingController controller = new HttpRequestHandlingController(true); controller.setBeanFactory(mock(BeanFactory.class)); controller.setRequestChannel(requestChannel); controller.setViewName("foo"); controller.afterPropertiesSet(); controller.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); //request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE //Instead do: request.addHeader("Content-Type", "text/plain"); request.setContent("hello".getBytes()); //For Spring 3.0.7.RELEASE the Content must be set, MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals("foo", modelAndView.getViewName()); assertEquals(1, modelAndView.getModel().size()); Object reply = modelAndView.getModel().get("reply"); assertNotNull(reply); assertEquals("HELLO", reply); }
From source file:org.springframework.integration.http.inbound.HttpRequestHandlingControllerTests.java
@Test public void requestReplyViewExpressionString() throws Exception { DirectChannel requestChannel = new DirectChannel(); AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override// w ww . j a v a2 s . c o m protected Message<String> handleRequestMessage(Message<?> requestMessage) { return MessageBuilder.withPayload("foo").setHeader("bar", "baz").build(); } }; requestChannel.subscribe(handler); HttpRequestHandlingController controller = new HttpRequestHandlingController(true); controller.setBeanFactory(mock(BeanFactory.class)); controller.setRequestChannel(requestChannel); Expression viewExpression = new SpelExpressionParser().parseExpression("headers['bar']"); controller.setViewExpression(viewExpression); controller.afterPropertiesSet(); controller.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContent("hello".getBytes()); request.setContentType("text/plain"); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals("baz", modelAndView.getViewName()); assertEquals(1, modelAndView.getModel().size()); Object reply = modelAndView.getModel().get("reply"); assertNotNull(reply); assertEquals("foo", reply); }
From source file:org.springframework.integration.http.inbound.HttpRequestHandlingControllerTests.java
@Test public void requestReplyWithCustomReplyKey() throws Exception { DirectChannel requestChannel = new DirectChannel(); AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override//from w w w.j av a 2 s . c om protected Object handleRequestMessage(Message<?> requestMessage) { return requestMessage.getPayload().toString().toUpperCase(); } }; requestChannel.subscribe(handler); HttpRequestHandlingController controller = new HttpRequestHandlingController(true); controller.setBeanFactory(mock(BeanFactory.class)); controller.setRequestChannel(requestChannel); controller.setViewName("foo"); controller.setReplyKey("myReply"); controller.afterPropertiesSet(); controller.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setContent("howdy".getBytes()); //request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE //Instead do: request.addHeader("Content-Type", "text/plain"); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals("foo", modelAndView.getViewName()); assertEquals(1, modelAndView.getModel().size()); assertNull(modelAndView.getModel().get("reply")); Object reply = modelAndView.getModel().get("myReply"); assertEquals("HOWDY", reply); }