Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:15:46+00:00 2026-05-30T19:15:46+00:00

I have the below route. In unit test, since I doesn’t have the FTP

  • 0

I have the below route. In unit test, since I doesn’t have the FTP server available, I’d like to use camel’s test support and send an invalid message to "ftp://hostname/input" and verify that it failed and routed to "ftp://hostname/error".

I gone through the documentation which mainly talks about using the “mock:” endpoint but I am not sure how to use it in this scenario.

public class MyRoute extends RouteBuilder
{
    @Override
    public void configure()
    {
        onException(EdiOrderParsingException.class).handled(true).to("ftp://hostname/error");

        from("ftp://hostname/input")
            .bean(new OrderEdiTocXml())
            .convertBodyTo(String.class)
            .convertBodyTo(Document.class)
            .choice()
            .when(xpath("/cXML/Response/Status/@text='OK'"))
            .to("ftp://hostname/valid").otherwise()
            .to("ftp://hostname/invalid");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:15:47+00:00Added an answer on May 30, 2026 at 7:15 pm

    As Ben says you can either setup a FTP server and use the real components. The FTP server can be embedded, or you can setup a FTP server in-house. The latter is more like an integration testing, where you may have a dedicated test environment.

    Camel is very flexible in its test kit, and if you want to build an unit test that do not use the real FTP component, then you can replace that before the test. For example in your example you can replace the input endpoint of a route to a direct endpoint to make it easier to send a message to the route. Then you can use an interceptor to intercept the sending to the ftp endpoints, and detour the message.

    The advice with part of the test kit offers these capabilities: http://camel.apache.org/advicewith.html. And is also discussed in chapter 6 of the Camel in action book, such as section 6.3, that talks about simulating errors.

    In your example you could do something a like

    public void testSendError() throws Exception {
        // first advice the route to replace the input, and catch sending to FTP servers
        context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:input");
    
                // intercept valid messages
                interceptSendToEndpoint("ftp://hostname/valid")
                    .skipSendToOriginalEndpoint()
                    .to("mock:valid");
    
                // intercept invalid messages
                interceptSendToEndpoint("ftp://hostname/invalid")
                    .skipSendToOriginalEndpoint()
                    .to("mock:invalid");
            }
        });
    
         // we must manually start when we are done with all the advice with
        context.start();
    
        // setup expectations on the mocks
        getMockEndpoint("mock:invalid").expectedMessageCount(1);
        getMockEndpoint("mock:valid").expectedMessageCount(0);
    
        // send the invalid message to the route
        template.sendBody("direct:input", "Some invalid content here");
    
        // assert that the test was okay
        assertMockEndpointsSatisfied();
    }
    

    From Camel 2.10 onwards we will make the intercept and mock a bit easier when using advice with. As well we are introducing a stub component. http://camel.apache.org/stub

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my ASP.NET MVC 3 App, I have a route constraint defined like below:
I am wondering if i can have a route like below. var newHandler =
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I
I have below code to insert a style into DOM (there is a use
i have defined a route as below: context.MapRoute(SearchEngineWebSearch, search/web/{query}/{index}/{size}, new { controller = search,
In ASP.NET MVC, I have a defined catch-all route as below: routes.MapRoute( TagsRoute, tags/{*tags},
In my global.asax I have url routing setup like below: routes.MapPageRoute(User Logon, {Vendor}/Logon, ~/Logon.aspx);
I have a simple file XML like below: <brandName type=http://example.com/codes/bmw# abbrev=BMW value=BMW />BMW</brandName> <maxspeed>
I have a number of different structs like below (obviously a little more involved
I have a form like below:- <% using ( Html.BeginForm(search, home, FormMethod.Get) ) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.