use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class BaseViewTests method renderWithStaticAttributesNoCollision.
/**
* Test attribute passing, NOT CSV parsing.
*/
@Test
public void renderWithStaticAttributesNoCollision() throws Exception {
WebServletApplicationContext wac = mock(WebServletApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("foo", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
tv.render(model, requestContext);
checkContainsAll(model, tv.model);
checkContainsAll(p, tv.model);
assertThat(tv.initialized).isTrue();
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class BaseViewTests method dynamicModelOverridesStaticAttributesIfCollision.
@Test
public void dynamicModelOverridesStaticAttributesIfCollision() throws Exception {
WebServletApplicationContext wac = mock(WebServletApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("one", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
tv.render(model, requestContext);
// Check it contains all
checkContainsAll(model, tv.model);
assertThat(tv.model.size()).isEqualTo(3);
assertThat(tv.model.get("something")).isEqualTo("else");
assertThat(tv.initialized).isTrue();
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method resourceNotFound.
@Test
public void resourceNotFound() throws Exception {
for (HttpMethod method : HttpMethod.values()) {
this.request = new MockHttpServletRequest("GET", "");
this.response = new MockHttpServletResponse();
resourceNotFound(method);
}
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method testInvalidPath.
private void testInvalidPath(String requestPath, ResourceHttpRequestHandler handler) throws Exception {
request.setRequestURI(requestPath);
this.response = new MockHttpServletResponse();
requestContext = new ServletRequestContext(null, request, response);
handler.handleRequest(requestContext);
assertThat(this.response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND.value());
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
List<Resource> paths = new ArrayList<>(2);
paths.add(new ClassPathResource("test/", getClass()));
paths.add(new ClassPathResource("testalternatepath/", getClass()));
paths.add(new ClassPathResource("META-INF/resources/webjars/"));
TestServletContext servletContext = new TestServletContext();
this.handler = new ResourceHttpRequestHandler();
this.handler.setLocations(paths);
this.handler.setCacheSeconds(3600);
this.handler.afterPropertiesSet();
this.request = new MockHttpServletRequest(servletContext, "GET", "");
this.response = new MockHttpServletResponse();
requestContext = new ServletRequestContext(null, request, response);
}
Aggregations