Added a missing test for message sending
This commit is contained in:
@@ -16,9 +16,14 @@
|
||||
|
||||
package org.springframework.cloud.contract.stubrunner
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import org.springframework.cloud.contract.stubrunner.util.StubsParser
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessage
|
||||
import org.springframework.cloud.contract.verifier.messaging.ContractVerifierMessaging
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class StubRunnerExecutorSpec extends Specification {
|
||||
|
||||
static final int MIN_PORT = 8999
|
||||
@@ -71,10 +76,55 @@ class StubRunnerExecutorSpec extends Specification {
|
||||
executor.findStubUrl("group", "artifact") == 'http://localhost:12345'.toURL()
|
||||
}
|
||||
|
||||
def 'should ensure that triggered contracts have properly parsed message body when a message is sent'() {
|
||||
given:
|
||||
StubRunnerExecutor executor = new StubRunnerExecutor(portScanner, new AssertingContractVerifierMessaging())
|
||||
executor.runStubs(stubRunnerOptions, repository, stub)
|
||||
when:
|
||||
executor.trigger('send_order')
|
||||
then:
|
||||
noExceptionThrown()
|
||||
}
|
||||
|
||||
Map<StubConfiguration, Integer> stubIdsWithPortsFromString(String stubIdsToPortMapping) {
|
||||
return stubIdsToPortMapping.split(',').collectEntries { String entry ->
|
||||
return StubsParser.fromStringWithPort(entry)
|
||||
}
|
||||
}
|
||||
|
||||
private class AssertingContractVerifierMessaging implements ContractVerifierMessaging {
|
||||
|
||||
@Override
|
||||
void send(ContractVerifierMessage message, String destination) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage receiveMessage(String destination, long timeout, TimeUnit timeUnit) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage receiveMessage(String destination) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
void send(Object o, Map headers, String destination) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage create(Object o, Map headers) {
|
||||
assert !(JsonOutput.toJson(o).contains("serverValue"))
|
||||
assert headers.entrySet().every { !(it.value.toString().contains("serverValue")) }
|
||||
return null
|
||||
}
|
||||
|
||||
@Override
|
||||
ContractVerifierMessage create(Object o) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
org.springframework.cloud.contract.verifier.dsl.Contract.make {
|
||||
// Human readable description
|
||||
description 'Sends an order message'
|
||||
// Label by means of which the output message can be triggered
|
||||
label 'send_order'
|
||||
// input to the contract
|
||||
input {
|
||||
// the contract will be triggered by a method
|
||||
triggeredBy('orderTrigger()')
|
||||
}
|
||||
// output message of the contract
|
||||
outputMessage {
|
||||
// destination to which the output message will be sent
|
||||
sentTo('orders')
|
||||
// any headers for the output message
|
||||
headers {
|
||||
header('contentType': 'application/json')
|
||||
}
|
||||
// the body of the output message
|
||||
body(
|
||||
orderId: value(
|
||||
consumer('40058c70-891c-4176-a033-f70bad0c5f77'),
|
||||
producer(regex('([0-9|a-f]*-*)*'))),
|
||||
description: "This is the order description"
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user