2121import static org .hamcrest .CoreMatchers .notNullValue ;
2222import static org .hamcrest .CoreMatchers .nullValue ;
2323import static org .hamcrest .MatcherAssert .assertThat ;
24+ import static org .junit .Assert .assertEquals ;
25+ import static org .junit .Assert .assertFalse ;
26+ import static org .junit .Assert .assertNull ;
27+ import static org .junit .Assert .assertTrue ;
2428import static org .junit .Assume .assumeFalse ;
2529
2630import com .google .cloud .spanner .ParallelIntegrationTest ;
@@ -801,6 +805,19 @@ public void testGetPrimaryKeys() throws SQLException {
801805 }
802806 }
803807
808+ @ Test
809+ public void testGetViews () throws SQLException {
810+ try (Connection connection = createConnection ()) {
811+ try (ResultSet rs = connection .getMetaData ().getTables ("" , "" , null , new String [] {"VIEW" })) {
812+ assertTrue (rs .next ());
813+ assertEquals (DEFAULT_SCHEMA , rs .getString ("TABLE_SCHEM" ));
814+ assertEquals (DEFAULT_CATALOG , rs .getString ("TABLE_CAT" ));
815+ assertEquals ("SingersView" , rs .getString ("TABLE_NAME" ));
816+ assertFalse (rs .next ());
817+ }
818+ }
819+ }
820+
804821 @ Test
805822 public void testGetSchemas () throws SQLException {
806823 try (Connection connection = createConnection ()) {
@@ -820,9 +837,15 @@ public void testGetSchemas() throws SQLException {
820837
821838 private static final class Table {
822839 private final String name ;
840+ private final String type ;
823841
824842 private Table (String name ) {
843+ this (name , "TABLE" );
844+ }
845+
846+ private Table (String name , String type ) {
825847 this .name = name ;
848+ this .type = type ;
826849 }
827850 }
828851
@@ -831,6 +854,7 @@ private Table(String name) {
831854 new Table ("Albums" ),
832855 new Table ("Concerts" ),
833856 new Table ("Singers" ),
857+ new Table ("SingersView" , "VIEW" ),
834858 new Table ("Songs" ),
835859 new Table ("TableWithAllColumnTypes" ),
836860 new Table ("TableWithRef" ));
@@ -841,17 +865,17 @@ public void testGetTables() throws SQLException {
841865 try (ResultSet rs =
842866 connection .getMetaData ().getTables (DEFAULT_CATALOG , DEFAULT_SCHEMA , null , null )) {
843867 for (Table table : EXPECTED_TABLES ) {
844- assertThat (rs .next (), is ( true ));
845- assertThat ( rs .getString ("TABLE_CAT" ), is ( equalTo ( DEFAULT_CATALOG ) ));
846- assertThat ( rs .getString ("TABLE_SCHEM" ), is ( equalTo ( DEFAULT_SCHEMA ) ));
847- assertThat ( rs .getString ("TABLE_NAME" ), is ( equalTo ( table . name ) ));
848- assertThat ( rs .getString ("TABLE_TYPE" ), is ( equalTo ( "TABLE" ) ));
849- assertThat (rs .getString ("REMARKS" ), is ( nullValue () ));
850- assertThat (rs .getString ("TYPE_CAT" ), is ( nullValue () ));
851- assertThat (rs .getString ("TYPE_SCHEM" ), is ( nullValue () ));
852- assertThat (rs .getString ("TYPE_NAME" ), is ( nullValue () ));
853- assertThat (rs .getString ("SELF_REFERENCING_COL_NAME" ), is ( nullValue () ));
854- assertThat (rs .getString ("REF_GENERATION" ), is ( nullValue () ));
868+ assertTrue (rs .next ());
869+ assertEquals ( DEFAULT_CATALOG , rs .getString ("TABLE_CAT" ));
870+ assertEquals ( DEFAULT_SCHEMA , rs .getString ("TABLE_SCHEM" ));
871+ assertEquals ( table . name , rs .getString ("TABLE_NAME" ));
872+ assertEquals ( table . type , rs .getString ("TABLE_TYPE" ));
873+ assertNull (rs .getString ("REMARKS" ));
874+ assertNull (rs .getString ("TYPE_CAT" ));
875+ assertNull (rs .getString ("TYPE_SCHEM" ));
876+ assertNull (rs .getString ("TYPE_NAME" ));
877+ assertNull (rs .getString ("SELF_REFERENCING_COL_NAME" ));
878+ assertNull (rs .getString ("REF_GENERATION" ));
855879 }
856880 assertThat (rs .next (), is (false ));
857881 }
0 commit comments