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

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

Introduction

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

Prototype

public MockHttpServletRequest() 

Source Link

Document

Create a new MockHttpServletRequest with a default MockServletContext .

Usage

From source file:com.nebhale.buildmonitor.web.resource.AbstractResourceAssemblerTest.java

@Before
public final void requestContext() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContextHolder.setRequestAttributes(new ServletWebRequest(request, response));
}

From source file:net.eusashead.hateoas.conditional.interceptor.RequestBuilder.java

public RequestBuilder(String path, String verb) {

    // Create the request
    this.request = new MockHttpServletRequest();

    // Set verb, path and query
    request.setRequestURI(path);//www  . ja va2  s.c  o m
    request.setMethod(verb);

}

From source file:be.dnsbelgium.rdap.spring.security.RDAPErrorHandlerTest.java

@Test
public void testHandler() throws IOException, ServletException {
    RDAPErrorHandler errorHandler = new RDAPErrorHandler();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RDAPErrorException exception = new RDAPErrorException(499, "title", "desc1", "desc2");
    errorHandler.handle(request, response, exception);
    Assert.assertEquals("{\"errorCode\":499,\"title\":\"title\",\"description\":[\"desc1\",\"desc2\"]}",
            response.getContentAsString());
}

From source file:com.safasoft.treeweb.controller.MainControllerTest.java

/**
 * Test of getAppPage method, of class MainController.
 *//*from w w  w.jav a 2  s .c  om*/
@Test
public void testGetAppPage() {
    System.out.println("getAppPage");
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MainController instance = new MainController();
    String expResult = "applicationpage";
    String result = instance.getAppPage(httpRequest);
    assertEquals(expResult, result);
    // TODO review the generated test code and remove the default call to fail.
}

From source file:test.com.azaptree.services.command.http.WebCommandContextTest.java

@Test
public void testWebCommandContext() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();

    WebCommandContext<String, Long> stringLongCtx = new WebCommandContext<>(request, response);

    Assert.assertNotNull(stringLongCtx.getHttpServletRequest());
    Assert.assertNotNull(stringLongCtx.getHttpServletResponse());

    stringLongCtx = new WebCommandContext<>(request, response, "REQUEST_MSG");
    Assert.assertNotNull(stringLongCtx.getHttpServletRequest());
    Assert.assertNotNull(stringLongCtx.getHttpServletResponse());
    Assert.assertEquals(stringLongCtx.getRequestMessage(), "REQUEST_MSG");

    stringLongCtx.setResponseMessage(5l);
    Assert.assertEquals(stringLongCtx.getResponseMessage(), Long.valueOf(5l));
}

From source file:com.google.api.server.spi.config.model.StandardParametersTest.java

@Test
public void shouldPrettyPrint_defaultValueIsTrue() {
    assertThat(StandardParameters.shouldPrettyPrint(new MockHttpServletRequest())).isTrue();
}

From source file:io.pivotal.cla.mvc.support.ImportedSignaturesSessionAttrTests.java

@Before
public void setup() {
    request = new MockHttpServletRequest();
    attr = new ImportedSignaturesSessionAttr(new ServletWebRequest(request));
}

From source file:org.jmesa.core.message.MessagesTest.java

@Test
public void getPreference() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    WebContext webContext = new HttpServletRequestWebContext(request);
    webContext.setLocale(Locale.US);

    Messages messages = new ResourceBundleMessages("org.jmesa.core.message.testResourceBundle", webContext);
    String message = messages.getMessage("test.normal");
    assertNotNull(message);/*from w w  w.j ava  2s .  c  o  m*/
    assertTrue(message.equals("foo"));

    message = messages.getMessage("test.args", new String[] { "1" });
    assertNotNull(message);
    assertTrue(message.equals("foo 1"));
}

From source file:org.openmrs.module.kenyaemr.SystemMonitorControllerTest.java

/**
 * @see SystemMonitorController#checkAccess(javax.servlet.http.HttpServletRequest)
 *///  ww  w.j a v  a2 s . com
@Test
public void checkAccess_shouldGrantAccessToLocalRequests() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setLocalAddr("1.2.3.4");
    request.setRemoteAddr("1.2.3.4");

    Assert.assertThat(controller.checkAccess(request), is(true));

    request = new MockHttpServletRequest();
    request.setLocalAddr("5.6.7.8");
    request.setRemoteAddr("1.2.3.4");

    Assert.assertThat(controller.checkAccess(request), is(false));

    request = new MockHttpServletRequest();
    request.setLocalAddr(null);
    request.setRemoteAddr("1.2.3.4");

    Assert.assertThat(controller.checkAccess(request), is(false));
}

From source file:ar.com.zauber.commons.web.proxy.impl.MutableURLRequestMapperTest.java

/** test */
public final void testNull() {
    final MutableURLRequestMapper c = new MutableURLRequestMapper();
    assertFalse(c.getProxiedURLFromRequest(new MockHttpServletRequest()).hasResult());
    c.setTarget(null);/*from w  w w  .j av a 2  s . com*/
    assertFalse(c.getProxiedURLFromRequest(new MockHttpServletRequest()).hasResult());
}