// 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;
  @Test
  public void getSchemaKeys_onlyTableFilter_success() {
    ImmutableSet<SchemaKey> results = schemaManager.getSchemaKeys(connection, ImmutableList.of());

    assertThat(results)
        .containsAtLeastElementsIn(
            ImmutableSet.of(
                SchemaKey.create("HSQL Database Engine", "FOO"),
                SchemaKey.create("HSQL Database Engine", "FOOBAR"),
                SchemaKey.create("HSQL Database Engine", "BAR")));
  }

  @Test
  public void getSchemaKeys_filterBothDatabaseAndTables_success() {
    ImmutableSet<SchemaKey> results =
        schemaManager.getSchemaKeys(
            connection,
            ImmutableList.of(
                SchemaFilter.builder()
                    .setDatabaseName(Pattern.compile("HSQL.*"))
                    .setTableName(Pattern.compile("FOO.*"))
                    .build()));

    assertThat(results)
        .containsAtLeastElementsIn(
            ImmutableSet.of(
                SchemaKey.create("HSQL Database Engine", "FOO"),
                SchemaKey.create("HSQL Database Engine", "FOOBAR")));
  }

// 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;

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

    assertThat(results)
        .containsAtLeastElementsIn(
            ImmutableSet.of(
                SchemaKey.create("HSQL Database Engine", "FOO"),
                SchemaKey.create("HSQL Database Engine", "FOOBAR"),
                SchemaKey.create("HSQL Database Engine", "BAR")));
  }

  @Test
  public void getSchemaKeys_filterBothDatabaseAndTables_success() {
    ImmutableSet<SchemaKey> results =
        schemaManager.getSchemaKeys(
            connection,
            ImmutableList.of(
                SchemaFilter.builder()
                    .setDatabaseName(Pattern.compile("HSQL.*"))
                    .setTableName(Pattern.compile("FOO.*"))
                    .build()));

    assertThat(results)
        .containsAtLeastElementsIn(
            ImmutableSet.of(
                SchemaKey.create("HSQL Database Engine", "FOO"),
                SchemaKey.create("HSQL Database Engine", "FOOBAR")));
  }

  @Test