apply plugin: 'kotlin'
apply plugin: 'kotlin-jpa'
apply plugin: 'net.corda.plugins.quasar-utils'
apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'net.corda.plugins.api-scanner'

description 'Corda core tests'

configurations {
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntimeOnly.extendsFrom testRuntimeOnly

    smokeTestCompile.extendsFrom compile
    smokeTestRuntimeOnly.extendsFrom runtimeOnly
}

evaluationDependsOn(':node:capsule')

sourceSets {
    integrationTest {
        kotlin {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/kotlin')
        }
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/java')
        }
    }
    smokeTest {
        kotlin {
            // We must NOT have any Node code on the classpath, so do NOT
            // include the test or integrationTest dependencies here.
            srcDir file('src/smoke-test/kotlin')
        }
        java {
            srcDir file('src/smoke-test/java')
        }
    }
}

processSmokeTestResources {
    // Bring in the fully built corda.jar for use by NodeFactory in the smoke tests
    from(project(':node:capsule').tasks['buildCordaJAR']) {
        rename 'corda-(.*)', 'corda.jar'
    }
}

dependencies {

    testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}"
    testImplementation "junit:junit:$junit_version"
    testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}"
    testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"

    testCompile "commons-fileupload:commons-fileupload:$fileupload_version"
    testCompile project(":core")
    testCompile project(path: ':core', configuration: 'testArtifacts')
    
    // Guava: Google test library (collections test suite)
    testCompile "com.google.guava:guava-testlib:$guava_version"

    // Bring in the MockNode infrastructure for writing protocol unit tests.
    testCompile project(":node-driver")

    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"

    // Hamkrest, for fluent, composable matchers
    testCompile "com.natpryce:hamkrest:$hamkrest_version"

    // SLF4J: commons-logging bindings for a SLF4J back end
    compile "org.slf4j:jcl-over-slf4j:$slf4j_version"
    compile "org.slf4j:slf4j-api:$slf4j_version"

    // AssertJ: for fluent assertions for testing
    testCompile "org.assertj:assertj-core:${assertj_version}"

    // Guava: Google utilities library.
    testCompile "com.google.guava:guava:$guava_version"

    // Smoke tests do NOT have any Node code on the classpath!
    smokeTestImplementation "org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}"
    smokeTestImplementation "junit:junit:$junit_version"

    smokeTestRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}"
    smokeTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}"
    smokeTestRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}"

    smokeTestCompile project(':smoke-test-utils')
    smokeTestCompile "org.assertj:assertj-core:${assertj_version}"

}

configurations {
    testArtifacts.extendsFrom testRuntimeClasspath
}

tasks.withType(Test) {
    // fork a new test process for every test class
    forkEvery = 10
}

task testJar(type: Jar) {
    classifier "tests"
    from sourceSets.test.output
}

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
}

task smokeTestJar(type: Jar) {
    classifier 'smokeTests'
    from sourceSets.smokeTest.output
}

task smokeTest(type: Test) {
    dependsOn smokeTestJar
    testClassesDirs = sourceSets.smokeTest.output.classesDirs
    classpath = sourceSets.smokeTest.runtimeClasspath
}

// quasar exclusions upon agent code instrumentation at run-time
quasar {
    excludePackages.addAll(
            "antlr**",
            "com.codahale**",
            "com.fasterxml.**",
            "com.github.benmanes.caffeine.**",
            "com.google.**",
            "com.lmax.**",
            "com.zaxxer.**",
            "net.bytebuddy**",
            "io.github.classgraph**",
            "io.netty*",
            "liquibase**",
            "net.i2p.crypto.**",
            "nonapi.io.github.classgraph.**",
            "org.apiguardian.**",
            "org.bouncycastle**",
            "org.codehaus.**",
            "org.h2**",
            "org.hibernate**",
            "org.jboss.**",
            "org.objenesis**",
            "org.w3c.**",
            "org.xml**",
            "org.yaml**",
            "rx**")
}

artifacts {
    testArtifacts testJar
}