/*
 * 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.faketd;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TeradataSimulatorTest {

  private static final String FAKE_TERADATA_URL = "jdbc:hsqldb:mem:faketd";

  @Test
  public void populate_success() throws SQLException, IOException {
    try (Connection connection = getFakeTeradataConnection()) {
      try (Statement statement = connection.createStatement()) {
        ResultSet rs = statement.executeQuery(
            "SELECT" +
                "  DatabaseName," +
                "  TableName," +
                "  LastAccessTimeStamp AT TIME ZONE INTERVAL '0:00' HOUR TO MINUTE " +
                "FROM DBC.TablesV");
        while (rs.next()) {
          System.out.printf("DB: %s, table: %s%n", rs.getString("DatabaseName"),
              rs.getString("TableName"));
        }
      }
    }
  }

  private static Connection getFakeTeradataConnection() throws SQLException, IOException {
    TeradataSimulator.populate(FAKE_TERADATA_URL);
    return DriverManager.getConnection(FAKE_TERADATA_URL);
  }
}

/*
 * 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.faketd;

import static com.google.common.truth.Truth.assertThat;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TeradataSimulatorTest {

  private static final String FAKE_TERADATA_URL = "jdbc:hsqldb:mem:faketd";

  @Test
  public void populate_success() throws SQLException, IOException {
    try (Connection connection = getFakeTeradataConnection()) {
      try (Statement statement = connection.createStatement()) {
        try (ResultSet rs =
            statement.executeQuery(
                "SELECT"
                    + "  DatabaseName,"
                    + "  TableName,"
                    + "  LastAccessTimeStamp AT TIME ZONE INTERVAL '0:00' HOUR TO MINUTE "
                    + "FROM DBC.TablesV")) {
          assertThat(rs.next()).isFalse();
        }
      }
    }
  }

  private static Connection getFakeTeradataConnection() throws SQLException, IOException {
    TeradataSimulator.populate(FAKE_TERADATA_URL);
    return DriverManager.getConnection(FAKE_TERADATA_URL);
  }
}

Improve test case for TeradataSimulator