/*
 * 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

    classifier '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 }
    }

    // This is required for Mockito to run under Java 17
    jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
    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'
    ]
}
