edi4r 0.9.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/AuthorCopyright +10 -0
  2. data/COPYING +56 -0
  3. data/ChangeLog +106 -0
  4. data/README +66 -0
  5. data/TO-DO +35 -0
  6. data/Tutorial +609 -0
  7. data/VERSION +1 -0
  8. data/bin/edi2xml.rb +103 -0
  9. data/bin/editool.rb +151 -0
  10. data/bin/xml2edi.rb +50 -0
  11. data/data/edifact/iso9735/SDCD.10000.csv +10 -0
  12. data/data/edifact/iso9735/SDCD.20000.csv +10 -0
  13. data/data/edifact/iso9735/SDCD.30000.csv +11 -0
  14. data/data/edifact/iso9735/SDCD.40000.csv +31 -0
  15. data/data/edifact/iso9735/SDCD.40100.csv +31 -0
  16. data/data/edifact/iso9735/SDED.10000.csv +37 -0
  17. data/data/edifact/iso9735/SDED.20000.csv +37 -0
  18. data/data/edifact/iso9735/SDED.30000.csv +43 -0
  19. data/data/edifact/iso9735/SDED.40000.csv +129 -0
  20. data/data/edifact/iso9735/SDED.40100.csv +130 -0
  21. data/data/edifact/iso9735/SDMD.10000.csv +0 -0
  22. data/data/edifact/iso9735/SDMD.20000.csv +0 -0
  23. data/data/edifact/iso9735/SDMD.30000.csv +6 -0
  24. data/data/edifact/iso9735/SDMD.40000.csv +17 -0
  25. data/data/edifact/iso9735/SDMD.40100.csv +17 -0
  26. data/data/edifact/iso9735/SDSD.10000.csv +8 -0
  27. data/data/edifact/iso9735/SDSD.20000.csv +8 -0
  28. data/data/edifact/iso9735/SDSD.30000.csv +12 -0
  29. data/data/edifact/iso9735/SDSD.40000.csv +34 -0
  30. data/data/edifact/iso9735/SDSD.40100.csv +34 -0
  31. data/data/edifact/untdid/EDCD.d01b.csv +200 -0
  32. data/data/edifact/untdid/EDCD.d96a.csv +161 -0
  33. data/data/edifact/untdid/EDED.d01b.csv +641 -0
  34. data/data/edifact/untdid/EDED.d96a.csv +462 -0
  35. data/data/edifact/untdid/EDMD.d01b.csv +3419 -0
  36. data/data/edifact/untdid/EDMD.d96a.csv +2144 -0
  37. data/data/edifact/untdid/EDSD.d01b.csv +158 -0
  38. data/data/edifact/untdid/EDSD.d96a.csv +127 -0
  39. data/data/edifact/untdid/IDCD.d01b.csv +95 -0
  40. data/data/edifact/untdid/IDMD.d01b.csv +238 -0
  41. data/data/edifact/untdid/IDSD.d01b.csv +75 -0
  42. data/lib/edi4r.rb +928 -0
  43. data/lib/edi4r/diagrams.rb +567 -0
  44. data/lib/edi4r/edi4r-1.2.dtd +20 -0
  45. data/lib/edi4r/edifact-rexml.rb +221 -0
  46. data/lib/edi4r/edifact.rb +1627 -0
  47. data/lib/edi4r/rexml.rb +256 -0
  48. data/lib/edi4r/standards.rb +495 -0
  49. data/test/eancom2webedi.rb +380 -0
  50. data/test/groups.edi +1 -0
  51. data/test/in1.edi +1 -0
  52. data/test/in1.inh +3 -0
  53. data/test/in2.edi +1 -0
  54. data/test/in2.xml +350 -0
  55. data/test/test_basics.rb +209 -0
  56. data/test/test_edi_split.rb +53 -0
  57. data/test/test_loopback.rb +21 -0
  58. data/test/test_minidemo.rb +84 -0
  59. data/test/test_rexml.rb +98 -0
  60. data/test/test_tut_examples.rb +131 -0
  61. data/test/webedi2eancom.rb +408 -0
  62. metadata +110 -0
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env ruby
2
+ # :include: ../AuthorCopyright
3
+
4
+ # Load path magic...
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
+
7
+ require 'test/unit'
8
+
9
+ require 'edi4r'
10
+ require 'edi4r/edifact'
11
+
12
+ class EDIFACT_Tests < Test::Unit::TestCase
13
+
14
+ # Utilities: Fill in just the required segments
15
+
16
+ def fill_ORDERS( msg )
17
+ seg = msg.new_segment('BGM')
18
+ msg.add seg
19
+ seg.d1004 = '220'
20
+ assert_equal(["C002", "1004", "1225", "4343"], seg.names )
21
+ seg = msg.new_segment('DTM')
22
+ msg.add seg
23
+ seg.cC507.d2005 = '137'
24
+ t = Time.edifact('20060703', 102)
25
+ seg.cC507.d2380 = t
26
+ seg.cC507.d2379 = t.format
27
+
28
+ assert_equal( ["2005", "2380", "2379"], seg.cC507.names )
29
+ seg = msg.new_segment('UNS')
30
+ seg.d0081 = 'S'
31
+ msg.add seg
32
+ # p seg.names
33
+ end
34
+
35
+
36
+ def fill_INVOIC( msg )
37
+ seg = msg.new_segment('BGM')
38
+ msg.add seg
39
+ seg.cC002.d1001 = '380'
40
+ assert_equal(["C002", "C106", "1225", "4343"], seg.names )
41
+ seg = msg.new_segment('DTM')
42
+ msg.add seg
43
+ seg.cC507.d2005 = '137'
44
+ t = Time.new
45
+ t.format = 204
46
+ seg.cC507.d2380 = t
47
+ seg.cC507.d2379 = t.format
48
+
49
+ assert_equal( ["2005", "2380", "2379"], seg.cC507.names )
50
+ seg = msg.new_segment('UNS')
51
+ seg.d0081 = 'S'
52
+ msg.add seg
53
+
54
+ seg = msg.new_segment('MOA')
55
+ msg.add seg
56
+ seg.cC516.d5025 = '86'
57
+ seg.cC516.d5004 = 0.0
58
+ # p seg.names
59
+ end
60
+
61
+
62
+ def test_interchange_creation
63
+ ic = nil
64
+
65
+ # All defaults working?
66
+ assert_nothing_raised { ic = EDI::E::Interchange.new() }
67
+ assert_match( /^UNA:\+\.\? 'UNB\+UNOB:3\+\+\+\d{6}:\d{4}\+1'UNZ\+0\+1'$/, ic.to_s )
68
+
69
+ # Change some parameters: Switch off UNA, try a different charset
70
+ assert_nothing_raised {
71
+ ic = EDI::E::Interchange.new({
72
+ :show_una=>false, :charset=>'UNOC',
73
+ :interchange_control_reference=>123,
74
+ :test_indicator=>1 })
75
+ }
76
+ assert_match( /^UNB\+UNOC:3\+\+\+\d{6}:\d{4}\+(123)\+{6}1'UNZ\+0\+\1'$/, ic.to_s )
77
+
78
+
79
+ # Now test special separator case SV2, UNOB. Is UNA on by default?
80
+ assert_nothing_raised {
81
+ ic = EDI::E::Interchange.new({:version=>2})
82
+ }
83
+ assert_match( /^UNA\021\022\.\? \024UNB\022UNOB\0212\022\022\022\d{6}\021\d{4}\0221\024UNZ\0220\0221\024$/, ic.to_s )
84
+
85
+ # Same again, now with a few defaults set explicitly
86
+ assert_nothing_raised {
87
+ ic = EDI::E::Interchange.new({:show_una=>true,:version=>2, :charset=>'UNOB'})
88
+ }
89
+ assert_match( /^UNA\021\022\.\? \024UNB\022UNOB\0212\022\022\022\d{6}\021\d{4}\0221\024UNZ\0220\0221\024$/, ic.to_s )
90
+
91
+ # SV4 working?
92
+ assert_nothing_raised { ic = EDI::E::Interchange.new({:version=>4, :charset=>'UNOC'}) }
93
+ assert_match( /^UNA:\+\.\?\*'UNB\+UNOC:4\+\+\+\d{8}:\d{4}\+1'UNZ\+0\+1'$/, ic.to_s )
94
+
95
+ # SV4 & I-EDI working?
96
+ assert_raise( RuntimeError) {
97
+ ic = EDI::E::Interchange.new({:version=>4, :charset=>'UNOC', :i_edi => true})
98
+ }
99
+ # assert_match( /^UNA:\+\.\?\*'UIB\+UNOC:4\+\+\+\d{8}:\d{4}\+1'UIZ\+0\+1'$/, ic.to_s )
100
+ end
101
+
102
+
103
+ def test_group_creation
104
+ ic = n = nil
105
+ assert_nothing_raised { ic = EDI::E::Interchange.new() }
106
+
107
+ # First group: No sender/recipient there to inherit:
108
+ # Expect 4 validation errors (2 x UNB, 2 x UNG)
109
+ grp = ic.new_msggroup
110
+ ic.add( grp, false )
111
+ assert_equal( 4, ic.validate )
112
+
113
+ # Second group: Now let's see if sender/recipient inheritance works:
114
+ # Expect no more validation errors
115
+ grp.header.cS006.d0040 = 'sender-g'
116
+ grp.header.cS007.d0044 = 'recipient-g'
117
+
118
+ ic.header.cS002.d0004 = 'sender'
119
+ ic.header.cS003.d0010 = 'recipient'
120
+ grp = ic.new_msggroup
121
+ assert_nothing_raised{ n = ic.validate}
122
+ assert_equal( 0, n )
123
+
124
+ msg = grp.new_message
125
+ fill_ORDERS(msg)
126
+ grp.add( msg )
127
+
128
+ # See if reference in trailer is updated when header ref. changes:
129
+ grp.header.d0048 = 5
130
+ ic.add( grp, false )
131
+
132
+ assert_nothing_raised{ n = ic.validate}
133
+ assert_equal( 0, n )
134
+
135
+ grp = ic.new_msggroup(:msg_type=>'INVOIC', :version=>'D', :release=>'01B',
136
+ :resp_agency=>'UN', :assigned_code=>'EAN010')
137
+ ic.add( grp, false )
138
+ msg = grp.new_message
139
+ fill_INVOIC(msg)
140
+ grp.add msg
141
+ assert_nothing_raised{ n = ic.validate}
142
+ assert_equal( 0, n )
143
+ assert_nothing_raised{ File.open("groups.edi",'w') {|f| f.print ic} }
144
+
145
+ msg.header.cS009.d0057 = 'EAN011' # provoke a grp/msg difference
146
+ assert_nothing_raised{ n = ic.validate}
147
+ assert_equal( 1, n )
148
+ # puts ic
149
+ end
150
+
151
+
152
+ def test_message_creation
153
+
154
+ ic = nil
155
+ assert_nothing_raised { ic = EDI::E::Interchange.new() }
156
+ msg = ic.new_message
157
+ fill_ORDERS(msg)
158
+
159
+ ic.add msg
160
+ ic.add msg
161
+ assert_equal( 1, msg.header.first.value ) # value of DE 0062
162
+ assert_equal( "ORDERS:D:96A:UN", msg.header[1].to_s ) # S009
163
+ assert_equal( "UNH+1+ORDERS:D:96A:UN", msg.header.to_s ) # UNH
164
+ assert_equal( "BGM++220", msg.first.to_s ) # BGM
165
+
166
+ # puts msg
167
+ # puts msg.inspect
168
+ ic.header.d0035 = 1 # Test indicator
169
+ # puts ic
170
+ end
171
+
172
+ def test_una_changes
173
+ ic = nil
174
+ assert_nothing_raised { ic = EDI::E::Interchange.new() }
175
+ msg = ic.new_message
176
+ pri = msg.parse_segment('PRI+AAA:30,0::LIU', 'PRI')
177
+ assert_equal( pri.to_s, 'PRI+AAA:30::LIU')
178
+ pri = msg.parse_segment('PRI+AAA:30.1::LIU', 'PRI')
179
+ assert_equal( pri.to_s, 'PRI+AAA:30.1::LIU')
180
+ ic.una.decimal_sign = ?,
181
+ pri = msg.parse_segment('PRI+AAA:30.1::LIU', 'PRI')
182
+ assert_equal( 'PRI+AAA:30,1::LIU', pri.to_s)
183
+ ic.una.decimal_sign = ?.
184
+ ic.una.ce_sep = ?-
185
+ assert_equal( 'PRI+AAA-30.1--LIU', pri.to_s)
186
+ pri.cC509.d5118 = -pri.cC509.d5118
187
+ assert_equal( 'PRI+AAA-?-30.1--LIU', pri.to_s)
188
+ ic.una.esc_char = ?#
189
+ assert_equal( 'PRI+AAA-#-30.1--LIU', pri.to_s)
190
+ ic.una.esc_char = ?\\
191
+ assert_equal( 'PRI+AAA-\\-30.1--LIU', pri.to_s)
192
+ end
193
+
194
+ begin
195
+ def test_interchange_parsing
196
+ assert_nothing_raised {
197
+ ic = EDI::E::Interchange.parse( File.open( './O0002248720','r' ), false )
198
+ ic.output_mode = :indented
199
+ File.open("invoic.out", "w") {|hnd| hnd.print ic}
200
+ }
201
+ assert_nothing_raised {
202
+ ic = EDI::E::Interchange.parse( File.open( './remadv101.edi', 'r' ) )
203
+ ic.output_mode = :indented
204
+ File.open("remadv.out", "w") {|hnd| hnd.print ic}
205
+ # $stdout.write ic
206
+ }
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ # :include: ../AuthorCopyright
3
+
4
+ =begin
5
+ E = ?? # ESC char
6
+ C = ?: # CDE separator char
7
+ D = ?+ # DE separator char
8
+ S = ?' # Segment terminator
9
+ =end
10
+
11
+ # Load path magic...
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
+
14
+ require 'test/unit'
15
+
16
+ require 'edi4r'
17
+ require 'edi4r/edifact'
18
+ include EDI::E
19
+
20
+ class TestClass < Test::Unit::TestCase
21
+
22
+ def test_cde_sep
23
+ assert_equal(['a','b'], edi_split('a:b', ?:, ??) )
24
+ assert_equal(['a:b'], edi_split('a?:b', ?:, ??) )
25
+ assert_equal(['a?','b'],edi_split('a??:b', ?:, ??) )
26
+ assert_equal(['a?:b'], edi_split('a???:b', ?:, ??) )
27
+ assert_raise( EDISyntaxError) { edi_split('a:b?', ?:, ??)}
28
+
29
+ assert_equal(['a','', 'b'], edi_split('a::b', ?:, ??) )
30
+ assert_equal(['a','', '', 'b'], edi_split('a:::b', ?:, ??) )
31
+ assert_equal(['a','b'], edi_split('a:b:', ?:, ??) )
32
+ assert_equal(['a','', 'b'], edi_split('a::b::', ?:, ??) )
33
+
34
+ assert_equal(['','a','b'], edi_split(':a:b', ?:, ??) )
35
+ assert_equal(['','','', 'a','', 'b'], edi_split(':::a::b::', ?:, ??) )
36
+
37
+ assert_equal( ['123456780', 'A + B LTD' ], edi_split('123456780:A + B LTD', ?:, ??) )
38
+ assert_equal( ['', '', '', '10010099', '25', '131' ], edi_split(':::10010099:25:131', ?:, ??) )
39
+ end
40
+
41
+ def test_de_sep
42
+ assert_equal( ['IMD', 'A','', ':::JEANS'], edi_split('IMD+A++:::JEANS', ?+, ??))
43
+ assert_equal( ['FII', 'OR','123456780:A + B LTD', ':::10010099:25:131' ], edi_split('FII+OR+123456780:A ?+ B LTD+:::10010099:25:131', ?+, ??) )
44
+ assert_raise(EDISyntaxError){edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC! ?', ?+, ??)}
45
+ assert_equal( ['TAG','SOME TEXT?', 'MORE TEXT', 'PENDING ESC ?'], edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC ??', ?+, ??) )
46
+ assert_raise(EDISyntaxError){edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC! ???', ?+, ??)}
47
+ end
48
+
49
+ def test_seg_term
50
+ assert_equal( ['RFF+ACK:12345/678', 'FII+BF+000000000:::EUR+:::10010099:25:131', 'SEQ++1', 'FII+OR+123456780:A ?+ B LTD+:::10010099:25:131', 'RFF+RA:YOUR ACCOUNT 1234-5678 9'], edi_split('RFF+ACK:12345/678\'FII+BF+000000000:::EUR+:::10010099:25:131\'SEQ++1\'FII+OR+123456780:A ?+ B LTD+:::10010099:25:131\'RFF+RA:YOUR ACCOUNT 1234-5678 9\'', ?', ??))
51
+ end
52
+
53
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # :include: ../AuthorCopyright
3
+
4
+ require 'test/unit'
5
+
6
+ #######################################################################
7
+ # Test the accompanying standalone mapping tools
8
+ #
9
+ # Mapping to EANCOM and back should yield the original inhouse data.
10
+
11
+ class EDIFACT_Tests < Test::Unit::TestCase
12
+
13
+ def test_loopback
14
+ s1 = nil
15
+ File.open('in1.inh') {|hnd| hnd.binmode; s1 = hnd.read}
16
+ s2 = `ruby ./webedi2eancom.rb -a in1.inh | ruby ./eancom2webedi.rb`
17
+ assert_equal( 0, $? )
18
+ assert_match( s1, s2 )
19
+ end
20
+
21
+ end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # :include: ../AuthorCopyright
3
+
4
+ # Load path magic...
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
+
7
+ require 'test/unit'
8
+ #require "rubygems"
9
+ #require_gem "edi4r"
10
+ require "edi4r"
11
+ require "edi4r/edifact"
12
+ require 'tempfile'
13
+
14
+
15
+ class EDIFACT_Minitests < Test::Unit::TestCase
16
+
17
+ def setup
18
+ @ic = EDI::E::Interchange.new({
19
+ :show_una => true,
20
+ :charset => 'UNOC',
21
+ :version => 3,
22
+ :interchange_control_reference => '12345',
23
+ :output_mode => :verbatim})
24
+
25
+ cde = @ic.header.cS002
26
+ cde.d0004 = '2965197000005'
27
+ cde.d0007 = '14'
28
+ cde = @ic.header.cS003
29
+ cde.d0010 = '2165197000009'
30
+ cde.d0007 = '14'
31
+
32
+ # ic.write $stdout
33
+
34
+ params = {
35
+ :msg_type => 'ORDERS',
36
+ :version => 'D',
37
+ :release => '01B',
38
+ :resp_agency => 'UN',
39
+ :assigned_code => 'EAN010'
40
+ }
41
+
42
+ msg = @ic.new_message params
43
+
44
+ # print msg
45
+
46
+ seg = msg.new_segment('BGM')
47
+ seg.cC002.d1001 = '220'
48
+ seg.cC106.d1004 = '1234567'
49
+ seg.d1225 = '9'
50
+ msg.add seg
51
+
52
+ seg = msg.new_segment('DTM')
53
+ cde = seg.cC507
54
+ cde.d2005 = '137'
55
+ cde.d2380 = '20050603'
56
+ cde.d2379 = '102'
57
+ msg.add seg
58
+
59
+ seg = msg.new_segment('UNS')
60
+ seg.d0081='S'
61
+
62
+ msg.add seg
63
+
64
+ @ic.add msg
65
+ end
66
+
67
+ def test_validation
68
+ rc = 0
69
+ assert_nothing_raised { rc=@ic.validate }
70
+ assert_equal( 0, rc)
71
+ end
72
+
73
+ def test_write_parse_validate
74
+ tf = Tempfile.new("minitest_edi")
75
+ tf.print @ic
76
+ tf.close
77
+ rc = 0
78
+ ic2 = EDI::E::Interchange.parse(tf.open)
79
+ assert_nothing_raised { rc=ic2.validate }
80
+ assert_equal( 0, rc)
81
+ assert_equal( @ic.to_s, ic2.to_s)
82
+ tf.close(true) unless tf.closed?
83
+ end
84
+ end
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ # :include: ../AuthorCopyright
3
+
4
+ #######################################################################
5
+ # Test conversion to and from XML representation
6
+ #
7
+ # Mapping to XML and back should yield the original UN/EDIFACT data.
8
+ # Mapping to UN/EDIFACT and back should yield the original XML data.
9
+
10
+ # Include statement during test setup:
11
+
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
+ require 'edi4r'
14
+ require 'edi4r/edifact'
15
+ require 'edi4r/rexml'
16
+
17
+ # Regular include statements:
18
+
19
+ #require "rubygems"
20
+ #require_gem "edi4r"
21
+ #require "edi4r/edifact"
22
+ #require 'edi4r/rexml'
23
+
24
+ require 'stringio'
25
+ require 'test/unit'
26
+
27
+
28
+ class EDIFACT_REXML_Tests < Test::Unit::TestCase
29
+
30
+ def setup
31
+ @ice = EDI::Interchange.parse(File.open("in2.edi"))
32
+ @se = @ice.to_s
33
+ @icg = EDI::Interchange.parse(File.open("groups.edi"))
34
+ end
35
+
36
+ def test_rexml
37
+ @icx = nil
38
+ assert_nothing_raised do
39
+ @icx = EDI::Interchange.parse(File.open("in2.xml"))
40
+ assert_equal( 0, @icx.validate )
41
+ end
42
+
43
+ assert_equal( @se, @icx.to_s ) # EDIFACT representations equal?
44
+
45
+ sx = File.open('in2.edi') { |hnd| hnd.read }.chop
46
+ se = @se.sub(/PRI\+AAA:30::LIU\'PRI\+AAE:99::/,
47
+ 'PRI+AAA:30.0::LIU\'PRI+AAE:99,0::')
48
+ assert_equal( se, sx ) # EDIFACT representations equal file content?
49
+
50
+ se = StringIO.new
51
+ xdoc_e = REXML::Document.new
52
+ @ice.to_xml(xdoc_e)
53
+ xdoc_e.write( se, 0 )
54
+ # xdoc_e.write( File.open('in2a.xml','w'), 0 )
55
+
56
+ sx = StringIO.new
57
+ xdoc_x = REXML::Document.new
58
+ @ice.to_xml(xdoc_x)
59
+ xdoc_x.write( sx, 0 )
60
+
61
+ assert_equal( se.string, sx.string ) # XML representations equal?
62
+ end
63
+
64
+
65
+ def test_groups
66
+
67
+ xdoc = REXML::Document.new
68
+ assert_nothing_raised{ @icg.to_xml( xdoc ) }
69
+
70
+ sg = StringIO.new
71
+ xdoc.write( sg, 0 )
72
+ # xdoc.write( File.open("groups2.xml",'w'), 0 )
73
+
74
+ ic = nil
75
+ assert_nothing_raised do
76
+ ic = EDI::E::Interchange.parse_xml( REXML::Document.new( sg.string ))
77
+ end
78
+ assert_equal( @icg.to_s, ic.to_s )
79
+ end
80
+
81
+
82
+ def test_din16557_4
83
+ xdoc = nil
84
+ assert_nothing_raised{ xdoc = @ice.to_din16557_4 }
85
+
86
+ sg = StringIO.new
87
+ # sg = $stdout
88
+ xdoc.write( sg, 0 )
89
+
90
+ xdoc = nil
91
+ assert_nothing_raised{ xdoc = @icg.to_din16557_4 }
92
+
93
+ # sg = $stdout
94
+ sg = StringIO.new
95
+ xdoc.write( sg, 0 )
96
+ # xdoc.write( File.open("groups2.xml",'w'), 0 )
97
+ end
98
+ end