From 4546634b78eb35b29473779513aa935f0a7d7d1f Mon Sep 17 00:00:00 2001 From: Mathias Vandaele Date: Tue, 16 Jul 2024 17:26:24 +0200 Subject: [PATCH] other(rabbitMQ): add integration test for rabbitMQ to verify message integrity --- .../integration/RabbitMqIntegrationTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/connectors/rabbitmq/src/test/java/io/camunda/connector/rabbitmq/integration/RabbitMqIntegrationTest.java b/connectors/rabbitmq/src/test/java/io/camunda/connector/rabbitmq/integration/RabbitMqIntegrationTest.java index 8698d9a4d4..3980f19d3a 100644 --- a/connectors/rabbitmq/src/test/java/io/camunda/connector/rabbitmq/integration/RabbitMqIntegrationTest.java +++ b/connectors/rabbitmq/src/test/java/io/camunda/connector/rabbitmq/integration/RabbitMqIntegrationTest.java @@ -136,6 +136,72 @@ void consumeMessageWithInboundConnector() throws Exception { assertEquals("Hello World", body.get("value")); } + @Test + @Order(3) + void publishMessageWithOutboundConnectorAndConsumeMessageWithInboundConnector() throws Exception { + // Given + OutboundConnectorFunction function = new RabbitMqFunction(); + + RabbitMqOutboundRouting routing = + new RabbitMqOutboundRouting( + Routing.EXCHANGE, + Routing.ROUTING_KEY, + Routing.VIRTUAL_HOST, + rabbitMq.getHost(), + rabbitMq.getAmqpPort().toString()); + + // '“' and '”' are special unicode char. + RabbitMqMessage messageOutbound = + new RabbitMqMessage(null, "{\"value\": \"Hello “ ” \\\"World\\\"\"}"); + + RabbitMqRequest request = new RabbitMqRequest(getAuth(), routing, messageOutbound); + + var json = ObjectMapperSupplier.instance().writeValueAsString(request); + OutboundConnectorContext context = + OutboundConnectorContextBuilder.create() + .validation(new DefaultValidationProvider()) + .variables(json) + .build(); + + // When + var result = function.execute(context); + + // Then + assertInstanceOf(RabbitMqResult.class, result); + RabbitMqResult castedResult = (RabbitMqResult) result; + assertEquals("success", castedResult.getStatusResult()); + + + // Given + RabbitMqExecutable executable = new RabbitMqExecutable(); + + RabbitMqInboundProperties properties = new RabbitMqInboundProperties(); + properties.setAuthentication(getAuth()); + properties.setQueueName(ActualValue.QUEUE_NAME); + + FactoryRoutingData routingData = + new FactoryRoutingData( + Routing.VIRTUAL_HOST, rabbitMq.getHost(), rabbitMq.getAmqpPort().toString()); + properties.setRouting(routingData); + + TestInboundConnectorContext contextInbound = + InboundConnectorContextBuilder.create().properties(properties).build(); + + // When + executable.activate(contextInbound); + await().atMost(Duration.ofSeconds(5)).until(() -> !contextInbound.getCorrelations().isEmpty()); + executable.deactivate(); + + // Then + assertEquals(1, contextInbound.getCorrelations().size()); + assertInstanceOf(RabbitMqInboundResult.class, contextInbound.getCorrelations().get(0)); + RabbitMqInboundResult castedResultInbound = (RabbitMqInboundResult) contextInbound.getCorrelations().get(0); + RabbitMqInboundMessage messageInbound = castedResultInbound.message(); + assertInstanceOf(Map.class, messageInbound.body()); + Map body = (Map) messageInbound.body(); + assertEquals("Hello “ ” \"World\"", body.get("value")); + } + private RabbitMqAuthentication getAuth() { return new CredentialsAuthentication(Authentication.USERNAME, Authentication.PASSWORD); }