sandozxmlconv 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,441 @@
1
+ #!/usr/bin/env ruby
2
+ # PostProcess::TestBbmb2 -- xmlconv2 -- 25.08.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'postprocess/bbmb2'
8
+ require 'flexmock'
9
+ require 'conversion/pharmacieplus_bdd'
10
+ require 'conversion/propharma_bdd'
11
+ require 'conversion/wbmb_bdd'
12
+
13
+ module XmlConv
14
+ module PostProcess
15
+ class TestBbmb2 < Test::Unit::TestCase
16
+ def test_inject
17
+ src = <<-XML
18
+ <?xml version="1.0" encoding="ISO-8859-1"?>
19
+ <commande id="1861" date="2006-08-16T09:32:35.303+02:00" xmlns="http://www.ofac.ch/XEDO">
20
+ <groupe>
21
+ <last-name>pharmacieplus Directe</last-name>
22
+ <first-name> </first-name>
23
+ <other-name>Messieurs Eric Bussat + Christian Rouvinez</other-name>
24
+ <address>
25
+ <street>les courbes 5</street>
26
+ <zip>1121</zip>
27
+ <city>Bremblens</city>
28
+ </address>
29
+ <telecom>
30
+ <phone number="021 811 48 88"/>
31
+ <fax number="021 811 48 89"/>
32
+ </telecom>
33
+ <online>
34
+ <email>secretariat@pharmacieplus.ch</email>
35
+ </online>
36
+ </groupe>
37
+ <fournisseur ean="7601001000681">
38
+ <last-name>GLOBOPHARM AG</last-name>
39
+ <first-name> </first-name>
40
+ <address>
41
+ <street>Seestrasse 200</street>
42
+ <zip>8700</zip>
43
+ <city>KUESNACHT</city>
44
+ <country>CH</country>
45
+ </address>
46
+ </fournisseur>
47
+ <com-global>
48
+ <article ean="7680543802083" pharmacode="2054106" qte-livraison="12" qte-facture="10">
49
+ <desc>ANTRA MUPS 10 Tabl 10 mg 100 Stk</desc>
50
+ <cond-com>
51
+ <bonus facture="10" livre="12"/>
52
+ </cond-com>
53
+ </article>
54
+ <article ean="7680543800386" pharmacode="2054081" qte-livraison="12" qte-facture="10">
55
+ <desc>ANTRA MUPS 10 Tabl 10 mg 28 Stk</desc>
56
+ <cond-com>
57
+ <bonus facture="10" livre="12"/>
58
+ </cond-com>
59
+ </article>
60
+ <article ean="7680543801949" pharmacode="2054098" qte-livraison="30" qte-facture="20">
61
+ <desc>ANTRA MUPS 10 Tabl 10 mg 56 Stk</desc>
62
+ <cond-com>
63
+ <bonus facture="10" livre="15"/>
64
+ </cond-com>
65
+ </article>
66
+ <article ean="7680543802403" pharmacode="2054158" qte-livraison="15" qte-facture="10">
67
+ <desc>ANTRA MUPS 20 Tabl 20 mg 100 Stk</desc>
68
+ <cond-com>
69
+ <bonus facture="10" livre="15"/>
70
+ </cond-com>
71
+ </article>
72
+ <article ean="7680543800898" pharmacode="2054129" qte-livraison="13" qte-facture="13">
73
+ <desc>ANTRA MUPS 20 Tabl 20 mg 14 Stk</desc>
74
+ <cond-com rabais="10.0"/>
75
+ </article>
76
+ <article ean="7680543800973" pharmacode="2054135" qte-livraison="28" qte-facture="20">
77
+ <desc>ANTRA MUPS 20 Tabl 20 mg 28 Stk</desc>
78
+ <cond-com>
79
+ <bonus facture="10" livre="14"/>
80
+ </cond-com>
81
+ </article>
82
+ <article ean="7680543802328" pharmacode="2054141" qte-livraison="17" qte-facture="17">
83
+ <desc>ANTRA MUPS 20 Tabl 20 mg 56 Stk</desc>
84
+ <cond-com rabais="15.0"/>
85
+ </article>
86
+ <article ean="7680543800706" pharmacode="2054112" qte-livraison="28" qte-facture="20">
87
+ <desc>ANTRA MUPS 20 Tabl 20 mg 7 Stk</desc>
88
+ <cond-com>
89
+ <bonus facture="10" livre="14"/>
90
+ </cond-com>
91
+ </article>
92
+ <article ean="7680548750532" pharmacode="2204899" qte-livraison="11" qte-facture="11">
93
+ <desc>ATACAND PLUS Tabl 16/12.5 mg 28 Stk</desc>
94
+ <cond-com rabais="5.0"/>
95
+ </article>
96
+ <article ean="7680548750617" pharmacode="2204907" qte-livraison="30" qte-facture="20">
97
+ <desc>ATACAND PLUS Tabl 16/12.5 mg 98 Stk</desc>
98
+ <cond-com>
99
+ <bonus facture="10" livre="15"/>
100
+ </cond-com>
101
+ </article>
102
+ </com-global>
103
+ <com-pharma ean="7601001368095">
104
+ <livraison>
105
+ <last-name>Pharmacie du Mandement</last-name>
106
+ <first-name> </first-name>
107
+ <other-name> Monsieur Fr�d�ric Recipient </other-name>
108
+ <address>
109
+ <street>3e adresse e-mail</street>
110
+ <zip>1242</zip>
111
+ <city>Satigny</city>
112
+ </address>
113
+ </livraison>
114
+ <article ean="7680543801949" pharmacode="2054098" qte-livraison="15" qte-facture="10">
115
+ <desc>ANTRA MUPS 10 Tabl 10 mg 56 Stk</desc>
116
+ </article>
117
+ <article ean="7680543802403" pharmacode="2054158" qte-livraison="15" qte-facture="10">
118
+ <desc>ANTRA MUPS 20 Tabl 20 mg 100 Stk</desc>
119
+ </article>
120
+ <article ean="7680543800898" pharmacode="2054129" qte-livraison="6" qte-facture="6">
121
+ <desc>ANTRA MUPS 20 Tabl 20 mg 14 Stk</desc>
122
+ </article>
123
+ <article ean="7680543802328" pharmacode="2054141" qte-livraison="9" qte-facture="9">
124
+ <desc>ANTRA MUPS 20 Tabl 20 mg 56 Stk</desc>
125
+ </article>
126
+ <article ean="7680543800706" pharmacode="2054112" qte-livraison="28" qte-facture="20">
127
+ <desc>ANTRA MUPS 20 Tabl 20 mg 7 Stk</desc>
128
+ </article>
129
+ <article ean="7680548750532" pharmacode="2204899" qte-livraison="11" qte-facture="11">
130
+ <desc>ATACAND PLUS Tabl 16/12.5 mg 28 Stk</desc>
131
+ </article>
132
+ <article ean="7680548750617" pharmacode="2204907" qte-livraison="30" qte-facture="20">
133
+ <desc>ATACAND PLUS Tabl 16/12.5 mg 98 Stk</desc>
134
+ </article>
135
+ </com-pharma>
136
+ <com-pharma ean="7601001368491">
137
+ <livraison>
138
+ <last-name>Pharm. Ecole-de-M�decine</last-name>
139
+ <first-name> </first-name>
140
+ <other-name> Madame Fran�oise Recipient </other-name>
141
+ <address>
142
+ <street>3e adresse e-mail</street>
143
+ <zip>1205</zip>
144
+ <city>Gen�ve</city>
145
+ </address>
146
+ </livraison>
147
+ <article ean="7680543802083" pharmacode="2054106" qte-livraison="12" qte-facture="10">
148
+ <desc>ANTRA MUPS 10 Tabl 10 mg 100 Stk</desc>
149
+ </article>
150
+ <article ean="7680543800386" pharmacode="2054081" qte-livraison="12" qte-facture="10">
151
+ <desc>ANTRA MUPS 10 Tabl 10 mg 28 Stk</desc>
152
+ </article>
153
+ <article ean="7680543801949" pharmacode="2054098" qte-livraison="15" qte-facture="10">
154
+ <desc>ANTRA MUPS 10 Tabl 10 mg 56 Stk</desc>
155
+ </article>
156
+ <article ean="7680543800898" pharmacode="2054129" qte-livraison="7" qte-facture="7">
157
+ <desc>ANTRA MUPS 20 Tabl 20 mg 14 Stk</desc>
158
+ </article>
159
+ <article ean="7680543800973" pharmacode="2054135" qte-livraison="28" qte-facture="20">
160
+ <desc>ANTRA MUPS 20 Tabl 20 mg 28 Stk</desc>
161
+ </article>
162
+ <article ean="7680543802328" pharmacode="2054141" qte-livraison="8" qte-facture="8">
163
+ <desc>ANTRA MUPS 20 Tabl 20 mg 56 Stk</desc>
164
+ </article>
165
+ </com-pharma>
166
+ </commande>
167
+ XML
168
+ xml_doc = REXML::Document.new(src)
169
+ bdd = Conversion::PharmaciePlusBdd.convert(xml_doc)
170
+ transaction = FlexMock.new
171
+ transaction.should_receive(:model).and_return { bdd }
172
+ transaction.should_receive(:status=).with(:bbmb_ok).times(1)
173
+ bbmb = FlexMock.new
174
+ expected_ids = %w{7601001368095 7601001368491}
175
+ expected_orders = [
176
+ [
177
+ { :ean13 => "7680543801949", :pcode => "2054098", :quantity => 10 },
178
+ { :ean13 => "7680543802403", :pcode => "2054158", :quantity => 10 },
179
+ { :ean13 => "7680543800898", :pcode => "2054129", :quantity => 6},
180
+ { :ean13 => "7680543802328", :pcode=>"2054141", :quantity => 9},
181
+ { :ean13 => "7680543800706", :pcode=>"2054112", :quantity => 20},
182
+ { :ean13 => "7680548750532", :pcode=>"2204899", :quantity => 11},
183
+ { :ean13 => "7680548750617", :pcode=>"2204907", :quantity => 20},
184
+ ],
185
+ [
186
+ { :ean13 => "7680543802083", :pcode=>"2054106", :quantity => 10},
187
+ { :ean13 => "7680543800386", :pcode=>"2054081", :quantity => 10},
188
+ { :ean13 => "7680543801949", :pcode=>"2054098", :quantity => 10},
189
+ { :ean13 => "7680543800898", :pcode=>"2054129", :quantity => 7},
190
+ { :ean13 => "7680543800973", :pcode=>"2054135", :quantity => 20},
191
+ { :ean13 => "7680543802328", :pcode=>"2054141", :quantity => 8},
192
+ ],
193
+ ]
194
+ expected_infos = [
195
+ {
196
+ :reference => "1861",
197
+ },
198
+ {
199
+ :reference => "1861",
200
+ },
201
+ ]
202
+ bbmb.should_receive(:inject_order).times(2)\
203
+ .and_return { |id, order, info|
204
+ assert_equal(expected_ids.shift, id)
205
+ assert_equal(expected_orders.shift, order)
206
+ assert_equal(expected_infos.shift, info)
207
+ }
208
+ svc = DRb.start_service('druby://localhost:0', bbmb)
209
+ Bbmb2.inject(svc.uri, 'ean13', transaction)
210
+ ensure
211
+ svc.stop_service
212
+ end
213
+ def test_inject__soap
214
+ src = <<-XML
215
+ <?xml version="1.0" encoding="ISO-8859-1" ?>
216
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
217
+ <SOAP-ENV:Body>
218
+ <wbmb:auftrag xmlns:wbmb="http://ywesee.com/wbmb" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema">
219
+ <wbmb:absender xsi:type="enc:Array" enc:arrayType="wbmb:identifier[3]">
220
+ <wbmb:identifier>
221
+ <wbmb:idtype>name</wbmb:idtype>
222
+ <wbmb:idvalue>ywesee Testspit�ler</wbmb:idvalue>
223
+ </wbmb:identifier>
224
+ <wbmb:identifier>
225
+ <wbmb:idtype>kundennummer</wbmb:idtype>
226
+ <wbmb:idvalue>99</wbmb:idvalue>
227
+ </wbmb:identifier>
228
+ <wbmb:identifier>
229
+ <wbmb:idtype>auftragsnummer</wbmb:idtype>
230
+ <wbmb:idvalue>10019</wbmb:idvalue>
231
+ </wbmb:identifier>
232
+ </wbmb:absender>
233
+ <wbmb:empfaenger xsi:type="enc:Array" enc:arrayType="wbmb:identifier[2]">
234
+ <wbmb:identifier>
235
+ <wbmb:idtype>ean13</wbmb:idtype>
236
+ <wbmb:idvalue>7601001000681</wbmb:idvalue>
237
+ </wbmb:identifier>
238
+ <wbmb:identifier>
239
+ <wbmb:idtype>auftragsnummer</wbmb:idtype>
240
+ <wbmb:idvalue>76</wbmb:idvalue>
241
+ </wbmb:identifier>
242
+ </wbmb:empfaenger>
243
+ <wbmb:artikelliste xsi:type="enc:Array" enc:arrayType="wbmb:artikel[1]">
244
+ <wbmb:artikel>
245
+ <wbmb:position>1</wbmb:position>
246
+ <wbmb:identifier>
247
+ <wbmb:idtype>gag-code</wbmb:idtype>
248
+ <wbmb:idvalue>300976</wbmb:idvalue>
249
+ </wbmb:identifier>
250
+ <wbmb:identifier>
251
+ <wbmb:idtype>ean13</wbmb:idtype>
252
+ <wbmb:idvalue>1234567890123</wbmb:idvalue>
253
+ </wbmb:identifier>
254
+ <wbmb:identifier>
255
+ <wbmb:idtype>pharmacode</wbmb:idtype>
256
+ <wbmb:idvalue>1234567</wbmb:idvalue>
257
+ </wbmb:identifier>
258
+ <wbmb:bestellmenge>12</wbmb:bestellmenge>
259
+ <wbmb:artikelpreis>6.20</wbmb:artikelpreis>
260
+ </wbmb:artikel>
261
+ </wbmb:artikelliste>
262
+ <wbmb:auftrag_info xsi:type="enc:Array" enc:arrayType="wbmb:info[5]">
263
+ <wbmb:info>
264
+ <wbmb:infotype>text</wbmb:infotype>
265
+ <wbmb:infovalue>\344h... Diese Bestellung ist dringend!</wbmb:infovalue>
266
+ </wbmb:info>
267
+ <wbmb:info>
268
+ <wbmb:infotype>lieferung_bis</wbmb:infotype>
269
+ <wbmb:infovalue>2003-03-01 08:30:00</wbmb:infovalue>
270
+ </wbmb:info>
271
+ <wbmb:info>
272
+ <wbmb:infotype>lieferadresse</wbmb:infotype>
273
+ <wbmb:address xsi:type="enc:Array" enc:arrayType="wbmb:info[7]">
274
+ <wbmb:info>
275
+ <wbmb:infotype>name</wbmb:infotype>
276
+ <wbmb:infovalue>ywesee</wbmb:infovalue>
277
+ </wbmb:info>
278
+ <wbmb:info>
279
+ <wbmb:infotype>name</wbmb:infotype>
280
+ <wbmb:infovalue>intellectual capital connected</wbmb:infovalue>
281
+ </wbmb:info>
282
+ <wbmb:info>
283
+ <wbmb:infotype>strasse</wbmb:infotype>
284
+ <wbmb:infovalue>Postfach 1234</wbmb:infovalue>
285
+ </wbmb:info>
286
+ <wbmb:info>
287
+ <wbmb:infotype>strasse</wbmb:infotype>
288
+ <wbmb:infovalue>Winterthurerstrasse 52</wbmb:infovalue>
289
+ </wbmb:info>
290
+ <wbmb:info>
291
+ <wbmb:infotype>plz</wbmb:infotype>
292
+ <wbmb:infovalue>8006</wbmb:infovalue>
293
+ </wbmb:info>
294
+ <wbmb:info>
295
+ <wbmb:infotype>ort</wbmb:infotype>
296
+ <wbmb:infovalue>Zuerich</wbmb:infovalue>
297
+ </wbmb:info>
298
+ <wbmb:info>
299
+ <wbmb:infotype>land</wbmb:infotype>
300
+ <wbmb:infovalue>Schweiz</wbmb:infovalue>
301
+ </wbmb:info>
302
+ </wbmb:address>
303
+ </wbmb:info>
304
+ <wbmb:info>
305
+ <wbmb:infotype>versandkosten</wbmb:infotype>
306
+ <wbmb:infovalue>12.34</wbmb:infovalue>
307
+ </wbmb:info>
308
+ <wbmb:info>
309
+ <wbmb:infotype>schnittstelle</wbmb:infotype>
310
+ <wbmb:infovalue>62</wbmb:infovalue>
311
+ </wbmb:info>
312
+ </wbmb:auftrag_info>
313
+ </wbmb:auftrag>
314
+ </SOAP-ENV:Body>
315
+ </SOAP-ENV:Envelope>
316
+ XML
317
+ soap = SOAP::Marshal.unmarshal(src)
318
+ bdd = Conversion::WbmbBdd.convert(soap)
319
+ transaction = FlexMock.new
320
+ transaction.should_receive(:model).and_return { bdd }
321
+ transaction.should_receive(:status=).with(:bbmb_ok).times(1)
322
+ bbmb = FlexMock.new
323
+ expected_orders = [
324
+ [
325
+ { :ean13 => "1234567890123", :pcode => "1234567",
326
+ :quantity => 12, :article_number => "300976" },
327
+ ],
328
+ ]
329
+ expected_infos = [
330
+ {
331
+ :reference => "10019",
332
+ :comment => <<-EOS.strip
333
+ \303\244h... Diese Bestellung ist dringend!
334
+ EOS
335
+ },
336
+ ]
337
+ bbmb.should_receive(:inject_order).times(1)\
338
+ .and_return { |id, order, info|
339
+ assert_equal('99', id)
340
+ assert_equal(expected_orders.shift, order)
341
+ assert_equal(expected_infos.shift, info)
342
+ }
343
+ svc = DRb.start_service('druby://localhost:0', bbmb)
344
+ Bbmb2.inject(svc.uri, transaction)
345
+ #ensure
346
+ #svc.stop_service
347
+ end
348
+ def test_inject__propharma
349
+ src = <<-EOS
350
+ [KUNDE]
351
+ idt=123456
352
+ nam=Linden APOTHEKE
353
+ ort=5430 Wettingen
354
+ [BSTELL]
355
+ ref=100446
356
+ dat=A70626
357
+ tim=2131
358
+ [ARTIK]
359
+ typ=P
360
+ phc=02201228
361
+ art=AVEENO ADULTS CREAM 100 ML
362
+ mge=1
363
+ [ARTIK]
364
+ typ=P
365
+ phc=00931796
366
+ art=MEPHAMESON 8 INJ LOES 8 MG 50 AMP 2 ML
367
+ mge=4
368
+ [ARTIK]
369
+ typ=P
370
+ phc=01995226
371
+ art=3M INDAIR TAPE HEISSLUFT 19MMX50M 12 STK
372
+ mge=19
373
+ [ARTIK]
374
+ typ=P
375
+ phc=02584519
376
+ art=ABRI NET NETZHOSE 130-190CM XXL ORANGE BTL 50 STK
377
+ mge=4
378
+ [ARTIK]
379
+ typ=P
380
+ phc=01901722
381
+ art=ASPIRIN CARDIO 300 TABL 300 MG 90 STK
382
+ mge=10
383
+ [ARTIK]
384
+ typ=P
385
+ phc=10001318
386
+ art=BLUTDRUCKMESSEN
387
+ mge=1
388
+ [ARTIK]
389
+ typ=P
390
+ phc=00829336
391
+ art=PONSTAN FILMTABS 500 MG 120 STK
392
+ mge=2
393
+ [ARTIK]
394
+ typ=P
395
+ phc=00703285
396
+ art=PONSTAN FILMTABS 500 MG 36 STK
397
+ mge=11
398
+ [ARTIK]
399
+ typ=P
400
+ phc=10001446
401
+ art=REZEPTEROEFFNUNG
402
+ mge=2
403
+ EOS
404
+ parsed = Conversion::ProPharmaBdd.parse(src)
405
+ bdd = Conversion::ProPharmaBdd.convert(parsed)
406
+ transaction = FlexMock.new
407
+ transaction.should_receive(:model).and_return { bdd }
408
+ transaction.should_receive(:status=).with(:bbmb_ok).times(1)
409
+ bbmb = FlexMock.new
410
+ expected_orders = [
411
+ [
412
+ {:pcode => "2201228", :quantity => 1},
413
+ {:pcode => "931796", :quantity => 4},
414
+ {:pcode => "1995226", :quantity => 19},
415
+ {:pcode => "2584519", :quantity => 4},
416
+ {:pcode => "1901722", :quantity => 10},
417
+ {:pcode => "10001318", :quantity => 1},
418
+ {:pcode => "829336", :quantity => 2},
419
+ {:pcode => "703285", :quantity => 11},
420
+ {:pcode => "10001446", :quantity => 2},
421
+ ],
422
+ ]
423
+ expected_infos = [
424
+ {
425
+ :reference => "100446",
426
+ },
427
+ ]
428
+ bbmb.should_receive(:inject_order).times(1)\
429
+ .and_return { |id, order, info|
430
+ assert_equal('123456', id)
431
+ assert_equal(expected_orders.shift, order)
432
+ assert_equal(expected_infos.shift, info)
433
+ }
434
+ svc = DRb.start_service('druby://localhost:0', bbmb)
435
+ Bbmb2.inject(svc.uri, 'customer_id', transaction)
436
+ #ensure
437
+ #svc.stop_service
438
+ end
439
+ end
440
+ end
441
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # PostProcess::TestSoap -- xmlconv2 -- 25.08.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'postprocess/soap'
8
+ require 'flexmock'
9
+
10
+ module XmlConv
11
+ module PostProcess
12
+ class TestSoap < Test::Unit::TestCase
13
+ def test_update_partner
14
+ customer = FlexMock.new
15
+ customer.should_receive(:acc_id)\
16
+ .times(1).and_return { 'SOAPPartner' }
17
+ bsr = FlexMock.new
18
+ bsr.should_receive(:customer)\
19
+ .times(1).and_return { customer }
20
+ delivery = FlexMock.new
21
+ delivery.should_receive(:bsr)\
22
+ .times(1).and_return { bsr }
23
+ model = FlexMock.new
24
+ model.should_receive(:deliveries)\
25
+ .times(1).and_return { [delivery] }
26
+ transaction = FlexMock.new
27
+ transaction.should_receive(:model)\
28
+ .times(1).and_return { model }
29
+ transaction.should_receive(:partner=, 1)\
30
+ .times(1).and_return { |partner|
31
+ assert_equal('SOAPPartner', partner)
32
+ }
33
+ Soap.update_partner(transaction)
34
+ end
35
+ end
36
+ end
37
+ end