xmlconv2 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/History.txt +6 -0
  2. data/LICENCE.txt +339 -0
  3. data/Manifest.txt +107 -0
  4. data/README.txt +25 -0
  5. data/Rakefile +28 -0
  6. data/bin/admin +65 -0
  7. data/bin/xmlconvd +19 -0
  8. data/data/grammar/i2.grammar +73 -0
  9. data/src/conversion/bdd_geh.rb +281 -0
  10. data/src/conversion/bdd_i2.rb +102 -0
  11. data/src/conversion/bdd_xml.rb +242 -0
  12. data/src/conversion/geh_bdd.rb +165 -0
  13. data/src/conversion/i2_bdd.rb +271 -0
  14. data/src/conversion/xml_bdd.rb +125 -0
  15. data/src/custom/lookandfeel.rb +47 -0
  16. data/src/i2/address.rb +33 -0
  17. data/src/i2/date.rb +37 -0
  18. data/src/i2/document.rb +26 -0
  19. data/src/i2/header.rb +24 -0
  20. data/src/i2/order.rb +44 -0
  21. data/src/i2/parser.rb +25 -0
  22. data/src/i2/position.rb +37 -0
  23. data/src/i2/record.rb +11 -0
  24. data/src/model/address.rb +20 -0
  25. data/src/model/agreement.rb +10 -0
  26. data/src/model/bdd.rb +26 -0
  27. data/src/model/bsr.rb +16 -0
  28. data/src/model/delivery.rb +15 -0
  29. data/src/model/delivery_item.rb +18 -0
  30. data/src/model/freetext_container.rb +26 -0
  31. data/src/model/id_container.rb +15 -0
  32. data/src/model/invoice.rb +18 -0
  33. data/src/model/invoice_item.rb +11 -0
  34. data/src/model/item.rb +19 -0
  35. data/src/model/item_container.rb +15 -0
  36. data/src/model/name.rb +27 -0
  37. data/src/model/part_info.rb +10 -0
  38. data/src/model/part_info_container.rb +15 -0
  39. data/src/model/party.rb +23 -0
  40. data/src/model/party_container.rb +20 -0
  41. data/src/model/price.rb +10 -0
  42. data/src/model/price_container.rb +18 -0
  43. data/src/model/transaction.rb +28 -0
  44. data/src/state/global.rb +28 -0
  45. data/src/state/global_predefine.rb +11 -0
  46. data/src/state/login.rb +38 -0
  47. data/src/state/transaction.rb +13 -0
  48. data/src/state/transactions.rb +130 -0
  49. data/src/util/application.rb +143 -0
  50. data/src/util/destination.rb +130 -0
  51. data/src/util/invoicer.rb +72 -0
  52. data/src/util/known_user.rb +16 -0
  53. data/src/util/polling_manager.rb +78 -0
  54. data/src/util/session.rb +23 -0
  55. data/src/util/transaction.rb +105 -0
  56. data/src/util/validator.rb +20 -0
  57. data/src/view/foot.rb +27 -0
  58. data/src/view/head.rb +13 -0
  59. data/src/view/login.rb +36 -0
  60. data/src/view/navigation.rb +30 -0
  61. data/src/view/navigationlink.rb +21 -0
  62. data/src/view/pager.rb +73 -0
  63. data/src/view/preformatted.rb +39 -0
  64. data/src/view/template.rb +17 -0
  65. data/src/view/transaction.rb +42 -0
  66. data/src/view/transactions.rb +90 -0
  67. data/test/mock.rb +149 -0
  68. data/test/suite.rb +16 -0
  69. data/test/test_conversion/bdd_geh.rb +533 -0
  70. data/test/test_conversion/bdd_i2.rb +314 -0
  71. data/test/test_conversion/bdd_xml.rb +556 -0
  72. data/test/test_conversion/geh_bdd.rb +372 -0
  73. data/test/test_conversion/i2_bdd.rb +804 -0
  74. data/test/test_conversion/xml_bdd.rb +203 -0
  75. data/test/test_i2/address.rb +88 -0
  76. data/test/test_i2/date.rb +49 -0
  77. data/test/test_i2/document.rb +62 -0
  78. data/test/test_i2/header.rb +39 -0
  79. data/test/test_i2/order.rb +94 -0
  80. data/test/test_i2/parser.rb +309 -0
  81. data/test/test_i2/position.rb +65 -0
  82. data/test/test_integration/geh_i2.rb +312 -0
  83. data/test/test_integration/i2_geh.rb +449 -0
  84. data/test/test_integration/i2_xml.rb +162 -0
  85. data/test/test_integration/xml_i2.rb +254 -0
  86. data/test/test_model/address.rb +35 -0
  87. data/test/test_model/agreement.rb +22 -0
  88. data/test/test_model/bdd.rb +55 -0
  89. data/test/test_model/bsr.rb +38 -0
  90. data/test/test_model/delivery.rb +79 -0
  91. data/test/test_model/delivery_item.rb +52 -0
  92. data/test/test_model/freetext_container.rb +45 -0
  93. data/test/test_model/invoice.rb +65 -0
  94. data/test/test_model/invoice_item.rb +41 -0
  95. data/test/test_model/name.rb +57 -0
  96. data/test/test_model/part_info.rb +24 -0
  97. data/test/test_model/party.rb +96 -0
  98. data/test/test_model/price.rb +24 -0
  99. data/test/test_util/application.rb +168 -0
  100. data/test/test_util/destination.rb +197 -0
  101. data/test/test_util/invoicer.rb +36 -0
  102. data/test/test_util/polling_manager.rb +111 -0
  103. data/test/test_util/transaction.rb +129 -0
  104. data/user-stories/UserStories_XmlConv2.txt +381 -0
  105. data/user-stories/doku/ABB.incoming.HTTP.invoice.xml +315 -0
  106. data/user-stories/doku/ABB.received.xml +259 -0
  107. data/user-stories/doku/BO_OrderProcessing.sxw +0 -0
  108. metadata +195 -0
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env ruby
2
+ # TestBddI2 -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('..', File.dirname(__FILE__))
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'conversion/bdd_i2'
9
+ require 'mock'
10
+
11
+ module XmlConv
12
+ module Conversion
13
+ class TestBddI2 < Test::Unit::TestCase
14
+ def test_convert
15
+ bdd = Mock.new
16
+ bdd.__next(:deliveries) { [] }
17
+ i2 = BddI2.convert(bdd)
18
+ assert_instance_of(I2::Document, i2)
19
+ header = i2.header
20
+ assert_instance_of(I2::Header, header)
21
+ # test filename... -> ???
22
+ assert_equal("EPIN_PL", header.recipient_id)
23
+ expected = Time.now.strftime("EPIN_PL_%Y%m%d%H%M%S")
24
+ assert_match(/#{expected}\d{3}.dat/, header.filename)
25
+ end
26
+ def test__doc_add_delivery
27
+ doc = I2::Document.new
28
+ agreement = Mock.new
29
+ agreement.__next(:terms_cond) { 'camion' }
30
+ delivery = Mock.new
31
+ delivery.__next(:bsr_id) { 'BSR-ID' }
32
+ delivery.__next(:customer_id) { 'Customer-Delivery-Id' }
33
+ delivery.__next(:customer) {}
34
+ delivery.__next(:agreement) { agreement }
35
+ delivery.__next(:items) { [] }
36
+ BddI2._doc_add_delivery(doc, delivery)
37
+ order = doc.orders.first
38
+ assert_equal('BSR-ID', order.sender_id)
39
+ assert_equal('Customer-Delivery-Id', order.delivery_id)
40
+ assert_equal(:camion, order.terms_cond)
41
+ delivery.__verify
42
+ end
43
+ def test__order_add_customer
44
+ order = Mock.new('Order')
45
+ customer = Mock.new('Customer')
46
+ employee = Mock.new('Employee')
47
+ bill_to = Mock.new('BillTo')
48
+ ship_to = Mock.new('ShipTo')
49
+ bill_addr = Mock.new('BillAddress')
50
+ ship_addr = Mock.new('ShipAddress')
51
+ customer.__next(:parties) {
52
+ [employee, ship_to, bill_to]
53
+ }
54
+ employee.__next(:acc_id) { }
55
+ employee.__next(:name) { 'EmployeeName' }
56
+ employee.__next(:role) { 'Employee' }
57
+ employee.__next(:address) { }
58
+ order.__next(:add_address) { |addr|
59
+ assert_instance_of(I2::Address, addr)
60
+ assert_equal(:employee, addr.code)
61
+ assert_nil(addr.party_id)
62
+ assert_equal('EmployeeName', addr.name1)
63
+ }
64
+
65
+ ship_to.__next(:acc_id) { }
66
+ ship_to.__next(:name) { 'Name' }
67
+ ship_to.__next(:role) { 'ShipTo' }
68
+ ship_to.__next(:address) { ship_addr }
69
+ ship_addr.__next(:size) { 0 }
70
+ ship_addr.__next(:lines) { [] }
71
+ ship_addr.__next(:city) { 'City' }
72
+ ship_addr.__next(:zip_code) { 'ZipCode' }
73
+ order.__next(:add_address) { |addr|
74
+ assert_instance_of(I2::Address, addr)
75
+ assert_equal(:delivery, addr.code)
76
+ assert_equal('Name', addr.name1)
77
+ assert_equal('City', addr.city)
78
+ assert_equal('ZipCode', addr.zip_code)
79
+ }
80
+
81
+ bill_to.__next(:acc_id) { 'BillToId' }
82
+ bill_to.__next(:name) { 'BillToName' }
83
+ bill_to.__next(:role) { 'BillTo' }
84
+ bill_to.__next(:address) { bill_addr }
85
+ bill_addr.__next(:size) { 2 }
86
+ bill_addr.__next(:lines) { ['BillLine1', 'BillLine2'] }
87
+ bill_addr.__next(:city) { 'BillCity' }
88
+ bill_addr.__next(:zip_code) { 'BillZipCode' }
89
+ order.__next(:add_address) { |addr|
90
+ assert_instance_of(I2::Address, addr)
91
+ assert_equal(:buyer, addr.code)
92
+ assert_equal('BillToId', addr.party_id)
93
+ assert_equal('BillToName', addr.name1)
94
+ assert_equal('BillLine1', addr.name2)
95
+ assert_equal('BillLine2', addr.street1)
96
+ assert_equal('BillCity', addr.city)
97
+ assert_equal('BillZipCode', addr.zip_code)
98
+ assert_equal(:buyer, addr.code)
99
+ }
100
+
101
+ BddI2._order_add_customer(order, customer)
102
+ order.__verify
103
+ customer.__verify
104
+ employee.__verify
105
+ bill_to.__verify
106
+ bill_addr.__verify
107
+ ship_to.__verify
108
+ ship_addr.__verify
109
+ end
110
+ def test__order_add_party
111
+ order = Mock.new('Order')
112
+ party = Mock.new('Party')
113
+ bdd_addr = Mock.new('Address')
114
+ party.__next(:acc_id) { 'id_string' }
115
+ party.__next(:name) { 'PartyName' }
116
+ party.__next(:role) { 'Employee' }
117
+ party.__next(:address) { bdd_addr }
118
+ bdd_addr.__next(:size) { 2 }
119
+ bdd_addr.__next(:lines) {
120
+ ['Line1', 'Line2']
121
+ }
122
+ bdd_addr.__next(:city) { 'City' }
123
+ bdd_addr.__next(:zip_code) { 'ZipCode' }
124
+ order.__next(:add_address) { |addr|
125
+ assert_equal(:employee, addr.code)
126
+ assert_equal('id_string', addr.party_id)
127
+ assert_equal('PartyName', addr.name1)
128
+ assert_equal('Line1', addr.name2)
129
+ assert_equal('Line2', addr.street1)
130
+ assert_equal('City', addr.city)
131
+ assert_equal('ZipCode', addr.zip_code)
132
+ }
133
+ BddI2._order_add_party(order, party)
134
+ order.__verify
135
+ party.__verify
136
+ bdd_addr.__verify
137
+ end
138
+ def test__address_add_bdd_addr__0_lines
139
+ address = Mock.new('Address')
140
+ bdd_addr = Mock.new('BddAddress')
141
+ bdd_addr.__next(:size) { 0 }
142
+ bdd_addr.__next(:lines) { [] }
143
+ bdd_addr.__next(:city) { 'City' }
144
+ bdd_addr.__next(:zip_code) { 'ZipCode' }
145
+ address.__next(:city=) { |city|
146
+ assert_equal('City', city)
147
+ }
148
+ address.__next(:zip_code=) { |zip_code|
149
+ assert_equal('ZipCode', zip_code)
150
+ }
151
+ BddI2._address_add_bdd_addr(address, bdd_addr)
152
+ address.__verify
153
+ bdd_addr.__verify
154
+ end
155
+ def test__address_add_bdd_addr__1_line
156
+ address = Mock.new('Address')
157
+ bdd_addr = Mock.new('BddAddress')
158
+ bdd_addr.__next(:size) { 1 }
159
+ bdd_addr.__next(:lines) {
160
+ ['Line1']
161
+ }
162
+ bdd_addr.__next(:city) { 'City' }
163
+ bdd_addr.__next(:zip_code) { 'ZipCode' }
164
+ address.__next(:street1=) { |line|
165
+ assert_equal('Line1', line)
166
+ }
167
+ address.__next(:city=) { |city|
168
+ assert_equal('City', city)
169
+ }
170
+ address.__next(:zip_code=) { |zip_code|
171
+ assert_equal('ZipCode', zip_code)
172
+ }
173
+ BddI2._address_add_bdd_addr(address, bdd_addr)
174
+ address.__verify
175
+ bdd_addr.__verify
176
+ end
177
+ def test__address_add_bdd_addr__2_lines
178
+ address = Mock.new('Address')
179
+ bdd_addr = Mock.new('BddAddress')
180
+ bdd_addr.__next(:size) { 2 }
181
+ bdd_addr.__next(:lines) {
182
+ ['Line1', 'Line2']
183
+ }
184
+ bdd_addr.__next(:city) { 'City' }
185
+ bdd_addr.__next(:zip_code) { 'ZipCode' }
186
+ address.__next(:name2=) { |line|
187
+ assert_equal('Line1', line)
188
+ }
189
+ address.__next(:street1=) { |line|
190
+ assert_equal('Line2', line)
191
+ }
192
+ address.__next(:city=) { |city|
193
+ assert_equal('City', city)
194
+ }
195
+ address.__next(:zip_code=) { |zip_code|
196
+ assert_equal('ZipCode', zip_code)
197
+ }
198
+ BddI2._address_add_bdd_addr(address, bdd_addr)
199
+ address.__verify
200
+ bdd_addr.__verify
201
+ end
202
+ def test__address_add_bdd_addr__3_lines
203
+ address = Mock.new('Address')
204
+ bdd_addr = Mock.new('BddAddress')
205
+ bdd_addr.__next(:size) { 3 }
206
+ bdd_addr.__next(:lines) {
207
+ ['Line1', 'Line2', 'Line3']
208
+ }
209
+ bdd_addr.__next(:city) { 'City' }
210
+ bdd_addr.__next(:zip_code) { 'ZipCode' }
211
+ address.__next(:name2=) { |name|
212
+ assert_equal('Line1', name)
213
+ }
214
+ address.__next(:street1=) { |line|
215
+ assert_equal('Line2', line)
216
+ }
217
+ address.__next(:street2=) { |line|
218
+ assert_equal('Line3', line)
219
+ }
220
+ address.__next(:city=) { |city|
221
+ assert_equal('City', city)
222
+ }
223
+ address.__next(:zip_code=) { |zip_code|
224
+ assert_equal('ZipCode', zip_code)
225
+ }
226
+ BddI2._address_add_bdd_addr(address, bdd_addr)
227
+ address.__verify
228
+ bdd_addr.__verify
229
+ end
230
+ def test__address_add_bdd_addr__more_than_3_lines
231
+ address = Mock.new('Address')
232
+ bdd_addr = Mock.new('BddAddress')
233
+ bdd_addr.__next(:size) { 9 }
234
+ bdd_addr.__next(:lines) {
235
+ ['Line1', 'Line2', 'Line3']
236
+ }
237
+ bdd_addr.__next(:city) { 'City' }
238
+ bdd_addr.__next(:zip_code) { 'ZipCode' }
239
+ address.__next(:name2=) { |name|
240
+ assert_equal('Line1', name)
241
+ }
242
+ address.__next(:street1=) { |line|
243
+ assert_equal('Line2', line)
244
+ }
245
+ address.__next(:street2=) { |line|
246
+ assert_equal('Line3', line)
247
+ }
248
+ address.__next(:city=) { |city|
249
+ assert_equal('City', city)
250
+ }
251
+ address.__next(:zip_code=) { |zip_code|
252
+ assert_equal('ZipCode', zip_code)
253
+ }
254
+ BddI2._address_add_bdd_addr(address, bdd_addr)
255
+ address.__verify
256
+ bdd_addr.__verify
257
+ end
258
+ def test__order_add_item__no_date
259
+ order = Mock.new('Order')
260
+ item = Mock.new('Item')
261
+ item.__next(:line_no) { 'LineNo' }
262
+ item.__next(:et_nummer_id) { 'EtNummerId' }
263
+ item.__next(:customer_id) { '12345' }
264
+ item.__next(:qty) { 17 }
265
+ item.__next(:unit) { }
266
+ item.__next(:delivery_date) { }
267
+ item.__next(:get_price) { }
268
+ order.__next(:add_position) { |position|
269
+ assert_instance_of(I2::Position, position)
270
+ assert_equal('LineNo', position.number)
271
+ assert_equal('EtNummerId', position.article_ean)
272
+ assert_equal(17, position.qty)
273
+ assert_nil(position.unit)
274
+ assert_nil(position.delivery_date)
275
+ }
276
+ BddI2._order_add_item(order, item)
277
+ order.__verify
278
+ item.__verify
279
+ end
280
+ def test__order_add_item
281
+ order = Mock.new('Order')
282
+ item = Mock.new('Item')
283
+ a_date = Date.new(1975,8,21)
284
+ item.__next(:line_no) { 'LineNo' }
285
+ item.__next(:et_nummer_id) { 'EtNummerId' }
286
+ item.__next(:customer_id) { '12345' }
287
+ item.__next(:qty) { 17 }
288
+ item.__next(:unit) { 'STK' }
289
+ item.__next(:delivery_date) { a_date }
290
+ price = Mock.new('Price')
291
+ price.__next(:amount) { '780.00' }
292
+ item.__next(:get_price) { |type|
293
+ assert_equal('NettoPreis', type)
294
+ price
295
+ }
296
+ order.__next(:add_position) { |position|
297
+ assert_instance_of(I2::Position, position)
298
+ assert_equal('LineNo', position.number)
299
+ assert_equal('EtNummerId', position.article_ean)
300
+ assert_equal(17, position.qty)
301
+ assert_equal('STK', position.unit)
302
+ i2date = position.delivery_date
303
+ assert_instance_of(I2::Date, i2date)
304
+ assert_equal(a_date, i2date)
305
+ assert_equal(:delivery, i2date.code)
306
+ assert_equal('780.00', position.price)
307
+ }
308
+ BddI2._order_add_item(order, item)
309
+ order.__verify
310
+ item.__verify
311
+ end
312
+ end
313
+ end
314
+ end
@@ -0,0 +1,556 @@
1
+ #!/usr/bin/env ruby
2
+ # TestBddXml -- xmlconv2 -- 21.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('..', File.dirname(__FILE__))
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'conversion/bdd_xml'
9
+ require 'date'
10
+ require 'mock'
11
+
12
+ module XmlConv
13
+ module Conversion
14
+ class TestBddXml < Test::Unit::TestCase
15
+ class ToSMock < Mock
16
+ def to_s
17
+ true
18
+ end
19
+ def type
20
+ true
21
+ end
22
+ end
23
+ def test_convert
24
+ bdd = Mock.new('Bdd')
25
+ bsr = Mock.new('Bsr')
26
+ delivery = Mock.new('Delivery')
27
+ invoice = Mock.new('Invoice')
28
+ invoice.__next(:invoice_id) { }
29
+ invoice.__next(:delivery_id) { }
30
+ invoice.__next(:status) { 'Invoiced' }
31
+ invoice.__next(:status_date) { }
32
+ invoice.__next(:ids) { [] }
33
+ invoice.__next(:parties) { [] }
34
+ invoice.__next(:items) { [] }
35
+ invoice.__next(:prices) { [] }
36
+ invoice.__next(:free_text) { }
37
+ invoice.__next(:agreement) { }
38
+ delivery.__next(:status) { 'Confirmed' }
39
+ delivery.__next(:status_date) { }
40
+ delivery.__next(:ids) { [] }
41
+ delivery.__next(:parties) { [] }
42
+ delivery.__next(:items) { [] }
43
+ delivery.__next(:prices) { [] }
44
+ delivery.__next(:free_text) { }
45
+ delivery.__next(:agreement) { }
46
+ bsr.__next(:timestamp) { }
47
+ bsr.__next(:verb) { }
48
+ bsr.__next(:noun) { }
49
+ bsr.__next(:parties) { [] }
50
+ bdd.__next(:bsr) { bsr }
51
+ bdd.__next(:deliveries) { [delivery] }
52
+ bdd.__next(:invoices) { [invoice] }
53
+ xml_doc = BddXml.convert(bdd)
54
+ assert_instance_of(REXML::Document, xml_doc)
55
+ decl = "<?xml version='1.0' encoding='UTF-8'?>"
56
+ assert_equal(decl, xml_doc.xml_decl.to_s)
57
+ dtd = '<!DOCTYPE BDD SYSTEM "ABB BDD.dtd">'
58
+ assert_equal(dtd, xml_doc.doctype.to_s)
59
+ root = xml_doc.root
60
+ assert_instance_of(REXML::Element, root)
61
+ assert_equal('BDD', root.name)
62
+ assert_equal(3, root.elements.size)
63
+ xml_bsr = root.elements[1]
64
+ assert_instance_of(REXML::Element, xml_bsr)
65
+ assert_equal('BSR', xml_bsr.name)
66
+ xml_delivery = root.elements[2]
67
+ assert_instance_of(REXML::Element, xml_delivery)
68
+ assert_equal('Delivery', xml_delivery.name)
69
+ xml_invoice = root.elements[3]
70
+ assert_instance_of(REXML::Element, xml_invoice)
71
+ assert_equal('Invoice', xml_invoice.name)
72
+ bdd.__verify
73
+ bsr.__verify
74
+ delivery.__verify
75
+ invoice.__verify
76
+ end
77
+ def test__xml_add_bdd_bsr
78
+ xml_bdd = REXML::Element.new('BDD')
79
+ party = Mock.new('Party')
80
+ bsr = Mock.new('Bsr')
81
+ name = ToSMock.new('Name')
82
+ name.__next(:text) { 'NameText' }
83
+ name.__next(:to_s) { 'NameString' }
84
+ bsr.__next(:timestamp) { Time.now }
85
+ bsr.__next(:verb) { 'Return' }
86
+ bsr.__next(:noun) { 'Status' }
87
+ bsr.__next(:parties) { [party] }
88
+ party.__next(:role) { 'Customer' }
89
+ party.__next(:ids) { {'ACC' => 'ACC-Id'} }
90
+ party.__next(:name) { name }
91
+ party.__next(:address) { }
92
+ party.__next(:parties) { [] }
93
+ BddXml._xml_add_bdd_bsr(xml_bdd, bsr)
94
+ xml_bsr = xml_bdd.elements['BSR']
95
+ assert_equal(4, xml_bsr.elements.size)
96
+ timestamp = xml_bsr.elements[1]
97
+ assert_equal('Timestamp', timestamp.name)
98
+ assert_equal(1, timestamp.attributes.size)
99
+ offset = Time.now.gmtoff / 3600
100
+ offstr = sprintf("%+i", offset)
101
+ timestr = Time.now.strftime('%Y%m%d%H%M%S')
102
+ assert_equal(offstr, timestamp.attributes['Zone'])
103
+ assert_equal(timestr, timestamp.text)
104
+ verb = xml_bsr.elements[2]
105
+ assert_equal('Verb', verb.name)
106
+ assert_equal('Return', verb.text)
107
+ noun = xml_bsr.elements[3]
108
+ assert_equal('Noun', noun.name)
109
+ assert_equal('Status', noun.text)
110
+ xml_party = xml_bsr.elements[4]
111
+ assert_equal('Party', xml_party.name)
112
+ assert_equal('2', xml_party.attributes['Version'])
113
+ assert_equal('Customer', xml_party.attributes['Role'])
114
+ assert_equal(2, xml_party.elements.size)
115
+ xml_id = xml_party.elements[1]
116
+ assert_equal('PartyId', xml_id.name)
117
+ assert_equal('ACC', xml_id.attributes['Domain'])
118
+ assert_equal('ACC-Id', xml_id.text)
119
+ xml_name = xml_party.elements[2]
120
+ assert_equal('Name', xml_name.name)
121
+ assert_equal('NameString', xml_name.text)
122
+ bsr.__verify
123
+ party.__verify
124
+ name.__verify
125
+ end
126
+ def test__xml_add_bdd_delivery
127
+ delivery = Mock.new('Delivery')
128
+ party = Mock.new('Party')
129
+ name = ToSMock.new('Name')
130
+ agreement = Mock.new('Agreement')
131
+ agreement.__next(:terms_cond) { 'Terms and Conditions' }
132
+ name.__next(:text) { 'NameText' }
133
+ name.__next(:to_s) { 'NameString' }
134
+ party.__next(:role) { 'Seller' }
135
+ party.__next(:ids) { {'ACC' => 12345} }
136
+ party.__next(:name) { name }
137
+ party.__next(:address) { }
138
+ party.__next(:parties) { [] }
139
+ delivery.__next(:status) { 'Confirmed' }
140
+ delivery.__next(:status_date) { Time.local(2004, 6, 29, 9, 45, 11) }
141
+ delivery.__next(:ids) { {'ACC' => 54321} }
142
+ delivery.__next(:parties) { [party] }
143
+ delivery.__next(:items) { [] }
144
+ delivery.__next(:prices) { [] }
145
+ delivery.__next(:free_text) { }
146
+ delivery.__next(:agreement) { agreement }
147
+ bdd = REXML::Element.new('BDD')
148
+ BddXml._xml_add_bdd_delivery(bdd, delivery)
149
+ assert_equal(1, bdd.elements.size)
150
+ xml_delivery = bdd.elements[1]
151
+ assert_equal(4, xml_delivery.elements.size)
152
+ del_status = xml_delivery.elements[1]
153
+ assert_equal('Status', del_status.name)
154
+ assert_equal('Confirmed', del_status.text)
155
+ assert_equal(1, del_status.attributes.size)
156
+ assert_equal('20040629094511', del_status.attributes['Date'])
157
+ del_id = xml_delivery.elements[2]
158
+ assert_equal('DeliveryId', del_id.name)
159
+ assert_equal(1, del_id.attributes.size)
160
+ assert_equal('ACC', del_id.attributes['Domain'])
161
+ assert_equal('54321', del_id.text)
162
+ seller = xml_delivery.elements[3]
163
+ assert_equal('Party', seller.name)
164
+ assert_equal(2, seller.attributes.size)
165
+ assert_equal('2', seller.attributes['Version'])
166
+ assert_equal('Seller', seller.attributes['Role'])
167
+ xml_agreement = xml_delivery.elements[4]
168
+ assert_equal('Agreement', xml_agreement.name)
169
+ assert_equal(1, xml_agreement.elements.size)
170
+ xml_terms = xml_agreement.elements[1]
171
+ assert_equal('TermsCond', xml_terms.name)
172
+ assert_equal('Terms and Conditions', xml_terms.text)
173
+ delivery.__verify
174
+ party.__verify
175
+ name.__verify
176
+ agreement.__verify
177
+ end
178
+ def test__xml_add_bdd_party
179
+ party = Mock.new('Party')
180
+ xml = Mock.new('Xml')
181
+ address = Mock.new('Address')
182
+ name = ToSMock.new('Name')
183
+ subdiv = Mock.new('SubdivParty')
184
+ employee = ToSMock.new('Employee')
185
+ employee.__next(:text) { }
186
+ employee.__next(:first) { }
187
+ employee.__next(:last) { 'Employee-Name' }
188
+ subdiv.__next(:role) { 'Employee' }
189
+ subdiv.__next(:ids) { [] }
190
+ subdiv.__next(:name) { employee }
191
+ subdiv.__next(:address) { }
192
+ subdiv.__next(:parties) { [] }
193
+ name.__next(:text) { 'The Name' }
194
+ name.__next(:to_s) { 'The Name' }
195
+ address.__next(:lines) { ['Address Line'] }
196
+ address.__next(:city) { 'City' }
197
+ address.__next(:zip_code) { 'Zip Code' }
198
+ address.__next(:country) { 'CH' }
199
+ party.__next(:role) { 'Customer' }
200
+ party.__next(:ids) {
201
+ {
202
+ "ACC" => 12345,
203
+ "EPIN"=> 54321,
204
+ }
205
+ }
206
+ party.__next(:name) { name }
207
+ party.__next(:address) { address }
208
+ party.__next(:parties) { [subdiv] }
209
+ xml.__next(:add_element) { |xml_party|
210
+ assert_instance_of(REXML::Element, xml_party)
211
+ assert_equal(2, xml_party.attributes.size)
212
+ assert_equal('2', xml_party.attributes['Version'])
213
+ assert_equal('Customer', xml_party.attributes['Role'])
214
+ assert_equal(5, xml_party.elements.size)
215
+ xml_id1 = xml_party.elements[1]
216
+ assert_equal('PartyId', xml_id1.name)
217
+ assert_equal('12345', xml_id1.text)
218
+ xml_id2 = xml_party.elements[2]
219
+ assert_equal('PartyId', xml_id2.name)
220
+ assert_equal('54321', xml_id2.text)
221
+ xml_name = xml_party.elements[3]
222
+ assert_equal('Name', xml_name.name)
223
+ assert_equal('The Name', xml_name.text)
224
+ xml_addr = xml_party.elements[4]
225
+ assert_equal('Address', xml_addr.name)
226
+ assert_equal(3, xml_addr.elements.size)
227
+ xml_employee = xml_party.elements[5]
228
+ assert_equal('Party', xml_employee.name)
229
+ assert_equal(1, xml_employee.elements.size)
230
+ xml_empname = xml_employee.elements[1]
231
+ assert_equal('Name', xml_empname.name)
232
+ }
233
+ BddXml._xml_add_bdd_party(xml, party)
234
+ party.__verify
235
+ xml.__verify
236
+ address.__verify
237
+ name.__verify
238
+ subdiv.__verify
239
+ employee.__verify
240
+ end
241
+ def test__xml_add_bdd_name__text
242
+ xml = Mock.new('Xml')
243
+ name = ToSMock.new('Name')
244
+ name.__next(:text) { 'The Text' }
245
+ name.__next(:to_s) { 'The String' }
246
+ xml.__next(:add_element) { |xml_name|
247
+ assert_instance_of(REXML::Element, xml_name)
248
+ assert_equal('Name', xml_name.name)
249
+ assert_equal(0, xml_name.elements.size)
250
+ assert_equal('The String', xml_name.text)
251
+ }
252
+ BddXml._xml_add_bdd_name(xml, name)
253
+ xml.__verify
254
+ name.__verify
255
+ end
256
+ def test__xml_add_bdd_name__name
257
+ xml = Mock.new('Xml')
258
+ name = Mock.new('Name')
259
+ name.__next(:text) { }
260
+ name.__next(:first) { 'First Name' }
261
+ name.__next(:last) { 'Last Name' }
262
+ xml.__next(:add_element) { |xml_name|
263
+ assert_instance_of(REXML::Element, xml_name)
264
+ assert_equal('Name', xml_name.name)
265
+ assert_equal(2, xml_name.elements.size)
266
+ first = xml_name.elements[1]
267
+ assert_equal('FirstName', first.name)
268
+ assert_equal(0, first.elements.size)
269
+ assert_equal('First Name', first.text)
270
+ last = xml_name.elements[2]
271
+ assert_equal('LastName', last.name)
272
+ assert_equal(0, last.elements.size)
273
+ assert_equal('Last Name', last.text)
274
+ }
275
+ BddXml._xml_add_bdd_name(xml, name)
276
+ xml.__verify
277
+ name.__verify
278
+ end
279
+ def test__xml_add_bdd_address
280
+ address = Mock.new('Address')
281
+ address.__next(:lines) { [ 'Line 1', 'Line 2' ] }
282
+ address.__next(:city) { 'The City' }
283
+ address.__next(:zip_code) { 'The ZipCode' }
284
+ address.__next(:country) { 'CH' }
285
+ xml = Mock.new('Xml')
286
+ xml.__next(:add_element) { |xml_addr|
287
+ assert_instance_of(REXML::Element, xml_addr)
288
+ assert_equal('Address', xml_addr.name)
289
+ assert_equal(4, xml_addr.elements.size)
290
+ line1 = xml_addr.elements[1]
291
+ assert_equal('AddressLine', line1.name)
292
+ assert_equal('Line 1', line1.text)
293
+ line2 = xml_addr.elements[2]
294
+ assert_equal('AddressLine', line2.name)
295
+ assert_equal('Line 2', line2.text)
296
+ city = xml_addr.elements[3]
297
+ assert_equal('City', city.name)
298
+ assert_equal('The City', city.text)
299
+ zip = xml_addr.elements[4]
300
+ assert_equal('ZipCode', zip.name)
301
+ assert_equal(1, zip.attributes.size)
302
+ assert_equal('CH', zip.attributes['Domain'])
303
+ assert_equal('The ZipCode', zip.text)
304
+ }
305
+ BddXml._xml_add_bdd_address(xml, address)
306
+ address.__verify
307
+ xml.__verify
308
+ end
309
+ def test__xml_add_delivery_item
310
+ xml = Mock.new('Xml')
311
+ item = Mock.new('DeliveryItem')
312
+ price1 = Mock.new('Price1')
313
+ price1.__next(:purpose) { 'Purpose1' }
314
+ price1.__next(:amount) { 1000 }
315
+ price2 = Mock.new('Price2')
316
+ price2.__next(:purpose) { 'Purpose2' }
317
+ price2.__next(:amount) { 2000 }
318
+ freetext = ToSMock.new('Freetext')
319
+ freetext.__next(:type) { 'Bezeichnung' }
320
+ freetext.__next(:to_s) { 'The FreeText' }
321
+ item.__next(:line_no) { 'The Line Number' }
322
+ item.__next(:ids) { {'ACC' => '12345'} }
323
+ item.__next(:part_infos) { [] }
324
+ item.__next(:qty) { 'Quantity' }
325
+ item.__next(:prices) { [price1, price2] }
326
+ item.__next(:free_text) { freetext }
327
+ item.__next(:delivery_date) { Date.new(2004,6,29) }
328
+ xml_item = nil
329
+ xml.__next(:add_element) { |xml_item|
330
+ assert_instance_of(REXML::Element, xml_item)
331
+ assert_equal('DeliveryItem', xml_item.name)
332
+ assert_equal(6, xml_item.elements.size)
333
+ line_no = xml_item.elements[1]
334
+ assert_equal('LineNo', line_no.name)
335
+ assert_equal('The Line Number', line_no.text)
336
+ part_id = xml_item.elements[2]
337
+ assert_equal('PartId', part_id.name)
338
+ assert_equal(1, part_id.elements.size)
339
+ ident_no = part_id.elements[1]
340
+ assert_equal('IdentNo', ident_no.name)
341
+ assert_equal(1, ident_no.attributes.size)
342
+ assert_equal('ACC', ident_no.attributes['Domain'])
343
+ assert_equal('12345', ident_no.text)
344
+ qty = xml_item.elements[3]
345
+ assert_equal('Qty', qty.name)
346
+ assert_equal('Quantity', qty.text)
347
+ xml_price1 = xml_item.elements[4]
348
+ assert_equal('Price', xml_price1.name)
349
+ xml_price2 = xml_item.elements[5]
350
+ assert_equal('Price', xml_price2.name)
351
+ xml_freetext = xml_item.elements[6]
352
+ assert_equal('FreeText', xml_freetext.name)
353
+ assert_equal(1, xml_freetext.attributes.size)
354
+ assert_equal('Bezeichnung', xml_freetext.attributes['Type'])
355
+ assert_equal('The FreeText', xml_freetext.text)
356
+ }
357
+ BddXml._xml_add_delivery_item(xml, item)
358
+ #assert_equal(7, xml_item.elements.size)
359
+ #xml_date = xml_item.elements[7]
360
+ #assert_equal('DeliveryDate', xml_date.name)
361
+ #assert_equal('20040629', xml_date.text)
362
+ xml.__verify
363
+ item.__verify
364
+ end
365
+ def test__xml_add_item_price__positive
366
+ xml_item = Mock.new('XmlItem')
367
+ price = Mock.new('Price')
368
+ price.__next(:purpose) { 'BruttoPreis' }
369
+ price.__next(:amount) { '10.05' }
370
+ xml_item.__next(:add_element) { |xml_price|
371
+ assert_instance_of(REXML::Element, xml_price)
372
+ assert_equal('Price', xml_price.name)
373
+ assert_equal(1, xml_price.attributes.size)
374
+ assert_equal('BruttoPreis', xml_price.attributes['Purpose'])
375
+ assert_equal('10.05', xml_price.text)
376
+ }
377
+ BddXml._xml_add_item_price(xml_item, price)
378
+ xml_item.__verify
379
+ price.__verify
380
+ end
381
+ def test__xml_add_item_price__negative
382
+ xml_item = Mock.new('XmlItem')
383
+ price = Mock.new('Price')
384
+ price.__next(:purpose) { 'Grundrabatt' }
385
+ price.__next(:amount) { '-1.50' }
386
+ xml_item.__next(:add_element) { |xml_price|
387
+ assert_instance_of(REXML::Element, xml_price)
388
+ assert_equal('Price', xml_price.name)
389
+ assert_equal(1, xml_price.attributes.size)
390
+ assert_equal('Grundrabatt', xml_price.attributes['Purpose'])
391
+ assert_equal('-1.50', xml_price.text)
392
+ }
393
+ BddXml._xml_add_item_price(xml_item, price)
394
+ xml_item.__verify
395
+ price.__verify
396
+ end
397
+ def test__xml_add_bdd_invoice
398
+ xml = Mock.new('Xml')
399
+ invoice = Mock.new('Invoice')
400
+ party = Mock.new('Party')
401
+ item1 = Mock.new('Item1')
402
+ item2 = Mock.new('Item2')
403
+ free_text = ToSMock.new('FreeText')
404
+ price1 = Mock.new('Price1')
405
+ price2 = Mock.new('Price2')
406
+ agreement = Mock.new('Agreement')
407
+ agreement.__next(:terms_cond) { 'TermsCond Text' }
408
+ price2.__next(:purpose) { 'Purpose2' }
409
+ price2.__next(:amount) { '23.45' }
410
+ price1.__next(:purpose) { 'Purpose1' }
411
+ price1.__next(:amount) { '12.34' }
412
+ free_text.__next(:type) { }
413
+ free_text.__next(:to_s) { 'Free Text' }
414
+ item2.__next(:line_no) { 2 }
415
+ item2.__next(:ids) { {} }
416
+ item2.__next(:part_infos) { [] }
417
+ item2.__next(:qty) { }
418
+ item2.__next(:prices) { [] }
419
+ item2.__next(:free_text) { }
420
+ item1.__next(:line_no) { 1 }
421
+ item1.__next(:ids) { {} }
422
+ item1.__next(:part_infos) { [] }
423
+ item1.__next(:qty) { }
424
+ item1.__next(:prices) { [] }
425
+ item1.__next(:free_text) { }
426
+ party.__next(:role) { 'Seller' }
427
+ party.__next(:ids) { [] }
428
+ party.__next(:name) { }
429
+ party.__next(:address) { }
430
+ party.__next(:parties) { [] }
431
+ invoice.__next(:invoice_id) { ['Invoice', '12345'] }
432
+ invoice.__next(:delivery_id) { ['ACC', '54321'] }
433
+ invoice.__next(:status) { 'Invoiced' }
434
+ invoice.__next(:status_date) { Date.new(2004, 6, 29) }
435
+ invoice.__next(:ids) { {'ACC' => '12345'} }
436
+ invoice.__next(:parties) { [party] }
437
+ invoice.__next(:items) { [item1, item2] }
438
+ invoice.__next(:prices) { [price1, price2] }
439
+ invoice.__next(:free_text) { free_text }
440
+ invoice.__next(:agreement) { agreement }
441
+ xml.__next(:add_element) { |xml_invoice|
442
+ assert_instance_of(REXML::Element, xml_invoice)
443
+ assert_equal('Invoice', xml_invoice.name)
444
+ assert_equal(11, xml_invoice.elements.size)
445
+ invoice_id = xml_invoice.elements[1]
446
+ assert_equal('InvoiceId', invoice_id.name)
447
+ assert_equal(1, invoice_id.attributes.size)
448
+ assert_equal('Invoice', invoice_id.attributes['Domain'])
449
+ assert_equal('12345', invoice_id.text)
450
+ delivery_id = xml_invoice.elements[2]
451
+ assert_equal('DeliveryId', delivery_id.name)
452
+ assert_equal(1, delivery_id.attributes.size)
453
+ assert_equal('ACC', delivery_id.attributes['Domain'])
454
+ assert_equal('54321', delivery_id.text)
455
+ invoice_status = xml_invoice.elements[3]
456
+ assert_equal('Status', invoice_status.name)
457
+ assert_equal('Invoiced', invoice_status.text)
458
+ assert_equal(1, invoice_status.attributes.size)
459
+ assert_equal('20040629', invoice_status.attributes['Date'])
460
+ invoice_id = xml_invoice.elements[4]
461
+ assert_equal('InvoiceId', invoice_id.name)
462
+ assert_equal(1, invoice_id.attributes.size)
463
+ assert_equal('ACC', invoice_id.attributes['Domain'])
464
+ assert_equal('12345', invoice_id.text)
465
+ xml_party = xml_invoice.elements[5]
466
+ assert_equal('Party', xml_party.name)
467
+ xml_item1 = xml_invoice.elements[6]
468
+ assert_equal('InvoiceItem', xml_item1.name)
469
+ xml_item2 = xml_invoice.elements[7]
470
+ assert_equal('InvoiceItem', xml_item2.name)
471
+ xml_price1 = xml_invoice.elements[8]
472
+ assert_equal('Price', xml_price1.name)
473
+ assert_equal(1, xml_price1.attributes.size)
474
+ assert_equal('Purpose1', xml_price1.attributes['Purpose'])
475
+ assert_equal('12.34', xml_price1.text)
476
+ xml_price2 = xml_invoice.elements[9]
477
+ assert_equal('Price', xml_price1.name)
478
+ assert_equal(1, xml_price2.attributes.size)
479
+ assert_equal('Purpose2', xml_price2.attributes['Purpose'])
480
+ assert_equal('23.45', xml_price2.text)
481
+ xml_txt = xml_invoice.elements[10]
482
+ assert_equal('FreeText', xml_txt.name)
483
+ assert_equal(0, xml_txt.attributes.size)
484
+ assert_equal('Free Text', xml_txt.text)
485
+ xml_agreement = xml_invoice.elements[11]
486
+ assert_equal('Agreement', xml_agreement.name)
487
+ assert_equal(1, xml_agreement.elements.size)
488
+ terms = xml_agreement.elements[1]
489
+ assert_equal('TermsCond', terms.name)
490
+ assert_equal('TermsCond Text', terms.text)
491
+ }
492
+ BddXml._xml_add_bdd_invoice(xml, invoice)
493
+ invoice.__verify
494
+ xml.__verify
495
+ party.__verify
496
+ item1.__verify
497
+ item2.__verify
498
+ free_text.__verify
499
+ price1.__verify
500
+ price2.__verify
501
+ agreement.__verify
502
+ end
503
+ def test__xml_add_invoice_item
504
+ xml = Mock.new('XML')
505
+ item = Mock.new('Item')
506
+ part_info = Mock.new('PartInfo')
507
+ price = Mock.new('Price')
508
+ price.__next(:purpose) { 'BruttoPreis' }
509
+ price.__next(:amount) { '123.45' }
510
+ part_info.__next(:dimension) { 'the Dimension' }
511
+ part_info.__next(:value) { 'the Value' }
512
+ item.__next(:line_no) { '10' }
513
+ item.__next(:ids) { {'ACC' => 'idstr'} }
514
+ item.__next(:part_infos) { [part_info] }
515
+ item.__next(:qty) { 14 }
516
+ item.__next(:prices) { [price] }
517
+ item.__next(:free_text) { }
518
+ xml.__next(:add_element) { |xml_item|
519
+ assert_instance_of(REXML::Element, xml_item)
520
+ assert_equal('InvoiceItem', xml_item.name)
521
+ assert_equal(4, xml_item.elements.size)
522
+ line_no = xml_item.elements[1]
523
+ assert_equal('LineNo', line_no.name)
524
+ assert_equal('10', line_no.text)
525
+ part_id = xml_item.elements[2]
526
+ assert_equal('PartId', part_id.name)
527
+ assert_equal(2, part_id.elements.size)
528
+ ident_no = part_id.elements[1]
529
+ assert_equal('IdentNo', ident_no.name)
530
+ assert_equal(1, ident_no.attributes.size)
531
+ assert_equal('ACC', ident_no.attributes['Domain'])
532
+ assert_equal('idstr', ident_no.text)
533
+ xml_part_info = part_id.elements[2]
534
+ assert_equal('PartInfo', xml_part_info.name)
535
+ assert_equal(1, xml_part_info.elements.size)
536
+ value = xml_part_info.elements[1]
537
+ assert_equal('Value', value.name)
538
+ assert_equal(1, value.attributes.size)
539
+ assert_equal('the Dimension', value.attributes['Dimension'])
540
+ assert_equal('the Value', value.text)
541
+ qty = xml_item.elements[3]
542
+ assert_equal('Qty', qty.name)
543
+ assert_equal('14', qty.text)
544
+ xml_price = xml_item.elements[4]
545
+ assert_equal('Price', xml_price.name)
546
+ assert_equal(1, xml_price.attributes.size)
547
+ assert_equal('BruttoPreis', xml_price.attributes['Purpose'])
548
+ assert_equal('123.45', xml_price.text)
549
+ }
550
+ BddXml._xml_add_invoice_item(xml, item)
551
+ xml.__verify
552
+ item.__verify
553
+ end
554
+ end
555
+ end
556
+ end