24
24
import com .google .cloud .spanner .MockSpannerServiceImpl .StatementResult ;
25
25
import com .google .cloud .spanner .Statement ;
26
26
import com .google .cloud .spanner .connection .AbstractMockServerTest ;
27
+ import com .google .common .collect .ImmutableList ;
27
28
import com .google .longrunning .Operation ;
28
29
import com .google .protobuf .Any ;
29
30
import com .google .protobuf .Empty ;
30
31
import com .google .rpc .Code ;
32
+ import com .google .spanner .admin .database .v1 .GetDatabaseDdlResponse ;
31
33
import com .google .spanner .admin .database .v1 .UpdateDatabaseDdlMetadata ;
32
34
import java .sql .Connection ;
33
35
import java .sql .DriverManager ;
34
36
import java .sql .PreparedStatement ;
35
37
import java .sql .SQLException ;
38
+ import java .util .List ;
36
39
import org .junit .Test ;
37
40
import org .junit .runner .RunWith ;
38
41
import org .junit .runners .JUnit4 ;
@@ -50,6 +53,29 @@ private Connection createConnection(boolean autoCommit) throws SQLException {
50
53
return DriverManager .getConnection (createUrl (autoCommit ));
51
54
}
52
55
56
+ @ Test
57
+ public void testGetDatabaseDdl () throws SQLException {
58
+ List <String > expectedDdl =
59
+ ImmutableList .of (
60
+ "create table foo (id int64) primary key (id)" ,
61
+ "create table bar (id int64) primary key (id)" );
62
+ mockDatabaseAdmin .addResponse (
63
+ GetDatabaseDdlResponse .newBuilder ().addAllStatements (expectedDdl ).build ());
64
+
65
+ try (Connection connection = createConnection (/* autoCommit = */ true )) {
66
+ CloudSpannerJdbcConnection spannerJdbcConnection =
67
+ connection .unwrap (CloudSpannerJdbcConnection .class );
68
+ List <String > ddl =
69
+ spannerJdbcConnection
70
+ .getSpanner ()
71
+ .getDatabaseAdminClient ()
72
+ .getDatabaseDdl (
73
+ spannerJdbcConnection .getDatabaseId ().getInstanceId ().getInstance (),
74
+ spannerJdbcConnection .getDatabaseId ().getDatabase ());
75
+ assertEquals (expectedDdl , ddl );
76
+ }
77
+ }
78
+
53
79
@ Test
54
80
public void testDdlInAutoCommitIsTrue_succeeds () throws SQLException {
55
81
mockDatabaseAdmin .addResponse (
0 commit comments