Search in sources :

Example 1 with MockPageContext

use of org.springframework.mock.web.MockPageContext in project spring-security by spring-projects.

the class AccessControlListTagTests method setup.

@Before
@SuppressWarnings("rawtypes")
public void setup() {
    SecurityContextHolder.getContext().setAuthentication(bob);
    tag = new AccessControlListTag();
    WebApplicationContext ctx = mock(WebApplicationContext.class);
    pe = mock(PermissionEvaluator.class);
    Map beanMap = new HashMap();
    beanMap.put("pe", pe);
    when(ctx.getBeansOfType(PermissionEvaluator.class)).thenReturn(beanMap);
    MockServletContext servletCtx = new MockServletContext();
    servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
    pageContext = new MockPageContext(servletCtx, new MockHttpServletRequest(), new MockHttpServletResponse());
    tag.setPageContext(pageContext);
}
Also used : PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPageContext(org.springframework.mock.web.MockPageContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with MockPageContext

use of org.springframework.mock.web.MockPageContext in project spring-security by spring-projects.

the class AuthorizeTagTests method setUp.

// ~ Methods
// ========================================================================================================
@Before
public void setUp() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(currentUser);
    StaticWebApplicationContext ctx = new StaticWebApplicationContext();
    BeanDefinitionBuilder webExpressionHandler = BeanDefinitionBuilder.rootBeanDefinition(DefaultWebSecurityExpressionHandler.class);
    webExpressionHandler.addPropertyValue("permissionEvaluator", permissionEvaluator);
    ctx.registerBeanDefinition("expressionHandler", webExpressionHandler.getBeanDefinition());
    ctx.registerSingleton("wipe", MockWebInvocationPrivilegeEvaluator.class);
    MockServletContext servletCtx = new MockServletContext();
    servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
    authorizeTag = new JspAuthorizeTag();
    authorizeTag.setPageContext(new MockPageContext(servletCtx, request, new MockHttpServletResponse()));
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) MockPageContext(org.springframework.mock.web.MockPageContext) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 3 with MockPageContext

use of org.springframework.mock.web.MockPageContext in project spring-security by spring-projects.

the class AbstractCsrfTagTests method setUp.

@Before
public void setUp() {
    MockServletContext servletContext = new MockServletContext();
    this.request = new MockHttpServletRequest(servletContext);
    this.response = new MockHttpServletResponse();
    MockPageContext pageContext = new MockPageContext(servletContext, this.request, this.response);
    this.tag = new MockTag();
    this.tag.setPageContext(pageContext);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPageContext(org.springframework.mock.web.MockPageContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 4 with MockPageContext

use of org.springframework.mock.web.MockPageContext in project logging-log4j2 by apache.

the class SetLoggerTagTest method setUp.

@Before
public void setUp() {
    this.context = new MockPageContext();
    this.tag = new SetLoggerTag();
    this.tag.setPageContext(this.context);
}
Also used : MockPageContext(org.springframework.mock.web.MockPageContext) Before(org.junit.Before)

Example 5 with MockPageContext

use of org.springframework.mock.web.MockPageContext in project logging-log4j2 by apache.

the class CatchingTagTest method setUp.

@Before
public void setUp() {
    this.tag = new CatchingTag();
    this.tag.setPageContext(new MockPageContext());
    this.tag.setLogger(this.logger);
}
Also used : MockPageContext(org.springframework.mock.web.MockPageContext) Before(org.junit.Before)

Aggregations

MockPageContext (org.springframework.mock.web.MockPageContext)11 Before (org.junit.Before)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockServletContext (org.springframework.mock.web.MockServletContext)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 JspWriter (javax.servlet.jsp.JspWriter)1 Level (org.apache.logging.log4j.Level)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1 MockJspWriter (org.springframework.mock.web.MockJspWriter)1 PermissionEvaluator (org.springframework.security.access.PermissionEvaluator)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)1