Search in sources :

Example 1 with MockRequestDispatcher

use of cn.taketoday.web.mock.MockRequestDispatcher in project today-infrastructure by TAKETODAY.

the class InternalResourceViewTests method includeOnAttribute.

@Test
public void includeOnAttribute() throws Exception {
    given(request.getRequestDispatcher(url)).willReturn(new MockRequestDispatcher(url));
    given(request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI)).willReturn("somepath");
    RequestContext context = new ServletRequestContext(null, request, response);
    view.setUrl(url);
    // Can now try multiple tests
    view.render(model, context);
    assertThat(response.getIncludedUrl()).isEqualTo(url);
    model.forEach((key, value) -> verify(request).setAttribute(key, value));
}
Also used : ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockRequestDispatcher(cn.taketoday.web.mock.MockRequestDispatcher) Test(org.junit.jupiter.api.Test)

Example 2 with MockRequestDispatcher

use of cn.taketoday.web.mock.MockRequestDispatcher in project today-infrastructure by TAKETODAY.

the class InternalResourceViewTests method alwaysInclude.

@Test
public void alwaysInclude() throws Exception {
    given(request.getRequestDispatcher(url)).willReturn(new MockRequestDispatcher(url));
    view.setUrl(url);
    view.setAlwaysInclude(true);
    RequestContext context = new ServletRequestContext(null, request, response);
    // Can now try multiple tests
    view.render(model, context);
    assertThat(response.getIncludedUrl()).isEqualTo(url);
    model.forEach((key, value) -> verify(request).setAttribute(key, value));
}
Also used : ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockRequestDispatcher(cn.taketoday.web.mock.MockRequestDispatcher) Test(org.junit.jupiter.api.Test)

Example 3 with MockRequestDispatcher

use of cn.taketoday.web.mock.MockRequestDispatcher in project today-infrastructure by TAKETODAY.

the class InternalResourceViewTests method includeOnCommitted.

@Test
public void includeOnCommitted() throws Exception {
    given(request.getRequestDispatcher(url)).willReturn(new MockRequestDispatcher(url));
    response.setCommitted(true);
    view.setUrl(url);
    RequestContext context = new ServletRequestContext(null, request, response);
    // Can now try multiple tests
    view.render(model, context);
    assertThat(response.getIncludedUrl()).isEqualTo(url);
    model.forEach((k, v) -> verify(request).setAttribute(k, v));
}
Also used : ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockRequestDispatcher(cn.taketoday.web.mock.MockRequestDispatcher) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContext (cn.taketoday.web.RequestContext)3 MockRequestDispatcher (cn.taketoday.web.mock.MockRequestDispatcher)3 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)3 Test (org.junit.jupiter.api.Test)3