plugins {
    id 'java'
}

configurations {
    antJUnit
}

dependencies {
    implementation 'org.junit.jupiter:junit-jupiter-params:5.11.2'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.11.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.2'
    implementation 'com.google.code.gson:gson:2.8.9'
    implementation 'ch.qos.logback:logback-classic:1.2.3'
    implementation project(':core')
    implementation project(':messagepack')
    antJUnit 'org.apache.ant:ant-junit:1.10.15'
}

sourceSets {
  test {
    java {
      srcDir 'src'
    }
  }
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }

    reports {
        html.required = false
        junitXml.outputPerTestCase = true
        junitXml.required = true
    }
}

// Merge test results into a single file for Helix to detect JUnit test file
task testReport {
    ext {
        resultsDir = file("$buildDir/test-results")
        mergedFile = "test-results/junit-results.xml"
    }

    doLast {
        mkdir 'test-results'
        ant.taskdef(name: 'junitreport',
                    classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
                    classpath: configurations.antJUnit.asPath)

        ant.junitreport(tofile: mergedFile) {
            fileset(dir: resultsDir, includes: '**/TEST-*.xml')
        }
    }
}

test.finalizedBy(testReport)