Search in sources :

Example 21 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-security by spring-projects.

the class DefaultWebSecurityExpressionHandlerTests method expressionPropertiesAreResolvedAgainstAppContextBeans.

@Test
public void expressionPropertiesAreResolvedAgainstAppContextBeans() {
    StaticApplicationContext appContext = new StaticApplicationContext();
    RootBeanDefinition bean = new RootBeanDefinition(SecurityConfig.class);
    bean.getConstructorArgumentValues().addGenericArgumentValue("ROLE_A");
    appContext.registerBeanDefinition("role", bean);
    this.handler.setApplicationContext(appContext);
    EvaluationContext ctx = this.handler.createEvaluationContext(mock(Authentication.class), mock(FilterInvocation.class));
    ExpressionParser parser = this.handler.getExpressionParser();
    assertThat(parser.parseExpression("@role.getAttribute() == 'ROLE_A'").getValue(ctx, Boolean.class)).isTrue();
    assertThat(parser.parseExpression("@role.attribute == 'ROLE_A'").getValue(ctx, Boolean.class)).isTrue();
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Authentication(org.springframework.security.core.Authentication) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ExpressionParser(org.springframework.expression.ExpressionParser) EvaluationContext(org.springframework.expression.EvaluationContext) FilterInvocation(org.springframework.security.web.FilterInvocation) Test(org.junit.jupiter.api.Test)

Example 22 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.

the class ScriptTemplateViewTests method setup.

@BeforeEach
public void setup() {
    this.configurer = new ScriptTemplateConfigurer();
    this.context = new StaticApplicationContext();
    this.context.getBeanFactory().registerSingleton("scriptTemplateConfigurer", this.configurer);
    this.view = new ScriptTemplateView();
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.

the class UrlBasedViewResolverTests method setup.

@BeforeEach
public void setup() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.resolver.setApplicationContext(context);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.

the class XsltViewResolverTests method resolveView.

@Test
public void resolveView() throws Exception {
    StaticApplicationContext ctx = new StaticApplicationContext();
    String prefix = ClassUtils.classPackageAsResourcePath(getClass());
    String suffix = ".xsl";
    String viewName = "products";
    XsltViewResolver viewResolver = new XsltViewResolver();
    viewResolver.setPrefix(prefix);
    viewResolver.setSuffix(suffix);
    viewResolver.setApplicationContext(ctx);
    XsltView view = (XsltView) viewResolver.resolveViewName(viewName, Locale.ENGLISH);
    assertThat(view).as("View should not be null").isNotNull();
    assertThat(view.getUrl()).as("Incorrect URL").isEqualTo((prefix + viewName + suffix));
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 25 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project spring-framework by spring-projects.

the class XsltViewTests method getXsltView.

private XsltView getXsltView(String templatePath) {
    XsltView view = new XsltView();
    view.setUrl(templatePath);
    view.setApplicationContext(new StaticApplicationContext());
    view.initApplicationContext();
    return view;
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext)

Aggregations

StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)322 Test (org.junit.jupiter.api.Test)218 lombok.val (lombok.val)159 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)59 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)39 BeforeEach (org.junit.jupiter.api.BeforeEach)36 Test (org.junit.Test)34 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)31 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)20 HashSet (java.util.HashSet)19 MockRequestContext (org.springframework.webflow.test.MockRequestContext)19 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)16 MockServletContext (org.springframework.mock.web.MockServletContext)16 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)15 BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)13 ApplicationContext (org.springframework.context.ApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11