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

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

Introduction

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

Prototype

public void setLocalAddr(String localAddr) 

Source Link

Usage

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

/**
 * @see SystemMonitorController#checkAccess(javax.servlet.http.HttpServletRequest)
 *//*  ww w.  ja  va  2s .c o  m*/
@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));
}