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,203 @@
1
+ #!/usr/bin/env ruby
2
+ # TestXmlBdd -- xmlconv2 -- 01.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'conversion/xml_bdd'
9
+
10
+ module XmlConv
11
+ module Conversion
12
+ class TestXmlBdd < Test::Unit::TestCase
13
+ def setup
14
+ @src = <<-EOS
15
+ <?xml version="1.0" encoding="ISO-8859-1"?>
16
+ <!DOCTYPE BDD SYSTEM "ABB BDD.dtd">
17
+ <BDD Version="2">
18
+ <BSR Version="3">
19
+ <Timestamp Zone="+1">20040416151630</Timestamp>
20
+ <Verb>Place</Verb>
21
+ <Noun>Order</Noun>
22
+ <Party Role="Customer" Version="2">
23
+ <Name>Winterhalter + Fenner AG</Name>
24
+ <PartyId Domain="ACC">%%%99999%%% Kundennummer ElectroLAN</PartyId>
25
+ </Party>
26
+ </BSR>
27
+ <Delivery Version="3">
28
+ <Status Date="20040416151441" Domain="">Order</Status>
29
+ <DeliveryId Domain="Customer">B-465178 W</DeliveryId>
30
+ <Party Version="2" Role="Seller">
31
+ <Name>Plica AG</Name>
32
+ <Address>
33
+ <AddressLine>Z�rcherstr. 350/Postfach 173</AddressLine>
34
+ <City>Frauenfeld</City>
35
+ <ZipCode Domain="">8501</ZipCode>
36
+ </Address>
37
+ </Party>
38
+ <Party Version="2" Role="Customer">
39
+ <Name>Winterhalter + Fenner AG</Name>
40
+ <Phone Domain="Business">01 / 839 58 44</Phone>
41
+ <Address>
42
+ <AddressLine>Birgistrasse 10</AddressLine>
43
+ <City>Wallisellen</City>
44
+ <ZipCode Domain="CH">8304</ZipCode>
45
+ </Address>
46
+ <Party Role="Employee">
47
+ <Name>
48
+ <LastName>Russo Giovanni</LastName>
49
+ </Name>
50
+ <Competency>Sachbearbeiter</Competency>
51
+ </Party>
52
+ <Party Role="ShipTo">
53
+ <Name>Winterhalter + Fenner AG</Name>
54
+ <PartyId Domain="ACC">%%%99999%%% Lieferadressnummer</PartyId>
55
+ <Address>
56
+ <AddressLine>Filiale Wallisellen</AddressLine>
57
+ <AddressLine>Hertistrasse 31</AddressLine>
58
+ <City>Wallisellen</City>
59
+ <ZipCode Domain="CH">8304</ZipCode>
60
+ </Address>
61
+ </Party>
62
+ <Party Role="BillTo">
63
+ <Name>Winterhalter + Fenner AG</Name>
64
+ <PartyId Domain="ACC">%%%99999%%% Rechnungsadressnummer</PartyId>
65
+ <Address>
66
+ <AddressLine>Birgistrasse 10</AddressLine>
67
+ <City>Wallisellen</City>
68
+ <ZipCode Domain="CH">8304</ZipCode>
69
+ </Address>
70
+ </Party>
71
+ </Party>
72
+ <DeliveryItem>
73
+ <LineNo>2508466</LineNo>
74
+ <PartId>
75
+ <IdentNo Domain="ET-NUMMER">125301307</IdentNo>
76
+ <IdentNo Domain="LIEFERANTENARTIKEL">15.0205.025</IdentNo>
77
+ </PartId>
78
+ <Qty>7200</Qty>
79
+ <FreeText Type="BEZEICHNUNG">KRF-ROHR PE O/DRAHT M25 OR</FreeText>
80
+ <DeliveryDate>14.04.2004</DeliveryDate>
81
+ </DeliveryItem>
82
+ <DeliveryItem>
83
+ <LineNo>2508467</LineNo>
84
+ <PartId>
85
+ <IdentNo Domain="ET-NUMMER">125301607</IdentNo>
86
+ <IdentNo Domain="LIEFERANTENARTIKEL">15.0202.550</IdentNo>
87
+ </PartId>
88
+ <Qty>900</Qty>
89
+ <FreeText Type="BEZEICHNUNG">KRF-ROHR PE O/DRAHT M50 OR</FreeText>
90
+ <DeliveryDate>SOFORT</DeliveryDate>
91
+ </DeliveryItem>
92
+ <DeliveryItem>
93
+ <LineNo>2508468</LineNo>
94
+ <PartId>
95
+ <IdentNo Domain="ET-NUMMER">125301707</IdentNo>
96
+ <IdentNo Domain="LIEFERANTENARTIKEL">15.0202.563</IdentNo>
97
+ </PartId>
98
+ <Qty>250</Qty>
99
+ <FreeText Type="BEZEICHNUNG">KRF-ROHR PE O/DRAHT M63 OR</FreeText>
100
+ <DeliveryDate>14.04.2004</DeliveryDate>
101
+ </DeliveryItem>
102
+ </Delivery>
103
+ </BDD>
104
+ EOS
105
+ @xml_doc = REXML::Document.new(@src)
106
+ end
107
+ def test_convert
108
+ bdd = XmlBdd.convert(@xml_doc)
109
+ assert_instance_of(Model::Bdd, bdd)
110
+ bsr = bdd.bsr
111
+ assert_instance_of(Model::Bsr, bsr)
112
+ delivery = bdd.deliveries.first
113
+ assert_instance_of(Model::Delivery, delivery)
114
+ assert_equal(bsr, delivery.bsr)
115
+ end
116
+ def test__bdd_add_xml_bsr
117
+ xml_bsr = REXML::XPath.first(@xml_doc, 'BDD/BSR')
118
+ bdd = Model::Bdd.new
119
+ XmlBdd._bdd_add_xml_bsr(bdd, xml_bsr)
120
+ bsr = bdd.bsr
121
+ assert_instance_of(Model::Bsr, bsr)
122
+ parties = bsr.parties
123
+ assert_instance_of(Model::Party, parties.first)
124
+ assert_equal('%%%99999%%% Kundennummer ElectroLAN', bsr.bsr_id)
125
+ end
126
+ def test__container_add_xml_party__seller
127
+ xml_party = REXML::XPath.first(@xml_doc, 'BDD/Delivery/Party')
128
+ delivery = Model::Delivery.new
129
+ XmlBdd._container_add_xml_party(delivery, xml_party)
130
+ seller = delivery.seller
131
+ assert_instance_of(Model::Party, seller)
132
+ assert_instance_of(Model::Name, seller.name)
133
+ assert_equal('Plica AG', seller.name.to_s)
134
+ seller_addr = seller.address
135
+ assert_instance_of(Model::Address, seller_addr)
136
+ assert_equal(['Z�rcherstr. 350/Postfach 173'], seller_addr.lines)
137
+ assert_equal('Frauenfeld', seller_addr.city)
138
+ assert_equal('8501', seller_addr.zip_code)
139
+ end
140
+ def test__container_add_xml_party__customer
141
+ xml_party = REXML::XPath.first(@xml_doc, "BDD/Delivery/Party[@Role='Customer']")
142
+ delivery = Model::Delivery.new
143
+ XmlBdd._container_add_xml_party(delivery, xml_party)
144
+ customer = delivery.customer
145
+ assert_instance_of(Model::Party, customer)
146
+ cust_addr = customer.address
147
+ assert_instance_of(Model::Address, cust_addr)
148
+ assert_equal(['Birgistrasse 10'], cust_addr.lines)
149
+ assert_equal('Wallisellen', cust_addr.city)
150
+ assert_equal('8304', cust_addr.zip_code)
151
+ assert_equal(3, customer.parties.size)
152
+ employee = customer.employee
153
+ assert_instance_of(Model::Party, employee)
154
+ assert_instance_of(Model::Name, employee.name)
155
+ assert_equal('Russo Giovanni', employee.name.last)
156
+ assert_equal('Russo Giovanni', employee.name.to_s)
157
+ ship_to = customer.ship_to
158
+ assert_instance_of(Model::Party, ship_to)
159
+ ship_to_addr = ship_to.address
160
+ assert_instance_of(Model::Address, ship_to_addr)
161
+ expected = [
162
+ 'Filiale Wallisellen',
163
+ 'Hertistrasse 31',
164
+ ]
165
+ assert_equal(expected, ship_to_addr.lines)
166
+ bill_to = customer.bill_to
167
+ assert_instance_of(Model::Party, bill_to)
168
+ bill_to_addr = bill_to.address
169
+ assert_instance_of(Model::Address, bill_to_addr)
170
+ end
171
+ def test__bdd_add_xml_delivery
172
+ xml_delivery = REXML::XPath.first(@xml_doc, 'BDD/Delivery')
173
+ bdd = Model::Bdd.new
174
+ XmlBdd._bdd_add_xml_delivery(bdd, xml_delivery)
175
+ delivery = bdd.deliveries.first
176
+ assert_instance_of(Model::Delivery, delivery)
177
+ assert_equal('B-465178 W', delivery.customer_id)
178
+ seller = delivery.seller
179
+ assert_instance_of(Model::Party, seller)
180
+ customer = delivery.customer
181
+ assert_instance_of(Model::Party, customer)
182
+ items = delivery.items
183
+ assert_equal(3, items.size)
184
+ item1 = items.first
185
+ assert_instance_of(Model::DeliveryItem, item1)
186
+ assert_equal('2508466', item1.line_no)
187
+ assert_equal('125301307', item1.et_nummer_id)
188
+ assert_equal('7200', item1.qty)
189
+ assert_equal(Date.new(2004,4,14), item1.delivery_date)
190
+ item2 = items.at(1)
191
+ assert_instance_of(Model::DeliveryItem, item2)
192
+ assert_equal('2508467', item2.line_no)
193
+ assert_equal('125301607', item2.et_nummer_id)
194
+ assert_equal('900', item2.qty)
195
+ assert_equal(Date.today, item2.delivery_date)
196
+ end
197
+ def test_parse
198
+ document = XmlBdd.parse(@src)
199
+ assert_instance_of(REXML::Document, document)
200
+ end
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+ # I2::TestAddress -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'i2/address'
9
+
10
+ module XmlConv
11
+ module I2
12
+ class TestAddress < Test::Unit::TestCase
13
+ def setup
14
+ @address = I2::Address.new
15
+ end
16
+ def test_attr_accessors
17
+ assert_respond_to(@address, :code)
18
+ assert_respond_to(@address, :code=)
19
+ assert_respond_to(@address, :party_id)
20
+ assert_respond_to(@address, :party_id=)
21
+ assert_respond_to(@address, :name1)
22
+ assert_respond_to(@address, :name1=)
23
+ assert_respond_to(@address, :name2)
24
+ assert_respond_to(@address, :name2=)
25
+ assert_respond_to(@address, :street1)
26
+ assert_respond_to(@address, :street1=)
27
+ assert_respond_to(@address, :street2)
28
+ assert_respond_to(@address, :street2=)
29
+ assert_respond_to(@address, :city)
30
+ assert_respond_to(@address, :city=)
31
+ assert_respond_to(@address, :zip_code)
32
+ assert_respond_to(@address, :zip_code=)
33
+ end
34
+ def test_to_s1
35
+ @address.code = :delivery
36
+ @address.name1 = 'Name1'
37
+ @address.name2 = 'Name2'
38
+ @address.street1 = 'Street1'
39
+ @address.street2 = 'Street2'
40
+ @address.city = 'City'
41
+ @address.zip_code = 'ZipCode'
42
+ expected = <<-EOS
43
+ 201:DP
44
+ 220:Name1
45
+ 221:Name2
46
+ 222:Street1
47
+ 223:City
48
+ 225:ZipCode
49
+ 226:Street2
50
+ EOS
51
+ assert_equal(expected, @address.to_s)
52
+ end
53
+ def test_to_s2
54
+ @address.party_id = 'BuyerId'
55
+ @address.name1 = 'Company Name'
56
+ @address.name2 = 'Employee Name'
57
+ expected = <<-EOS
58
+ 201:BY
59
+ 202:BuyerId
60
+ 220:Company Name
61
+ 221:Employee Name
62
+ EOS
63
+ assert_equal(expected, @address.to_s)
64
+ end
65
+ def test_to_s3
66
+ @address.code = :employee
67
+ @address.party_id = 'Delivery Code'
68
+ @address.name1 = 'Name1'
69
+ @address.name2 = 'Name2'
70
+ @address.street1 = 'Street1'
71
+ @address.street2 = 'Street2'
72
+ @address.city = 'City'
73
+ @address.zip_code = 'ZipCode'
74
+ expected = <<-EOS
75
+ 201:EP
76
+ 202:Delivery Code
77
+ 220:Name1
78
+ 221:Name2
79
+ 222:Street1
80
+ 223:City
81
+ 225:ZipCode
82
+ 226:Street2
83
+ EOS
84
+ assert_equal(expected, @address.to_s)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ # I2::TestDate -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'i2/date'
9
+
10
+ module XmlConv
11
+ module I2
12
+ class TestDate < Test::Unit::TestCase
13
+ def test_from_date
14
+ a_date = Date.new(1975, 8, 21)
15
+ date = I2::Date.from_date(a_date)
16
+ assert_equal(a_date, date)
17
+ end
18
+ def test_to_s1
19
+ # NOTE
20
+ # DTSTTCPW here and now is to allow only two possibilities for
21
+ # I2::Date:
22
+ # Order-Date on the Order-Level (300:4\n301:strftime) and
23
+ # Delivery-Date on the Position-Level (540:2\n540:strftime)
24
+ # This code is likely to change.
25
+ date = I2::Date.new(1975, 8, 21)
26
+ expected = <<-EOS
27
+ 300:4
28
+ 301:19750821
29
+ EOS
30
+ assert_equal(expected, date.to_s)
31
+ end
32
+ def test_to_s2
33
+ # NOTE
34
+ # DTSTTCPW here and now is to allow only two possibilities for
35
+ # I2::Date:
36
+ # Order-Date on the Order-Level (300:4\n301:strftime) and
37
+ # Delivery-Date on the Position-Level (540:2\n540:strftime)
38
+ # This code is likely to change.
39
+ date = I2::Date.new(1975, 8, 21)
40
+ date.code = :delivery
41
+ expected = <<-EOS
42
+ 540:2
43
+ 541:19750821
44
+ EOS
45
+ assert_equal(expected, date.to_s)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ # I2::TestDocument -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'i2/document'
9
+ require 'mock'
10
+
11
+ module XmlConv
12
+ module I2
13
+ class TestDocument < Test::Unit::TestCase
14
+ class ToSMock < Mock
15
+ def to_s
16
+ true
17
+ end
18
+ end
19
+ def setup
20
+ @document = I2::Document.new
21
+ end
22
+ def test_attr_accessors
23
+ assert_respond_to(@document, :header)
24
+ assert_respond_to(@document, :header=)
25
+ end
26
+ def test_add_order
27
+ assert_equal([], @document.orders)
28
+ order = Mock.new
29
+ @document.add_order(order)
30
+ assert_equal([order], @document.orders)
31
+ order.__verify
32
+ end
33
+ def test_to_s
34
+ header = ToSMock.new('Header')
35
+ @document.header = header
36
+ header.__next(:to_s) { "000:A Header\n" }
37
+ order1 = ToSMock.new('Order1')
38
+ @document.add_order(order1)
39
+ order1.__next(:to_s) { "100:An Order\n" }
40
+ order2 = ToSMock.new('Order2')
41
+ @document.add_order(order2)
42
+ order2.__next(:to_s) { "100:Another Order\n" }
43
+ expected = <<-EOS
44
+ 000:A Header
45
+ 100:An Order
46
+ 100:Another Order
47
+ EOS
48
+ assert_equal(expected, @document.to_s)
49
+ header.__verify
50
+ order1.__verify
51
+ order2.__verify
52
+ end
53
+ def test_filename
54
+ header = Mock.new
55
+ header.__next(:filename) { 'result.dat' }
56
+ @document.header = header
57
+ assert_equal('result.dat', @document.filename)
58
+ header.__verify
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ # I2::TestHeader -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'i2/header'
9
+
10
+ module XmlConv
11
+ module I2
12
+ class TestHeader < Test::Unit::TestCase
13
+ def setup
14
+ @header = Header.new
15
+ end
16
+ def test_attr_accessors
17
+ assert_respond_to(@header, :recipient_id)
18
+ assert_respond_to(@header, :recipient_id=)
19
+ assert_respond_to(@header, :filename)
20
+ assert_respond_to(@header, :filename=)
21
+ end
22
+ def test_to_s
23
+ @header.recipient_id = 'Recipient'
24
+ @header.filename = 'filename.dat'
25
+ expected = <<-EOS
26
+ 001:Recipient
27
+ 002:ORDERX
28
+ 003:220
29
+ 010:filename.dat
30
+ EOS
31
+ assert_equal(expected, @header.to_s)
32
+ end
33
+ def test_filename
34
+ expected = Time.now.strftime("#{@header.recipient_id}_%Y%m%d%H%M%S")
35
+ assert_match(/#{expected}\d{3}.dat/, @header.filename)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+ # I2::TestOrder -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.expand_path('../../src', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'i2/order'
9
+ require 'mock'
10
+
11
+ module XmlConv
12
+ module I2
13
+ class TestOrder < Test::Unit::TestCase
14
+ class ToSMock < Mock
15
+ def to_s
16
+ true
17
+ end
18
+ end
19
+ def setup
20
+ @order = Order.new
21
+ end
22
+ def test_attr_accessors
23
+ assert_respond_to(@order, :sender_id)
24
+ assert_respond_to(@order, :sender_id=)
25
+ assert_respond_to(@order, :delivery_id)
26
+ assert_respond_to(@order, :delivery_id=)
27
+ end
28
+ def test_attr_readers
29
+ assert_respond_to(@order, :addresses)
30
+ end
31
+ def test_add_address
32
+ assert_equal([], @order.addresses)
33
+ address = Mock.new
34
+ @order.add_address(address)
35
+ assert_equal([address], @order.addresses)
36
+ address.__verify
37
+ end
38
+ def test_add_date
39
+ assert_equal([], @order.dates)
40
+ date = Mock.new
41
+ @order.add_date(date)
42
+ assert_equal([date], @order.dates)
43
+ date.__verify
44
+ end
45
+ def test_add_position
46
+ assert_equal([], @order.positions)
47
+ position = Mock.new
48
+ @order.add_position(position)
49
+ assert_equal([position], @order.positions)
50
+ position.__verify
51
+ end
52
+ def test_to_s
53
+ @order.sender_id = 'Sender'
54
+ @order.delivery_id = 'DeliveryId'
55
+ address1 = ToSMock.new('Address1')
56
+ @order.add_address(address1)
57
+ address1.__next(:to_s) { "200:An Address\n" }
58
+ address2 = ToSMock.new('Address2')
59
+ @order.add_address(address2)
60
+ address2.__next(:to_s) { "200:Another Address\n" }
61
+ date1 = ToSMock.new('Date1')
62
+ @order.add_date(date1)
63
+ date1.__next(:to_s) { "300:A Date\n" }
64
+ date2 = ToSMock.new('Date2')
65
+ @order.add_date(date2)
66
+ date2.__next(:to_s) { "300:Another Date\n" }
67
+ pos1 = ToSMock.new('Position1')
68
+ @order.add_position(pos1)
69
+ pos1.__next(:to_s) { "500:A Position\n" }
70
+ pos2 = ToSMock.new('Position2')
71
+ @order.add_position(pos2)
72
+ pos2.__next(:to_s) { "500:Another Position\n" }
73
+ expected = <<-EOS
74
+ 100:Sender
75
+ 101:DeliveryId
76
+ 200:An Address
77
+ 200:Another Address
78
+ 237:61
79
+ 300:A Date
80
+ 300:Another Date
81
+ 500:A Position
82
+ 500:Another Position
83
+ EOS
84
+ assert_equal(expected, @order.to_s)
85
+ address1.__verify
86
+ address2.__verify
87
+ date1.__verify
88
+ date2.__verify
89
+ pos1.__verify
90
+ pos2.__verify
91
+ end
92
+ end
93
+ end
94
+ end