You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:58:48 UTC

[GitHub] [camel-quarkus] rschlegel-cc opened a new issue #1981: Mocking endpoints in camel-quarkus tests

rschlegel-cc opened a new issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981


   camel-quarkus seems to be lacking a way for dealing with mocks for external endpoints in tests: we have Camel routes and use them in Quarkus. For testing, @QuarkusTest works really well and provides us with a CamelContext and everything else we need. 
   
   Things get tricky though when we want to mock external endpoints within existing routes, e.g. a call to an external HTTP service. This can be done using AdviceWithRouteBuilder and mockEndpointsAndSkip or more elaborate interceptors, but it modifies the CamelContext. Therefore tests are no longer independent and may fail or succeed depending on the execution order. 
   
   Using CamelTestSupport fixes this, as the CamelContext is recreated between tests but using a different CamelContext than the one created by QuarkusTest seems like a bad idea. It also seems to cause issues for certain routes, as the context might not contain everything that is needed, so I would assume that mixing CamelTestSupport and @QuarkusTest should be avoided. 
   
   To get a better idea of how this could be done I also looked at the Spring integration and saw that there are annotations that help with endpoint mocking and dealing with dirty contexts. Does something comparable (or plans for it) exist for camel-quarkus? If not, are there examples/best practices for dealing with scenarios like this? Thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] neoxu999 commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
neoxu999 commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-941738193


   Hi @jamesnetherton , in most cases, we only need CamelTestSupport in JVM testing, mocking routes.
   For native, we can use integration test.
   Can you please provide some advice? How to move camel-test to camel-quarkus-test? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] neoxu999 edited a comment on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
neoxu999 edited a comment on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-942753749






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
aldettinger commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-993348284


   Hey, great hack :)
   
   It reminds me of an e-mail with Dennis Holunder posted in the community
   with the subject "Testing route in Camel Quarkus".
   I think it reported that it was working in JVM mode and there was just an
   issue with logging. Not sure it's still the case anyway.
   
   My 2 cents,
   Alex
   
   On Tue, Dec 14, 2021 at 10:23 AM Amos Feng ***@***.***> wrote:
   
   > A simple hack way could be
   >
   > @QuarkusTest
   > public class TransactedTest extends CamelTestSupport {
   >     @Inject
   >     CamelContext context;
   >
   >     @Override
   >     protected CamelContext createCamelContext() throws Exception {
   >         return this.context;
   >     }
   > }
   >
   > you can check it out on camel-test-demo
   > <https://github.com/zhfeng/camel-test-demo>.
   >
   > —
   > You are receiving this because you were mentioned.
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/camel-quarkus/issues/1981#issuecomment-993339484>,
   > or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AFJABNOJ65KG5MBPRUEVVILUQ4EKTANCNFSM4THJUCVA>
   > .
   > Triage notifications on the go with GitHub Mobile for iOS
   > <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
   > or Android
   > <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
   >
   >
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] neoxu999 commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
neoxu999 commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-941738193


   Hi @jamesnetherton , in most cases, we only need CamelTestSupport in JVM testing, mocking routes.
   For native, we can use integration test.
   Can you please provide some advice? How to move camel-test to camel-quarkus-test? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
aldettinger commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-942007484


   Hi @neoxu999, I think we are all very busy with other subjects those days but if you are able to invest time for a long effort to explore this path on your own, then here are few directions I could point.
   
   Some users reported that they were able to @Inject a camel route in a @QuarkusTest. This apporach can't be the solution in my opinion and it had some limitations, for instance logging. But it could be a way to start playing with this subject.
   
   Camel Quarkus is about mixing the best of Camel and Quarkus, so for tests I would naively say we would need a @CamelQuarkusTest junit 5 annotation that would somehow assemble the functionalities from @QuarkusTest and CamelTestSupport. Maybe, the first step would be to read/train with JUnit5 annotations, quarkus/cdi lifecycle, see how @QuarkusTest and CamelTestSupport have been implemented.
   
   And on the long run, thinking about an approach that would allow @CamelQuarkusTest to be executed in native mode also would be killer feature. We would maybe need a way to serialize every test related objects from test process to the quarkus application under test process...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] neoxu999 edited a comment on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
neoxu999 edited a comment on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-942753749


   Hi @aldettinger , thanks for your very detailed guides, including short and long plan. I will try to add @CamelQuarkusTest and make the JVM works first.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] zhfeng commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
zhfeng commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-993339484


   A simple hack way could be 
   ```
   @QuarkusTest
   public class TransactedTest extends CamelTestSupport {
       @Inject
       CamelContext context;
   
       @Override
       protected CamelContext createCamelContext() throws Exception {
           return this.context;
       }
   }
   ```
   
   you can check it out on [camel-test-demo](https://github.com/zhfeng/camel-test-demo).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] ppalaga commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
ppalaga commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-848998234


   I filed https://github.com/apache/camel-quarkus/issues/2679 to improve the testing page in our user guide.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] neoxu999 commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
neoxu999 commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-942753749


   Hi @aldettinger , thanks for your very detailed guides. I will try to add @CamelQuarkusTest first and make the JVM works first.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] rschlegel-cc commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
rschlegel-cc commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-721033489


   Thanks for the quick response, this helps quite a bit. And just to be absolutely sure that I did not misunderstand anything: CamelTestSupport should not be used together with camel-quarkus, right? 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] tstuber commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
tstuber commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-790781526


   I agree with @rschlegel-cc , it would be very helpful if there would be some more guidance for how to mock endpoints.
   We face many situations where we would like to build unit tests routes while mocking the actual endpoints.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] jamesnetherton commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-720559807






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
aldettinger commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-942007484


   Hi @neoxu999, I think we are all very busy with other subjects those days but if you are able to invest time for a long effort to explore this path on your own, then here are few directions I could point.
   
   Some users reported that they were able to @Inject a camel route in a @QuarkusTest. This apporach can't be the solution in my opinion and it had some limitations, for instance logging. But it could be a way to start playing with this subject.
   
   Camel Quarkus is about mixing the best of Camel and Quarkus, so for tests I would naively say we would need a @CamelQuarkusTest junit 5 annotation that would somehow assemble the functionalities from @QuarkusTest and CamelTestSupport. Maybe, the first step would be to read/train with JUnit5 annotations, quarkus/cdi lifecycle, see how @QuarkusTest and CamelTestSupport have been implemented.
   
   And on the long run, thinking about an approach that would allow @CamelQuarkusTest to be executed in native mode also would be killer feature. We would maybe need a way to serialize every test related objects from test process to the quarkus application under test process...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
aldettinger commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-943165023


   The root of this ticket is about being able to mock an endpoint. I guess experimenting with @CamelQuarkusTest that allow to mock an endpoint would be a good first experiment in scope of this ticket. We can refine later on if needed. Let me assign the ticket then.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] neoxu999 commented on issue #1981: Mocking endpoints in camel-quarkus tests

Posted by GitBox <gi...@apache.org>.
neoxu999 commented on issue #1981:
URL: https://github.com/apache/camel-quarkus/issues/1981#issuecomment-942838086


   Hi @aldettinger, I checked the new extension guide. 
   _"Let others know that you work on the given extension by either creating a new issue or asking to assign an existing one to you."_
   https://camel.apache.org/camel-quarkus/latest/contributor-guide/create-new-extension.html
   
   May I get your permission to assign this task to me?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org