Search in sources :

Example 6 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class ThymeleafServletAutoConfigurationTests method renderNonWebAppTemplate.

@Test
void renderNonWebAppTemplate() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(ThymeleafAutoConfiguration.class)).run((context) -> {
        assertThat(context).doesNotHaveBean(ViewResolver.class);
        TemplateEngine engine = context.getBean(TemplateEngine.class);
        Context attrs = new Context(Locale.UK, Collections.singletonMap("greeting", "Hello World"));
        String result = engine.process("message", attrs);
        assertThat(result).contains("Hello World");
    });
}
Also used : RequestContext(org.springframework.web.servlet.support.RequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) WebContext(org.thymeleaf.context.WebContext) ServletContext(jakarta.servlet.ServletContext) Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) SpringTemplateEngine(org.thymeleaf.spring6.SpringTemplateEngine) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 7 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class ReactiveUserDetailsServiceAutoConfigurationTests method userDetailsServiceWhenRSocketConfigured.

@Test
void userDetailsServiceWhenRSocketConfigured() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(ReactiveUserDetailsServiceAutoConfiguration.class, RSocketMessagingAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class)).withUserConfiguration(TestRSocketSecurityConfiguration.class).run((context) -> {
        ReactiveUserDetailsService userDetailsService = context.getBean(ReactiveUserDetailsService.class);
        assertThat(userDetailsService.findByUsername("user").block(Duration.ofSeconds(30))).isNotNull();
    });
}
Also used : RSocketStrategiesAutoConfiguration(org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) ReactiveUserDetailsService(org.springframework.security.core.userdetails.ReactiveUserDetailsService) MapReactiveUserDetailsService(org.springframework.security.core.userdetails.MapReactiveUserDetailsService) RSocketMessagingAutoConfiguration(org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 8 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class TaskSchedulingAutoConfigurationTests method enableSchedulingWithLazyInitializationInvokeScheduledMethods.

@Test
void enableSchedulingWithLazyInitializationInvokeScheduledMethods() {
    List<String> threadNames = new ArrayList<>();
    new ApplicationContextRunner().withInitializer((context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor())).withPropertyValues("spring.task.scheduling.thread-name-prefix=scheduling-test-").withBean(LazyTestBean.class, () -> new LazyTestBean(threadNames)).withUserConfiguration(SchedulingConfiguration.class).withConfiguration(AutoConfigurations.of(TaskSchedulingAutoConfiguration.class)).run((context) -> {
        // No lazy lookup.
        Awaitility.waitAtMost(Duration.ofSeconds(3)).until(() -> !threadNames.isEmpty());
        assertThat(threadNames).allMatch((name) -> name.contains("scheduling-test-"));
    });
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskSchedulerCustomizer(org.springframework.boot.task.TaskSchedulerCustomizer) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) SchedulingConfigurer(org.springframework.scheduling.annotation.SchedulingConfigurer) LazyInitializationBeanFactoryPostProcessor(org.springframework.boot.LazyInitializationBeanFactoryPostProcessor) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TaskExecutor(org.springframework.core.task.TaskExecutor) ScheduledTaskRegistrar(org.springframework.scheduling.config.ScheduledTaskRegistrar) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TaskScheduler(org.springframework.scheduling.TaskScheduler) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Bean(org.springframework.context.annotation.Bean) Awaitility(org.awaitility.Awaitility) LazyInitializationBeanFactoryPostProcessor(org.springframework.boot.LazyInitializationBeanFactoryPostProcessor) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class NoDslContextBeanFailureAnalyzerTests method analysisWithR2dbcAutoConfiguration.

@Test
void analysisWithR2dbcAutoConfiguration() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(R2dbcAutoConfiguration.class)).run((context) -> {
        NoDslContextBeanFailureAnalyzer failureAnalyzer = new NoDslContextBeanFailureAnalyzer(context.getBeanFactory());
        assertThat(failureAnalyzer.analyze(new NoSuchBeanDefinitionException(DSLContext.class))).isNotNull();
    });
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) DSLContext(org.jooq.DSLContext) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.jupiter.api.Test)

Example 10 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner in project spring-boot by spring-projects.

the class XADataSourceAutoConfigurationTests method createNonEmbeddedFromXAProperties.

@Test
void createNonEmbeddedFromXAProperties() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(XADataSourceAutoConfiguration.class)).withUserConfiguration(FromProperties.class).withClassLoader(new FilteredClassLoader("org.h2.Driver", "org.hsqldb.jdbcDriver")).withPropertyValues("spring.datasource.xa.data-source-class-name:com.ibm.db2.jcc.DB2XADataSource", "spring.datasource.xa.properties.user:test", "spring.datasource.xa.properties.password:secret").run((context) -> {
        MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class);
        XADataSource xaDataSource = wrapper.getXaDataSource();
        assertThat(xaDataSource).isInstanceOf(DB2XADataSource.class);
    });
}
Also used : DB2XADataSource(com.ibm.db2.jcc.DB2XADataSource) XADataSource(javax.sql.XADataSource) JDBCXADataSource(org.hsqldb.jdbc.pool.JDBCXADataSource) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)53 Test (org.junit.jupiter.api.Test)49 ApplicationConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties)21 ConfigurationPropertiesBeanDescriptor (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor)16 Map (java.util.Map)7 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)6 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)6 HashMap (java.util.HashMap)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ContextConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties)5 Bean (org.springframework.context.annotation.Bean)5 Configuration (org.springframework.context.annotation.Configuration)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 GraphiteMeterRegistry (io.micrometer.graphite.GraphiteMeterRegistry)4 JmxMeterRegistry (io.micrometer.jmx.JmxMeterRegistry)4 ApplicationBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans)4 Test (org.junit.Test)3 ContextBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans)3