01: package com.bostechcorp.cbesb.runtime.parser;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.FileOutputStream;
06: import java.io.InputStream;
07:
08: import junit.framework.TestCase;
09:
10: import org.w3c.dom.Document;
11:
12: import com.bostechcorp.cbesb.common.util.Dom;
13: import com.bostechcorp.cbesb.common.util.FileUtil;
14: import com.bostechcorp.cbesb.runtime.parser.util.ParserUtil;
15: import com.bostechcorp.cbesb.runtime.parser.util.SerializerUtil;
16:
17: public class TestX12 extends TestCase {
18:
19: File dataFile = null;
20:
21: File outputFile = null;
22:
23: public TestX12() {
24: super ();
25:
26: dataFile = new File("target/test-data/in/x12.txt");
27: outputFile = new File("target/test-data/out/x12out.txt");
28: }
29:
30: public void testX12() throws Throwable {
31:
32: Document domDoc = null;
33: String msgDefStr = "ESB::v003050//M824";
34:
35: String remainStr = msgDefStr;
36:
37: String[] msgDefs = remainStr.split("/");
38: // String x12ver = msgDefs[0];
39: // String variant = msgDefs[1];
40: String msgType = msgDefs[2];
41:
42: // X12Parser parser = new X12Parser( x12ver, variant, msgType);
43: try {
44: InputStream is = new FileInputStream(dataFile);
45: ParserUtil parser = new ParserUtil();
46: domDoc = parser.parse(is, "x12", msgDefStr, msgType);
47: // domDoc = parser.parse(is);
48: String result = Dom.createStringFromDOMDocument(domDoc,
49: true);
50: System.out.println(result);
51: } catch (ParserException pe) {
52: Throwable ex = pe.getCause();
53: ex.printStackTrace();
54: //pe.printStackTrace();
55: fail();
56: } catch (Exception pe) {
57: pe.printStackTrace();
58: fail();
59: }
60:
61: try {
62: FileOutputStream fio = new FileOutputStream(outputFile);
63: SerializerUtil serUtil = new SerializerUtil();
64: serUtil.serialize(System.out, domDoc, "x12", msgDefStr,
65: msgType);
66: serUtil.serialize(fio, domDoc, "x12", msgDefStr, msgType);
67: String rsuleString = FileUtil
68: .readStringFromFile("target/test-data/out/x12out.txt");
69: String beginString = FileUtil
70: .readStringFromFile("target/test-data/in/x12.txt");
71: assertTrue(rsuleString.equals(beginString));
72: } catch (Exception e) {
73: System.err.println("Error Serializer:");
74: System.err.println(e.getMessage());
75: System.exit(0);
76: }
77:
78: }
79: }
|