// Path: src/java/com/google/cloud/bigquery/dwhassessment/extractiontool/db/AvroHelper.java
// public static Schema getAvroSchema(
//     String schemaName, String namespace, ResultSetMetaData metaData) throws SQLException {
//   Preconditions.checkArgument(!schemaName.isEmpty(), "Schema name cannot be empty.");
//   Preconditions.checkArgument(!namespace.isEmpty(), "Namespace cannot be empty.");
//   SchemaBuilder.FieldAssembler<Schema> schemaAssembler =
//       SchemaBuilder.record(schemaName).namespace(namespace).fields();
// 
//   for (int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++) {
//     SchemaBuilder.FieldBuilder<Schema> fieldBuilder =
//         schemaAssembler.name(metaData.getColumnName(columnIndex));
//     AvroHelper.convertColumnTypeToAvroType(fieldBuilder, metaData, columnIndex);
//   }
//   return schemaAssembler.endRecord();
// }
// 
// Path: src/java/com/google/cloud/bigquery/dwhassessment/extractiontool/db/SchemaManager.java
// @AutoValue
// abstract class SchemaKey {
//   public static SchemaKey create(String databaseName, String tableName) {
//     return new AutoValue_SchemaManager_SchemaKey(databaseName, tableName);
//   }
// 
//   public abstract String databaseName();
// 
//   public abstract String tableName();
// }


import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static com.google.cloud.bigquery.dwhassessment.extractiontool.db.AvroHelper.getAvroSchema;
import static com.google.common.truth.Truth.assertThat;
import com.google.cloud.bigquery.dwhassessment.extractiontool.db.SchemaManager.SchemaKey;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.re2j.Pattern;
import java.io.ByteArrayOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.GenericRecordBuilder;
import org.junit.BeforeClass;
/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.cloud.bigquery.dwhassessment.extractiontool.db;



@RunWith(JUnit4.class)
public final class SchemaManagerImplTest {

  private static SchemaManager schemaManager;
  private static Connection connection;

  @BeforeClass
  public static void setUp() throws Exception {
    schemaManager = new SchemaManagerImpl();
    connection = DriverManager.getConnection("jdbc:hsqldb:mem:db_0");
    Statement baseStmt = connection.createStatement();
    baseStmt.execute("CREATE TABLE FOO (ID VARCHAR(1), NAME VARCHAR(100))");
    baseStmt.execute("CREATE TABLE FOOBAR (ID INTEGER, NAME VARCHAR(100))");
    baseStmt.execute("CREATE TABLE BAR (ID INTEGER, NAME VARCHAR(100))");
    baseStmt.close();
    connection.commit();
  }

  @Test
  public void getSchemaKeys_onlyTableFilter_success() {
// Path: src/java/com/google/cloud/bigquery/dwhassessment/extractiontool/db/AvroHelper.java
// public static Schema getAvroSchema(
//     String schemaName, String namespace, ResultSetMetaData metaData) throws SQLException {
//   Preconditions.checkArgument(!schemaName.isEmpty(), "Schema name cannot be empty.");
//   Preconditions.checkArgument(!namespace.isEmpty(), "Namespace cannot be empty.");
//   SchemaBuilder.FieldAssembler<Schema> schemaAssembler =
//       SchemaBuilder.record(schemaName).namespace(namespace).fields();
// 
//   for (int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++) {
//     SchemaBuilder.FieldBuilder<Schema> fieldBuilder =
//         schemaAssembler.name(metaData.getColumnName(columnIndex));
//     AvroHelper.convertColumnTypeToAvroType(fieldBuilder, metaData, columnIndex);
//   }
//   return schemaAssembler.endRecord();
// }
// 
// Path: src/java/com/google/cloud/bigquery/dwhassessment/extractiontool/db/SchemaManager.java
// @AutoValue
// abstract class SchemaKey {
//   public static SchemaKey create(String databaseName, String tableName) {
//     return new AutoValue_SchemaManager_SchemaKey(databaseName, tableName);
//   }
// 
//   public abstract String databaseName();
// 
//   public abstract String tableName();
// }


// Path: src/javatests/com/google/cloud/bigquery/dwhassessment/extractiontool/db/SchemaManagerImplTest.java
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static com.google.cloud.bigquery.dwhassessment.extractiontool.db.AvroHelper.getAvroSchema;
import static com.google.common.truth.Truth.assertThat;
import com.google.cloud.bigquery.dwhassessment.extractiontool.db.SchemaManager.SchemaKey;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.re2j.Pattern;
import java.io.ByteArrayOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.GenericRecordBuilder;
import org.junit.BeforeClass;

/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.cloud.bigquery.dwhassessment.extractiontool.db;



@RunWith(JUnit4.class)
public final class SchemaManagerImplTest {

  private static SchemaManager schemaManager;
  private static Connection connection;

  @BeforeClass
  public static void setUp() throws Exception {
    schemaManager = new SchemaManagerImpl();
    connection = DriverManager.getConnection("jdbc:hsqldb:mem:db_0");
    Statement baseStmt = connection.createStatement();
    baseStmt.execute("CREATE TABLE FOO (ID VARCHAR(1), NAME VARCHAR(100))");
    baseStmt.execute("CREATE TABLE FOOBAR (ID INTEGER, NAME VARCHAR(100))");
    baseStmt.execute("CREATE TABLE BAR (ID INTEGER, NAME VARCHAR(100))");
    baseStmt.close();
    connection.commit();
  }

  @Test
  public void getSchemaKeys_onlyTableFilter_success() {
    ImmutableSet<SchemaKey> results = schemaManager.getSchemaKeys(connection, ImmutableList.of());