/*
 * 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 = [
        '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'
    ]
}
