Search in sources :

Example 41 with StaticApplicationContext

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

the class SimpAnnotationMethodMessageHandlerTests method setup.

@BeforeEach
public void setup() {
    SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
    brokerTemplate.setMessageConverter(this.converter);
    this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, this.channel, this.channel);
    this.messageHandler.setApplicationContext(new StaticApplicationContext());
    this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
    this.messageHandler.afterPropertiesSet();
}
Also used : SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 42 with StaticApplicationContext

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

the class DynamicPropertiesContextCustomizerTests method emptyPropertyNameResultsInException.

@Test
void emptyPropertyNameResultsInException() throws Exception {
    DynamicPropertiesContextCustomizer customizer = customizerFor("emptyName");
    ConfigurableApplicationContext context = new StaticApplicationContext();
    assertThatIllegalArgumentException().isThrownBy(() -> customizer.customizeContext(context, mock(MergedContextConfiguration.class))).withMessage("'name' must not be null or blank");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 43 with StaticApplicationContext

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

the class DynamicPropertiesContextCustomizerTests method nullValueSupplierResultsInException.

@Test
void nullValueSupplierResultsInException() throws Exception {
    DynamicPropertiesContextCustomizer customizer = customizerFor("nullValueSupplier");
    ConfigurableApplicationContext context = new StaticApplicationContext();
    assertThatIllegalArgumentException().isThrownBy(() -> customizer.customizeContext(context, mock(MergedContextConfiguration.class))).withMessage("'valueSupplier' must not be null");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 44 with StaticApplicationContext

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

the class DynamicPropertiesContextCustomizerTests method customizeContextAddsPropertySource.

@Test
void customizeContextAddsPropertySource() throws Exception {
    ConfigurableApplicationContext context = new StaticApplicationContext();
    DynamicPropertiesContextCustomizer customizer = customizerFor("valid1", "valid2");
    customizer.customizeContext(context, mock(MergedContextConfiguration.class));
    ConfigurableEnvironment environment = context.getEnvironment();
    assertThat(environment.getRequiredProperty("p1a")).isEqualTo("v1a");
    assertThat(environment.getRequiredProperty("p1b")).isEqualTo("v1b");
    assertThat(environment.getRequiredProperty("p2a")).isEqualTo("v2a");
    assertThat(environment.getRequiredProperty("p2b")).isEqualTo("v2b");
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Example 45 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class ExcludedAuthenticationHandlerAuthenticationPolicyTests method verifyOperation.

@Test
public void verifyOperation() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val input = new ExcludedAuthenticationHandlerAuthenticationPolicy(Set.of("Hello"), true);
    assertTrue(input.isSatisfiedBy(CoreAuthenticationTestUtils.getAuthentication(), Set.of(), applicationContext, Optional.empty()).isSuccess());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

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