tasks.register('IntelliJ', Test) {
    useJUnitPlatform {}

    testlogger {
        theme 'plain'
        showExceptions true
        showStackTraces true
        showFullStackTraces false
        showCauses true
        showSummary true
        showSimpleNames false
        showPassed true
        showSkipped true
        showFailed true
        showStandardStreams true
        showPassedStandardStreams true
        showSkippedStandardStreams true
        showFailedStandardStreams true
    }
}

test {
    minHeapSize = "512m"
    maxHeapSize = "4069m"
}

tasks.register('unitTests', Test) {
    testClassesDirs = testing.suites.test.sources.output.classesDirs
    classpath = testing.suites.test.sources.runtimeClasspath

    doFirst {
        systemProperty 'spring.profiles.active', 'unit'
    }
    // We need to load the tenants for the tests too
    useJUnitPlatform {
        includeTags 'unit'
    }
}

tasks.register('itTests', Test) {
    testClassesDirs = testing.suites.test.sources.output.classesDirs
    classpath = testing.suites.test.sources.runtimeClasspath

    // this loads the correct configuration
    doFirst {
        systemProperty 'spring.profiles.active', 'it'
    }
    // We need to load the tenants for the tests too
    useJUnitPlatform {
        includeTags 'it'
    }
}

tasks.register('e2eTests', Test) {
    testClassesDirs = testing.suites.test.sources.output.classesDirs
    classpath = testing.suites.test.sources.runtimeClasspath

    // this loads the correct configuration
    doFirst {
        systemProperty 'spring.profiles.active', 'e2e'
    }
    // We need to load the tenants for the tests too
    useJUnitPlatform {
        includeTags 'e2e'
    }
}

tasks.withType(Test).configureEach {
    testClassesDirs = testing.suites.test.sources.output.classesDirs
    classpath = testing.suites.test.sources.runtimeClasspath

//    reports {
//        junitXml.enabled = true
//        html.enabled = true
//    }

    if (project.hasProperty('debug')) {
        jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5007"]
    }

    // hide all the refelction access warnings during compile
    //allow embedded executer to modify environment variables
    jvmArgs += "--add-opens=java.base/java.util=ALL-UNNAMED"
    //allow embedded executer to inject legacy types into the system classloader
    jvmArgs += "--add-opens=java.base/java.lang=ALL-UNNAMED"

    // ****************************************************
    // ************* speed optimization *******************
    // ****************************************************
    jvmArgs += "-noverify"
}
