1
1
/*
2
- * Copyright 2012-2017 the original author or authors.
2
+ * Copyright 2012-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .boot .actuate .endpoint ;
18
18
19
+ import java .sql .Connection ;
20
+ import java .sql .SQLException ;
21
+
22
+ import javax .sql .DataSource ;
23
+
19
24
import liquibase .integration .spring .SpringLiquibase ;
20
25
import org .junit .Test ;
21
26
22
27
import org .springframework .boot .autoconfigure .jdbc .DataSourceAutoConfiguration ;
23
- import org .springframework .boot .autoconfigure .jdbc .EmbeddedDataSourceConfiguration ;
24
28
import org .springframework .boot .autoconfigure .liquibase .LiquibaseAutoConfiguration ;
25
29
import org .springframework .boot .test .util .EnvironmentTestUtils ;
26
30
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
@@ -44,7 +48,20 @@ public LiquibaseEndpointTests() {
44
48
45
49
@ Test
46
50
public void invoke () throws Exception {
51
+ DataSource dataSource = this .context .getBean (DataSource .class );
52
+ assertThat (getAutoCommit (dataSource )).isTrue ();
47
53
assertThat (getEndpointBean ().invoke ()).hasSize (1 );
54
+ assertThat (getAutoCommit (dataSource )).isTrue ();
55
+ }
56
+
57
+ private boolean getAutoCommit (DataSource dataSource ) throws SQLException {
58
+ Connection connection = dataSource .getConnection ();
59
+ try {
60
+ return connection .getAutoCommit ();
61
+ }
62
+ finally {
63
+ connection .close ();
64
+ }
48
65
}
49
66
50
67
@ Test
@@ -55,13 +72,13 @@ public void invokeWithCustomSchema() throws Exception {
55
72
"liquibase.default-schema=CUSTOMSCHEMA" ,
56
73
"spring.datasource.generate-unique-name=true" ,
57
74
"spring.datasource.schema=classpath:/db/create-custom-schema.sql" );
58
- this .context .register (CustomSchemaConfig .class );
75
+ this .context .register (Config .class );
59
76
this .context .refresh ();
60
77
assertThat (getEndpointBean ().invoke ()).hasSize (1 );
61
78
}
62
79
63
80
@ Configuration
64
- @ Import ({ EmbeddedDataSourceConfiguration .class , LiquibaseAutoConfiguration .class })
81
+ @ Import ({ DataSourceAutoConfiguration .class , LiquibaseAutoConfiguration .class })
65
82
public static class Config {
66
83
67
84
private final SpringLiquibase liquibase ;
@@ -77,21 +94,4 @@ public LiquibaseEndpoint endpoint() {
77
94
78
95
}
79
96
80
- @ Configuration
81
- @ Import ({ DataSourceAutoConfiguration .class , LiquibaseAutoConfiguration .class })
82
- public static class CustomSchemaConfig {
83
-
84
- private final SpringLiquibase liquibase ;
85
-
86
- public CustomSchemaConfig (SpringLiquibase liquibase ) {
87
- this .liquibase = liquibase ;
88
- }
89
-
90
- @ Bean
91
- public LiquibaseEndpoint endpoint () {
92
- return new LiquibaseEndpoint (this .liquibase );
93
- }
94
-
95
- }
96
-
97
97
}
0 commit comments