// Path: src/main/java/com/google/cloud/solutions/datalineage/model/CloudStorageFile.java
// @AutoValue
// @JsonDeserialize(builder = CloudStorageFile.Builder.class)
// public abstract class CloudStorageFile implements DataEntityConvertible, Serializable {
// 
//   public abstract String getBucket();
// 
//   public abstract String getFile();
// 
//   @Override
//   public DataEntity dataEntity() {
//     return DataEntity.newBuilder()
//         .setKind(DataEntityTypes.CLOUD_STORAGE_FILE)
//         .setSqlResource("gs://" + getBucket() + "/" + getFile())
//         .setLinkedResource("storage.googleapis.com/" + getBucket() + "/" + getFile())
//         .build();
//   }
// 
//   public static CloudStorageFile create(String fileName) {
// 
//     Matcher matcher = Pattern.compile("^gs://(?<bucket>[^/]+)/(?<file>.+)$").matcher(fileName);
// 
//     if (!matcher.find()) {
//       throw new IllegalArgumentException(
//           String
//               .format("fileName (%s) needs to start with gs://<bucketName>/<filepath>", fileName));
//     }
// 
//     return builder()
//         .setBucket(matcher.group("bucket"))
//         .setFile(matcher.group("file")).build();
//   }
// 
//   @JsonCreator
//   public static Builder builder() {
//     return new AutoValue_CloudStorageFile.Builder();
//   }
// 
//   @AutoValue.Builder
//   @JsonPOJOBuilder(withPrefix = "set")
//   public abstract static class Builder {
// 
//     public abstract Builder setBucket(String bucket);
// 
//     public abstract Builder setFile(String file);
// 
//     public abstract CloudStorageFile build();
//   }
// 
// 
// }
// 
// Path: src/test/java/com/google/cloud/solutions/datalineage/testing/TestResourceLoader.java
// public final class TestResourceLoader {
// 
//   private static final String TEST_RESOURCE_FOLDER = "test";
// 
//   public static String load(String resourceFileName) {
//     try {
//       byte[] bytes = Files
//           .readAllBytes(Paths.get("src", TEST_RESOURCE_FOLDER, "resources", resourceFileName));
//       return new String(bytes, StandardCharsets.UTF_8);
//     } catch (IOException ioException) {
//       return "";
//     }
//   }
// 
//   private TestResourceLoader() {
//   }
// }


