| /* |
| * 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. |
| */ |
| |
| import org.scoverage.ScoverageReport |
| import static groovy.json.JsonOutput.* |
| |
| apply plugin: 'scala' |
| apply plugin: 'eclipse' |
| apply plugin: 'maven' |
| apply plugin: 'org.scoverage' |
| compileTestScala.options.encoding = 'UTF-8' |
| |
| repositories { |
| mavenCentral() |
| } |
| |
| install.dependsOn ':tools:admin:install' |
| |
| project.archivesBaseName = "openwhisk-tests" |
| |
| tasks.withType(Test) { |
| systemProperties(System.getProperties()) |
| |
| testLogging { |
| events "passed", "skipped", "failed" |
| showStandardStreams = true |
| exceptionFormat = 'full' |
| } |
| outputs.upToDateWhen { false } // force tests to run every time |
| } |
| |
| def leanExcludes = [ |
| '**/*ThrottleTests*', |
| '**/MaxActionDurationTests*', |
| ] |
| |
| ext.testSets = [ |
| "REQUIRE_ONLY_DB" : [ |
| "includes" : [ |
| "ha/**", |
| "whisk/**" |
| ], |
| "excludes" : [ |
| "whisk/core/admin/**", |
| "whisk/core/apigw/actions/test/**", |
| "whisk/core/cli/test/**", |
| "whisk/core/limits/**", |
| "**/*CacheConcurrencyTests*", |
| "**/*ControllerApiTests*", |
| ] |
| ], |
| "REQUIRE_SYSTEM" : [ |
| "includes" : [ |
| "apigw/healthtests/**", |
| "services/**", |
| "system/basic/**", |
| "system/rest/**", |
| "whisk/core/admin/**", |
| "whisk/core/cli/test/**", |
| "whisk/core/apigw/actions/test/**", |
| "whisk/core/limits/**", |
| "whisk/core/database/test/*CacheConcurrencyTests*", |
| "whisk/core/controller/test/*ControllerApiTests*", |
| ] |
| ], |
| "LEAN" : [ |
| "excludes" : leanExcludes |
| ] |
| ] |
| |
| testSets.each {setName, patterns -> |
| def excludes = patterns["excludes"] ?: new HashSet<>() |
| excludes.addAll(leanExcludes) |
| patterns["excludes"] = excludes |
| } |
| |
| //The value can be specified either via env variable |
| // ORG_GRADLE_PROJECT_testSetName |
| //Or via property -PtestSetName |
| if (!project.hasProperty("testSetName")) { |
| ext.testSetName = "LEAN" |
| } |
| |
| def getPattern(String name, String type) { |
| def patterns = testSets[name] |
| assert patterns : "No pattern found for $name" |
| return patterns[type] ?: [] |
| } |
| |
| def logTestSetInfo(){ |
| println "Using testSet $testSetName - ${prettyPrint(toJson(testSets[testSetName]))}" |
| } |
| |
| task testLean(type: Test) { |
| doFirst { |
| logTestSetInfo() |
| } |
| exclude getPattern(testSetName, "excludes") |
| include getPattern(testSetName, "includes") |
| } |
| |
| task testUnit(type: Test) { |
| systemProperty("whisk.spi.ArtifactStoreProvider", "whisk.core.database.memory.MemoryArtifactStoreProvider") |
| exclude getPattern("REQUIRE_ONLY_DB", "excludes") |
| include getPattern("REQUIRE_ONLY_DB", "includes") |
| |
| //Test below have direct dependency on CouchDB running |
| def couchDbExcludes = [ |
| "**/*NamespaceBlacklistTests*", |
| "**/*CleanUpActivationsTest*", |
| "**/*CouchDbRestClientTests*", |
| "**/*RemoveLogsTests*", |
| "**/*ReplicatorTest*", |
| "**/*CouchDBArtifactStoreTests*", |
| ] |
| |
| exclude couchDbExcludes |
| } |
| |
| dependencies { |
| compile "org.scala-lang:scala-library:${gradle.scala.version}" |
| compile 'org.apache.commons:commons-lang3:3.3.2' |
| compile 'org.apache.httpcomponents:httpclient:4.5.2:tests' |
| compile 'org.apache.httpcomponents:httpmime:4.3.6' |
| compile 'junit:junit:4.11' |
| compile 'com.jayway.restassured:rest-assured:2.6.0' |
| compile 'org.scalatest:scalatest_2.11:3.0.1' |
| compile 'com.typesafe.akka:akka-testkit_2.11:2.5.12' |
| compile 'com.google.code.gson:gson:2.3.1' |
| compile 'org.scalamock:scalamock-scalatest-support_2.11:3.4.2' |
| compile 'com.typesafe.akka:akka-http-testkit_2.11:10.1.1' |
| compile 'com.github.java-json-tools:json-schema-validator:2.2.8' |
| compile "org.mockito:mockito-core:2.15.0" |
| compile 'io.opentracing:opentracing-mock:0.31.0' |
| |
| compile project(':common:scala') |
| compile project(':core:controller') |
| compile project(':core:invoker') |
| compile project(':tools:admin') |
| |
| |
| |
| scoverage gradle.scoverage.deps |
| } |
| |
| tasks.withType(ScalaCompile) { |
| scalaCompileOptions.additionalParameters = gradle.scala.compileFlags |
| } |
| |
| def keystorePath = new File(sourceSets.test.scala.outputDir, 'keystore') |
| task deleteKeystore(type: Delete) { |
| delete keystorePath |
| } |
| task createKeystore(dependsOn: deleteKeystore) { |
| doLast { |
| Properties props = new Properties() |
| props.load(new FileInputStream(file('../whisk.properties'))) |
| keystorePath.parentFile.mkdirs() |
| def cmd = ['keytool', '-import', '-alias', 'Whisk', '-noprompt', '-trustcacerts', '-file', file(props['whisk.ssl.cert']), '-keystore', keystorePath, '-storepass', 'openwhisk'] |
| cmd.execute().waitForProcessOutput(System.out, System.err) |
| } |
| } |
| |
| tasks.withType(Test) { |
| dependsOn createKeystore |
| } |
| createKeystore.mustRunAfter(testClasses) |
| |
| gradle.projectsEvaluated { |
| task testCoverageLean(type: Test) { |
| doFirst { |
| logTestSetInfo() |
| } |
| classpath = getScoverageClasspath(project) |
| exclude getPattern(testSetName, "excludes") |
| include getPattern(testSetName, "includes") |
| } |
| |
| task testCoverage(type: Test) { |
| classpath = getScoverageClasspath(project) |
| } |
| } |
| |
| /** |
| * Task to generate coverage xml report. Requires the |
| * tests to be executed prior to its invocation |
| */ |
| task reportCoverage(type: ScoverageReport) { |
| dependsOn([ |
| ':common:scala:reportScoverage', |
| ':core:controller:reportScoverage', |
| ':core:invoker:reportScoverage', |
| ':tools:admin:reportScoverage' |
| ]) |
| } |
| |
| /** |
| * Aggregates the scoverage xml reports from various modules into a |
| * single report |
| */ |
| task aggregateCoverage(type: JavaExec, dependsOn: reportCoverage) { |
| //Taken from ScoverageAggregate |
| main = 'org.scoverage.AggregateReportApp' |
| classpath = project.extensions.scoverage.pluginClasspath |
| args = [ |
| project.rootProject.projectDir, //Use the root project path so as to "see" all source paths |
| new File(project.buildDir, 'scoverage-aggregate'), |
| false, //Clean scoverage report post process |
| true, //coverageOutputCobertura |
| true, //coverageOutputXML |
| true, //coverageOutputHTML |
| false //coverageDebug |
| ] |
| } |
| |
| /** |
| * Prepares the classpath which refer to scoverage instrumented classes from |
| * dependent projects "before" the non instrumented classes |
| */ |
| def getScoverageClasspath(Project project) { |
| def projectNames = [ |
| ':common:scala', |
| ':core:controller', |
| ':core:invoker', |
| ':tools:admin' |
| ] |
| def combinedClasspath = projectNames.inject(project.files([])) { result, name -> |
| def cp = project.project(name).sourceSets.scoverage.runtimeClasspath |
| result + cp.filter {it.name.contains('scoverage')} |
| } |
| |
| combinedClasspath + sourceSets.test.runtimeClasspath |
| } |