11package com .alipay .rdf .file .codec ;
22
3- import com .alipay .rdf .file .exception .RdfFileException ;
43import com .alipay .rdf .file .interfaces .FileFactory ;
54import com .alipay .rdf .file .interfaces .FileReader ;
65import com .alipay .rdf .file .interfaces .FileWriter ;
@@ -31,9 +30,9 @@ public void setUp() throws IOException {
3130 }
3231
3332 /**
34- * de 有columnInfo的序列化与反序列化不支持
33+ * de 有columnInfo的序列化与反序列化
3534 */
36- @ Test ( expected = RdfFileException . class )
35+ @ Test
3736 public void test () throws Exception {
3837 String filePath = tf .getRoot ().getAbsolutePath ();
3938 FileConfig config = new FileConfig (new File (filePath , "test.txt" ).getAbsolutePath (),
@@ -55,7 +54,7 @@ public void test() throws Exception {
5554 body .put ("gmtApply" , testDate );
5655 body .put ("date" , testDate );
5756 body .put ("dateTime" , testDate );
58- body .put ("applyNumber" , 12 );
57+ body .put ("applyNumber" , new BigDecimal ( "12" ) );
5958 body .put ("amount" , new BigDecimal ("1.22" ));
6059 body .put ("age" , new Integer (33 ));
6160 body .put ("longN" , new Long (33 ));
@@ -64,14 +63,14 @@ public void test() throws Exception {
6463 fileWriter .writeRow (body );
6564
6665 testDate = DateUtil .parse ("2016-02-03 12:22:33" , "yyyy-MM-dd HH:mm:ss" );
67-
66+ body = new HashMap < String , Object >();
6867 body .put ("seq" , "seq234567" );
6968 body .put ("instSeq" , "505" );
7069 body .put ("gmtApply" , testDate );
7170 body .put ("date" , testDate );
7271 body .put ("dateTime" , testDate );
73- body .put ("applyNumber" , 12 );
74- body .put ("amount" , new BigDecimal ("1.09" ));
72+ body .put ("applyNumber" , new BigDecimal ( "12" ) );
73+ // body.put("amount", new BigDecimal("1.09"));
7574 body .put ("age" , 66 );
7675 body .put ("longN" , 125 );
7776 body .put ("bol" , false );
@@ -83,17 +82,37 @@ public void test() throws Exception {
8382 //校验文件
8483 BufferedReader reader = new BufferedReader (
8584 new InputStreamReader (new FileInputStream (new File (config .getFilePath ())), "UTF-8" ));
86- Assert .assertEquals ("总笔数:2|总金额:23.22" , reader .readLine ());
85+ Assert .assertEquals ("totalCount: 总笔数:2|totalAmount: 总金额:23.22" , reader .readLine ());
8786 Assert .assertEquals ("流水号|基金公司订单号|订单申请时间|普通日期|普通日期时间|普通数字|金额|年龄|长整型|布尔值|备注" ,
8887 reader .readLine ());
8988 Assert .assertEquals (
90- "seq12345|303|2017-01-03 12:22:33|20170103|20170103 12:22:33|12|1.22|33|33|true|memo1" ,
89+ "seq: seq12345|instSeq: 303|gmtApply: 2017-01-03 12:22:33|date: 20170103|dateTime: 20170103 12:22:33|applyNumber: 12|amount: 1.22|age: 33|longN: 33|bol: true|memo: memo1" ,
9190 reader .readLine ());
9291 Assert .assertEquals (
93- "seq234567|505|2016-02-03 12:22:33|20160203|20160203 12:22:33|12|1.09| 66|125|false|memo2" ,
92+ "seq: seq234567|instSeq: 505|gmtApply: 2016-02-03 12:22:33|date: 20160203|dateTime: 20160203 12:22:33|applyNumber: 12|age: 66|longN: 125|bol: false|memo: memo2" ,
9493 reader .readLine ());
9594
9695 reader .close ();
96+
97+ FileReader fileReader = FileFactory .createReader (config );
98+ head = fileReader .readHead (HashMap .class );
99+ Assert .assertEquals (2L , head .get ("totalCount" ));
100+ Assert .assertEquals (new BigDecimal ("23.22" ), head .get ("totalAmount" ));
101+
102+ body = fileReader .readRow (HashMap .class );
103+ body = fileReader .readRow (HashMap .class );
104+
105+ Assert .assertEquals ("seq234567" , body .get ("seq" ));
106+ Assert .assertEquals ("505" , body .get ("instSeq" ));
107+ Assert .assertEquals ("2016-02-03 12:22:33" , DateUtil .format ((Date ) body .get ("gmtApply" ), "yyyy-MM-dd HH:mm:ss" ));
108+ Assert .assertEquals (new BigDecimal ("12" ), body .get ("applyNumber" ));
109+ Assert .assertEquals (null , body .get ("amount" ));
110+ Assert .assertEquals (66 , body .get ("age" ));
111+ Assert .assertEquals (125L , body .get ("longN" ));
112+ Assert .assertEquals (false , body .get ("bol" ));
113+ Assert .assertEquals ("memo2" , body .get ("memo" ));
114+
115+ fileReader .close ();
97116 }
98117
99118 @ Test
@@ -289,7 +308,7 @@ public void test3() throws Exception {
289308 "|instSeq:999|gmtApply:2016-02-03 12:22:33|dateTime:20160203 12:22:33|amount:1.09|age:66|longN:125|" ,
290309 reader .readLine ());
291310
292- Assert .assertEquals ("|fileEnd:OFDCFEND|" ,reader .readLine ());
311+ Assert .assertEquals ("|fileEnd:OFDCFEND|" , reader .readLine ());
293312
294313 Assert .assertNull (reader .readLine ());
295314 reader .close ();
@@ -309,7 +328,7 @@ public void test3() throws Exception {
309328 }
310329
311330 @ Test
312- public void testKVSplit () throws Exception {
331+ public void testKVSplit () throws Exception {
313332 String filePath = tf .getRoot ().getAbsolutePath ();
314333 FileConfig config = new FileConfig (new File (filePath , "test.txt" ).getAbsolutePath (),
315334 "/codec/kv/template/template6.json" , new StorageConfig ("nas" ));
@@ -370,7 +389,7 @@ public void testKVSplit() throws Exception{
370389 "|seq_@_seq234568|instSeq_@_505|gmtApply_@_2016-02-03 12:22:33|dateTime_@_20160203 12:22:33|amount_@_1.09|age_@_66|longN_@_125|" ,
371390 reader .readLine ());
372391
373- Assert .assertEquals ("|fileEnd_@_OFDCFEND|" ,reader .readLine ());
392+ Assert .assertEquals ("|fileEnd_@_OFDCFEND|" , reader .readLine ());
374393
375394 Assert .assertNull (reader .readLine ());
376395 reader .close ();
0 commit comments