List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:alpha.portal.webapp.controller.CaseFormControllerTest.java
/** * Test last./*from w w w .j ava2s . c om*/ * * @throws Exception * the exception */ @Test public void testLast() throws Exception { MockHttpServletRequest request = this.newGet("/caseform"); request.setParameter("caseId", "550e4713-e22b-11d4-a716-446655440002"); request.setRemoteUser("admin"); ModelAndView mv = this.form.showForm(this.filters, request, new MockHttpServletResponse()); request = this.newGet("/caseform"); request.setParameter("caseId", "last"); request.setRemoteUser("admin"); final AlphaCase aCase = this.caseManager.get("550e4713-e22b-11d4-a716-446655440002"); mv = this.form.showForm(this.filters, request, new MockHttpServletResponse()); Assert.assertEquals("caseform", mv.getViewName()); Assert.assertEquals(aCase, mv.getModel().get("case")); }
From source file:net.cloudkit.enterprises.infrastructure.commons.ExecuteTimeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { Long startTime = (Long) request.getAttribute(EXECUTE_TIME_ATTRIBUTE_NAME); Object localObject;//from w ww .j av a2s .c o m if (startTime == null) { localObject = request.getAttribute(START_TIME); Long endTime = Long.valueOf(System.currentTimeMillis()); startTime = Long.valueOf(endTime.longValue() - ((Long) localObject).longValue()); request.setAttribute(START_TIME, localObject); } if (modelAndView != null) { localObject = modelAndView.getViewName(); if (!StringUtils.startsWith((String) localObject, redirect)) { modelAndView.addObject(EXECUTE_TIME_ATTRIBUTE_NAME, startTime); } } if (logger.isDebugEnabled()) { logger.debug("[" + handler + "] executeTime: " + startTime + "ms"); } }
From source file:com.technologicaloddity.saha.util.AjaxPageRendererImpl.java
public String render(ModelAndView modelAndView, HttpServletRequest request, HttpServletResponse response) { String result = null;/*from w w w. j a v a 2 s . co m*/ StringWriter sout = new StringWriter(); StringBuffer buffer = sout.getBuffer(); HttpServletResponse fakeResponse = new SwallowingHttpServletResponse(response, sout, response.getCharacterEncoding()); Locale locale = this.localeResolver.resolveLocale(request); fakeResponse.setLocale(locale); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver); try { View view = viewResolver.resolveViewName(modelAndView.getViewName(), locale); view.render(modelAndView.getModel(), request, fakeResponse); result = buffer.toString(); } catch (Exception e) { result = "Ajax render error:" + e.getMessage(); } return result; }
From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Integer) *//*ww w. j a v a 2 s . c o m*/ @Test @Verifies(value = "should populate model and view with new radiology order without prefilled patient if given patient is null", method = "getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Integer)") public void getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient_shouldPopulateModelAndViewWithNewRadiologyOrderWithoutPrefilledPatientIfGivenPatientIsNull() throws Exception { ModelAndView modelAndView = radiologyOrderFormController .getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(null); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm")); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertNull(order.getOrderId()); assertNotNull(order.getStudy()); assertNull(order.getStudy().getStudyId()); assertNull(order.getPatient()); assertThat(modelAndView.getModelMap(), not(hasKey("patientId"))); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#getRadiologyOrderFormWithExistingRadiologyOrderByOrderId(Integer) *///from w w w . java2s .c o m @Test @Verifies(value = "should populate model and view with existing radiology order matching given order id", method = "getRadiologyOrderFormWithExistingRadiologyOrderByOrderId(Integer)") public void getRadiologyOrderFormWithExistingRadiologyOrderByOrderId_shouldPopulateModelAndViewWithExistingRadiologyOrderMatchingGivenOrderId() throws Exception { //given RadiologyOrder mockRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1(); when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrder.getOrderId())) .thenReturn(mockRadiologyOrder); ModelAndView modelAndView = radiologyOrderFormController .getRadiologyOrderFormWithExistingRadiologyOrderByOrderId(mockRadiologyOrder); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm")); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertThat(order, is(mockRadiologyOrder)); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Integer) *//*from w ww . j a v a2 s. co m*/ @Test @Verifies(value = "should populate model and view with new radiology order prefilled with given patient", method = "getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Integer)") public void getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient_shouldPopulateModelAndViewWithNewRadiologyOrderPrefilledWithGivenPatient() throws Exception { //given Patient mockPatient = RadiologyTestData.getMockPatient1(); ModelAndView modelAndView = radiologyOrderFormController .getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(mockPatient); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm")); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertNull(order.getOrderId()); assertNotNull(order.getStudy()); assertNull(order.getStudy().getStudyId()); assertNotNull(order.getPatient()); assertThat(order.getPatient(), is(mockPatient)); assertThat(modelAndView.getModelMap(), hasKey("patientId")); Integer patientId = (Integer) modelAndView.getModelMap().get("patientId"); assertThat(patientId, is(mockPatient.getPatientId())); }
From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#postSaveRadiologyOrder(HttpServletRequest, Integer, Order, * BindingResult)/* ww w. j a v a2 s.c o m*/ */ @Test @Verifies(value = "should set http session attribute openmrs message to order saved and redirect to radiology order list when save study was successful", method = "postSaveRadiologyOrder(HttpServletRequest, Integer, RadiologyOrder, BindingResult)") public void postSaveRadiologyOrder_shouldSetHttpSessionAttributeOpenmrsMessageToOrderSavedAndRedirectToRadiologyOrderListWhenSaveStudyWasSuccessful() throws Exception { //given RadiologyOrder mockRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1(); mockRadiologyOrder.getStudy().setMwlStatus(MwlStatus.SAVE_OK); when(radiologyService.placeRadiologyOrder(mockRadiologyOrder)).thenReturn(mockRadiologyOrder); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("saveOrder", "saveOrder"); MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); BindingResult orderErrors = mock(BindingResult.class); when(orderErrors.hasErrors()).thenReturn(false); ModelAndView modelAndView = radiologyOrderFormController.postSaveRadiologyOrder(mockRequest, null, mockRadiologyOrder, mockRadiologyOrder, orderErrors); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("redirect:/module/radiology/radiologyOrder.list")); assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR), is("Order.saved")); }
From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrder() * @verifies populate model and view with new radiology order *//*w w w .j av a 2 s. c o m*/ @Test public void getRadiologyOrderFormWithNewRadiologyOrder_shouldPopulateModelAndViewWithNewRadiologyOrder() throws Exception { ModelAndView modelAndView = radiologyOrderFormController.getRadiologyOrderFormWithNewRadiologyOrder(); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW)); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertNull(order.getOrderId()); assertNotNull(order.getStudy()); assertNull(order.getStudy().getStudyId()); assertNull(order.getOrderer()); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyOK() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, OAuthConstants.APPROVAL_PROMPT_FORCE); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName()); final Map<String, Object> map = modelAndView.getModel(); assertEquals(SERVICE_NAME, map.get("serviceName")); assertEquals(scopeMap.hashCode(), map.get("scopeMap").hashCode()); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }
From source file:org.jasig.cas.support.oauth.web.OAuth20AuthorizeCallbackControllerTests.java
@Test public void verifyOKWhenBypassApprovalFalse() throws Exception { final Principal principal = mock(Principal.class); when(principal.getId()).thenReturn(PRINCIPAL_ID); final Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principal); final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class); when(ticketGrantingTicket.isExpired()).thenReturn(false); when(ticketGrantingTicket.getAuthentication()).thenReturn(authentication); final TicketRegistry ticketRegistry = mock(TicketRegistry.class); when(ticketRegistry.getTicket(TICKET_GRANTING_TICKET_ID)).thenReturn(ticketGrantingTicket); final Map<String, Scope> scopeMap = new HashMap<>(); scopeMap.put("scope1", new Scope("scope1", "description2")); scopeMap.put("scope2", new Scope("scope2", "description2")); final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class); when(centralOAuthService.getScopes(anySetOf(String.class))).thenReturn(scopeMap); final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL); final MockHttpSession mockSession = new MockHttpSession(); mockSession.putValue(OAuthConstants.OAUTH20_LOGIN_TICKET_ID, TICKET_GRANTING_TICKET_ID); mockSession.putValue(OAuthConstants.OAUTH20_SCOPE, SCOPE); mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME); mockSession.putValue(OAuthConstants.OAUTH20_TOKEN_TYPE, TokenType.OFFLINE); mockSession.putValue(OAuthConstants.OAUTH20_APPROVAL_PROMPT, OAuthConstants.APPROVAL_PROMPT_FORCE); mockSession.putValue(OAuthConstants.BYPASS_APPROVAL_PROMPT, false); mockRequest.setSession(mockSession); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.setTicketRegistry(ticketRegistry); oauth20WrapperController.setCentralOAuthService(centralOAuthService); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName()); final Map<String, Object> map = modelAndView.getModel(); assertEquals(SERVICE_NAME, map.get("serviceName")); assertEquals(scopeMap.hashCode(), map.get("scopeMap").hashCode()); assertEquals(scopeMap.keySet(), mockSession.getAttribute(OAuthConstants.OAUTH20_SCOPE_SET)); }