0

使用 bindy 时,我创建了一个提供无效 CSV 输入的测试。查看文档(http://camel.apache.org/bindy.html)时,它指出:

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 :

但是当我运行我的测试时,无效行会被忽略,不会引发错误。我声明了三个必填字段,所以我预计会出现错误......我做错了什么?

巴里

这里有一些代码片段来澄清

路线

@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");

        }
    };
}

我测试的一部分

@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());

输入 csv 字符串

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

还有我的(直截了当的)绑定:

@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;
4

1 回答 1

1

我遇到了在同一个包中具有绑定注释的多个类无法正确解组的问题。原因是 bindy 试图将每个 CSV 行解组为每个带注释的类的实例。我的第一个解决方法是将每个绑定类放入自己的包中。从那以后,我编写了自己的绑定数据格式,允许将单个类指定为解组目标。这是代码。

于 2013-05-06T23:17:45.210 回答