Java Code Examples for org.springframework.boot.test.context.runner.ApplicationContextRunner#run()
The following examples show how to use
org.springframework.boot.test.context.runner.ApplicationContextRunner#run() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlexyPoolConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void testDecoratingHikariDataSourceWithCustomPropertyStrategies() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.datasource.type:" + HikariDataSource.class.getName(), "decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.max-overflow-pool-size:15", "decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.timeout-millis:500", "decorator.datasource.flexy-pool.acquiring-strategy.retry.attempts:5") .withUserConfiguration(HikariConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class); IncrementPoolOnTimeoutConnectionAcquiringStrategy<HikariDataSource> strategy1 = findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class); assertThat(strategy1).isNotNull(); assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 35); assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 10000); RetryConnectionAcquiringStrategy<HikariDataSource> strategy2 = findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class); assertThat(strategy2).isNotNull(); assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 5); }); }
Example 2
Source File: MongoTracingAutoConfigurationTest.java From java-spring-cloud with Apache License 2.0 | 5 votes |
@Test public void createsTracingPostProcessor() { final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withPropertyValues("spring.data.mongodb.port=27017") // Otherwise a random embedded mongo port is used .withConfiguration(UserConfigurations.of(TracerConfig.class, MongoConfig.class)) .withConfiguration(AutoConfigurations.of( MongoTracingAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class )); contextRunner.run(context -> Assertions.assertThat(context).hasSingleBean(TracingMongoClientPostProcessor.class)); }
Example 3
Source File: GcpPubSubReactiveAutoConfigurationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void reactiveConfigDisabledWhenPubSubDisabled() { ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( AutoConfigurations.of(TestConfig.class)) .withPropertyValues("spring.cloud.gcp.pubsub.enabled=false"); contextRunner.run(ctx -> { assertThat(ctx.containsBean("pubSubReactiveFactory")).isFalse(); }); }
Example 4
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testScopedDataSourceIsNotDecorated() { ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(TestScopedDataSourceConfiguration.class); contextRunner.run(context -> { assertThat(context).getBeanNames(DataSource.class).containsOnly("dataSource", "scopedTarget.dataSource"); assertThat(context).getBean("dataSource").isInstanceOf(DecoratedDataSource.class); assertThat(context).getBean("scopedTarget.dataSource").isNotInstanceOf(DecoratedDataSource.class); }); }
Example 5
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testCustomDataSourceIsDecorated() { ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); assertThat(dataSource).isInstanceOf(DecoratedDataSource.class); DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource(); assertThat(realDataSource).isInstanceOf(BasicDataSource.class); }); }
Example 6
Source File: MongoTracingAutoConfigurationTest.java From java-spring-cloud with Apache License 2.0 | 5 votes |
@Test public void doesNotCreateTracingPostProcessorWhenDisabled() { final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withPropertyValues("opentracing.spring.cloud.mongo.enabled=false") .withConfiguration(UserConfigurations.of(TracerConfig.class, MongoConfig.class)) .withConfiguration(AutoConfigurations.of(MongoTracingAutoConfiguration.class)); contextRunner.run(context -> Assertions.assertThat(context).doesNotHaveBean(TracingMongoClientPostProcessor.class)); }
Example 7
Source File: GcpPubSubReactiveAutoConfigurationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void defaultSchedulerUsedWhenNoneProvided() { setUpThreadPrefixVerification("parallel"); ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withBean(PubSubSubscriberOperations.class, () -> mockSubscriberTemplate) .withConfiguration(AutoConfigurations.of(GcpPubSubReactiveAutoConfiguration.class)); contextRunner.run(this::pollAndVerify); }
Example 8
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testNoDecoratingForExcludeBeans() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.exclude-beans:dataSource"); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); assertThat(dataSource).isInstanceOf(HikariDataSource.class); }); }
Example 9
Source File: ProxyDataSourceConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testCustomConnectionIdManager() { ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomDataSourceProxyConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource(); assertThat(proxyDataSource.getConnectionIdManager()).isInstanceOf(DefaultConnectionIdManager.class); }); }
Example 10
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDecoratingCanBeDisabledForSpecificBeans() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.exclude-beans:secondDataSource") .withUserConfiguration(TestMultiDataSourceConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean("dataSource", DataSource.class); assertThat(dataSource).isInstanceOf(DecoratedDataSource.class); DataSource secondDataSource = context.getBean("secondDataSource", DataSource.class); assertThat(secondDataSource).isInstanceOf(BasicDataSource.class); }); }
Example 11
Source File: GcpPubSubReactiveAutoConfigurationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void customSchedulerUsedWhenAvailable() { setUpThreadPrefixVerification("myCustomScheduler"); ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withBean(PubSubSubscriberOperations.class, () -> mockSubscriberTemplate) .withConfiguration(AutoConfigurations.of(GcpPubSubReactiveAutoConfiguration.class)) .withUserConfiguration(TestConfigWithOverriddenScheduler.class); contextRunner.run(this::pollAndVerify); }
Example 12
Source File: SleuthP6SpyListenerAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDoesNotAddP6SpyListenerIfNoTracer() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.sleuth.enabled:false"); contextRunner.run(context -> { JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class); CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener(); assertThat(jdbcEventListener.getEventListeners()).extracting("class").doesNotContain(TracingJdbcEventListener.class); }); }
Example 13
Source File: ProxyDataSourceConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testRegisterLogAndSlowQueryLogUsingJUL() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.datasourceProxy.logging:jul"); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource(); ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener(); assertThat(chainListener.getListeners()).extracting("class").contains(JULSlowQueryListener.class); assertThat(chainListener.getListeners()).extracting("class").contains(JULQueryLoggingListener.class); }); }
Example 14
Source File: GcpPubSubAutoConfigurationTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void keepAliveValue_default() { ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class)) .withUserConfiguration(TestConfig.class); contextRunner.run(ctx -> { GcpPubSubProperties props = ctx.getBean(GcpPubSubProperties.class); assertThat(props.getKeepAliveIntervalMinutes()).isEqualTo(5); TransportChannelProvider tcp = ctx.getBean(TransportChannelProvider.class); assertThat(((InstantiatingGrpcChannelProvider) tcp).getKeepAliveTime().toMinutes()) .isEqualTo(5); }); }
Example 15
Source File: GcpDatastoreAutoConfigurationTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testUserDatastoreBeanNamespace() { ApplicationContextRunner runner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(GcpDatastoreAutoConfiguration.class, GcpContextAutoConfiguration.class)) .withUserConfiguration(TestConfigurationWithDatastoreBeanNamespaceProvider.class) .withPropertyValues("spring.cloud.gcp.datastore.project-id=test-project", "spring.cloud.gcp.datastore.namespace=testNamespace", "spring.cloud.gcp.datastore.host=localhost:8081", "management.health.datastore.enabled=false"); this.expectedException.expectMessage("failed to start"); runner.run(context -> getDatastoreBean(context)); }
Example 16
Source File: P6SpyConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testCanSetCustomLoggingFormat() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.p6spy.log-format:test %{connectionId}"); contextRunner.run(context -> { JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class); CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener(); assertThat(jdbcEventListener.getEventListeners()).extracting("class").contains(LoggingEventListener.class); assertThat(P6LogQuery.getLogger()).extracting("strategy").extracting("class").isEqualTo(CustomLineFormat.class); }); }
Example 17
Source File: P6SpyConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDoesNotRegisterLoggingListenerIfDisabled() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.p6spy.enable-logging:false"); contextRunner.run(context -> { JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class); CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener(); assertThat(jdbcEventListener.getEventListeners()).extracting("class").doesNotContain(LoggingEventListener.class); }); }
Example 18
Source File: P6SpyConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testCustomListeners() { ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomListenerConfiguration.class); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class); GetCountingListener getCountingListener = context.getBean(GetCountingListener.class); ClosingCountingListener closingCountingListener = context.getBean(ClosingCountingListener.class); P6DataSource p6DataSource = (P6DataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource(); assertThat(p6DataSource).extracting("jdbcEventListenerFactory").isEqualTo(jdbcEventListenerFactory); CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener(); assertThat(jdbcEventListener.getEventListeners()).contains(getCountingListener, closingCountingListener); assertThat(getCountingListener.connectionCount).isEqualTo(0); Connection connection1 = p6DataSource.getConnection(); assertThat(getCountingListener.connectionCount).isEqualTo(1); assertThat(closingCountingListener.connectionCount).isEqualTo(0); Connection connection2 = p6DataSource.getConnection(); assertThat(getCountingListener.connectionCount).isEqualTo(2); connection1.close(); assertThat(closingCountingListener.connectionCount).isEqualTo(1); connection2.close(); assertThat(closingCountingListener.connectionCount).isEqualTo(2); }); }
Example 19
Source File: GcpPubSubReactiveAutoConfigurationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void reactiveFactoryAutoconfiguredByDefault() { ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( AutoConfigurations.of(TestConfig.class)); contextRunner.run(ctx -> { assertThat(ctx.containsBean("pubSubReactiveFactory")).isTrue(); }); }
Example 20
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Test void testDecoratingCanBeDisabled() { ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.enabled:false"); contextRunner.run(context -> { DataSource dataSource = context.getBean(DataSource.class); assertThat(dataSource).isInstanceOf(HikariDataSource.class); }); }