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");
});
}
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();
});
}
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-"));
});
}
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();
});
}
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);
});
}
Aggregations