use of com.thinkbiganalytics.discovery.schema.JdbcCatalog in project kylo by Teradata.
the class PostgreSqlSchemaParserTest method listCatalogsWithPostgres.
/**
* Verify listing catalogs from the {@code postgres} database.
*/
@Test
public void listCatalogsWithPostgres() throws SQLException {
try (final Connection h2c = DriverManager.getConnection("jdbc:h2:mem:postgresql")) {
// Setup H2 tables
final Statement h2s = h2c.createStatement();
h2s.execute("CREATE TABLE pg_database (datname VARCHAR(16))");
h2s.execute("INSERT INTO pg_database VALUES ('kylo'), ('postgres'), ('test')");
// Mock connection
final Connection connection = Mockito.mock(Connection.class);
Mockito.when(connection.createStatement()).thenReturn(h2c.createStatement());
Mockito.when(connection.getCatalog()).thenReturn("postgres");
// Test listing catalogs
final JdbcSchemaParser parser = new PostgreSqlSchemaParser();
final List<JdbcCatalog> catalogs = parser.listCatalogs(connection, null, null);
Assert.assertEquals("kylo", catalogs.get(0).getCatalog());
Assert.assertEquals("postgres", catalogs.get(1).getCatalog());
Assert.assertEquals("test", catalogs.get(2).getCatalog());
Assert.assertEquals(3, catalogs.size());
}
}
use of com.thinkbiganalytics.discovery.schema.JdbcCatalog in project kylo by Teradata.
the class PostgreSqlSchemaParserTest method listCatalogsWithOther.
/**
* Verify listing catalogs from a user-created database.
*/
@Test
public void listCatalogsWithOther() throws SQLException {
// Mock connection
final Connection connection = Mockito.mock(Connection.class);
Mockito.when(connection.getCatalog()).thenReturn("kylo");
// Test listing catalogs
final JdbcSchemaParser parser = new PostgreSqlSchemaParser();
final List<JdbcCatalog> catalogs = parser.listCatalogs(connection, null, null);
Assert.assertEquals(Collections.emptyList(), catalogs);
}
Aggregations