Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Junit 5 with CamelTestSupport

I'm trying to write unit test with JUnit 5 and Camel support.

  1. JUnit 5 (5.0.0) Using following annotation @ method level in Class A:
@Test
@ParameterizedTest(name = "Test case [{index}] name={3}")
@MethodSource("data")
@IfEnvProfile(profiles = {"preprod"}) (Customized Annotation)
  1. Class A extends CamelTestSupport which is using Junit 4.Trying to hit service with below code:
protected ResponseDto  getReponse(String testFile) throws Exception {
    Transaction tx= new Transaction ();
    final Map<String,Object> headers= setAllHeader(tx);
    // enter code here
    ResponseDto response =
        (RatingResponseDto) template.sendBodyAndHeaders("{{.location.enricher.uri}}",
            ExchangePattern.InOut, tx, headers);
}

where location.enricher.uri - http://localhost/rating-service/api/v1/rate/d155446421121/location/ (is up and running).

but when I run it, I'm always receiving Nullpointer exception on response.

Doubts:

  1. Is it possible to combine JUnit 5 in class A and JUnit 4 in CamelSupport which extends Class A?

  2. Do we have CamelTestSupportClass for JUnit 5?

Could anyone help?

Thanks, Rajesh S

like image 215
Rajesh Avatar asked Jan 03 '23 22:01

Rajesh


2 Answers

Currently Camel supports Junit 5. You just have to include this in your pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-test-junit5</artifactId>
</dependency>

And import the class:

import org.apache.camel.test.junit5.CamelTestSupport;

See here for more information.

like image 58
Joselo Avatar answered Jan 13 '23 18:01

Joselo


  1. No: The class org.apache.camel.test.junit4.CamelTestSupport only works with JUnit 4.
  2. No: Camel does not yet have support for JUnit Jupiter (i.e., JUnit 5), but they have an open issue to add such support in a later release.
like image 45
Sam Brannen Avatar answered Jan 13 '23 20:01

Sam Brannen