Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ab43bf46
Commit
ab43bf46
authored
Jul 25, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
663ff058
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
46 deletions
+33
-46
InfluxDbAutoConfigurationTests.java
.../autoconfigure/influx/InfluxDbAutoConfigurationTests.java
+33
-46
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfigurationTests.java
View file @
ab43bf46
...
@@ -20,13 +20,13 @@ import java.util.concurrent.TimeUnit;
...
@@ -20,13 +20,13 @@ import java.util.concurrent.TimeUnit;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
org.influxdb.InfluxDB
;
import
org.influxdb.InfluxDB
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
retrofit2.Retrofit
;
import
retrofit2.Retrofit
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.ApplicationContextTester
;
import
org.springframework.boot.test.context.AssertableApplicationContext
;
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,55 +41,57 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -41,55 +41,57 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
*/
public
class
InfluxDbAutoConfigurationTests
{
public
class
InfluxDbAutoConfigurationTests
{
private
AnnotationConfigApplicationContext
context
;
private
final
ApplicationContextTester
context
=
new
ApplicationContextTester
()
.
withConfiguration
(
AutoConfigurations
.
of
(
InfluxDbAutoConfiguration
.
class
));
@After
public
void
tearDown
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
@Test
public
void
influxDbRequiresUrl
()
{
public
void
influxDbRequiresUrl
()
{
load
();
this
.
context
.
run
((
loaded
)
->
assertThat
(
this
.
context
.
getBeansOfType
(
InfluxDB
.
class
)).
isEmpty
(
);
assertThat
(
loaded
.
getBeansOfType
(
InfluxDB
.
class
)).
isEmpty
()
);
}
}
@Test
@Test
public
void
influxDbCanBeCustomized
()
{
public
void
influxDbCanBeCustomized
()
{
load
(
"spring.influx.url=http://localhost"
,
"spring.influx.password:password"
,
this
.
context
.
withPropertyValues
(
"spring.influx.url=http://localhost"
,
"spring.influx.user:user"
);
"spring.influx.password:password"
,
"spring.influx.user:user"
)
assertThat
(
this
.
context
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
.
run
((
loaded
->
assertThat
(
loaded
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
)));
}
}
@Test
@Test
public
void
influxDbCanBeCreatedWithoutCredentials
()
{
public
void
influxDbCanBeCreatedWithoutCredentials
()
{
load
(
"spring.influx.url=http://localhost"
);
this
.
context
.
withPropertyValues
(
"spring.influx.url=http://localhost"
)
assertThat
(
this
.
context
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
.
run
((
loaded
)
->
{
int
readTimeout
=
getReadTimeoutProperty
();
assertThat
(
loaded
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
assertThat
(
readTimeout
).
isEqualTo
(
10_000
);
int
readTimeout
=
getReadTimeoutProperty
(
loaded
);
assertThat
(
readTimeout
).
isEqualTo
(
10_000
);
});
}
}
@Test
@Test
public
void
influxDbWithoutCredentialsAndOkHttpClientBuilder
()
{
public
void
influxDbWithoutCredentialsAndOkHttpClientBuilder
()
{
load
(
CustomOkHttpClientBuilderConfig
.
class
,
"spring.influx.url=http://localhost"
);
this
.
context
.
withUserConfiguration
(
CustomOkHttpClientBuilderConfig
.
class
)
assertThat
(
this
.
context
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
.
withPropertyValues
(
"spring.influx.url=http://localhost"
).
run
((
loaded
)
->
{
int
readTimeout
=
getReadTimeoutProperty
();
assertThat
(
loaded
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
assertThat
(
readTimeout
).
isEqualTo
(
30_000
);
int
readTimeout
=
getReadTimeoutProperty
(
loaded
);
assertThat
(
readTimeout
).
isEqualTo
(
30_000
);
});
}
}
@Test
@Test
public
void
influxDbWithOkHttpClientBuilder
()
{
public
void
influxDbWithOkHttpClientBuilder
()
{
load
(
CustomOkHttpClientBuilderConfig
.
class
,
"spring.influx.url=http://localhost"
,
this
.
context
.
withUserConfiguration
(
CustomOkHttpClientBuilderConfig
.
class
)
"spring.influx.password:password"
,
"spring.influx.user:user"
);
.
withPropertyValues
(
"spring.influx.url=http://localhost"
,
assertThat
(
this
.
context
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
"spring.influx.password:password"
,
"spring.influx.user:user"
)
int
readTimeout
=
getReadTimeoutProperty
();
.
run
((
loaded
)
->
{
assertThat
(
readTimeout
).
isEqualTo
(
30_000
);
assertThat
(
loaded
.
getBeansOfType
(
InfluxDB
.
class
)).
hasSize
(
1
);
int
readTimeout
=
getReadTimeoutProperty
(
loaded
);
assertThat
(
readTimeout
).
isEqualTo
(
30_000
);
});
}
}
private
int
getReadTimeoutProperty
()
{
private
int
getReadTimeoutProperty
(
AssertableApplicationContext
loaded
)
{
InfluxDB
influxDB
=
this
.
context
.
getBean
(
InfluxDB
.
class
);
InfluxDB
influxDB
=
loaded
.
getBean
(
InfluxDB
.
class
);
Retrofit
retrofit
=
(
Retrofit
)
new
DirectFieldAccessor
(
influxDB
)
Retrofit
retrofit
=
(
Retrofit
)
new
DirectFieldAccessor
(
influxDB
)
.
getPropertyValue
(
"retrofit"
);
.
getPropertyValue
(
"retrofit"
);
OkHttpClient
callFactory
=
(
OkHttpClient
)
new
DirectFieldAccessor
(
retrofit
)
OkHttpClient
callFactory
=
(
OkHttpClient
)
new
DirectFieldAccessor
(
retrofit
)
...
@@ -97,21 +99,6 @@ public class InfluxDbAutoConfigurationTests {
...
@@ -97,21 +99,6 @@ public class InfluxDbAutoConfigurationTests {
return
callFactory
.
readTimeoutMillis
();
return
callFactory
.
readTimeoutMillis
();
}
}
private
void
load
(
Class
<?>
clazz
,
String
...
environment
)
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
TestPropertyValues
.
of
(
environment
).
applyTo
(
ctx
);
ctx
.
register
(
InfluxDbAutoConfiguration
.
class
);
if
(
clazz
!=
null
)
{
ctx
.
register
(
clazz
);
}
ctx
.
refresh
();
this
.
context
=
ctx
;
}
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
@Configuration
@Configuration
static
class
CustomOkHttpClientBuilderConfig
{
static
class
CustomOkHttpClientBuilderConfig
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment