org.springframework.web.servlet.support.RequestDataValueProcessorWrapper Java Examples

The following examples show how to use org.springframework.web.servlet.support.RequestDataValueProcessorWrapper. 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: RedirectViewTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void updateTargetUrl() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	wac.setServletContext(new MockServletContext());
	wac.refresh();

	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

	RedirectView rv = new RedirectView();
	rv.setApplicationContext(wac);	// Init RedirectView with WebAppCxt
	rv.setUrl("/path");

	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

	given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
	rv.render(new ModelMap(), request, response);
	verify(mockProcessor).processUrl(request, "/path");
}
 
Example #2
Source File: RedirectViewTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void updateTargetUrlWithContextLoader() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);

	MockServletContext servletContext = new MockServletContext();
	ContextLoader contextLoader = new ContextLoader(wac);
	contextLoader.initWebApplicationContext(servletContext);

	try {
		RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
		wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

		RedirectView rv = new RedirectView();
		rv.setUrl("/path");

		given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
		rv.render(new ModelMap(), request, response);
		verify(mockProcessor).processUrl(request, "/path");
	}
	finally {
		contextLoader.closeWebApplicationContext(servletContext);
	}
}
 
Example #3
Source File: RedirectViewTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void updateTargetUrl() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	wac.setServletContext(new MockServletContext());
	wac.refresh();

	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

	RedirectView rv = new RedirectView();
	rv.setApplicationContext(wac);	// Init RedirectView with WebAppCxt
	rv.setUrl("/path");

	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

	given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
	rv.render(new ModelMap(), request, response);
	verify(mockProcessor).processUrl(request, "/path");
}
 
Example #4
Source File: RedirectViewTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void updateTargetUrlWithContextLoader() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);

	MockServletContext servletContext = new MockServletContext();
	ContextLoader contextLoader = new ContextLoader(wac);
	contextLoader.initWebApplicationContext(servletContext);

	try {
		RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
		wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

		RedirectView rv = new RedirectView();
		rv.setUrl("/path");

		given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
		rv.render(new ModelMap(), request, response);
		verify(mockProcessor).processUrl(request, "/path");
	}
	finally {
		contextLoader.closeWebApplicationContext(servletContext);
	}
}
 
Example #5
Source File: RedirectViewTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void updateTargetUrl() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	wac.setServletContext(new MockServletContext());
	wac.refresh();

	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

	RedirectView rv = new RedirectView();
	rv.setApplicationContext(wac);	// Init RedirectView with WebAppCxt
	rv.setUrl("/path");

	MockHttpServletRequest request = createRequest();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	HttpServletResponse response = new MockHttpServletResponse();

	given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");

	rv.render(new ModelMap(), request, response);

	verify(mockProcessor).processUrl(request, "/path");
}
 
Example #6
Source File: AbstractHtmlElementTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected MockPageContext createAndPopulatePageContext() throws JspException {
	MockPageContext pageContext = createPageContext();
	MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
	((StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request))
			.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	extendRequest(request);
	extendPageContext(pageContext);
	RequestContext requestContext = new JspAwareRequestContext(pageContext);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
	return pageContext;
}
 
Example #7
Source File: AbstractHtmlElementTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();
	WebApplicationContext wac = RequestContextUtils.findWebApplicationContext(request);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
	return mockProcessor;
}
 
Example #8
Source File: AbstractHtmlElementTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected MockPageContext createAndPopulatePageContext() throws JspException {
	MockPageContext pageContext = createPageContext();
	MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
	((StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request))
			.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	extendRequest(request);
	extendPageContext(pageContext);
	RequestContext requestContext = new JspAwareRequestContext(pageContext);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
	return pageContext;
}
 
Example #9
Source File: AbstractHtmlElementTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();
	WebApplicationContext wac = RequestContextUtils.findWebApplicationContext(request);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
	return mockProcessor;
}
 
Example #10
Source File: RedirectViewTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void updateTargetUrlWithContextLoader() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);

	MockServletContext servletContext = new MockServletContext();
	ContextLoader contextLoader = new ContextLoader(wac);
	contextLoader.initWebApplicationContext(servletContext);

	try {
		RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
		wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

		RedirectView rv = new RedirectView();
		rv.setUrl("/path");

		MockHttpServletRequest request = createRequest();
		HttpServletResponse response = new MockHttpServletResponse();

		given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");

		rv.render(new ModelMap(), request, response);

		verify(mockProcessor).processUrl(request, "/path");
	}
	finally {
		contextLoader.closeWebApplicationContext(servletContext);
	}
}
 
Example #11
Source File: AbstractHtmlElementTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected MockPageContext createAndPopulatePageContext() throws JspException {
	MockPageContext pageContext = createPageContext();
	MockHttpServletRequest request = (MockHttpServletRequest) pageContext.getRequest();
	StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request);
	wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
	extendRequest(request);
	extendPageContext(pageContext);
	RequestContext requestContext = new JspAwareRequestContext(pageContext);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, requestContext);
	return pageContext;
}
 
Example #12
Source File: AbstractHtmlElementTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
	RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
	ServletRequest request = getPageContext().getRequest();
	StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.getWebApplicationContext(request);
	wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
	return mockProcessor;
}