import org.junit.runners.JUnit4;
import com.google.cloud.solutions.datalineage.model.CloudStorageFile;
import com.google.cloud.solutions.datalineage.model.LineageMessages.CompositeLineage;
import com.google.cloud.solutions.datalineage.model.LineageMessages.JobInformation;
import com.google.cloud.solutions.datalineage.model.LineageMessages.TableLineage;
import com.google.cloud.solutions.datalineage.model.LineageMessages.TransformInformation;
import com.google.cloud.solutions.datalineage.testing.TestResourceLoader;
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.Truth;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
                            ImmutableSet.of(
                                BigQueryTableCreator.fromBigQueryResource(
                                    "projects/myproject/datasets/demo/tables/transactions")
                                    .dataEntity()))
                        .setOperation("QUERY_JOB")
                        .build())
                .build());
  }

  @Test
  public void extract_noReferencedTables_lineageWithEmptyParents() {
    Truth.assertThat(
        new InsertJobTableLineageExtractor(
            testClock,
            TestResourceLoader.load("bq_last_message_without_reference_tables.json"))
            .extract())
        .isEqualTo(
            CompositeLineage.newBuilder()
                .setReconcileTime(testClock.instant().toEpochMilli())
                .setJobInformation(
                    JobInformation.newBuilder()
                        .setJobId("projects/myproject/jobs/bquxjob_4103dfda_17173ccc9a4")
                        .setJobTime(Instant.parse("2020-04-13T13:57:08.14Z").toEpochMilli())
                        .setActuator("user@example.com")
                        .setTransform(
                            TransformInformation.newBuilder()
                                .setSql("SELECT * FROM `myproject.demo.events` LIMIT 10")
                                .build())
                        .build())
                .setTableLineage(
// Path: src/main/java/com/google/cloud/solutions/datalineage/model/CloudStorageFile.java
// @AutoValue
// @JsonDeserialize(builder = CloudStorageFile.Builder.class)
// public abstract class CloudStorageFile implements DataEntityConvertible, Serializable {
// 
//   public abstract String getBucket();
// 
//   public abstract String getFile();
// 
//   @Override
//   public DataEntity dataEntity() {
//     return DataEntity.newBuilder()
//         .setKind(DataEntityTypes.CLOUD_STORAGE_FILE)
//         .setSqlResource("gs://" + getBucket() + "/" + getFile())
//         .setLinkedResource("storage.googleapis.com/" + getBucket() + "/" + getFile())
//         .build();
//   }
// 
//   public static CloudStorageFile create(String fileName) {
// 
//     Matcher matcher = Pattern.compile("^gs://(?<bucket>[^/]+)/(?<file>.+)$").matcher(fileName);
// 
//     if (!matcher.find()) {
//       throw new IllegalArgumentException(
//           String
//               .format("fileName (%s) needs to start with gs://<bucketName>/<filepath>", fileName));
//     }
// 
//     return builder()
//         .setBucket(matcher.group("bucket"))
//         .setFile(matcher.group("file")).build();
//   }
// 
//   @JsonCreator
//   public static Builder builder() {
//     return new AutoValue_CloudStorageFile.Builder();
//   }
// 
//   @AutoValue.Builder
//   @JsonPOJOBuilder(withPrefix = "set")
//   public abstract static class Builder {
// 
//     public abstract Builder setBucket(String bucket);
// 
//     public abstract Builder setFile(String file);
// 
//     public abstract CloudStorageFile build();
//   }
// 
// 
// }
// 
// Path: src/test/java/com/google/cloud/solutions/datalineage/testing/TestResourceLoader.java
// public final class TestResourceLoader {
// 
//   private static final String TEST_RESOURCE_FOLDER = "test";
// 
//   public static String load(String resourceFileName) {
//     try {
//       byte[] bytes = Files
//           .readAllBytes(Paths.get("src", TEST_RESOURCE_FOLDER, "resources", resourceFileName));
//       return new String(bytes, StandardCharsets.UTF_8);
//     } catch (IOException ioException) {
//       return "";
//     }
//   }
// 
//   private TestResourceLoader() {
//   }
// }


// Path: src/test/java/com/google/cloud/solutions/datalineage/extractor/InsertJobTableLineageExtractorTest.java
import org.junit.runners.JUnit4;
import com.google.cloud.solutions.datalineage.model.CloudStorageFile;
import com.google.cloud.solutions.datalineage.model.LineageMessages.CompositeLineage;
import com.google.cloud.solutions.datalineage.model.LineageMessages.JobInformation;
import com.google.cloud.solutions.datalineage.model.LineageMessages.TableLineage;
import com.google.cloud.solutions.datalineage.model.LineageMessages.TransformInformation;
import com.google.cloud.solutions.datalineage.testing.TestResourceLoader;
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.Truth;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

                            ImmutableSet.of(
                                BigQueryTableCreator.fromBigQueryResource(
                                    "projects/myproject/datasets/demo/tables/transactions")
                                    .dataEntity()))
                        .setOperation("QUERY_JOB")
                        .build())
                .build());
  }

  @Test
  public void extract_noReferencedTables_lineageWithEmptyParents() {
    Truth.assertThat(
        new InsertJobTableLineageExtractor(
            testClock,
            TestResourceLoader.load("bq_last_message_without_reference_tables.json"))
            .extract())
        .isEqualTo(
            CompositeLineage.newBuilder()
                .setReconcileTime(testClock.instant().toEpochMilli())
                .setJobInformation(
                    JobInformation.newBuilder()
                        .setJobId("projects/myproject/jobs/bquxjob_4103dfda_17173ccc9a4")
                        .setJobTime(Instant.parse("2020-04-13T13:57:08.14Z").toEpochMilli())
                        .setActuator("user@example.com")
                        .setTransform(
                            TransformInformation.newBuilder()
                                .setSql("SELECT * FROM `myproject.demo.events` LIMIT 10")
                                .build())
                        .build())
                .setTableLineage(
                    TableLineage.newBuilder()