// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/MavenDependency.java
// public class MavenDependency extends MavenArtifact {
// 
//     private String scope;
//     public boolean optional;
// 
//     @Nonnull
//     public String getScope() {
//         return scope == null ? "compile" : scope;
//     }
// 
//     public void setScope(String scope) {
//         this.scope = scope == null || scope.isEmpty() ? null : scope;
//     }
// 
//     @Override
//     public String toString() {
//         return "MavenDependency{" +
//                 getGroupId() + ":" +
//                 getArtifactId() + ":" +
//                 getType() +
//                 (getClassifier() == null ? "" : ":" + getClassifier()) + ":" +
//                 getBaseVersion() + ", " +
//                 "scope: " + scope + ", " +
//                 " optional: " + optional +
//                 " version: " + getVersion() +
//                 " snapshot: " + isSnapshot() +
//                 (getFile() == null ? "" : " " + getFile()) +
//                 '}';
//     }
// 
//     public MavenArtifact asMavenArtifact() {
//         MavenArtifact result = new MavenArtifact();
// 
//         result.setGroupId(getGroupId());
//         result.setArtifactId(getArtifactId());
//         result.setVersion(getVersion());
//         result.setBaseVersion(getBaseVersion());
//         result.setType(getType());
//         result.setClassifier(getClassifier());
//         result.setExtension(getExtension());
//         result.setFile(getFile());
//         result.setSnapshot(isSnapshot());
// 
//         return result;
//     }
// 
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(super.hashCode(), optional, scope);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (!super.equals(obj))
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         MavenDependency other = (MavenDependency) obj;
//         if (optional != other.optional)
//             return false;
//         if (scope == null) {
//             return other.scope == null;
//         } else return scope.equals(other.scope);
//     }
// }


import hudson.model.Result;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
import org.jenkinsci.plugins.pipeline.maven.util.SqlTestsUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import javax.annotation.Nonnull;
import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.in;
        // AFTER DELETE FIRST
        SqlTestsUtils.dump("select * from JENKINS_JOB", ds, System.out);

        dao.deleteBuild("my-pipeline", 3);
        System.out.println("AFTER DELETE LAST BUILD");
        SqlTestsUtils.dump("select * from JENKINS_JOB", ds, System.out);

    }


    @Test
    public void record_one_dependency() throws Exception {

        dao.recordDependency("my-pipeline", 1, "com.h2.database", "h2", "1.4.196", "jar", "compile", false, null);

        SqlTestsUtils.dump("select * from JENKINS_BUILD LEFT OUTER JOIN JENKINS_JOB ON JENKINS_BUILD.JOB_ID = JENKINS_JOB.ID", ds, System.out);
        SqlTestsUtils.dump("select * from MAVEN_ARTIFACT", ds, System.out);
        SqlTestsUtils.dump("select * from MAVEN_DEPENDENCY", ds, System.out);

        assertThat(
                SqlTestsUtils.countRows("select * from JENKINS_BUILD", ds),
                is(1));

        assertThat(
                SqlTestsUtils.countRows("select * from MAVEN_ARTIFACT", ds),
                is(1));
        assertThat(
                SqlTestsUtils.countRows("select * from MAVEN_DEPENDENCY", ds),
                is(1));

// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/MavenDependency.java
// public class MavenDependency extends MavenArtifact {
// 
//     private String scope;
//     public boolean optional;
// 
//     @Nonnull
//     public String getScope() {
//         return scope == null ? "compile" : scope;
//     }
// 
//     public void setScope(String scope) {
//         this.scope = scope == null || scope.isEmpty() ? null : scope;
//     }
// 
//     @Override
//     public String toString() {
//         return "MavenDependency{" +
//                 getGroupId() + ":" +
//                 getArtifactId() + ":" +
//                 getType() +
//                 (getClassifier() == null ? "" : ":" + getClassifier()) + ":" +
//                 getBaseVersion() + ", " +
//                 "scope: " + scope + ", " +
//                 " optional: " + optional +
//                 " version: " + getVersion() +
//                 " snapshot: " + isSnapshot() +
//                 (getFile() == null ? "" : " " + getFile()) +
//                 '}';
//     }
// 
//     public MavenArtifact asMavenArtifact() {
//         MavenArtifact result = new MavenArtifact();
// 
//         result.setGroupId(getGroupId());
//         result.setArtifactId(getArtifactId());
//         result.setVersion(getVersion());
//         result.setBaseVersion(getBaseVersion());
//         result.setType(getType());
//         result.setClassifier(getClassifier());
//         result.setExtension(getExtension());
//         result.setFile(getFile());
//         result.setSnapshot(isSnapshot());
// 
//         return result;
//     }
// 
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(super.hashCode(), optional, scope);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (!super.equals(obj))
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         MavenDependency other = (MavenDependency) obj;
//         if (optional != other.optional)
//             return false;
//         if (scope == null) {
//             return other.scope == null;
//         } else return scope.equals(other.scope);
//     }
// }


// Path: jenkins-plugin/src/test/java/org/jenkinsci/plugins/pipeline/maven/dao/PipelineMavenPluginDaoAbstractTest.java
import hudson.model.Result;
import org.hamcrest.Matchers;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
import org.jenkinsci.plugins.pipeline.maven.util.SqlTestsUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import javax.annotation.Nonnull;
import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.in;

        // AFTER DELETE FIRST
        SqlTestsUtils.dump("select * from JENKINS_JOB", ds, System.out);

        dao.deleteBuild("my-pipeline", 3);
        System.out.println("AFTER DELETE LAST BUILD");
        SqlTestsUtils.dump("select * from JENKINS_JOB", ds, System.out);

    }


    @Test
    public void record_one_dependency() throws Exception {

        dao.recordDependency("my-pipeline", 1, "com.h2.database", "h2", "1.4.196", "jar", "compile", false, null);

        SqlTestsUtils.dump("select * from JENKINS_BUILD LEFT OUTER JOIN JENKINS_JOB ON JENKINS_BUILD.JOB_ID = JENKINS_JOB.ID", ds, System.out);
        SqlTestsUtils.dump("select * from MAVEN_ARTIFACT", ds, System.out);
        SqlTestsUtils.dump("select * from MAVEN_DEPENDENCY", ds, System.out);

        assertThat(
                SqlTestsUtils.countRows("select * from JENKINS_BUILD", ds),
                is(1));

        assertThat(
                SqlTestsUtils.countRows("select * from MAVEN_ARTIFACT", ds),
                is(1));
        assertThat(
                SqlTestsUtils.countRows("select * from MAVEN_DEPENDENCY", ds),
                is(1));

        List<MavenDependency> mavenDependencies = dao.listDependencies("my-pipeline", 1);