Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMS Support for Quarkus #1198

Open
npapageorgopoulos opened this issue Aug 12, 2024 · 1 comment
Open

JMS Support for Quarkus #1198

npapageorgopoulos opened this issue Aug 12, 2024 · 1 comment
Labels
Prio: Medium State: To discuss In case there are open questions concerning the issue Type: Question

Comments

@npapageorgopoulos
Copy link

npapageorgopoulos commented Aug 12, 2024

Citrus Version
4.1.0

I am getting error:

Unable to find bean reference for type 'class org.citrusframework.jms.endpoint.JmsEndpoint'

If I use Spring Beans instead, it is going to work.
I tried to follow similar format as Kafka sample from here

Test case sample

@ApplicationScoped
public class EndpointConfig {

    private final Config config = ConfigProvider.getConfig();
    //You can assume i am getting from configfile the brokerUrl, username,  password, inboundDestination, reportDestination variables

    @BindToRegistry
    public ConnectionFactory connectionFactory() {
        JmsConnectionFactory connectionFactory = new JmsConnectionFactory(brokerUrl);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        return connectionFactory;
    }
    @BindToRegistry
    public JmsEndpoint todoJmsEndpoint(@Mock ConnectionFactory connectionFactory) {
        System.out.println("Inbound Destination: " + inboundDestination);
        return CitrusEndpoints.jms()
                .asynchronous()
                .connectionFactory(connectionFactory)
                .destination(inboundDestination)
                .build();
    }

    @BindToRegistry
    public JmsEndpoint todoReportEndpoint(@Mock ConnectionFactory connectionFactory) {
        System.out.println("Report Destination: " + reportDestination);
        return CitrusEndpoints.jms()
                .asynchronous()
                .connectionFactory(connectionFactory)
                .destination(reportDestination)
                .build();
    }
}

@QuarkusTest
@CitrusSupport
@CitrusConfiguration(classes = {EndpointConfig.class})
public class MyTests extends TestNGCitrusSupport {

    @CitrusEndpoint
    private JmsEndpoint todoJmsEndpoint;

    @CitrusEndpoint
    private JmsEndpoint todoReportEndpoint;

    @CitrusResource
    TestCaseRunner t;

    @Test
    public void testSendTodoMessage() throws IOException {

        String addTodoEntryPayload = new String(Files.readAllBytes(Paths.get("src/test/resources/mocks/addTodoEntry.json")));

        t.when(send(todoJmsEndpoint)
                .message()
                .header("_type", "JSONObject")
                .body(addTodoEntryPayload));
    }

    @Test
    public void testReceiveMessage() throws IOException {

        String addTodoEntryPayload = new String(Files.readAllBytes(Paths.get("src/test/resources/mocks/addTodoEntry.json")));
        t.then(receive(todoJmsEndpoint)
                .message()
                        .timeout(1500L)
                .header("_type", "JSONObject")
                .body(addTodoEntryPayload));
    }

    @Test
    public void testSendTodoReportMessage() throws IOException {

        String addTodoEntryPayload = new String(Files.readAllBytes(Paths.get("src/test/resources/mocks/reportTodoEntryDone.json")));

        t.when(send(todoReportEndpoint)
                .message()
                .header("_type", "JSONObject")
                .body(addTodoEntryPayload));
    }

    @Test
    public void testReceiveNoBodyMessage() throws IOException {

        String addTodoEntryPayload = new String(Files.readAllBytes(Paths.get("src/test/resources/mocks/reportTodoEntryDone.json")));

        t.then(receive(todoReportEndpoint)
                .message()
                .header("_type", "JSONObject")
                .validate((message, context) -> {
                    // Only validate headers
                    Assert.assertEquals(message.getHeader("_type"), "JSONObject");
                    // Ignore body
                }));
    }
}
@bbortt
Copy link
Collaborator

bbortt commented Aug 31, 2024

that sounds like a dependency/setup problem. are you mixing citrus-spring and citrus-quarkus? spring beans are quit obviously not going to work with quarkus...

@bbortt bbortt added State: To discuss In case there are open questions concerning the issue Type: Question Prio: Medium labels Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prio: Medium State: To discuss In case there are open questions concerning the issue Type: Question
Projects
None yet
Development

No branches or pull requests

2 participants