@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2012 - 201 7 the original author or authors .
* Copyright 2012 - 201 8 the original author or authors .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient ;
import okhttp3.OkHttpClient ;
import org.influxdb.InfluxDB ;
import org.influxdb.InfluxDB ;
import org.junit.Rule ;
import org.junit.Test ;
import org.junit.Test ;
import retrofit2.Retrofit ;
import retrofit2.Retrofit ;
@ -27,6 +28,7 @@ import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext ;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.boot.test.context.runner.ApplicationContextRunner ;
import org.springframework.boot.test.rule.OutputCapture ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
@ -41,6 +43,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* /
* /
public class InfluxDbAutoConfigurationTests {
public class InfluxDbAutoConfigurationTests {
@Rule
public OutputCapture output = new OutputCapture ( ) ;
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ( )
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ( )
. withConfiguration ( AutoConfigurations . of ( InfluxDbAutoConfiguration . class ) ) ;
. withConfiguration ( AutoConfigurations . of ( InfluxDbAutoConfiguration . class ) ) ;
@ -71,25 +76,43 @@ public class InfluxDbAutoConfigurationTests {
}
}
@Test
@Test
public void influxDbWithoutCredentialsAndOkHttpClientBuilder ( ) {
public void influxDbWithOkHttpClientBuilderProvider ( ) {
this . contextRunner . withUserConfiguration ( CustomOkHttpClientBuilderConfig . class )
this . contextRunner
. withUserConfiguration ( CustomOkHttpClientBuilderProviderConfig . class )
. withPropertyValues ( "spring.influx.url=http://localhost" )
. withPropertyValues ( "spring.influx.url=http://localhost" )
. run ( ( context ) - > {
. run ( ( context ) - > {
assertThat ( context . getBeansOfType ( InfluxDB . class ) ) . hasSize ( 1 ) ;
assertThat ( context . getBeansOfType ( InfluxDB . class ) ) . hasSize ( 1 ) ;
int readTimeout = getReadTimeoutProperty ( context ) ;
int readTimeout = getReadTimeoutProperty ( context ) ;
assertThat ( readTimeout ) . isEqualTo ( 3 0_000) ;
assertThat ( readTimeout ) . isEqualTo ( 4 0_000) ;
} ) ;
} ) ;
}
}
@Test
@Test
public void influxDbWithOkHttpClientBuilderProviderIgnoreOkHttpClientBuilder ( ) {
this . contextRunner
. withUserConfiguration ( CustomOkHttpClientBuilderConfig . class ,
CustomOkHttpClientBuilderProviderConfig . class )
. withPropertyValues ( "spring.influx.url=http://localhost" )
. run ( ( context ) - > {
assertThat ( context . getBeansOfType ( InfluxDB . class ) ) . hasSize ( 1 ) ;
int readTimeout = getReadTimeoutProperty ( context ) ;
assertThat ( readTimeout ) . isEqualTo ( 40_000 ) ;
assertThat ( this . output . toString ( ) ) . doesNotContain (
"InfluxDB client customizations using a OkHttpClient.Builder is deprecated" ) ;
} ) ;
}
@Test
@Deprecated
public void influxDbWithOkHttpClientBuilder ( ) {
public void influxDbWithOkHttpClientBuilder ( ) {
this . contextRunner . withUserConfiguration ( CustomOkHttpClientBuilderConfig . class )
this . contextRunner . withUserConfiguration ( CustomOkHttpClientBuilderConfig . class )
. withPropertyValues ( "spring.influx.url=http://localhost" ,
. withPropertyValues ( "spring.influx.url=http://localhost" )
"spring.influx.password:password" , "spring.influx.user:user" )
. run ( ( context ) - > {
. run ( ( context ) - > {
assertThat ( context . getBeansOfType ( InfluxDB . class ) ) . hasSize ( 1 ) ;
assertThat ( context . getBeansOfType ( InfluxDB . class ) ) . hasSize ( 1 ) ;
int readTimeout = getReadTimeoutProperty ( context ) ;
int readTimeout = getReadTimeoutProperty ( context ) ;
assertThat ( readTimeout ) . isEqualTo ( 30_000 ) ;
assertThat ( readTimeout ) . isEqualTo ( 30_000 ) ;
assertThat ( this . output . toString ( ) ) . contains (
"InfluxDB client customizations using a OkHttpClient.Builder is deprecated" ) ;
} ) ;
} ) ;
}
}
@ -102,6 +125,16 @@ public class InfluxDbAutoConfigurationTests {
return callFactory . readTimeoutMillis ( ) ;
return callFactory . readTimeoutMillis ( ) ;
}
}
@Configuration
static class CustomOkHttpClientBuilderProviderConfig {
@Bean
public InfluxDbOkHttpClientBuilderProvider influxDbOkHttpClientBuilderProvider ( ) {
return ( ) - > new OkHttpClient . Builder ( ) . readTimeout ( 40 , TimeUnit . SECONDS ) ;
}
}
@Configuration
@Configuration
static class CustomOkHttpClientBuilderConfig {
static class CustomOkHttpClientBuilderConfig {