Search in sources :

Example 1 with JdbcSchemaParser

use of com.thinkbiganalytics.discovery.schema.JdbcSchemaParser in project kylo by Teradata.

the class PostgreSqlSchemaParserTest method prepareDataSourceWithDatabaseUrl.

/**
 * Verify ignoring catalog name if already specified by the data source URL.
 */
@Test
public void prepareDataSourceWithDatabaseUrl() throws SQLException {
    // Test preparing data source with existing catalog
    DataSourceProperties dataSource = new DataSourceProperties("user", "password", "jdbc:postgresql://localhost:5432/kylo");
    final JdbcSchemaParser parser = new PostgreSqlSchemaParser();
    DataSourceProperties prepared = parser.prepareDataSource(dataSource, null);
    Assert.assertEquals(dataSource, prepared);
    Assert.assertEquals(dataSource.getUrl(), prepared.getUrl());
}
Also used : JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) Test(org.junit.Test)

Example 2 with JdbcSchemaParser

use of com.thinkbiganalytics.discovery.schema.JdbcSchemaParser 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());
    }
}
Also used : JdbcCatalog(com.thinkbiganalytics.discovery.schema.JdbcCatalog) JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Example 3 with JdbcSchemaParser

use of com.thinkbiganalytics.discovery.schema.JdbcSchemaParser in project kylo by Teradata.

the class PostgreSqlSchemaParserTest method prepareDataSourceWithDatabaseInfo.

/**
 * Verify ignoring catalog name if already specified by the data source info.
 */
@Test
public void prepareDataSourceWithDatabaseInfo() throws SQLException {
    // Mock data source properties
    final Properties properties = new Properties();
    properties.put("PGDBNAME", "kylo");
    properties.put("PGHOST", "server");
    properties.put("PGPORT", "5000");
    final DataSourceProperties dataSource = new DataSourceProperties("user", "password", "jdbc:postgresql:");
    dataSource.setProperties(properties);
    // Test preparing data source with existing catalog
    final JdbcSchemaParser parser = new PostgreSqlSchemaParser();
    final DataSourceProperties prepared = parser.prepareDataSource(dataSource, null);
    Assert.assertEquals(dataSource, prepared);
    Assert.assertEquals("kylo", prepared.getProperties().getProperty("PGDBNAME"));
    Assert.assertEquals(dataSource.getUrl(), prepared.getUrl());
}
Also used : JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Properties(java.util.Properties) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) Test(org.junit.Test)

Example 4 with JdbcSchemaParser

use of com.thinkbiganalytics.discovery.schema.JdbcSchemaParser 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);
}
Also used : JdbcCatalog(com.thinkbiganalytics.discovery.schema.JdbcCatalog) JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Connection(java.sql.Connection) Test(org.junit.Test)

Example 5 with JdbcSchemaParser

use of com.thinkbiganalytics.discovery.schema.JdbcSchemaParser in project kylo by Teradata.

the class PostgreSqlSchemaParserTest method prepareDataSourceWithBasicInfo.

/**
 * Verify updating data source info with a catalog name.
 */
@Test
public void prepareDataSourceWithBasicInfo() throws SQLException {
    // Mock data source properties
    final Properties properties = new Properties();
    properties.put("PGHOST", "server");
    properties.put("PGPORT", "5000");
    final DataSourceProperties dataSource = new DataSourceProperties("user", "password", "jdbc:postgresql:");
    dataSource.setProperties(properties);
    // Test preparing data source with no catalog
    final JdbcSchemaParser parser = new PostgreSqlSchemaParser();
    DataSourceProperties prepared = parser.prepareDataSource(dataSource, null);
    Assert.assertNotEquals(dataSource, prepared);
    Assert.assertEquals("postgres", prepared.getProperties().getProperty("PGDBNAME"));
    Assert.assertEquals(dataSource.getUrl(), prepared.getUrl());
    // Test preparing data source with user-defined catalog
    prepared = parser.prepareDataSource(dataSource, "kylo");
    Assert.assertNotEquals(dataSource, prepared);
    Assert.assertEquals("kylo", prepared.getProperties().getProperty("PGDBNAME"));
    Assert.assertEquals(dataSource.getUrl(), prepared.getUrl());
}
Also used : JdbcSchemaParser(com.thinkbiganalytics.discovery.schema.JdbcSchemaParser) Properties(java.util.Properties) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) DataSourceProperties(com.thinkbiganalytics.db.DataSourceProperties) Test(org.junit.Test)

Aggregations

JdbcSchemaParser (com.thinkbiganalytics.discovery.schema.JdbcSchemaParser)7 Test (org.junit.Test)6 DataSourceProperties (com.thinkbiganalytics.db.DataSourceProperties)5 Connection (java.sql.Connection)3 JdbcCatalog (com.thinkbiganalytics.discovery.schema.JdbcCatalog)2 Properties (java.util.Properties)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)1 HadoopClassLoader (com.thinkbiganalytics.kylo.util.HadoopClassLoader)1 Statement (java.sql.Statement)1 Configuration (org.apache.hadoop.conf.Configuration)1