nickmza / BlogComments

Store Comments from the Blog using GitTalk
0 stars 0 forks source link

Unit Testing Camel - A simple example | nick dot blog #13

Open nickmza opened 1 year ago

nickmza commented 1 year ago

https://nickmck.net/2023/05/18/camel-simple/

imne commented 1 year ago

this worked perfectly, thank you so much appreciate the speedy response and effort on this.

I tried to write a test where a number format exception happens I was trying to verify if the test would go into the onexception section and that seems to have worked fine

    @Test
    public void error() throws Exception {

        AdviceWith.adviceWith(camelContext,
                "simple-rest",
                rb -> rb.replaceFromWith("direct:file:start"));

        AdviceWith.adviceWith(camelContext,
                "simple-rest",
                rb -> rb.weaveByToUri("https://en1gvb5qo7vg4.x.pipedream.net")
                        .replace()
                        .throwException(new NumberFormatException()));

        camelContext.start();

        producerTemplate.sendBody("direct:file:start", "Hello");
    }

on the simpleRestRoute all I added was a catch to handle the number format exception

        onException(NumberFormatException.class)
                .handled(true)
                        .log("Dummy Number Format"); 
imne commented 1 year ago

think I have a much better understanding now