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

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

Introduction

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

Prototype

@Nullable
public String getViewName() 

Source Link

Document

Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.

Usage

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

@Test
public void shouldGiveSuccessMessageWhenImportWasSuccessful() throws Exception {

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            multipartFile);// w  w w  .jav  a  2  s  .co  m

    verify(mrrtReportTemplateService).importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);
    verifyNoMoreInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    String message = (String) request.getSession().getAttribute(WebConstants.OPENMRS_MSG_ATTR);
    assertThat(message, is("radiology.MrrtReportTemplate.imported"));
}

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

/**
 * @see RadiologyDashboardReportTemplatesTabController#uploadReportTemplate(HttpServletRequest,MultipartFile)
 *//*  w ww  . j  ava  2 s .  co  m*/
@Test
public void shouldGiveErrorMessageWhenTemplateFileIsEmpty() throws Exception {

    MultipartFile emptyFile = mock(MultipartFile.class);
    when(emptyFile.isEmpty()).thenReturn(true);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            emptyFile);

    verifyZeroInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));

    String message = (String) request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR);
    assertThat(message, is("radiology.MrrtReportTemplate.not.imported.empty"));
}

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

@Test
public void shouldSetErrorMessageInSessionWhenMrrtReportTemplateValidationExceptionIsThrown() throws Exception {

    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("Missing header", "err.missing.header"));
    MrrtReportTemplateValidationException mrrtReportTemplateValidationException = new MrrtReportTemplateValidationException(
            validationResult);/*from   w ww.  j a  va 2  s  .c om*/
    doThrow(mrrtReportTemplateValidationException).when(mrrtReportTemplateService)
            .importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            multipartFile);

    verify(mrrtReportTemplateService).importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);
    verifyNoMoreInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    String errorMessage = (String) request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR);
    assertNotNull(errorMessage);
    assertThat(errorMessage, is("Failed to import mrrtReportTemplate.html"));
    assertThat(modelAndView.getModelMap().get("mrrtReportTemplateValidationErrors"),
            is(validationResult.getErrors()));
}

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

@Test
public void shouldSetErrorMessageInSessionWhenApiExceptionIsThrown() throws Exception {

    doThrow(new APIException("Cannot import the same template twice.")).when(mrrtReportTemplateService)
            .importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            multipartFile);/*from ww w  .j a  v  a 2 s . c  o  m*/

    verify(mrrtReportTemplateService).importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);
    verifyNoMoreInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    String errorMessage = (String) request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR);
    assertNotNull(errorMessage);
    assertThat(errorMessage,
            is("Failed to import mrrtReportTemplate.html => Cannot import the same template twice."));
}

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

@Test
public void shouldSetErrorMessageInSessionWhenIoExceptionIsThrown() throws Exception {

    doThrow(new IOException("File could not be read.")).when(mrrtReportTemplateService)
            .importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            multipartFile);//from ww w .j  a va 2 s. c  o  m

    verify(mrrtReportTemplateService).importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);
    verifyNoMoreInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    String errorMessage = (String) request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR);
    assertNotNull(errorMessage);
    assertThat(errorMessage, is("Failed to import mrrtReportTemplate.html => File could not be read."));
}

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

@Test
public void deleteMrrtReportTemplate_shouldReturnAModelAndViewOfTheRadiologyDashboardReportTemplatesPageWithAStatusMessage() {

    MockHttpSession mockSession = new MockHttpSession();
    MrrtReportTemplate mockTemplate = mock(MrrtReportTemplate.class);
    request.setSession(mockSession);//from  w  ww .j  a v  a 2 s .  co m

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.deleteMrrtReportTemplate(request,
            mockTemplate);

    verify(mrrtReportTemplateService).purgeMrrtReportTemplate(mockTemplate);
    verifyNoMoreInteractions(mrrtReportTemplateService);
    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    assertThat(mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
            is("radiology.MrrtReportTemplate.deleted"));
}

From source file:org.openmrs.module.radiology.legacyui.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

@Test
public void shouldCatchApiExceptionAndSetErrorMessageInSession() throws Exception {

    MrrtReportTemplate mockTemplate = mock(MrrtReportTemplate.class);
    doThrow(new APIException("File could not be deleted.")).when(mrrtReportTemplateService)
            .purgeMrrtReportTemplate(mockTemplate);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.deleteMrrtReportTemplate(request,
            mockTemplate);//from  www  . j  a v a 2 s  .c  om

    verify(mrrtReportTemplateService).purgeMrrtReportTemplate(mockTemplate);
    verifyNoMoreInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    String errorMessage = (String) request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR);
    assertNotNull(errorMessage);
    assertThat(errorMessage, is("Failed to delete template file => File could not be deleted."));
}

From source file:org.openmrs.module.radiology.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

/**
 * @see RadiologyDashboardReportTemplatesTabController#getRadiologyReportTemplatesTab(HttpServletRequest)
 * @verifies return model and view of the radiology report templates tab
 *           page and set tab session attribute to radiology reports tab
 *           page//from   w  w w . j a  va 2s  .  c o m
 */
@Test
public void getRadiologyReportTemplatesTab_shouldReturnModelAndViewOfTheRadiologyReportTemplatesTabPageAndSetTabSessionAttributeToRadiologyReportsTabPage()
        throws Exception {

    MockHttpSession mockSession = new MockHttpSession();
    request.setSession(mockSession);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController
            .getRadiologyReportTemplatesTab(request);

    verifyZeroInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    assertThat(mockSession.getAttribute(RadiologyWebConstants.RADIOLOGY_DASHBOARD_TAB_SESSION_ATTRIBUTE),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_REQUEST_MAPPING));
}

From source file:org.openmrs.module.radiology.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

/**
 * @see RadiologyDashboardReportTemplatesTabController#uploadReportTemplate(HttpServletRequest,MultipartFile)
 * @verifies give success message when import was successful
 *//*from   ww  w .  j  a v  a2 s.c o  m*/
@Test
public void uploadReportTemplate_shouldGiveSuccessMessageWhenImportWasSuccessful() throws Exception {

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            multipartFile);

    verify(mrrtReportTemplateService).importMrrtReportTemplate(MOCK_TEMPLATE_CONTENT);
    verifyNoMoreInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));
    String message = (String) request.getSession().getAttribute(WebConstants.OPENMRS_MSG_ATTR);
    assertThat(message, is("radiology.MrrtReportTemplate.imported"));
}

From source file:org.openmrs.module.radiology.report.template.web.RadiologyDashboardReportTemplatesTabControllerTest.java

/**
 * @see RadiologyDashboardReportTemplatesTabController#uploadReportTemplate(HttpServletRequest,MultipartFile)
 * @verifies give error message when template file is empty
 *///from ww w  . ja  va 2 s. c o m
@Test
public void uploadReportTemplate_shouldGiveErrorMessageWhenTemplateFileIsEmpty() throws Exception {

    MultipartFile emptyFile = mock(MultipartFile.class);
    when(emptyFile.isEmpty()).thenReturn(true);

    ModelAndView modelAndView = radiologyDashboardReportTemplatesTabController.uploadReportTemplate(request,
            emptyFile);

    verifyZeroInteractions(mrrtReportTemplateService);

    assertNotNull(modelAndView);
    assertThat(modelAndView.getViewName(),
            is(RadiologyDashboardReportTemplatesTabController.RADIOLOGY_REPORT_TEMPLATES_TAB_VIEW));

    String message = (String) request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR);
    assertThat(message, is("radiology.MrrtReportTemplate.not.imported.empty"));
}