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

Commit

Permalink
chore: allow body and payload to be String or Map
Browse files Browse the repository at this point in the history
- minor fixes
  • Loading branch information
iguissouma authored and nbrouand committed Sep 30, 2020
1 parent c0fcb06 commit 16a5fea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ChutneyStepBuilder(var description: String = "") {
target: String,
uri: String,
headers: Map<String, Any> = mapOf(),
body: Map<String, Any> = mapOf(),
body: Any,
timeout: String = "2 sec",
outputs: Map<String, Any> = mapOf("body".toSpelPair()),
strategy: Strategy? = null
Expand All @@ -133,7 +133,7 @@ class ChutneyStepBuilder(var description: String = "") {
target: String,
topic: String,
headers: Map<String, Any> = mapOf(),
payload: Map<String, Any> = mapOf()
payload: Any
) {
implementation = ChutneyStepImpl(
type = "kafka-basic-publish",
Expand All @@ -149,7 +149,7 @@ class ChutneyStepBuilder(var description: String = "") {
group: String,
properties: Map<String, String> = mapOf("auto.offset.reset" to "earliest"),
timeout: String = "60 sec",
selector: String,
selector: String = "",
outputs: Map<String, Any> = mapOf()
) {
implementation = ChutneyStepImpl(
Expand All @@ -171,7 +171,7 @@ class ChutneyStepBuilder(var description: String = "") {
queueName: String,
nbMessages: Int = 1,
timeout: String = "60 sec",
selector: String,
selector: String = "",
outputs: Map<String, Any> = mapOf()
) {
implementation = ChutneyStepImpl(
Expand Down Expand Up @@ -205,14 +205,14 @@ class ChutneyStepBuilder(var description: String = "") {
)
}

fun JmsSenderTask(target: String, queueName: String, payload: String) {
fun JmsSenderTask(target: String, queueName: String, headers: Map<String, Any> = mapOf(), payload: String) {
implementation = ChutneyStepImpl(
type = "jms-sender",
target = target,
inputs = mapOf(
"destination" to queueName,
"body" to payload,
"headers" to mapOf("X--JMS-VERSION" to "1.0", "X--HEADER-1" to "42")
"headers" to headers
),
outputs = mapOf()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.chutneytesting.kotlin.dsl
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import java.io.File
import java.util.regex.Pattern

class ChutneyScenarioDslGenerator {

Expand Down Expand Up @@ -81,9 +82,9 @@ private fun mapDebugTask(implementation: ChutneyStepImpl): String {

private fun mapSleepTask(implementation: ChutneyStepImpl): String {
val inputs = implementation.inputs
val timeout = inputAsString(inputs, "queue-name")
val duration = inputAsString(inputs, "duration")
val listOfArgs = listOf(
"timeout" to timeout
"duration" to duration
)
val args = mapArgs(listOfArgs)
return """{
Expand Down Expand Up @@ -282,3 +283,14 @@ fun escapeKotlin(s: String): String {
//.replace("'£", "'$")
}

val spelPattern = Pattern.compile("\\$\\{#(.*?)}")

fun toKotlinSpelString(s: String): String {
val sb = StringBuffer()
val m = spelPattern.matcher(s)
while (m.find()) {
m.appendReplacement(sb, "\\$\\{\"${m.group(1)}\".spEL()}")
}
m.appendTail(sb)
return sb.toString()
}

0 comments on commit 16a5fea

Please sign in to comment.