fix: assert Camel route body as String after JSON marshalling

The route calls .marshal().json() before reaching the mock endpoint,
so the body is a JSON String, not a POJO. Removed expectedBodiesReceived
with POJO and getBody(BusinessRulesPayload.class), replaced with
String body assertion using contains().
This commit is contained in:
AlexisLeDain
2026-04-09 16:42:26 +02:00
parent c399627377
commit e928ceacee
2 changed files with 6 additions and 8 deletions
+3 -4
View File
@@ -285,7 +285,6 @@ class BusinessRulesRouteTest {
// ARRANGE // ARRANGE
MockEndpoint mockRabbitMQ = camelContext.getEndpoint("mock:rabbitmq", MockEndpoint.class); MockEndpoint mockRabbitMQ = camelContext.getEndpoint("mock:rabbitmq", MockEndpoint.class);
mockRabbitMQ.expectedMessageCount(1); mockRabbitMQ.expectedMessageCount(1);
mockRabbitMQ.expectedBodiesReceived(testPayload);
// Test için gerçek endpoint'i mock ile değiştir // Test için gerçek endpoint'i mock ile değiştir
camelContext.getRouteController().stopRoute("business-rules-publisher"); camelContext.getRouteController().stopRoute("business-rules-publisher");
@@ -298,12 +297,12 @@ class BusinessRulesRouteTest {
// ACT // ACT
producerTemplate.sendBody("direct:business-rules-publisher", testPayload); producerTemplate.sendBody("direct:business-rules-publisher", testPayload);
// ASSERT // ASSERT — .marshal().json() sonrası body JSON String'dir
mockRabbitMQ.assertIsSatisfied(5000); mockRabbitMQ.assertIsSatisfied(5000);
assertThat(mockRabbitMQ.getExchanges()).hasSize(1); assertThat(mockRabbitMQ.getExchanges()).hasSize(1);
assertThat(mockRabbitMQ.getExchanges().get(0).getIn().getBody(BusinessRulesPayload.class)) String body = mockRabbitMQ.getExchanges().get(0).getIn().getBody(String.class);
.isEqualTo(testPayload); assertThat(body).contains("\"documentId\":1");
} }
@Test @Test
+3 -4
View File
@@ -288,7 +288,6 @@ class BusinessRulesRouteTest {
// ARRANGE // ARRANGE
MockEndpoint mockRabbitMQ = camelContext.getEndpoint("mock:rabbitmq", MockEndpoint.class); MockEndpoint mockRabbitMQ = camelContext.getEndpoint("mock:rabbitmq", MockEndpoint.class);
mockRabbitMQ.expectedMessageCount(1); mockRabbitMQ.expectedMessageCount(1);
mockRabbitMQ.expectedBodiesReceived(testPayload);
// Replace real endpoint with mock for testing // Replace real endpoint with mock for testing
camelContext.getRouteController().stopRoute("business-rules-publisher"); camelContext.getRouteController().stopRoute("business-rules-publisher");
@@ -301,12 +300,12 @@ class BusinessRulesRouteTest {
// ACT // ACT
producerTemplate.sendBody("direct:business-rules-publisher", testPayload); producerTemplate.sendBody("direct:business-rules-publisher", testPayload);
// ASSERT // ASSERT — body is a JSON String after .marshal().json(JsonLibrary.Jackson)
mockRabbitMQ.assertIsSatisfied(5000); mockRabbitMQ.assertIsSatisfied(5000);
assertThat(mockRabbitMQ.getExchanges()).hasSize(1); assertThat(mockRabbitMQ.getExchanges()).hasSize(1);
assertThat(mockRabbitMQ.getExchanges().get(0).getIn().getBody(BusinessRulesPayload.class)) String body = mockRabbitMQ.getExchanges().get(0).getIn().getBody(String.class);
.isEqualTo(testPayload); assertThat(body).contains("\"documentId\":1");
} }
@Test @Test