List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java
@Test public void shouldGetArtifactFileRestfully() throws Exception { createFile(artifactsRoot, "foo.xml"); ModelAndView mav = getFileAsHtml("/foo.xml"); assertThat(mav.getViewName(), is("fileView")); }
From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java
@Test public void shouldChooseFileOverDirectory() throws Exception { createFile(artifactsRoot, "foo.html"); createFile(artifactsRoot, "foo/bar.xml"); ModelAndView mav = getFileAsHtml("/foo.html"); assertThat(mav.getViewName(), is("fileView")); }
From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java
@Test public void shouldTreatSlashSlashAsOne() throws Exception { createFile(artifactsRoot, "tmp/1.xml"); ModelAndView mav = getFileAsHtml("//tmp/1.xml"); assertThat(mav.getViewName(), is("fileView")); }
From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java
@Test public void shouldGetDirectoryWithHtmlView() throws Exception { createFile(artifactsRoot, "directory/foo"); ModelAndView mav = getFileAsHtml("/directory.html"); assertThat(mav.getViewName(), is("rest/html")); }
From source file:fr.univrouen.poste.utils.ConfigInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { // we want to add usual model in modelAndView only when needed, ie with // direct html view : // not for download response (for example) because we don't need it // not for redirect view because we don't need it and we don't want that // they appears in the url if (modelAndView != null && modelAndView.hasView()) { boolean isViewObject = modelAndView.getView() == null; boolean isRedirectView = !isViewObject && modelAndView.getView() instanceof RedirectView; boolean viewNameStartsWithRedirect = isViewObject && modelAndView.getViewName().startsWith(UrlBasedViewResolver.REDIRECT_URL_PREFIX); if (!isRedirectView && !viewNameStartsWithRedirect) { String title = AppliConfig.getCacheTitre(); modelAndView.addObject("title", title); String piedPage = AppliConfig.getCachePiedPage(); modelAndView.addObject("piedPage", piedPage); String imageUrl = AppliConfig.getCacheImageUrl(); modelAndView.addObject("imageUrl", imageUrl); String path = request.getServletPath(); String subTitle = subTitles.get(path); String activeMenu = path.replaceAll("/", ""); if (subTitle == null) { List<String> keys = new Vector<String>(subTitles.keySet()); Collections.reverse(keys); for (String key : keys) { if (path.startsWith(key)) { subTitle = subTitles.get(key); ;/*from w w w . j a v a 2s .com*/ activeMenu = key.replaceAll("/", ""); break; } } } modelAndView.addObject("subTitle", subTitle); modelAndView.addObject("activeMenu", activeMenu); modelAndView.addObject("candidatCanSignup", AppliConfig.getCacheCandidatCanSignup()); modelAndView.addObject("versionEsupDematEC", AppliVersion.getCacheVersion()); } if (request.getParameter("size") != null) { Integer size = Integer.valueOf(request.getParameter("size")); request.getSession().setAttribute("size_in_session", size); } else if (request.getSession(false) != null && request.getSession().getAttribute("size_in_session") == null) { request.getSession().setAttribute("size_in_session", new Integer(40)); } } }
From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java
@Test public void rawConsoleOutShouldReturnTempFileWhenJobIsInProgress() throws Exception { Stage firstStage = pipeline.getFirstStage(); JobInstance firstJob = firstStage.getFirstJob(); firstJob.setState(JobState.Building); prepareTempConsoleOut(/* w w w . j a va 2 s . c o m*/ new JobIdentifier(pipeline.getName(), pipeline.getCounter(), pipeline.getLabel(), firstStage.getName(), String.valueOf(firstStage.getCounter()), firstJob.getName()), "fantastic curly coated retriever"); ModelAndView view = getFileAsHtml("cruise-output/console.log"); assertThat(view.getViewName(), is("fileView")); File targetFile = (File) (view.getModel().get("targetFile")); String separator = FileUtil.fileseparator(); assertThat(targetFile.getPath(), is(String.format("data%sconsole%s%s.log", separator, separator, DigestUtils.md5Hex(firstJob.buildLocator())))); }
From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#discontinueRadiologyOrder(HttpServletRequest,RadiologyOrder,DiscontinuationOrderRequest,BindingResult) * @verifies discontinue non discontinued radiology order and redirect to discontinuation order *//*from w w w.j a v a 2 s . c o m*/ @Test public void discontinueRadiologyOrder_shouldDiscontinueNonDiscontinuedRadiologyOrderAndRedirectToDiscontinuationOrder() throws Exception { // given RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1(); DiscontinuationOrderRequest discontinuationOrderRequest = new DiscontinuationOrderRequest(); discontinuationOrderRequest.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer()); discontinuationOrderRequest.setReasonNonCoded("Wrong Procedure"); Order mockDiscontinuationOrder = new Order(); mockDiscontinuationOrder.setOrderId(2); mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE); mockDiscontinuationOrder.setOrderer(discontinuationOrderRequest.getOrderer()); mockDiscontinuationOrder.setOrderReasonNonCoded(discontinuationOrderRequest.getReasonNonCoded()); mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("discontinueOrder", "discontinueOrder"); MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); when(radiologyOrderService.getRadiologyOrder(mockRadiologyOrderToDiscontinue.getOrderId())) .thenReturn(mockRadiologyOrderToDiscontinue); when(radiologyOrderService.discontinueRadiologyOrder(mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder.getOrderer(), mockDiscontinuationOrder.getOrderReasonNonCoded())) .thenReturn(mockDiscontinuationOrder); BindingResult resultDiscontinueOrderRequest = mock(BindingResult.class); assertThat(mockRadiologyOrderToDiscontinue.getAction(), is(Order.Action.NEW)); ModelAndView modelAndView = radiologyOrderFormController.discontinueRadiologyOrder(mockRequest, mockRadiologyOrderToDiscontinue, discontinuationOrderRequest, resultDiscontinueOrderRequest); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is( "redirect:/module/radiology/radiologyOrder.form?orderId=" + mockDiscontinuationOrder.getOrderId())); assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR), is("Order.discontinuedSuccessfully")); }
From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#discontinueRadiologyOrder(HttpServletRequest,HttpServletResponse,RadiologyOrder,DiscontinuationOrderRequest,BindingResult) * @verifies not discontinue given radiology order and not redirect if discontinuation order request is not valid *///from w ww .j a v a2s. c o m @Test public void discontinueRadiologyOrder_shouldNotDiscontinueGivenRadiologyOrderAndNotRedirectIfDiscontinuationOrderRequestIsNotValid() throws Exception { // given RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1(); DiscontinuationOrderRequest discontinuationOrderRequest = new DiscontinuationOrderRequest(); discontinuationOrderRequest.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer()); discontinuationOrderRequest.setReasonNonCoded(""); Order mockDiscontinuationOrder = new Order(); mockDiscontinuationOrder.setOrderId(2); mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE); mockDiscontinuationOrder.setOrderer(discontinuationOrderRequest.getOrderer()); mockDiscontinuationOrder.setOrderReasonNonCoded(discontinuationOrderRequest.getReasonNonCoded()); mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("discontinueOrder", "discontinueOrder"); MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); when(radiologyOrderService.getRadiologyOrder(mockRadiologyOrderToDiscontinue.getOrderId())) .thenReturn(mockRadiologyOrderToDiscontinue); when(radiologyOrderService.discontinueRadiologyOrder(mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder.getOrderer(), mockDiscontinuationOrder.getOrderReasonNonCoded())) .thenReturn(mockDiscontinuationOrder); BindingResult resultDiscontinueOrderRequest = mock(BindingResult.class); when(resultDiscontinueOrderRequest.hasErrors()).thenReturn(true); assertThat(mockRadiologyOrderToDiscontinue.getAction(), is(Order.Action.NEW)); ModelAndView modelAndView = radiologyOrderFormController.discontinueRadiologyOrder(mockRequest, mockRadiologyOrderToDiscontinue, discontinuationOrderRequest, resultDiscontinueOrderRequest); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW)); assertThat(modelAndView.getModelMap(), hasKey("order")); Order order = (Order) modelAndView.getModelMap().get("order"); assertThat(order, is(mockRadiologyOrderToDiscontinue)); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue)); }
From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#discontinueRadiologyOrder(HttpServletRequest,RadiologyOrder,DiscontinuationOrderRequest,BindingResult) * @verifies not redirect and set session attribute with openmrs error if api exception is thrown by discontinue * radiology order/*from w w w.ja v a 2 s . c om*/ */ @Test public void discontinueRadiologyOrder_shouldNotRedirectAndSetSessionAttributeWithOpenmrsErrorIfApiExceptionIsThrownByDiscontinueRadiologyOrder() throws Exception { // given RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1(); DiscontinuationOrderRequest discontinuationOrderRequest = new DiscontinuationOrderRequest(); discontinuationOrderRequest.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer()); discontinuationOrderRequest.setReasonNonCoded("some"); Order mockDiscontinuationOrder = new Order(); mockDiscontinuationOrder.setOrderId(2); mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE); mockDiscontinuationOrder.setOrderer(discontinuationOrderRequest.getOrderer()); mockDiscontinuationOrder.setOrderReasonNonCoded(discontinuationOrderRequest.getReasonNonCoded()); mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("discontinueOrder", "discontinueOrder"); MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); when(radiologyOrderService.getRadiologyOrder(mockRadiologyOrderToDiscontinue.getOrderId())) .thenReturn(mockRadiologyOrderToDiscontinue); when(radiologyOrderService.discontinueRadiologyOrder(mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder.getOrderer(), mockDiscontinuationOrder.getOrderReasonNonCoded())) .thenThrow(new APIException( "Cannot discontinue an order that is already stopped, expired or voided")); BindingResult resultDiscontinueOrderRequest = mock(BindingResult.class); assertThat(mockRadiologyOrderToDiscontinue.getAction(), is(Order.Action.NEW)); ModelAndView modelAndView = radiologyOrderFormController.discontinueRadiologyOrder(mockRequest, mockRadiologyOrderToDiscontinue, discontinuationOrderRequest, resultDiscontinueOrderRequest); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW)); assertThat(modelAndView.getModelMap(), hasKey("order")); Order order = (Order) modelAndView.getModelMap().get("order"); assertThat(order, is(mockRadiologyOrderToDiscontinue)); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue)); assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR), is("Cannot discontinue an order that is already stopped, expired or voided")); }