org.springframework.mock.web.test.MockPageContext Java Examples

The following examples show how to use org.springframework.mock.web.test.MockPageContext. 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: AbstractTagTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected MockPageContext createPageContext() {
	MockServletContext sc = new MockServletContext();
	SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
	wac.setServletContext(sc);
	wac.setNamespace("test");
	wac.refresh();

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	MockHttpServletResponse response = new MockHttpServletResponse();
	if (inDispatcherServlet()) {
		request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
		LocaleResolver lr = new AcceptHeaderLocaleResolver();
		request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
		ThemeResolver tr = new FixedThemeResolver();
		request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
		request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
	}
	else {
		sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	}

	return new MockPageContext(sc, request, response);
}
 
Example #2
Source File: AbstractTagTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected MockPageContext createPageContext() {
	MockServletContext sc = new MockServletContext();
	SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
	wac.setServletContext(sc);
	wac.setNamespace("test");
	wac.refresh();

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	MockHttpServletResponse response = new MockHttpServletResponse();
	if (inDispatcherServlet()) {
		request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
		LocaleResolver lr = new AcceptHeaderLocaleResolver();
		request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
		ThemeResolver tr = new FixedThemeResolver();
		request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
		request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
	}
	else {
		sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	}

	return new MockPageContext(sc, request, response);
}
 
Example #3
Source File: AbstractTagTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected MockPageContext createPageContext() {
	MockServletContext sc = new MockServletContext();
	SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
	wac.setServletContext(sc);
	wac.setNamespace("test");
	wac.refresh();

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	MockHttpServletResponse response = new MockHttpServletResponse();
	if (inDispatcherServlet()) {
		request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
		LocaleResolver lr = new AcceptHeaderLocaleResolver();
		request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
		ThemeResolver tr = new FixedThemeResolver();
		request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
		request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
	}
	else {
		sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	}

	return new MockPageContext(sc, request, response);
}
 
Example #4
Source File: TagIdGeneratorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertNextId() {
	PageContext pageContext = new MockPageContext();
	assertEquals("foo1", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo2", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo3", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo4", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("bar1", TagIdGenerator.nextId("bar", pageContext));
}
 
Example #5
Source File: LabelTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void extendPageContext(MockPageContext pageContext) throws JspException {
	super.extendPageContext(pageContext);

	NestedPathTag nestedPathTag = new NestedPathTag();
	nestedPathTag.setPath("spouse.");
	nestedPathTag.setPageContext(pageContext);
	nestedPathTag.doStartTag();
}
 
Example #6
Source File: OptionsTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #7
Source File: AbstractFormTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void extendPageContext(MockPageContext pageContext) throws JspException {
	this.formTag.setCommandName(COMMAND_NAME);
	this.formTag.setAction("myAction");
	this.formTag.setPageContext(pageContext);
	this.formTag.doStartTag();
}
 
Example #8
Source File: AbstractHtmlElementTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map<String, Object> model = Collections.singletonMap(
			BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #9
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 #10
Source File: ErrorsTagTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #11
Source File: TagIdGeneratorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void assertNextId() {
	PageContext pageContext = new MockPageContext();
	assertEquals("foo1", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo2", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo3", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo4", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("bar1", TagIdGenerator.nextId("bar", pageContext));
}
 
Example #12
Source File: LabelTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void extendPageContext(MockPageContext pageContext) throws JspException {
	super.extendPageContext(pageContext);

	NestedPathTag nestedPathTag = new NestedPathTag();
	nestedPathTag.setPath("spouse.");
	nestedPathTag.setPageContext(pageContext);
	nestedPathTag.doStartTag();
}
 
Example #13
Source File: OptionsTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #14
Source File: AbstractFormTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void extendPageContext(MockPageContext pageContext) throws JspException {
	this.formTag.setModelAttribute(COMMAND_NAME);
	this.formTag.setAction("myAction");
	this.formTag.setPageContext(pageContext);
	this.formTag.doStartTag();
}
 
Example #15
Source File: AbstractHtmlElementTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map<String, Object> model = Collections.singletonMap(
			BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #16
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 #17
Source File: ErrorsTagTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #18
Source File: TagIdGeneratorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertNextId() {
	PageContext pageContext = new MockPageContext();
	assertEquals("foo1", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo2", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo3", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("foo4", TagIdGenerator.nextId("foo", pageContext));
	assertEquals("bar1", TagIdGenerator.nextId("bar", pageContext));
}
 
Example #19
Source File: LabelTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void extendPageContext(MockPageContext pageContext) throws JspException {
	super.extendPageContext(pageContext);

	NestedPathTag nestedPathTag = new NestedPathTag();
	nestedPathTag.setPath("spouse.");
	nestedPathTag.setPageContext(pageContext);
	nestedPathTag.doStartTag();
}
 
Example #20
Source File: OptionsTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #21
Source File: AbstractFormTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void extendPageContext(MockPageContext pageContext) throws JspException {
	this.formTag.setModelAttribute(COMMAND_NAME);
	this.formTag.setAction("myAction");
	this.formTag.setPageContext(pageContext);
	this.formTag.doStartTag();
}
 
Example #22
Source File: AbstractHtmlElementTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map<String, Object> model = Collections.singletonMap(
			BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #23
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 #24
Source File: ErrorsTagTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void exposeBindingResult(Errors errors) {
	// wrap errors in a Model
	Map model = new HashMap();
	model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

	// replace the request context with one containing the errors
	MockPageContext pageContext = getPageContext();
	RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
	pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
}
 
Example #25
Source File: AbstractHtmlElementTagTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected MockPageContext getPageContext() {
	return this.pageContext;
}
 
Example #26
Source File: AbstractHtmlElementTagTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected void extendPageContext(MockPageContext pageContext) throws JspException {
}
 
Example #27
Source File: AbstractHtmlElementTagTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected void extendPageContext(MockPageContext pageContext) throws JspException {
}
 
Example #28
Source File: AbstractHtmlElementTagTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected MockPageContext getPageContext() {
	return this.pageContext;
}
 
Example #29
Source File: AbstractHtmlElementTagTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected MockPageContext getPageContext() {
	return this.pageContext;
}
 
Example #30
Source File: AbstractHtmlElementTagTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected void extendPageContext(MockPageContext pageContext) throws JspException {
}