Example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse.

Prototype

MockHttpServletResponse

Source Link

Usage

From source file:nl.eveoh.sakai.mytimetable.tool.ToolControllerTest.java

@Test
public void testIndexPage() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");

    ModelAndView modelAndView = toolController.handleRequest(request, response);

    Assert.assertEquals("Should get index page.", "index", modelAndView.getViewName());
    Assert.assertEquals(200, response.getStatus());
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.ConceptDescriptionControllerTest.java

@Before
public void before() throws Exception {
    this.service = Context.getConceptService();
    this.controller = new ConceptDescriptionController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:ejportal.webapp.filter.StaticFilterTest.java

/**
 * Test filter doesnt forward when path matches.
 * //ww w  .  j av a 2 s.  co  m
 * @throws Exception
 *             the exception
 */
public void testFilterDoesntForwardWhenPathMatches() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/scripts/dojo/test.html");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockFilterChain chain = new MockFilterChain();

    this.filter.doFilter(request, response, chain);

    Assert.assertNull(chain.getForwardURL());
}

From source file:org.soybeanMilk.test.unit.web.TestDefaultWebObjectSource.java

@Before
public void setUp() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    application = new MockServletContext();

    webObjectSource = new DefaultWebObjectSource(request, response, application, new WebGenericConverter());
}

From source file:org.mifos.ui.loan.controller.AppInfoControllerTest.java

@SuppressWarnings("PMD.SignatureDeclareThrowsException") // Exception is thrown by AppInfoController.handleRequest
public void testHandleRequestView() throws Exception {
    applicationInformationDto = new ApplicationInformationDto();
    String expectedSvnRevision = "123456";
    applicationInformationDto.setSvnRevision(expectedSvnRevision);
    String expectedBuildId = "fooId";
    applicationInformationDto.setBuildId(expectedBuildId);
    String expectedBuildTag = "bar-baz-tag-1";
    applicationInformationDto.setBuildTag(expectedBuildTag);
    AppInfoController controller = new AppInfoController();
    controller.setAppInfo(applicationInformationDto);
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setMethod("GET");
    mockRequest.setRequestURI("/appInfo.ftl");
    MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse);

    Assert.assertNotNull(modelAndView.getModel());
    Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model");
    Assert.assertNotNull(modelMap);//from  ww w  .ja v a  2s . co m
    ApplicationInformationDto actualApplicationInformationDto = (ApplicationInformationDto) modelMap
            .get("appInfo");
    Assert.assertNotNull(actualApplicationInformationDto);
    Assert.assertEquals(actualApplicationInformationDto.getSvnRevision(), expectedSvnRevision);
    Assert.assertEquals(actualApplicationInformationDto.getBuildId(), expectedBuildId);
    Assert.assertEquals(actualApplicationInformationDto.getBuildTag(), expectedBuildTag);
}

From source file:org.openmrs.contrib.metadatarepository.webapp.filter.LocaleFilterTest.java

public void testSetLocaleInSessionWhenSessionNotNull() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "es");

    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setSession(new MockHttpSession(null));

    filter.doFilter(request, response, new MockFilterChain());

    // session not null, should result in not null
    Locale locale = (Locale) request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY);
    assertNotNull(locale);/* w  ww. j  a v a2 s . c  o  m*/
    assertNotNull(LocaleContextHolder.getLocale());
    assertEquals(new Locale("es"), locale);
}

From source file:net.solarnetwork.web.test.SimpleCsvHttpMessageCoverterTest.java

@Before
public void setupTest() {
    response = new MockHttpServletResponse();
    output = new ServletServerHttpResponse(response);
}

From source file:org.openmrs.module.feedback.web.SubmitFeedbackControllerTest.java

@Before
public void setUp() throws Exception {

    /* executed before the test is run */
    this.service = Context.getService(FeedbackService.class);
    this.controller = new FeedbackAdminListController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();

    /* this file is in the same folder of test resources where the hibernate mapping file is located */
    initializeInMemoryDatabase();// ww  w .ja v a2 s . c o m
    executeDataSet("SeverityDataset.xml");
    executeDataSet("PredefinedSubjectDataset.xml");

    /* Sample data is loaded into the system */
    authenticate();
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestControllerTest.java

@Before
public void before()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    controller = new BaseRestController();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    spyOnLog = spy(LogFactory.getLog(BaseRestController.class));
    // Need to get the logger using reflection
    Field log;/*from  w w  w  . ja va2s. co  m*/
    log = controller.getClass().getDeclaredField("log");
    log.setAccessible(true);

    log.set(controller, spyOnLog);

}