/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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
 *
 *   http://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.
 */

// Following Gradle best practices to keep build logic organized

// Bundle the test classes in a JAR for other Ant based builds
task testJar(type: Jar, group: 'Build') {
    description = 'Assembles a jar archive containing the test classes.'
    project.test.dependsOn it

    archiveClassifier = 'test'
    from sourceSets.test.output
}

// ----------------------------------------------------------------------------
// Unit test tasks and configurations

// Help the up to date algorithm to make these tests done
ext.markTaskDone = { task ->
    def buildFile = file("$buildDir/${task.name}.flag")
    task.inputs.files task.classpath
    task.outputs.file buildFile
    task.doLast {
        buildFile.text = 'Passed!'
    }
}

task deprecatedEqualityTest(type: JavaExec, group: 'Verification') {
    description = 'Run the non-JUnit test suite '
    classpath = sourceSets.test.runtimeClasspath
    mainClass.set('org.apache.thrift.test.EqualityTest')
    markTaskDone(it)
}

task deprecatedJavaBeansTest(type: JavaExec, group: 'Verification') {
    description = 'Run the non-JUnit test suite '
    classpath = sourceSets.test.runtimeClasspath
    mainClass.set('org.apache.thrift.test.JavaBeansTest')
    markTaskDone(it)
}

// Main Unit Test task configuration
test {
    description="Run the full test suite"
    dependsOn deprecatedEqualityTest, deprecatedJavaBeansTest

    // Allow repeating tests even after successful execution
    if (project.hasProperty('rerunTests')) {
        outputs.upToDateWhen { false }
    }

    include '**/Test*.class'
    exclude '**/Test*\$*.class'

    // https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle
    useJUnitPlatform() {
        // https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution
        systemProperty("junit.jupiter.execution.parallel.enabled", "true")
        systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
        systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "concurrent")
    }

    maxHeapSize = '512m'

    systemProperties = [
        'build.test': "${compileTestJava.destinationDir}",
        'test.port': "${testPort}",
        'javax.net.ssl.trustStore': "${projectDir}/src/crossTest/resources/.truststore",
        'javax.net.ssl.trustStorePassword': 'thrift',
        'javax.net.ssl.keyStore': "${projectDir}/src/crossTest/resources/.keystore",
        'javax.net.ssl.keyStorePassword': 'thrift'
    ]
}
