Fixed the bug with regex in GString in messaging

This commit is contained in:
Marcin Grzejszczak
2016-06-21 20:24:20 +02:00
parent bad5d6de50
commit b38372011c
4 changed files with 97 additions and 3 deletions

View File

@@ -64,4 +64,35 @@ class StubRunnerCamelProcessorSpec extends Specification {
then:
message.getIn().getBody(String) == '{"responseId":"123"}'
}
def dslWithRegexInGString = Contract.make {
// Human readable description
description 'Should produce valid sensor data'
// Label by means of which the output message can be triggered
label 'sensor1'
// input to the contract
input {
// the contract will be triggered by a method
triggeredBy('createSensorData()')
}
// output message of the contract
outputMessage {
// destination to which the output message will be sent
sentTo 'sensor-data'
headers {
header('contentType': 'application/json')
}
// the body of the output message
body("""{"id":"${value(producer(regex('[0-9]+')), consumer('99'))}","temperature":"123.45"}""")
}
}
def 'should convert dsl into message with regex in GString'() {
given:
StubRunnerCamelProcessor processor = new StubRunnerCamelProcessor(dslWithRegexInGString)
when:
processor.process(message)
then:
message.getIn().getBody(String) == '''{"id":"99","temperature":"123.45"}'''
}
}

View File

@@ -61,4 +61,35 @@ class StubRunnerIntegrationTransformerSpec extends Specification {
then:
result.payload == '{"responseId":"123"}'
}
def dslWithRegexInGString = Contract.make {
// Human readable description
description 'Should produce valid sensor data'
// Label by means of which the output message can be triggered
label 'sensor1'
// input to the contract
input {
// the contract will be triggered by a method
triggeredBy('createSensorData()')
}
// output message of the contract
outputMessage {
// destination to which the output message will be sent
sentTo 'sensor-data'
headers {
header('contentType': 'application/json')
}
// the body of the output message
body("""{"id":"${value(producer(regex('[0-9]+')), consumer('99'))}","temperature":"123.45"}""")
}
}
def 'should convert dsl into message with regex in GString'() {
given:
StubRunnerIntegrationTransformer transformer = new StubRunnerIntegrationTransformer(dslWithRegexInGString)
when:
def result = transformer.transform(message)
then:
result.payload == '''{"id":"99","temperature":"123.45"}'''
}
}

View File

@@ -61,4 +61,35 @@ class StubRunnerStreamTransformerSpec extends Specification {
then:
result.payload == '{"responseId":"123"}'
}
def dslWithRegexInGString = Contract.make {
// Human readable description
description 'Should produce valid sensor data'
// Label by means of which the output message can be triggered
label 'sensor1'
// input to the contract
input {
// the contract will be triggered by a method
triggeredBy('createSensorData()')
}
// output message of the contract
outputMessage {
// destination to which the output message will be sent
sentTo 'sensor-data'
headers {
header('contentType': 'application/json')
}
// the body of the output message
body("""{"id":"${value(producer(regex('[0-9]+')), consumer('99'))}","temperature":"123.45"}""")
}
}
def 'should convert dsl into message with regex in GString'() {
given:
StubRunnerStreamTransformer streamTransformer = new StubRunnerStreamTransformer(dslWithRegexInGString)
when:
def result = streamTransformer.transform(message)
then:
result.payload == '''{"id":"99","temperature":"123.45"}'''
}
}

View File

@@ -74,10 +74,11 @@ class BodyAsStringUtil {
private static Object extractClientValueFromBody(bodyValue) {
if (bodyValue instanceof GString) {
bodyValue = extractValue(bodyValue, { DslProperty dslProperty -> dslProperty.clientValue })
return extractValue(bodyValue, { DslProperty dslProperty -> dslProperty.clientValue })
} else if (bodyValue instanceof DslProperty) {
return extractClientValueFromBody(bodyValue.clientValue)
} else {
bodyValue = MapConverter.transformValues(bodyValue, { it instanceof DslProperty ? it.clientValue : it })
return MapConverter.transformValues(bodyValue, { it instanceof DslProperty ? it.clientValue : it })
}
return bodyValue
}
}