How can I test a direct route with MQ?

Viewed 30

I have a camel 3 with springboot application that contains this route:

public class SendForRatingRoute  extends RouteBuilder
{   
    public void configure() throws Exception
    {
        onException(Exception.class)
            .handled(true)
            .process(exProcessor);
        
            // Queue
            String qn = "ratingmq:queue:MY_OUT_QUEUE");         
            from("direct:sendRate") 
            .routeId("sendRate")        
            .bean(MessagingBean.class, "createMessage" )//creates input object 
            .marshal().xstream()
            .log(LoggingLevel.INFO,logger, "~~~ sending to MQ: ${body} " )
            .to(qn)
            .log(LoggingLevel.INFO,logger, "~~~ Message was sent to MQ successfully ");
    }   `
}

this route takes an Order object as input, converts it to a java class that matches the Queue message schema (in the MessagingBean) and then mashall that class to XML and send it to an IBM MQ endpoint. (for simplicity the configuration of the queue is skipped)

I need to write a test case that passes a sample order to this route and see if it actually sends it to the queue correctly. (I want the message to get sent and not mock the sending)

I created a test class like this:

class SendForRatingTest extends CamelTestSupport 
{
    public void setUp() throws Exception 
    {
        super.setUp();
    }   
    
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
         return new SendForRatingRoute();
    }    
    
    @Test
    void testSendingForRating()  throws Exception 
    {       
        template.sendBody("direct:sendRate", getSampleOrder());
        assertTrue(true); //??
    }
}

The method GetSampleOrder() creates the order object with sample data to pass to the route.

I am not sure if I am doing this right (I have never written test case for camel before) When I try to run the test case using maven:
mvn test -Dtest=SendForRatingTest -X

I am getting this error:

<<< ERROR!
org.junit.platform.commons.PreconditionViolationException: You must register at least one TestTemplateInvocationContextProvider that supports @TestTemplate method [void SendForRatingTest.testSendingForRating() throws java.lang.Exception]

What am I doing wrong? Also I am not sure how to test that the route was executed successfully. Ultimately I am going to check the queue for a message but also I want the route test to validate it worked without errors. Since I don't return anything in the route, I am not sure what to put in the assertTrue()

Thank you in advance.

0 Answers
Related