Example usage for org.springframework.web.servlet ModelAndView getModelMap

List of usage examples for org.springframework.web.servlet ModelAndView getModelMap

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getModelMap.

Prototype

public ModelMap getModelMap() 

Source Link

Document

Return the underlying ModelMap instance (never null ).

Usage

From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(Patient)
 * @verifies populate model and view with new radiology order prefilled with given patient
 *///from  w w  w. ja  v  a 2 s. c om
@Test
public void getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient_shouldPopulateModelAndViewWithNewRadiologyOrderPrefilledWithGivenPatient()

        throws Exception {

    // given
    Patient mockPatient = RadiologyTestData.getMockPatient1();

    ModelAndView modelAndView = radiologyOrderFormController
            .getRadiologyOrderFormWithNewRadiologyOrderAndPrefilledPatient(mockPatient);

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

    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.order.web.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithExistingRadiologyOrder(Order)
 * @verifies populate model and view with existing order if given order id only matches an order
 *           and not a radiology order//from   w  w w.  j  av  a  2  s. co  m
 */
@Test
public void getRadiologyOrderFormWithExistingRadiologyOrder_shouldPopulateModelAndViewWithExistingOrderIfGivenOrderIdOnlyMatchesAnOrderAndNotARadiologyOrder()
        throws Exception {

    // given
    RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1();
    String discontinueReason = "Wrong Procedure";

    Order mockDiscontinuationOrder = new Order();
    mockDiscontinuationOrder.setOrderId(2);
    mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE);
    mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer());
    mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason);
    mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue);

    ModelAndView modelAndView = radiologyOrderFormController
            .getRadiologyOrderFormWithExistingRadiologyOrder(mockDiscontinuationOrder);

    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(mockDiscontinuationOrder));

    assertThat(modelAndView.getModelMap(), not(hasKey("radiologyOrder")));

    assertThat(modelAndView.getModelMap(), not(hasKey("dicomViewerUrl")));
}

From source file:org.openmrs.module.radiology.order.web.RadiologyOrderFormControllerTest.java

/**
 * @see RadiologyOrderFormController#getRadiologyOrderFormWithExistingRadiologyOrder(Order)
 * @verifies populate model and view with existing radiology order if given order id matches a
 *           radiology order and dicom viewer url if order completed
 *//*from   ww  w .j a  va2s . c om*/
@Test
public void getRadiologyOrderFormWithExistingRadiologyOrder_shouldPopulateModelAndViewWithExistingRadiologyOrderIfGivenOrderIdMatchesARadiologyOrderAndDicomViewerUrlIfOrderCompleted()
        throws Exception {

    // given
    RadiologyOrder mockCompletedRadiologyOrder = RadiologyTestData.getMockRadiologyOrder1();
    mockCompletedRadiologyOrder.getStudy().setPerformedStatus(PerformedProcedureStepStatus.COMPLETED);

    when(dicomWebViewer.getDicomViewerUrl(mockCompletedRadiologyOrder.getStudy())).thenReturn(
            "http://localhost:8081/weasis-pacs-connector/viewer?studyUID=1.2.826.0.1.3680043.8.2186.1.1");

    ModelAndView modelAndView = radiologyOrderFormController
            .getRadiologyOrderFormWithExistingRadiologyOrder(mockCompletedRadiologyOrder);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(), is(RadiologyOrderFormController.RADIOLOGY_ORDER_FORM_VIEW));

    assertThat(modelAndView.getModelMap(), hasKey("order"));
    RadiologyOrder order = (RadiologyOrder) modelAndView.getModelMap().get("order");
    assertThat(order, is(mockCompletedRadiologyOrder));

    assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder"));
    RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder");
    assertThat(radiologyOrder, is(mockCompletedRadiologyOrder));

    assertThat(modelAndView.getModelMap(), hasKey("dicomViewerUrl"));
    String dicomViewerUrl = (String) modelAndView.getModelMap().get("dicomViewerUrl");
    assertThat(dicomViewerUrl,
            is("http://localhost:8081/weasis-pacs-connector/viewer?studyUID=1.2.826.0.1.3680043.8.2186.1.1"));
}

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 w w .j  a v a2  s.co 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  ww w. j a  v a2 s  .c o  m*/
 */
@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"));
}

From source file:de.iteratec.iteraplan.presentation.dialog.GuiSearchController.java

