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:org.raxa.module.raxacore.web.v1_0.controller.DrugGroupControllerTest.java

@Before
public void before() throws Exception {
    executeDataSet(MODULE_TEST_DATA_XML);
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    this.controller = new DrugGroupController();
    this.service = Context.getService(DrugGroupService.class);
}

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

@Before
public void setupTest() {
    request = new MockHttpServletRequest("GET", "/csv");
    response = new MockHttpServletResponse();
}

From source file:org.openmrs.module.webservices.rest19ext.web.v1_0.controller.ProviderAttributeControllerTest.java

@Before
public void before() throws Exception {
    executeDataSet(Rest19ExtTestConstants.TEST_DATASET);
    this.service = Context.getProviderService();
    this.controller = new ProviderAttributeController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:ru.org.linux.topic.TopicListControllerTest.java

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

From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpointTest.java

@Test
public void logfile() throws IOException {
    try {//from  ww w. j av  a2s. c o m
        FileCopyUtils.copy("--TEST--".getBytes(), new File("test.log"));
        controller.setLogfile("test.log");

        assertEquals(HttpStatus.OK, controller.available().getStatusCode());

        MockHttpServletResponse response = new MockHttpServletResponse();
        controller.invoke(response);
        assertEquals(HttpStatus.OK.value(), response.getStatus());
        assertEquals("--TEST--", response.getContentAsString());
    } finally {
        new File("test.log").delete();
    }
}

From source file:com.hastybox.lesscss.compileservice.controller.spring.UrlBasedSpringLessControllerTest.java

/**
 * @throws java.lang.Exception/*from  w  w w .  jav a2s .c o  m*/
 */
@Before
public void setUp() throws Exception {

    controller = new UrlBasedSpringLessController();

    compileService = mock(LessCompileService.class);

    resourceLoader = mock(ResourceLoader.class);
    resource = mock(Resource.class);

    controller.setCompileService(compileService);
    controller.setResourceLoader(resourceLoader);

    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();

}

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

/**
 * @see RoleController#create(SimpleObject, javax.servlet.http.HttpServletRequest, HttpServletResponse)
 * @verifies create a new Role/*  w  w w  .java  2 s.c  o  m*/
 */
@Test
public void createRole_shouldCreateANewRole() throws Exception {
    int before = Context.getUserService().getAllRoles().size();
    String json = "{\"name\":\"test\",\"description\":\"This is a test role for RoleControllerTest.\"}}";
    SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class);
    Object newRole = new RoleController().create(post, new MockHttpServletRequest(),
            new MockHttpServletResponse());
    Assert.assertEquals(before + 1, Context.getUserService().getAllRoles().size());
}

From source file:com.jl.crm.web.OAuthTest.java

@Before
public void setup() {
    request = new MockHttpServletRequest();
    request.setMethod("GET");
    response = new MockHttpServletResponse();
    chain = new MockFilterChain();
}

From source file:org.openmrs.web.controller.concept.ConceptSourceFormControllerTest.java

/**
 * @see ConceptSourceListController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)
 *//*from  ww w .  j  a  va  2 s .co  m*/
@Test
@Verifies(value = "should retire concept source", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)")
public void onSubmit_shouldRetireConceptSource() throws Exception {
    ConceptService cs = Context.getConceptService();
    ConceptSourceFormController controller = (ConceptSourceFormController) applicationContext
            .getBean("conceptSourceForm");

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setMethod("POST");
    mockRequest.setParameter("conceptSourceId", "3");
    mockRequest.setParameter("retireReason", "dummy reason for retirement");
    mockRequest.setParameter("retire", "dummy reason for retirement");

    controller.handleRequest(mockRequest, new MockHttpServletResponse());

    ConceptSource conceptSource = cs.getConceptSource(3);
    Assert.assertTrue(conceptSource.isRetired());
    Assert.assertEquals("dummy reason for retirement", conceptSource.getRetireReason());
}

From source file:com.nebhale.cyclinglibrary.web.GzipFilterTest.java

@Test
public void gzipRequest() throws ServletException, IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Content-Encoding", "gzip");
    request.setContent(gzipContent("test-request-content"));

    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain filterChain = new MockFilterChain();

    this.filter.doFilterInternal(request, response, filterChain);
    writeContent("test-response-content", filterChain.getResponse().getOutputStream());

    assertEquals("test-request-content", readContent(filterChain.getRequest().getInputStream()));
    assertEquals("test-response-content", response.getContentAsString());
}