1616
1717package com .example ;
1818
19-
2019import java .util .HashMap ;
2120import java .util .Map ;
2221import java .util .concurrent .TimeUnit ;
2322
2423import javax .annotation .Nullable ;
2524
26- import com .fasterxml .jackson .core .JsonProcessingException ;
27- import com .fasterxml .jackson .databind .ObjectMapper ;
2825import org .assertj .core .api .BDDAssertions ;
2926import org .awaitility .Awaitility ;
3027import org .junit .jupiter .api .Test ;
5148import org .springframework .test .context .DynamicPropertyRegistry ;
5249import org .springframework .test .context .DynamicPropertySource ;
5350
54- @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .NONE , classes = { TestConfig .class , Application .class }, properties = "stubrunner.amqp.mockConnection=false" )
51+ @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .NONE , classes = {TestConfig .class , Application .class }, properties = "stubrunner.amqp.mockConnection=false" )
5552@ AutoConfigureStubRunner (ids = "com.example:beer-api-producer-rabbit-middleware" , stubsMode = StubRunnerProperties .StubsMode .LOCAL )
5653@ Testcontainers
5754@ ActiveProfiles ("test" )
@@ -77,7 +74,7 @@ public void contextLoads() {
7774
7875 Awaitility .await ().untilAsserted (() -> {
7976 BDDAssertions .then (this .application .storedFoo ).isNotNull ();
80- BDDAssertions .then (this .application .storedFoo .getFoo ()).contains ("example" );
77+ BDDAssertions .then (this .application .storedFoo .getFoo ()).isEqualTo ("example" );
8178 });
8279 }
8380}
@@ -103,7 +100,7 @@ public Message receive(String destination, YamlContract contract) {
103100
104101 @ Override
105102 public void send (Message message , String destination , @ Nullable YamlContract contract ) {
106- rabbitTemplate .send (destination , message );
103+ rabbitTemplate .send (destination , message );
107104 }
108105
109106 @ Override
@@ -112,12 +109,12 @@ public <T> void send(T payload, Map<String, Object> headers, String destination,
112109 MessageProperties messageProperties = new MessageProperties ();
113110 newHeaders .forEach (messageProperties ::setHeader );
114111 log .info ("Sending a message to destination [{}] with routing key" , destination );
115- try {
116- Message message = MessageBuilder .withBody (new ObjectMapper ().writeValueAsBytes (payload )).andProperties (messageProperties ).build ();
112+ if (payload instanceof String ) {
113+ String json = (String ) payload ;
114+ Message message = MessageBuilder .withBody (json .getBytes (StandardCharsets .UTF_8 )).andProperties (messageProperties ).build ();
117115 send (message , destination , contract );
118- }
119- catch (JsonProcessingException e ) {
120- throw new IllegalStateException (e );
116+ } else {
117+ throw new IllegalStateException ("Payload is not a String" );
121118 }
122119 }
123120 };
0 commit comments