@Override
public ModelAndView handleIteraplanException(Throwable ex, HttpServletRequest req, HttpServletResponse resp) {
    // set flag for reset
    errorOccurred = true;//from  www .  j  a v  a  2s . c  o  m

    // the newly created ModelAndView needs some of the attributes stored here, e.g. the building block type, if available
    ModelAndView mav = super.handleIteraplanException(ex, req, resp);
    addBuildingBlockTypeToModel(mav.getModelMap());

    return mav;
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#populateModelAndView(RadiologyOrder,Obs)
 * @verifies populate the model and view for given radiology order without completed study and obs
 *//*from   w w  w  . j  a v  a 2s  .  co  m*/
@Test
public void populateModelAndView_shouldPopulateTheModelAndViewForGivenRadiologyOrderWithoutCompletedStudyAndObs()
        throws Exception {
    //given
    mockStudy.setPerformedStatus(PerformedProcedureStepStatus.IN_PROGRESS);

    Method populateModelAndViewMethod = radiologyObsFormController.getClass().getDeclaredMethod(
            "populateModelAndView",
            new Class[] { org.openmrs.module.radiology.RadiologyOrder.class, org.openmrs.Obs.class });
    populateModelAndViewMethod.setAccessible(true);

    ModelAndView modelAndView = (ModelAndView) populateModelAndViewMethod.invoke(radiologyObsFormController,
            new Object[] { mockRadiologyOrder, mockObs });

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");
    assertThat(obs, is(mockObs));

    assertThat(modelAndView.getModelMap(), hasKey("studyUID"));
    String studyUID = (String) modelAndView.getModelMap().get("studyUID");
    assertThat(studyUID, nullValue());

    assertThat(modelAndView.getModelMap(), hasKey("previousObs"));
    List<Obs> previousObs = (List<Obs>) modelAndView.getModelMap().get("previousObs");
    assertThat(previousObs, is(notNullValue()));
    assertThat(previousObs.isEmpty(), is(true));

    assertThat(modelAndView.getModelMap(), hasKey("dicomViewerUrl"));
    String dicomViewerUrl = (String) modelAndView.getModelMap().get("dicomViewerUrl");
    assertThat(dicomViewerUrl, is(nullValue()));

    assertThat(modelAndView.getModelMap(), hasKey(not("htmlView")));
    assertThat(modelAndView.getModelMap(), hasKey(not("hyperlinkView")));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#populateModelAndView(RadiologyOrder,Obs,String)
 * @verifies populate model and view with edit reason
 *//*from  w  ww  .j a  v a  2 s .  co m*/
@Test
public void populateModelAndView_shouldPopulateModelAndViewWithEditReason() throws Exception {

    Method populateModelAndViewMethod = radiologyObsFormController.getClass().getDeclaredMethod(
            "populateModelAndView", new Class[] { org.openmrs.module.radiology.RadiologyOrder.class,
                    org.openmrs.Obs.class, java.lang.String.class });
    populateModelAndViewMethod.setAccessible(true);

    ModelAndView modelAndView = (ModelAndView) populateModelAndViewMethod.invoke(radiologyObsFormController,
            new Object[] { mockRadiologyOrder, mockObs, "Changed obs date" });

    assertThat(modelAndView.getModelMap(), hasKey("editReason"));
    String editReason = (String) modelAndView.getModelMap().get("editReason");
    assertThat(editReason, is("Changed obs date"));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#populateModelAndView(RadiologyOrder,Obs)
 * @verifies populate the model and view for given radiology order with completed study and obs
 *///ww  w . jav  a 2 s  .  c  om
@Test
public void populateModelAndView_shouldPopulateTheModelAndViewForGivenRadiologyOrderWithCompletedStudyAndObs()
        throws Exception {
    //given
    mockStudy.setPerformedStatus(PerformedProcedureStepStatus.COMPLETED);

    when(radiologyProperties.getDicomViewerUrl()).thenReturn("http://localhost:8081/weasis/viewer?");

    Method populateModelAndViewMethod = radiologyObsFormController.getClass().getDeclaredMethod(
            "populateModelAndView",
            new Class[] { org.openmrs.module.radiology.RadiologyOrder.class, org.openmrs.Obs.class });
    populateModelAndViewMethod.setAccessible(true);

    ModelAndView modelAndView = (ModelAndView) populateModelAndViewMethod.invoke(radiologyObsFormController,
            new Object[] { mockRadiologyOrder, mockObs });

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");
    assertThat(obs, is(mockObs));

    assertThat(modelAndView.getModelMap(), hasKey("studyUID"));
    String studyUID = (String) modelAndView.getModelMap().get("studyUID");
    assertThat(studyUID, is(notNullValue()));
    assertThat(studyUID, is(mockStudy.getStudyInstanceUid()));

    assertThat(modelAndView.getModelMap(), hasKey("previousObs"));
    List<Obs> previousObs = (List<Obs>) modelAndView.getModelMap().get("previousObs");
    assertThat(previousObs, is(notNullValue()));
    assertThat(previousObs.isEmpty(), is(true));

    assertThat(modelAndView.getModelMap(), hasKey("dicomViewerUrl"));
    String dicomViewerUrl = (String) modelAndView.getModelMap().get("dicomViewerUrl");
    assertThat(dicomViewerUrl, is(notNullValue()));
    assertThat(dicomViewerUrl,
            is("http://localhost:8081/weasis/viewer?studyUID=1.2.826.0.1.3680043.8.2186.1.1"));

    assertThat(modelAndView.getModelMap(), hasKey(not("htmlView")));
    assertThat(modelAndView.getModelMap(), hasKey(not("hyperlinkView")));
}

From source file:org.openmrs.module.radiology.web.controller.RadiologyObsFormControllerTest.java

/**
 * @see RadiologyObsFormController#populateModelAndView(RadiologyOrder,Obs)
 * @verifies populate the model and view for given obs with complex concept
 *//*from  ww w.  j a v a2  s  . com*/
@Test
public void populateModelAndView_shouldPopulateTheModelAndViewForGivenObsWithComplexConcept() throws Exception {
    //given
    ConceptComplex concept = new ConceptComplex();
    ConceptDatatype cdt = new ConceptDatatype();
    cdt.setHl7Abbreviation("ED");
    concept.setDatatype(cdt);
    mockObs.setConcept(concept);
    mockObs.setComplexData(RadiologyTestData.getMockComplexDataForMockObsWithComplexConcept());

    Field obsServiceField = RadiologyObsFormController.class.getDeclaredField("obsService");
    obsServiceField.setAccessible(true);
    obsServiceField.set(radiologyObsFormController, obsService);

    when(obsService.getComplexObs(mockObs.getId(), WebConstants.HTML_VIEW))
            .thenReturn(RadiologyTestData.getMockComplexObsAsHtmlViewForMockObs());
    when(obsService.getComplexObs(mockObs.getId(), WebConstants.HYPERLINK_VIEW))
            .thenReturn(RadiologyTestData.getMockComplexObsAsHyperlinkViewForMockObs());

    Method populateModelAndViewMethod = radiologyObsFormController.getClass().getDeclaredMethod(
            "populateModelAndView",
            new Class[] { org.openmrs.module.radiology.RadiologyOrder.class, org.openmrs.Obs.class });
    populateModelAndViewMethod.setAccessible(true);

    ModelAndView modelAndView = (ModelAndView) populateModelAndViewMethod.invoke(radiologyObsFormController,
            new Object[] { mockRadiologyOrder, mockObs });

    assertThat(modelAndView.getModelMap(), hasKey("obs"));
    Obs obs = (Obs) modelAndView.getModelMap().get("obs");
    assertThat(obs, is(mockObs));

    assertThat(modelAndView.getModelMap(), hasKey("htmlView"));
    CharArrayReader htmlComplexData = (CharArrayReader) modelAndView.getModelMap().get("htmlView");
    assertThat(htmlComplexData, is(notNullValue()));
    char[] htmlComplexDataCharArray = new char[47];
    htmlComplexData.read(htmlComplexDataCharArray);
    assertThat(String.copyValueOf(htmlComplexDataCharArray),
            is("<img src='/openmrs/complexObsServlet?obsId=1'/>"));

    assertThat(modelAndView.getModelMap(), hasKey("hyperlinkView"));
    CharArrayReader hyperlinkViewComplexData = (CharArrayReader) modelAndView.getModelMap()
            .get("hyperlinkView");
    assertThat(hyperlinkViewComplexData, is(notNullValue()));
    char[] hyperlinkViewComplexDataCharArray = new char[33];
    hyperlinkViewComplexData.read(hyperlinkViewComplexDataCharArray);
    assertThat(String.copyValueOf(hyperlinkViewComplexDataCharArray), is("openmrs/complexObsServlet?obsId=1"));
}