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:de.codecentric.boot.admin.actuate.LogfileMvcEndpointTest.java

@Test
public void logfile_noProperty() throws IOException {
    assertEquals(HttpStatus.NOT_FOUND, controller.available().getStatusCode());

    MockHttpServletResponse response = new MockHttpServletResponse();
    controller.invoke(response);/*w ww.  j  av a2 s.co  m*/
    assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatus());
}

From source file:org.jasig.cas.web.flow.DynamicRedirectViewSelectorTests.java

public void testNoService() {
    try {// w  ww.jav  a  2  s  .  c o  m
        final MockRequestContext context = new MockRequestContext();
        context.setExternalContext(new ServletExternalContext(new MockServletContext(),
                new MockHttpServletRequest(), new MockHttpServletResponse()));
        this.selector.makeEntrySelection(context);
        fail("null pointer expected.");
    } catch (final NullPointerException e) {
        return;
    }
}

From source file:de.science.hack.jetstream.web.DownloadFilterTest.java

@Before
public void setUp() {
    classUnderTest = new DownloadFilter();

    response = new MockHttpServletResponse();
    request = mock(HttpServletRequest.class);
    chain = mock(FilterChain.class);
}

From source file:org.energyos.espi.datacustodian.web.filter.CORSFilterTests.java

@Test
public void testDoFilterInternal() throws Exception {
    CORSFilter corsFilter = new CORSFilter();
    FilterChain filterChain = mock(FilterChain.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    corsFilter.doFilter(request, response, filterChain);

    verify(filterChain).doFilter(request, response);
}

From source file:com.mtt.myapp.common.util.FileDownloadUtilsTest.java

@Test
public void testDownloadFileHttpServletResponseString() throws IOException {
    File downFile = new ClassPathResource("TEST_USER.zip").getFile();
    String filePath = downFile.getAbsolutePath();
    MockHttpServletResponse resp = new MockHttpServletResponse();
    FileDownloadUtil.downloadFile(resp, filePath);
    String lengthHeader = resp.getHeader("Content-Length");

    assertThat(lengthHeader).isEqualTo(String.valueOf(downFile.length()));
}

From source file:org.araneaframework.tests.StandardServletOutputDataTests.java

public void setUp() {
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();

    out = new StandardServletOutputData(req, resp);
}

From source file:org.ngrinder.common.util.FileDownloadUtilTest.java

@Test
public void testDownloadFileHttpServletResponseString() throws IOException {
    File downFile = new ClassPathResource("TEST_USER.zip").getFile();
    String filePath = downFile.getAbsolutePath();
    MockHttpServletResponse resp = new MockHttpServletResponse();
    FileDownloadUtil.downloadFile(resp, filePath);
    String lengthHeader = resp.getHeader("Content-Length");

    assertThat(lengthHeader, is(String.valueOf(downFile.length())));
}

From source file:org.ngrinder.common.util.FileDownloadUtilsTest.java

@Test
public void testDownloadFileHttpServletResponseString() throws IOException {
    File downFile = new ClassPathResource("TEST_USER.zip").getFile();
    String filePath = downFile.getAbsolutePath();
    MockHttpServletResponse resp = new MockHttpServletResponse();
    FileDownloadUtils.downloadFile(resp, filePath);
    String lengthHeader = resp.getHeader("Content-Length");

    assertThat(lengthHeader, is(String.valueOf(downFile.length())));
}

From source file:io.lavagna.web.helper.UserSessionTest.java

@Test
public void isUserAuthenticated() {
    HttpServletRequest req = new MockHttpServletRequest();
    HttpServletResponse resp = new MockHttpServletResponse();
    User user = Mockito.mock(User.class);
    Assert.assertFalse(UserSession.isUserAuthenticated(req));

    UserSession.setUser(user, req, resp, Mockito.mock(UserRepository.class));

    Assert.assertTrue(UserSession.isUserAuthenticated(req));

    Assert.assertEquals(user.getId(), UserSession.getUserId(req));
}

From source file:org.energyos.espi.thirdparty.web.filter.CORSFilterTests.java

@Test
@Ignore//from  w  w w .  j av a2 s . co m
public void testDoFilterInternal() throws Exception {
    CORSFilter corsFilter = new CORSFilter();
    FilterChain filterChain = mock(FilterChain.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    corsFilter.doFilter(request, response, filterChain);

    verify(filterChain).doFilter(request, response);
}