org.springframework.boot.test.context.runner.ApplicationContextRunner Java Examples

The following examples show how to use org.springframework.boot.test.context.runner.ApplicationContextRunner. 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: PubSubChannelAdaptersIntegrationTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Before
public void setUpPubSubResources() {
	this.topicName = "desafinado-" + UUID.randomUUID();
	this.subscriptionName = "doralice-" + UUID.randomUUID();

	if (pubSubAdmin.getTopic(this.topicName) == null) {
		pubSubAdmin.createTopic(this.topicName);
	}

	if (pubSubAdmin.getSubscription(this.subscriptionName) == null) {
		pubSubAdmin.createSubscription(this.subscriptionName, this.topicName, 10);
	}

	this.contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					GcpContextAutoConfiguration.class,
					GcpPubSubAutoConfiguration.class))
			.withBean("topicName", String.class, this.topicName)
			.withBean("subscriptionName", String.class, this.subscriptionName);
}
 
Example #2
Source File: FeignCompressionTests.java    From spring-cloud-openfeign with Apache License 2.0 6 votes vote down vote up
@Test
public void testInterceptors() {
	new ApplicationContextRunner()
			.withPropertyValues("feign.compression.response.enabled=true",
					"feign.compression.request.enabled=true",
					"feign.okhttp.enabled=false")
			.withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class,
					FeignContentGzipEncodingAutoConfiguration.class,
					FeignAcceptGzipEncodingAutoConfiguration.class,
					HttpClientConfiguration.class, PlainConfig.class))
			.run(context -> {
				FeignContext feignContext = context.getBean(FeignContext.class);
				Map<String, RequestInterceptor> interceptors = feignContext
						.getInstances("foo", RequestInterceptor.class);
				assertThat(interceptors.size()).isEqualTo(2);
				assertThat(interceptors.get("feignAcceptGzipEncodingInterceptor"))
						.isInstanceOf(FeignAcceptGzipEncodingInterceptor.class);
				assertThat(interceptors.get("feignContentGzipEncodingInterceptor"))
						.isInstanceOf(FeignContentGzipEncodingInterceptor.class);
			});
}
 
Example #3
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 6 votes vote down vote up
@Test
void testCustomDataSourceDecoratorApplied() {
    ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(TestDataSourceDecoratorConfiguration.class);

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertThat(dataSource).isNotNull();

        DataSource customDataSource = ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        assertThat(customDataSource).isInstanceOf(CustomDataSourceProxy.class);

        DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
        assertThat(realDataSource).isInstanceOf(HikariDataSource.class);

        assertThatDataSourceDecoratingChain(dataSource).containsExactly(CustomDataSourceProxy.class, P6DataSource.class, ProxyDataSource.class,
                FlexyPoolDataSource.class);
    });
}
 
Example #4
Source File: GRPCConfigurationTest.java    From liiklus with MIT License 6 votes vote down vote up
@Test
void shouldConsiderTransportConfigurers() {
    var service = ServerServiceDefinition.builder("test").build();

    new ApplicationContextRunner()
            .withInitializer((ApplicationContextInitializer) new GRPCConfiguration())
            .withPropertyValues(
                    "spring.profiles.active: gateway",
                    "grpc.port: 0"
            )
            .withInitializer(ctx -> {
                var context = (GenericApplicationContext) ctx;
                context.registerBean(LiiklusService.class, () -> Mockito.mock(LiiklusService.class));
                context.registerBean(GRPCLiiklusTransportConfigurer.class, () -> builder -> builder.addService(() -> service));
            })
            .run(context -> {
                assertThat(context).getBeans(GRPCLiiklusTransportConfigurer.class).isNotEmpty();

                assertThat(context)
                        .getBean(Server.class)
                        .satisfies(server -> {
                            assertThat(server.getServices()).contains(service);
                        });
            });
}
 
Example #5
Source File: AppBrokerAutoConfigurationTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private ApplicationContextRunner configuredContext() {
	return this.contextRunner
		.withPropertyValues(
			"spring.cloud.appbroker.services[0].service-name=service1",
			"spring.cloud.appbroker.services[0].plan-name=service1-plan1",

			"spring.cloud.appbroker.services[0].apps[0].path=classpath:app1.jar",
			"spring.cloud.appbroker.services[0].apps[0].name=app1",
			"spring.cloud.appbroker.services[0].apps[0].properties.memory=1G",

			"spring.cloud.appbroker.services[0].apps[1].path=classpath:app2.jar",
			"spring.cloud.appbroker.services[0].apps[1].name=app2",
			"spring.cloud.appbroker.services[0].apps[1].properties.memory=2G",
			"spring.cloud.appbroker.services[0].apps[1].properties.instances=2",

			"spring.cloud.appbroker.services[1].service-name=service2",
			"spring.cloud.appbroker.services[1].plan-name=service2-plan1",

			"spring.cloud.appbroker.services[1].apps[0].path=classpath:app3.jar",
			"spring.cloud.appbroker.services[1].apps[0].name=app3",

			"spring.cloud.appbroker.deployer.cloudfoundry.api-host=https://api.example.local",
			"spring.cloud.appbroker.deployer.cloudfoundry.username=user",
			"spring.cloud.appbroker.deployer.cloudfoundry.password=secret"
		);
}
 
