Skip to content

Commit

Permalink
ci(#1208): reproducer for amqp jms
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Aug 31, 2024
1 parent 622d733 commit 253d38c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
13 changes: 13 additions & 0 deletions endpoints/citrus-jms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
</dependency>

<!-- Test scoped dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>3.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jms</artifactId>
Expand All @@ -102,6 +108,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.rabbitmq.jms</groupId>
<artifactId>rabbitmq-jms</artifactId>
<version>3.2.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-test-support</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.citrusframework.jms.integration;

import com.rabbitmq.jms.admin.RMQConnectionFactory;
import com.rabbitmq.jms.admin.RMQDestination;
import jakarta.jms.ConnectionFactory;
import org.citrusframework.TestCaseRunner;
import org.citrusframework.actions.ReceiveMessageAction;
import org.citrusframework.actions.SendMessageAction;
import org.citrusframework.annotations.CitrusEndpoint;
import org.citrusframework.annotations.CitrusResource;
import org.citrusframework.annotations.CitrusTest;
import org.citrusframework.config.CitrusSpringConfig;
import org.citrusframework.jms.endpoint.JmsEndpoint;
import org.citrusframework.jms.endpoint.JmsEndpoints;
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.testng.annotations.Test;

@Test
@Import({RabbitMQIT.JmsConfiguration.class})
public class RabbitMQIT extends TestNGCitrusSpringSupport {

@CitrusEndpoint
private JmsEndpoint personsQueueCreate;

@Autowired
private CitrusSpringConfig citrusSpringConfig;

@CitrusTest
public void testPost(@CitrusResource TestCaseRunner test) {
test.variable("todoName", "citrus:concat('todo_', citrus:randomNumber(4))");
test.variable("todoDescription", "Description: ${todoName}");

// Use the endpoint configured without a specific destination, set headers in the send action
test.$(SendMessageAction.Builder.send()
.endpoint(personsQueueCreate)
// .fork(false)
.message()
// .header(MP.MIDSA_PARAM_PERSON_ID.s(), "46b85fef-02a0-4f3f-bdf1-aaaa")
// .header(MP.MIDSA_PARAM_BIOMETRIC_INCLUDED.s(), "false")
// .header(MP.MIDSA_PARAM_MAX_RECENT_MOVEMENTS.s(), 1)
.body("{ \"title\": \"${todoName}\", \"description\": \"${todoDescription}\" }")
);

test.$(ReceiveMessageAction.Builder.receive()
.endpoint(personsQueueCreate)
.message()
.body("\"Message received\""));
}

@TestConfiguration
static class JmsConfiguration {

@Bean
public ConnectionFactory connectionFactory() {
RMQConnectionFactory connectionFactory = new RMQConnectionFactory();
connectionFactory.setUsername("xxxxx");
connectionFactory.setPassword("xxxxx");
connectionFactory.setVirtualHost("xxxxxx");
connectionFactory.setHost("localhost");
connectionFactory.setPort(5672); // Replace with appropriate port
return connectionFactory;
}


@Bean
public RMQDestination jmsDestination() {
RMQDestination jmsDestination = new RMQDestination();
jmsDestination.setAmqp(true);
return jmsDestination;
}


@Bean
public JmsEndpoint personsQueueCreate(@Qualifier("connectionFactory") ConnectionFactory connectionFactory,
RMQDestination jmsDestination) {
jmsDestination.setDestinationName("midsa-service-border-guard.persons.get");
jmsDestination.setAmqpExchangeName("midsa.persons.get");
jmsDestination.setAmqpRoutingKey("");
jmsDestination.setAmqpQueueName("midsa-service-border-guard.persons.get");

// Equivalent to:
// return JmsEndpointCatalog.jms()
// .synchronous()

return JmsEndpoints.jms().synchronous()
.connectionFactory(connectionFactory)
.destination(jmsDestination)
.build();
}
}
}

0 comments on commit 253d38c

Please sign in to comment.