Hi Evert-Jan,

I found a working Junit5 solution in current camel and addded a comment a working files to the JIRA issue. But so far I didn't figure out why it no longer works with Junit4.

Regards,
Karen Lease

On 06/09/2021 11:22, Evert-Jan de Bruin wrote:
Hi Claus,

I have created a JIRA issue with a sample testcase: 
https://issues.apache.org/jira/browse/CAMEL-16925

Thank you!

Evert-Jan de Bruin

-----Oorspronkelijk bericht-----
Van: Claus Ibsen <[email protected]>
Verzonden: zaterdag 4 september 2021 22:50
Aan: [email protected]
Onderwerp: Re: CamelSpringBootRunner no longer working since 3.5.0?

Hi

Put together a small spring boot sample app that does this web app port number 
testing thingy, and add the Camel route.
Then put it on github somewhere or create a JIRA and attach a .zip file so 
others can take a look.

On Sat, Sep 4, 2021 at 10:34 PM Evert-Jan de Bruin 
<[email protected]> wrote:

Hi there,

Thanks, but this is not what we are looking for nor how all our integration 
tests are setup right now.

I know Camel provides a myriad of ways to test your routes by changing parts of 
the route as a mock. We also use that for unit-testing our Processors. It is 
how I started out for integration tests as well, until a colleague pointed out 
we should test the route *as is* and just mock the REST call and other 
endpoints. From an integration point of view (treating camel routes as a black 
box) this is a more 'pure' form of testing. Also, it makes it easier to test 
certain how our route is handling HTTP requests and responses, which are harder 
to mock with direct: routes.

So from a functional point of view: can we still do integration tests on REST 
services in Camel, where the routes are not altered in any form and an actual 
webserver boots and runs the route? Or has there been a conscious choice to no 
longer support that scenario?

Regards,
Evert-Jan


-----Oorspronkelijk bericht-----
Van: [email protected] <[email protected]>
Verzonden: vrijdag 3 september 2021 22:06
Aan: Evert-Jan de Bruin <[email protected]>
CC: [email protected]
Onderwerp: Re: CamelSpringBootRunner no longer working since 3.5.0?

Hi!

I have walked your way recently.

That is what I achieved.

build.gradle:
_____________
     testImplementation 'org.springframework.boot:spring-boot-starter-
test'
     testImplementation 'org.apache.camel:camel-test-spring-
junit5:3.11.0'


test:
_____

@SpringBootTest(classes = MyApplication.class) // for run test
@CamelSpringBootTest // for autowire and start Camel Context
@UseAdviceWith // for modify routes to be able to test them
@Transactional // for not to save into database public class MyTest {

   @Autowired
   CamelContext camelContext;

   @Test
   void anyTest {
     // you must use advice before starting Camel context
     doMockEndpoints();
     // prepare your data

     MockEndpoint resultEndpoint =
camelContext.getEndpoint(MOKED_ENPOINT_URI, MockEndpoint.class);

     // you must start the context manually
     camelContext.start();

     // set up of mock endpoint
     resultEndpoint.expectedMessageCount(1);
     resultEndpoint.expectedBodiesReceived(aRequest());

     producerTemplate.sendBody(START_ENDPOINT_URI,
objectMapper.writeValueAsString(anIssueCardRequest()));

     // check if result was satisfied
     resultEndpoint.assertIsSatisfied();
     // and stop the context manually
     camelContext.stop();

   }

   private void doMockEndpoints() throws Exception {
     AdviceWith.adviceWith(camelContext, ROUTE_ID, in -> {
             in.interceptSendToEndpoint(ENDPOINT_URI).setBody().body(ex
-> marshal(aDto()));
     });
   }
}

_________

All endpoints URIs must be changed from real connections to "direct".
If you write second test (method) inside this class (if you have two and more 
tests inside the Class Test) you should mark each test with @DirtiesContext.


On Fri, 2021-09-03 at 19:09 +0000, Evert-Jan de Bruin wrote:
Hi,

I have tried the Junit5 / spring-boot example as well. Does not work
either, unfortunately.

The difference with the sample in github is that I am trying to run
an actual webserver in my test listening on a certain port, the
example is only running a timer router.

I have tried to modify the example to run as a webserver, but that
gives me problems as well.

Regards
Evert-Jan


-----Oorspronkelijk bericht-----
Van: Claus Ibsen <[email protected]>
Verzonden: vrijdag 3 september 2021 17:09
Aan: [email protected]
Onderwerp: Re: CamelSpringBootRunner no longer working since 3.5.0?

Hi

Take a look at the camel-spring-boot example how its unit tested
https://github.com/apache/camel-spring-boot-examples/blob/main/sprin
g- boot/src/test/java/sample/camel/MyCamelApplicationJUnit5Test.java

You should not use @RuntWith anymore

On Fri, Sep 3, 2021 at 4:33 PM Evert-Jan de Bruin
<[email protected]> wrote:

Hello,



We are currently (happily) using Camel 3.4.4.



When trying to upgrade to any version beyond 3.5.0 (also 3.11.1),
our integration tests won’t run anymore. At first it complained
about the @LocalServerPort annotation not working, but it turned
out the spring boot (including the webserver) just wasn’t loading properly.



I have reduced it to a very simple testcase:

@SpringBootTest(classes = StudentMain.class, webEnvironment =
SpringBootTest.WebEnvironment.DEFINED_PORT)

@ActiveProfiles("integrationtest")

@RunWith(CamelSpringBootRunner.class)

public class ConfigsRouteBuilderTest  {



     private int port = 8080;



     @Test

     public void testConfigsRoute() throws Exception {

         HttpEntity<String> httpEntity = new HttpEntity<String>(new
HttpHeaders());

         String uri =
String.format(http://localhost:%d/integrationtest/hello, port);

         ResponseEntity<String> response = new
RestTemplate().exchange(uri, HttpMethod.GET, httpEntity,
String.class);



         assertEquals("<text>hello world!</text>",
response.getBody());

     }



}


When I try to run this test with 3.4.4, it runs fine. When I try
to run it with Apache camel 3.5.0 or 3.11.1, it is simply not
starting right. The CampelSpringBootRunner does not seem to kick into action.
There is no spring boot logo, no tomcat starting and the test
obviously fails with “I/O error on GET request for
http://localhost:8080/integrationtest/hello: Connection refused”

Does anyone know what I miss to get things going? Do I need to use
different annotations since 3.5.0?

I have also tested with jUnit5 instead of 4, this didn’t make a
difference.

I am new to this group and not sure if this group allows
attachments, but I have added my pom.xml for reference and could
provide a ZIP of the whole testcase as well.

Regards,
Evert-Jan







Evert-Jan de Bruin | Software Architect | CACI bv | De Ruijterkade
7,
1013 AA Amsterdam | +31 (088) 654 35 00 |
[email protected]
| www.caci.nl





--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

--
_________________
Vyacheslav Boyko,
mailto:[email protected]



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to