Java Code Examples for org.springframework.mock.web.test.MockHttpServletRequest#setPathInfo()

The following examples show how to use org.springframework.mock.web.test.MockHttpServletRequest#setPathInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalResourceViewTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void forward() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myservlet/handler.do");
	request.setContextPath("/mycontext");
	request.setServletPath("/myservlet");
	request.setPathInfo(";mypathinfo");
	request.setQueryString("?param1=value1");

	view.setUrl(url);
	view.setServletContext(new MockServletContext() {
		@Override
		public int getMinorVersion() {
			return 4;
		}
	});

	view.render(model, request, response);
	assertEquals(url, response.getForwardedUrl());

	model.forEach((key, value) -> assertEquals("Values for model key '" + key
			+ "' must match", value, request.getAttribute(key)));
}
 
Example 2
Source File: InternalResourceViewTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void forward() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myservlet/handler.do");
	request.setContextPath("/mycontext");
	request.setServletPath("/myservlet");
	request.setPathInfo(";mypathinfo");
	request.setQueryString("?param1=value1");

	view.setUrl(url);
	view.setServletContext(new MockServletContext() {
		@Override
		public int getMinorVersion() {
			return 4;
		}
	});

	view.render(model, request, response);
	assertEquals(url, response.getForwardedUrl());

	model.forEach((key, value) -> assertEquals("Values for model key '" + key
			+ "' must match", value, request.getAttribute(key)));
}
 
Example 3
Source File: InternalResourceViewTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void forward() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myservlet/handler.do");
	request.setContextPath("/mycontext");
	request.setServletPath("/myservlet");
	request.setPathInfo(";mypathinfo");
	request.setQueryString("?param1=value1");

	view.setUrl(url);
	view.setServletContext(new MockServletContext() {
		@Override
		public int getMinorVersion() {
			return 4;
		}
	});

	view.render(model, request, response);
	assertEquals(url, response.getForwardedUrl());

	model.keySet().stream().forEach(
		key -> assertEquals("Values for model key '" + key + "' must match", model.get(key), request.getAttribute(key))
	);
}
 
Example 4
Source File: Spr7766Tests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@Deprecated
public void test() throws Exception {
	AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
	ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
	GenericConversionService service = new DefaultConversionService();
	service.addConverter(new ColorConverter());
	binder.setConversionService(service);
	adapter.setWebBindingInitializer(binder);
	Spr7766Controller controller = new Spr7766Controller();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/colors");
	request.setPathInfo("/colors");
	request.addParameter("colors", "#ffffff,000000");
	MockHttpServletResponse response = new MockHttpServletResponse();
	adapter.handle(request, response, controller);
}