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

  • Home
  • SEARCH
  • 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 6056643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:23:59+00:00 2026-05-23T08:23:59+00:00

I’m trying to write my first code with Apache Camel right now. I try

  • 0

I’m trying to write my first code with Apache Camel right now. I try to follow the examples from Camel in Action, but I want to use my own example data.

What I want to do

Right now I want to read from a CSV file and get each line as a java bean.

Here is my junit test:

@Test
public void testCsvWithBindy() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:queue.csv");
    mock.expectedMessageCount(2);

    assertMockEndpointsSatisfied();

    CsvBean line1 = mock.getReceivedExchanges().get(0).getIn()
            .getBody(CsvBean.class);
    assertEquals("row 01", line1.getFirst());
}

public RouteBuilder createRoute() {
    return new RouteBuilder() {
        public void configure() throws Exception {
            context.setTracing(true);

            from("file://src/test/resources?noop=true&fileName=test.csv")
                .unmarshal().bindy(BindyType.Csv, "my.package.for.csvrecord")
                .to("mock:queue.csv");
        }
    };
}

The CSV contains this:

row 01,row 02,,row 04
row 11, row 12, row 13, row 14

And this is my CsvRecord:

@CsvRecord(separator = ",")
public class CsvBean {
@DataField(pos = 1)
private String first;
@DataField(pos = 2)
private String second;
@DataField(pos = 3)
private String third;
@DataField(pos = 4)
private String fourth;

public String getFirst() {
    return first;
}

public void setFirst(String first) {
    this.first = first;
}

public String getSecond() {
    return second;
}

public void setSecond(String second) {
    this.second = second;
}

public String getThird() {
    return third;
}

public void setThird(String third) {
    this.third = third;
}

public String getFourth() {
    return fourth;
}

public void setFourth(String fourth) {
    this.fourth = fourth;
}
}

My Problem

When I run this test, the context is started and the route is loaded. But nothing is coming through. After about 10s the context is automatically stopped and my test fails. This is the stacktrace:

java.lang.AssertionError: mock://queue.csv Received message count. Expected: <2> but was: <0>
at org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
at org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:1068)
at org.apache.camel.component.mock.MockEndpoint.doAssertIsSatisfied(MockEndpoint.java:367)
at org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:346)
at org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:334)
at org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:172)
at org.apache.camel.test.junit4.CamelTestSupport.assertMockEndpointsSatisfied(CamelTestSupport.java:391)
at my.package.for.unittests.CsvToBeanWithBindyTest.testCsvWithBindy(CsvToBeanWithBindyTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

Need help with

I guess I’m missing something obvious, maybe something that has to do with the test setup and not so much with my CsvRecord or my route. Can you give me a tip or maybe an URL to a better tutorial? The book is not very helpful at this point… 🙁

  • 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-23T08:24:00+00:00Added an answer on May 23, 2026 at 8:24 am

    Again, right after posting my question, I found the answer myself. 😉 Here is a working junit test:

    public class CsvToBeanWithBindyTest extends CamelTestSupport {
    @Test
    public void testCsv() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:queue.csv");
        mock.expectedMessageCount(1);
    
        assertMockEndpointsSatisfied();
    
        List line1 = (List) mock.getReceivedExchanges().get(0).getIn()
                .getBody();
        Map map1 = (Map) line1.get(0);
        CsvBean csv1 = (CsvBean) map1.get("my.package.CsvBean");
        assertEquals("row 01", csv1.getFirst());
    
        Map map2 = (Map) line1.get(1);
        CsvBean csv2 = (CsvBean) map2.get("my.package.CsvBean");
        assertEquals("row 11", csv2.getFirst());
    }
    
    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                context.setTracing(true);
    
                from("file://src/test/resources?noop=true&fileName=test.csv")
                    .unmarshal(new BindyCsvDataFormat("my.package"))
                    .to("mock:queue.csv");
            }
        };
    }
    }
    

    The unexpected thing for me is that I get a List from my endpoint route which in turn holds many Maps. Each map has a key my.package.MyBeanClass with the value set to the actual unmarshalled row from my CSV file.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.