Example #6
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 6 votes vote down vote up
@Test
void testDecoratedHikariSpecificPropertiesIsSet() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues(
            "spring.datasource.type:" + HikariDataSource.class.getName(),
            "spring.datasource.hikari.catalog:test_catalog"
    );

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertThat(dataSource).isNotNull();
        assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
        DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
        assertThat(realDataSource).isInstanceOf(HikariDataSource.class);
        assertThat(((HikariDataSource) realDataSource).getCatalog()).isEqualTo("test_catalog");
    });
}
 
Example #7
Source File: GcpDatastoreEmulatorAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void testDatastoreOptionsCorrectlySet() {
	new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					GcpDatastoreEmulatorAutoConfiguration.class))
			.withPropertyValues(
					"spring.cloud.gcp.datastore.emulator.port=8182",
					"spring.cloud.gcp.datastore.emulator.enabled=true",
					"spring.cloud.gcp.datastore.emulator.consistency=0.8")
			.run((context) -> {
				LocalDatastoreHelper helper = context.getBean(LocalDatastoreHelper.class);
				DatastoreOptions datastoreOptions = helper.getOptions();
				assertThat(datastoreOptions.getHost()).isEqualTo("localhost:8182");
				assertThat(helper.getConsistency()).isEqualTo(0.8D);
			});
}
 
Example #8
Source File: FlexyPoolConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: FlexyPoolConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void testDecoratingHikariDataSourceWithDefaultStrategies() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.datasource.type:" + HikariDataSource.class.getName());

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertDataSourceOfType(dataSource, HikariDataSource.class);
        FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
        IncrementPoolOnTimeoutConnectionAcquiringStrategy<HikariDataSource> strategy1 =
                findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
        assertThat(strategy1).isNotNull();
        assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 15);
        assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 500);

        RetryConnectionAcquiringStrategy<HikariDataSource> strategy2 =
                findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
        assertThat(strategy2).isNotNull();
        assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 2);
    });
}
 
Example #10
Source File: GcpPubSubAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void keepAliveValue_custom() {
	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(GcpPubSubAutoConfiguration.class))
			.withUserConfiguration(TestConfig.class)
			.withPropertyValues("spring.cloud.gcp.pubsub.keepAliveIntervalMinutes=2");

	contextRunner.run(ctx -> {
		GcpPubSubProperties props = ctx.getBean(GcpPubSubProperties.class);
		assertThat(props.getKeepAliveIntervalMinutes()).isEqualTo(2);

		TransportChannelProvider tcp = ctx.getBean(TransportChannelProvider.class);
		assertThat(((InstantiatingGrpcChannelProvider) tcp).getKeepAliveTime().toMinutes())
				.isEqualTo(2);
	});
}
 
Example #11
Source File: KubernetesServiceDiscoveryAutoConfigurationTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceDiscoveryWithClient() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=client")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesClientServiceDiscovery.class);
            }
        );
}
 
Example #12
Source File: KubernetesServiceDiscoveryAutoConfigurationTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceDiscoveryWithDnsSrv() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=dnssrv",
            "camel.cloud.kubernetes.service-discovery.port-name=myportname",
            "camel.cloud.kubernetes.service-discovery.port-proocole=myportproto",
            "camel.cloud.kubernetes.service-discovery.dns-domain=mydomain",
            "camel.cloud.kubernetes.service-discovery.namespace=mynamespace")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesDnsSrvServiceDiscovery.class);
            }
        );
}
 
Example #13
Source File: KubernetesServiceDiscoveryAutoConfigurationTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceDiscoveryWithDns() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=dns",
            "camel.cloud.kubernetes.service-discovery.dns-domain=mydomain",
            "camel.cloud.kubernetes.service-discovery.namespace=mynamespace")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesDnsServiceDiscovery.class);
            }
        );
}
 
