Bug Report
I am using Spring-Cloud-Contract in Version 2.1.2.RELEASE together with camel-spring-boot-starter(2.24.1) and camel-jms(2.24.1) and an apache-artemis-2.9.0 for Consumer-Driven-Contract-Testing for Messaging. The Bug seems to be also in many other Versions (all Versions i tried have the same problem).
I have the following Contracts:
Contract.make {
name "first command and event A"
input {
messageFrom("jms:queue:myCommandQueue")
messageBody([
xyId : 4711,
timeStamp: "2019-06-28T11:33:45.312"
])
messageHeaders {
header("_MY_MSG_TYPE", "FirstCommand")
}
}
outputMessage {
sentTo("jms:topic:myEventTopic")
body([
erzeugtAm: anyNumber()
])
headers {
header("_MY_MSG_TYPE", "EventA")
}
}
},
Contract.make {
name "second command and event B"
input {
messageFrom("jms:queue:myCommandQueue")
messageBody([
name : "Test",
timeStamp: "2019-06-28T11:33:45.312"
])
messageHeaders {
header("_MY_MSG_TYPE", "SecondCommand")
}
}
outputMessage {
sentTo("jms:topic:myEventTopic")
body([
name:"Test"
])
headers {
header("_MY_MSG_TYPE", "EventB")
}
}
},
Contract.make {
name "Another try with SecondCommand and event B This will fail"
input {
messageFrom("jms:queue:myCommandQueue")
messageBody([
name : "Something really different",
timeStamp: "2019-07-28T11:33:45.312"
])
messageHeaders {
header("_MY_MSG_TYPE", "SecondCommand")
}
}
outputMessage {
sentTo("jms:topic:myEventTopic")
body([
name:"Something really different"
])
headers {
header("_MY_MSG_TYPE", "EventB")
}
}
}
When i write two contracts for a producer in the same Queues and Topics, everything is fine. But(!) when i write the secound Contract with the same message-type, it fails.
(In my real use-cases there are different Contracts, because different consumer use the same message-types and every consumer wants/needs an own Contract)
Failing means the following Exception:
java.lang.NullPointerException: null
at org.springframework.cloud.contract.verifier.messaging.camel.CamelStubMessages.receive(CamelStubMessages.java:79) [spring-cloud-contract-verifier-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.camel.CamelStubMessages.receive(CamelStubMessages.java:90) [spring-cloud-contract-verifier-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.camel.CamelStubMessages.receive(CamelStubMessages.java:38) [spring-cloud-contract-verifier-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging.receive(ContractVerifierMessaging.java:44) [spring-cloud-contract-verifier-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at my.sample.ContractVerifierTest.validate_another_try_with_Secondcommand_and_event_B_This_will_fail(ContractVerifierTest.java:85) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
I have attached the maven-output and a sample-Project (Needs an Artemis on localhost):
maven-output.txt
sample.zip
I am really thankfull for any help with this Problem!
Fixed the NPE and please try adding @DirtiesContext to the base class after each test method https://github.com/spring-cloud/spring-cloud-contract/blob/master/tests/spring-cloud-contract-stub-runner-camel/src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy#L52
Thank you very much! With the @DirtiesContext its working now.
Most helpful comment
Thank you very much! With the @DirtiesContext its working now.