// Path: src/java/com/google/cloud/bigquery/dwhassessment/extractiontool/common/ChunkCheckpoint.java
// @AutoValue
// public abstract class ChunkCheckpoint {
// 
//   public abstract Integer lastSavedChunkNumber();
// 
//   public abstract Instant lastSavedInstant();
// 
//   public static Builder builder() {
//     return new AutoValue_ChunkCheckpoint.Builder()
//         .setLastSavedChunkNumber(-1)
//         .setLastSavedInstant(Instant.ofEpochMilli(0));
//   }
// 
//   @AutoValue.Builder
//   public abstract static class Builder {
// 
//     public abstract Builder setLastSavedChunkNumber(Integer value);
// 
//     public abstract Builder setLastSavedInstant(Instant value);
// 
//     public abstract ChunkCheckpoint build();
//   }
// }


import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import com.google.cloud.bigquery.dwhassessment.extractiontool.common.ChunkCheckpoint;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/*
 * 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.executor;



@RunWith(JUnit4.class)
public class SaveCheckerImplTest {
  private Path tmpDir;
  private SaveCheckerImpl saveChecker;
  private static final String DIR_NAME = "testDir";
  private static final String SCRIPT_NAME = "test_script";
  private static final String AVRO_SUFFIX = ".avro";

  @Before
  public void setUp() throws IOException {
    tmpDir = Files.createTempDirectory(DIR_NAME);
    saveChecker =
        new SaveCheckerImpl(ImmutableMap.of(SCRIPT_NAME, ImmutableList.of("testTimestampColumn")));
  }

  @Test
  public void getScriptCheckpoints_success() throws IOException {
    Files.createFile(
        tmpDir.resolve(
            SCRIPT_NAME + "-20140707T170707S000007-20140707T170707S000008_0" + AVRO_SUFFIX));
    Files.createFile(
        tmpDir.resolve(
            SCRIPT_NAME + "-20140707T170707S000017-20140707T170707S000018_1" + AVRO_SUFFIX));
    Files.createFile(
        tmpDir.resolve(
            SCRIPT_NAME + "-20140707T170707S000027-20140707T170707S000028_2" + AVRO_SUFFIX));
    Files.createFile(tmpDir.resolve("file_to_be_ignored"));

// Path: src/java/com/google/cloud/bigquery/dwhassessment/extractiontool/common/ChunkCheckpoint.java
// @AutoValue
// public abstract class ChunkCheckpoint {
// 
//   public abstract Integer lastSavedChunkNumber();
// 
//   public abstract Instant lastSavedInstant();
// 
//   public static Builder builder() {
//     return new AutoValue_ChunkCheckpoint.Builder()
//         .setLastSavedChunkNumber(-1)
//         .setLastSavedInstant(Instant.ofEpochMilli(0));
//   }
// 
//   @AutoValue.Builder
//   public abstract static class Builder {
// 
//     public abstract Builder setLastSavedChunkNumber(Integer value);
// 
//     public abstract Builder setLastSavedInstant(Instant value);
// 
//     public abstract ChunkCheckpoint build();
//   }
// }


// Path: src/javatests/com/google/cloud/bigquery/dwhassessment/extractiontool/executor/SaveCheckerImplTest.java
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import com.google.cloud.bigquery.dwhassessment.extractiontool.common.ChunkCheckpoint;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

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



@RunWith(JUnit4.class)
public class SaveCheckerImplTest {
  private Path tmpDir;
  private SaveCheckerImpl saveChecker;
  private static final String DIR_NAME = "testDir";
  private static final String SCRIPT_NAME = "test_script";
  private static final String AVRO_SUFFIX = ".avro";

  @Before
  public void setUp() throws IOException {
    tmpDir = Files.createTempDirectory(DIR_NAME);
    saveChecker =
        new SaveCheckerImpl(ImmutableMap.of(SCRIPT_NAME, ImmutableList.of("testTimestampColumn")));
  }

  @Test
  public void getScriptCheckpoints_success() throws IOException {
    Files.createFile(
        tmpDir.resolve(
            SCRIPT_NAME + "-20140707T170707S000007-20140707T170707S000008_0" + AVRO_SUFFIX));
    Files.createFile(
        tmpDir.resolve(
            SCRIPT_NAME + "-20140707T170707S000017-20140707T170707S000018_1" + AVRO_SUFFIX));
    Files.createFile(
        tmpDir.resolve(
            SCRIPT_NAME + "-20140707T170707S000027-20140707T170707S000028_2" + AVRO_SUFFIX));
    Files.createFile(tmpDir.resolve("file_to_be_ignored"));

    ImmutableMap<String, ChunkCheckpoint> checkpoints = saveChecker.getScriptCheckPoints(tmpDir);