diff --git a/build.gradle.kts b/build.gradle.kts index 02b44b9..93f1ef3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("org.ajoberstar.reckon") version "0.18.0" - kotlin("jvm") version "1.8.22" apply false + kotlin("jvm") version "1.9.21" apply false } reckon { @@ -14,9 +14,10 @@ reckon { } subprojects { - extra["chutneyTestingVersion"] = "2.5.1" + extra["chutneyTestingVersion"] = "2.6.1" repositories { + mavenLocal() mavenCentral() } @@ -34,13 +35,13 @@ subprojects { implementation(enforcedPlatform("com.chutneytesting:chutney-parent:${project.extra["chutneyTestingVersion"]}")) // Resolve conflicts from chutney-parent for runtime classpath - runtimeOnly("com.fasterxml.jackson.module:jackson-module-scala_2.13") // :2.15.2 - runtimeOnly("com.fasterxml.jackson.dataformat:jackson-dataformat-csv") // :2.15.2 - runtimeOnly("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") // :2.15.2 - runtimeOnly("org.eclipse.jetty:jetty-client:11.0.15") // :11.0.15 - runtimeOnly("org.eclipse.jetty:jetty-security:11.0.15") // :11.0.15 - runtimeOnly("org.eclipse.jetty:jetty-xml:11.0.15") // :11.0.15 - runtimeOnly("org.eclipse.jetty.http2:http2-common:11.0.15") // :11.0.15 + runtimeOnly("com.fasterxml.jackson.module:jackson-module-scala_2.13") // :2.15.3 + runtimeOnly("com.fasterxml.jackson.dataformat:jackson-dataformat-csv") // :2.15.3 + runtimeOnly("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") // :2.15.3 + runtimeOnly("org.eclipse.jetty:jetty-client") // :12.0.5 + runtimeOnly("org.eclipse.jetty:jetty-security") // :12.0.5 + runtimeOnly("org.eclipse.jetty:jetty-xml") // :12.0.5 + runtimeOnly("org.eclipse.jetty.http2:http2-common:11.0.19") } tasks.withType { diff --git a/dsl/build.gradle.kts b/dsl/build.gradle.kts index 3538796..5f4c096 100644 --- a/dsl/build.gradle.kts +++ b/dsl/build.gradle.kts @@ -40,7 +40,7 @@ dependencies { testImplementation(kotlin("scripting-jsr223")) testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") testImplementation("org.junit-pioneer:junit-pioneer:2.0.0") - testImplementation("org.wiremock:wiremock:3.2.0") + testImplementation("org.wiremock:wiremock-standalone") // JUnit5 engine dependencies implementation("org.junit.platform:junit-platform-engine") diff --git a/dsl/src/main/kotlin/com/chutneytesting/kotlin/dsl/ChutneyEnvironmentDsl.kt b/dsl/src/main/kotlin/com/chutneytesting/kotlin/dsl/ChutneyEnvironmentDsl.kt index 9c1ca10..f340c67 100644 --- a/dsl/src/main/kotlin/com/chutneytesting/kotlin/dsl/ChutneyEnvironmentDsl.kt +++ b/dsl/src/main/kotlin/com/chutneytesting/kotlin/dsl/ChutneyEnvironmentDsl.kt @@ -1,11 +1,10 @@ package com.chutneytesting.kotlin.dsl -import java.util.stream.Collectors - data class ChutneyEnvironment( val name: String, val description: String = "", - val targets: List = emptyList() + val targets: List = emptyList(), + val variables: Map = emptyMap() ) { init { diff --git a/dsl/src/main/kotlin/com/chutneytesting/kotlin/execution/ExecutionService.kt b/dsl/src/main/kotlin/com/chutneytesting/kotlin/execution/ExecutionService.kt index 6e0afec..329d8e1 100644 --- a/dsl/src/main/kotlin/com/chutneytesting/kotlin/execution/ExecutionService.kt +++ b/dsl/src/main/kotlin/com/chutneytesting/kotlin/execution/ExecutionService.kt @@ -5,7 +5,7 @@ import com.chutneytesting.engine.api.execution.DatasetDto import com.chutneytesting.engine.api.execution.ExecutionRequestDto import com.chutneytesting.engine.api.execution.StepExecutionReportDto import com.chutneytesting.environment.EnvironmentConfiguration -import com.chutneytesting.environment.api.dto.EnvironmentDto +import com.chutneytesting.environment.api.environment.dto.EnvironmentDto import com.chutneytesting.kotlin.dsl.ChutneyEnvironment import com.chutneytesting.kotlin.dsl.ChutneyScenario import com.chutneytesting.kotlin.dsl.ChutneyTarget @@ -13,7 +13,6 @@ import com.chutneytesting.kotlin.dsl.ChutneyTarget const val CHUTNEY_ROOT_PATH_DEFAULT = ".chutney" const val CHUTNEY_ENV_ROOT_PATH_DEFAULT = "$CHUTNEY_ROOT_PATH_DEFAULT/environments" -class CannotResolveDefaultEnvironmentException : Exception("No environment name was given and there is more than one environment. Defaulting is impossible. Please, specify a name or declare only one environment.") class ExecutionService( environmentJsonRootPath: String = CHUTNEY_ENV_ROOT_PATH_DEFAULT @@ -22,9 +21,6 @@ class ExecutionService( private val executionConfiguration = ExecutionConfiguration() private val embeddedEnvironmentApi = EnvironmentConfiguration(environmentJsonRootPath).embeddedEnvironmentApi - companion object { - val EMPTY = ChutneyEnvironment("EMPTY") - } fun execute( scenario: ChutneyScenario, @@ -37,7 +33,7 @@ class ExecutionService( .executeAsync( ExecutionRequestDto( ExecutionRequestMapper.mapScenarioToExecutionRequest(scenario, environment), - environment.name, + com.chutneytesting.engine.api.execution.EnvironmentDto(environment.name, environment.variables), datasetDto ) ) @@ -59,23 +55,8 @@ class ExecutionService( } fun getEnvironment(environmentName: String? = null): ChutneyEnvironment { - val environmentDto: EnvironmentDto - val environments = embeddedEnvironmentApi.listEnvironments() - - environmentDto = if (environmentName.isNullOrBlank()) { - if (environments.isNotEmpty()) { - if (environments.size > 1) { - throw CannotResolveDefaultEnvironmentException() - } else { - environments.first() - } - } else { - return EMPTY - } - } else { - embeddedEnvironmentApi.getEnvironment(environmentName) - } - + val executionEnv = environmentName.takeUnless { it.isNullOrBlank() } ?: embeddedEnvironmentApi.defaultEnvironmentName() + val environmentDto = embeddedEnvironmentApi.getEnvironment(executionEnv) return mapEnvironmentNameToChutneyEnvironment(environmentDto) } diff --git a/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ChutneyScenarioExecutionContext.kt b/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ChutneyScenarioExecutionContext.kt index 2f5e87f..0c40ff7 100644 --- a/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ChutneyScenarioExecutionContext.kt +++ b/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ChutneyScenarioExecutionContext.kt @@ -3,11 +3,12 @@ package com.chutneytesting.kotlin.junit.engine.execution import com.chutneytesting.engine.domain.execution.engine.step.Step import com.chutneytesting.engine.domain.execution.report.Status import com.chutneytesting.environment.domain.exception.EnvironmentNotFoundException +import com.chutneytesting.environment.domain.exception.NoEnvironmentFoundException +import com.chutneytesting.environment.domain.exception.UnresolvedEnvironmentException import com.chutneytesting.kotlin.ChutneyConfigurationParameters import com.chutneytesting.kotlin.dsl.ChutneyStep import com.chutneytesting.kotlin.dsl.ChutneyStepImpl import com.chutneytesting.kotlin.dsl.Strategy -import com.chutneytesting.kotlin.execution.CannotResolveDefaultEnvironmentException import com.chutneytesting.kotlin.execution.report.JsonReportWriter import com.chutneytesting.kotlin.junit.engine.ChutneyScenarioDescriptor import com.chutneytesting.kotlin.junit.engine.ChutneyStepDescriptor @@ -173,7 +174,8 @@ class ChutneyScenarioExecutionContext( private fun convertExecuteException(t: Throwable, scenarioDescriptor: ChutneyScenarioDescriptor): Throwable { return when (t) { - is CannotResolveDefaultEnvironmentException -> UnresolvedScenarioEnvironmentException(t.message) + is UnresolvedEnvironmentException -> UnresolvedScenarioEnvironmentException(t.message + " Please, specify a name or declare only one environment.") + is NoEnvironmentFoundException -> UnresolvedScenarioEnvironmentException(t.message + " Please, declare one.") is EnvironmentNotFoundException -> UnresolvedScenarioEnvironmentException("Environment [${scenarioDescriptor.environmentName}] not found. ${t.message}") else -> AssertionError(t) } diff --git a/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ReportUtil.kt b/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ReportUtil.kt index 263c3c5..bdeb2c6 100644 --- a/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ReportUtil.kt +++ b/dsl/src/main/kotlin/com/chutneytesting/kotlin/junit/engine/execution/ReportUtil.kt @@ -11,27 +11,33 @@ import com.chutneytesting.engine.domain.execution.report.StepExecutionReportBuil object ReportUtil { fun generateReportDto(step: Step): StepExecutionReportDto { - return toDto(generateReport(step)) + return toDto(generateReport(step, getEnvironment(step))) } - private fun generateReport(step: Step): StepExecutionReport { + private fun generateReport(step: Step, env: String): StepExecutionReport { return StepExecutionReportBuilder().setName(step.definition().name) .setDuration(step.duration().toMillis()) .setStartDate(step.startDate()) .setStatus(step.status()) .setInformation(step.informations()) .setErrors(step.errors()) - .setSteps(step.subSteps().map { generateReport(it) }.toList()) + .setSteps(step.subSteps().map { generateReport(it, env) }.toList()) .setEvaluatedInputs(step.evaluatedInputs) .setStepResults(step.stepOutputs) .setScenarioContext(step.scenarioContext) .setType(step.type()) .setTarget(step.target()) .setStrategy(step.strategy().map { it.type }.orElse(null)) - .setEnvironment(step.definition().environment) + .setEnvironment(env) .createStepExecutionReport() } + private fun getEnvironment(step: Step): String { + return if (step.isParentStep) { + getEnvironment(step.subSteps()[0]) + } else step.scenarioContext["environment"] as String + } + private fun toDto(report: StepExecutionReport): StepExecutionReportDto { return StepExecutionReportDto( report.name, diff --git a/dsl/src/main/kotlin/com/chutneytesting/kotlin/synchronize/ChutneyServerServiceImpl.kt b/dsl/src/main/kotlin/com/chutneytesting/kotlin/synchronize/ChutneyServerServiceImpl.kt index e7594d3..672819e 100644 --- a/dsl/src/main/kotlin/com/chutneytesting/kotlin/synchronize/ChutneyServerServiceImpl.kt +++ b/dsl/src/main/kotlin/com/chutneytesting/kotlin/synchronize/ChutneyServerServiceImpl.kt @@ -1,6 +1,6 @@ package com.chutneytesting.kotlin.synchronize -import com.chutneytesting.environment.api.dto.EnvironmentDto +import com.chutneytesting.environment.api.environment.dto.EnvironmentDto import com.chutneytesting.kotlin.dsl.ChutneyScenario import com.chutneytesting.kotlin.dsl.Mapper import com.chutneytesting.kotlin.util.ChutneyServerInfo diff --git a/dsl/src/test/kotlin/com/chutneytesting/kotlin/execution/ExecutionServiceTest.kt b/dsl/src/test/kotlin/com/chutneytesting/kotlin/execution/ExecutionServiceTest.kt index c7e620c..c00d223 100644 --- a/dsl/src/test/kotlin/com/chutneytesting/kotlin/execution/ExecutionServiceTest.kt +++ b/dsl/src/test/kotlin/com/chutneytesting/kotlin/execution/ExecutionServiceTest.kt @@ -2,6 +2,7 @@ package com.chutneytesting.kotlin.execution import com.chutneytesting.engine.api.execution.StatusDto import com.chutneytesting.environment.domain.exception.EnvironmentNotFoundException +import com.chutneytesting.environment.domain.exception.UnresolvedEnvironmentException import com.chutneytesting.kotlin.asResource import com.chutneytesting.kotlin.dsl.ForStrategy import com.chutneytesting.kotlin.dsl.Scenario @@ -42,11 +43,11 @@ class ExecutionServiceTest { fun `should throw exception when multi env defined and none asked for`() { val sut = ExecutionService(File("execution/multiEnv".asResource().path).path) - assertThrows { + assertThrows { sut.getEnvironment() } - assertThrows { + assertThrows { sut.getEnvironment(null) } }