Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Feat/vars #132

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,9 +14,10 @@ reckon {
}

subprojects {
extra["chutneyTestingVersion"] = "2.5.1"
extra["chutneyTestingVersion"] = "2.6.1"

repositories {
mavenLocal()
mavenCentral()
}

Expand All @@ -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<KotlinCompile> {
Expand Down
2 changes: 1 addition & 1 deletion dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ChutneyTarget> = emptyList()
val targets: List<ChutneyTarget> = emptyList(),
val variables: Map<String, String> = emptyMap()
) {

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ 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

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
Expand All @@ -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,
Expand All @@ -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
)
)
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<CannotResolveDefaultEnvironmentException> {
assertThrows<UnresolvedEnvironmentException> {
sut.getEnvironment()
}

assertThrows<CannotResolveDefaultEnvironmentException> {
assertThrows<UnresolvedEnvironmentException> {
sut.getEnvironment(null)
}
}
Expand Down
Loading