barrel
barrel

Reputation: 974

Unexpected Bindy behaviour - camel

When working with bindy, I have create a test that provides invalid CSV input. When looking at the documentation ( http://camel.apache.org/bindy.html ), it states:

If this field is not present in the record, than an error will be raised by the parser with the following information :
Some fields are missing (optional or mandatory), line :

But when I run my test, the invalid line is simply ignored, no errors are raised. I declare three required fields, so I'd expect an error.... What am I doing wrong?

Barry

Here are some code-snippets to clarify

The route

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {

            JaxbDataFormat xmlFormat = new JaxbDataFormat();
            xmlFormat.setContextPath("be.smals.dp.asktutor.response");
            BindyCsvDataFormat csvFormat = new BindyCsvDataFormat ("be.smals.dp.asktutor.response");
            context.setTracing(true);

            from("direct:marshall")
                    .wireTap("log:test")
                    .unmarshal(csvFormat)
                    .to("mock:marshall");

            from("direct:unmarshall")
                    .marshal(xmlFormat)
                    .wireTap("log:test")
                    .to("mock:unmarshall");

        }
    };
}

Part of my test

@Test
public void testTransformFromCSVToXML() throws Exception {

    // Create CSV input and process it
    String payload = AskTutorResponseCSVMother.getInvalidCSVLines();
    template.sendBody("direct:marshall", payload);

    AskTutorsResponse askTutorsResponse = 
        ExchangeToObjectHelper.getAskTutorsResponseObjectFromExchange(
            mockMarshall.getExchanges().get(0));
    assertEquals("00000000123", askTutorsResponse.getAskTutorResponses().get(0).getSsinChild());

The input csv string

public static String getInvalidCSVLines () {
    String payload = "";
    payload += "00000000321;20121212" + NEWLINE;
    payload += "10000000123;10000000321;20131010" + NEWLINE;
    payload += "20000000123;20000000321;20100909" + NEWLINE;
    return payload;        
}

And my (straight-forward) bindings:

@XmlType
@XmlAccessorType(XmlAccessType.NONE)
@CsvRecord(separator = ";", skipFirstLine = false)
public class AskTutorResponse {

    @DataField(pos = 1, required = true)
    @XmlElement(name = "SINNChild", required = true)
    private String ssinChild;

    @DataField(pos = 2)
    @XmlElement(name = "SINNTutor", required = true)
    private String ssinTutor;

    @DataField(pos = 3)
    @XmlElement(name = "date", required = true)
    private String date;

Upvotes: 0

Views: 1087

Answers (1)

Spina
Spina

Reputation: 9366

I've had problems where multiple classes with bindy annotations in the same package failed to properly unmarshal. The reason is that bindy tried to unmarshall each CSV line into an instance of each annotated class. My first fix was to put each bindy class into its own package. I've since written my own bindy data format that allows a single class to be specified as the unmarshal target. Here is the code.

Upvotes: 1

Related Questions