Example #14
Source File: KubernetesServiceDiscoveryAutoConfigurationTest.java    From camel-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceDiscoveryWithEnv() {
    new ApplicationContextRunner()
        .withUserConfiguration(TestConfiguration.class)
        .withPropertyValues(
            "spring.main.banner-mode=off",
            "camel.cloud.kubernetes.service-discovery.enabled=true",
            "camel.cloud.kubernetes.service-discovery.lookup=env")
        .run(
            context -> {
                assertThat(context).hasSingleBean(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
                assertThat(context).getBeans(ServiceDiscovery.class).containsKeys("kubernetes-service-discovery");
                assertThat(context).getBean("kubernetes-service-discovery").isInstanceOf(KubernetesEnvServiceDiscovery.class);
            }
        );
}
 
Example #15
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: FlexyPoolConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testDecoratingDbcp2DataSource() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("spring.datasource.type:" + BasicDataSource.class.getName());

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        assertDataSourceOfType(dataSource, BasicDataSource.class);
    });
}
 
Example #17
Source File: FlexyPoolConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testNoDecoratingDefaultDataSourceWithoutAdapterDependency() {
    ApplicationContextRunner contextRunner = this.contextRunner.withClassLoader(
            new HidePackagesClassLoader("net.ttddyy.dsproxy", "com.p6spy", "com.vladmihalcea.flexypool.adaptor"));

    contextRunner.run(context -> {
        assertThat(context).doesNotHaveBean(DecoratedDataSource.class);
    });
}
 
Example #18
Source File: GcpPubSubReactiveAutoConfigurationTest.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultSchedulerUsedWhenNoneProvided() {
	setUpThreadPrefixVerification("parallel");

	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withBean(PubSubSubscriberOperations.class, () -> mockSubscriberTemplate)
			.withConfiguration(AutoConfigurations.of(GcpPubSubReactiveAutoConfiguration.class));

	contextRunner.run(this::pollAndVerify);
}
 
Example #19
Source File: PubSubHealthIndicatorTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void healthIndicatorDisabledWhenPubSubTurnedOff() {
	ApplicationContextRunner contextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					GcpPubSubAutoConfiguration.class, PubSubHealthIndicatorAutoConfiguration.class))
			.withPropertyValues("spring.cloud.gcp.datastore.project-id=test-project",
					"management.health.pubsub.enabled=true",
					"spring.cloud.gcp.pubsub.enabled=false");
	contextRunner.run(ctx -> {
		assertThat(ctx.getBeansOfType(PubSubHealthIndicator.class)).isEmpty();
	});
}
 
Example #20
Source File: GcpPubSubReactiveAutoConfigurationTest.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@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);
    });
}
 
Example #23
Source File: MongoTracingAutoConfigurationTest.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testDecoratingWhenDefaultProxyProviderNotAvailable() {
    ApplicationContextRunner contextRunner = this.contextRunner.withClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool"));

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);

        assertThat(((DecoratedDataSource) dataSource).getRealDataSource()).isInstanceOf(HikariDataSource.class);
        assertThatDataSourceDecoratingChain(dataSource).containsExactly(P6DataSource.class, ProxyDataSource.class);
    });
}
 
Example #26
Source File: DataSourceDecoratorAutoConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@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 #27
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@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 #28
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testCustomListeners() {
    ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomListenerConfiguration.class);

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        QueryExecutionListener queryExecutionListener = context.getBean(QueryExecutionListener.class);

        ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
        assertThat(chainListener.getListeners()).contains(queryExecutionListener);
    });
}
 
Example #29
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testCustomParameterAndQueryTransformer() {
    ApplicationContextRunner contextRunner = this.contextRunner.withUserConfiguration(CustomDataSourceProxyConfiguration.class);

    contextRunner.run(context -> {
        DataSource dataSource = context.getBean(DataSource.class);
        ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
        ParameterTransformer parameterTransformer = context.getBean(ParameterTransformer.class);
        QueryTransformer queryTransformer = context.getBean(QueryTransformer.class);
        assertThat(proxyDataSource.getProxyConfig().getParameterTransformer()).isSameAs(parameterTransformer);
        assertThat(proxyDataSource.getProxyConfig().getQueryTransformer()).isSameAs(queryTransformer);
    });
}
 
Example #30
Source File: ProxyDataSourceConfigurationTests.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Test
void testRegisterLogAndSlowQueryLogUsingApacheCommons() {
    ApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("decorator.datasource.datasourceProxy.logging:commons");

    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(CommonsSlowQueryListener.class);
        assertThat(chainListener.getListeners()).extracting("class").contains(CommonsQueryLoggingListener.class);
    });
}