xmlconv 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/LICENSE +339 -0
- data/README.txt +29 -0
- data/Rakefile +37 -0
- data/bin/admin +68 -0
- data/bin/xmlconvd +38 -0
- data/data/grammar/i2.grammar +73 -0
- data/lib/xmlconv/config.rb +61 -0
- data/lib/xmlconv/custom/lookandfeel.rb +50 -0
- data/lib/xmlconv/i2/address.rb +35 -0
- data/lib/xmlconv/i2/date.rb +41 -0
- data/lib/xmlconv/i2/document.rb +27 -0
- data/lib/xmlconv/i2/header.rb +32 -0
- data/lib/xmlconv/i2/order.rb +61 -0
- data/lib/xmlconv/i2/parser.rb +23 -0
- data/lib/xmlconv/i2/position.rb +45 -0
- data/lib/xmlconv/i2/record.rb +11 -0
- data/lib/xmlconv/model/address.rb +20 -0
- data/lib/xmlconv/model/agreement.rb +10 -0
- data/lib/xmlconv/model/bdd.rb +37 -0
- data/lib/xmlconv/model/bsr.rb +16 -0
- data/lib/xmlconv/model/delivery.rb +15 -0
- data/lib/xmlconv/model/delivery_item.rb +24 -0
- data/lib/xmlconv/model/document.rb +25 -0
- data/lib/xmlconv/model/freetext_container.rb +26 -0
- data/lib/xmlconv/model/id_container.rb +22 -0
- data/lib/xmlconv/model/invoice.rb +18 -0
- data/lib/xmlconv/model/invoice_item.rb +11 -0
- data/lib/xmlconv/model/item.rb +19 -0
- data/lib/xmlconv/model/item_container.rb +15 -0
- data/lib/xmlconv/model/name.rb +27 -0
- data/lib/xmlconv/model/part_info.rb +10 -0
- data/lib/xmlconv/model/part_info_container.rb +15 -0
- data/lib/xmlconv/model/party.rb +20 -0
- data/lib/xmlconv/model/party_container.rb +20 -0
- data/lib/xmlconv/model/price.rb +10 -0
- data/lib/xmlconv/model/price_container.rb +18 -0
- data/lib/xmlconv/model/transaction.rb +28 -0
- data/lib/xmlconv/state/global.rb +28 -0
- data/lib/xmlconv/state/global_predefine.rb +11 -0
- data/lib/xmlconv/state/login.rb +39 -0
- data/lib/xmlconv/state/transaction.rb +13 -0
- data/lib/xmlconv/state/transactions.rb +130 -0
- data/lib/xmlconv/util/application.rb +142 -0
- data/lib/xmlconv/util/autoload.rb +35 -0
- data/lib/xmlconv/util/destination.rb +249 -0
- data/lib/xmlconv/util/invoicer.rb +71 -0
- data/lib/xmlconv/util/known_user.rb +16 -0
- data/lib/xmlconv/util/mail.rb +31 -0
- data/lib/xmlconv/util/polling_manager.rb +198 -0
- data/lib/xmlconv/util/session.rb +23 -0
- data/lib/xmlconv/util/transaction.rb +133 -0
- data/lib/xmlconv/util/validator.rb +20 -0
- data/lib/xmlconv/view/foot.rb +27 -0
- data/lib/xmlconv/view/head.rb +13 -0
- data/lib/xmlconv/view/login.rb +36 -0
- data/lib/xmlconv/view/navigation.rb +30 -0
- data/lib/xmlconv/view/navigationlink.rb +21 -0
- data/lib/xmlconv/view/pager.rb +73 -0
- data/lib/xmlconv/view/preformatted.rb +54 -0
- data/lib/xmlconv/view/template.rb +17 -0
- data/lib/xmlconv/view/transaction.rb +42 -0
- data/lib/xmlconv/view/transactions.rb +90 -0
- data/lib/xmlconv.rb +3 -0
- data/test/config.rb +12 -0
- data/test/mock.rb +149 -0
- data/test/suite.rb +16 -0
- data/test/test_i2/address.rb +88 -0
- data/test/test_i2/date.rb +50 -0
- data/test/test_i2/document.rb +62 -0
- data/test/test_i2/header.rb +39 -0
- data/test/test_i2/order.rb +94 -0
- data/test/test_i2/parser.rb +312 -0
- data/test/test_i2/position.rb +65 -0
- data/test/test_model/address.rb +35 -0
- data/test/test_model/agreement.rb +22 -0
- data/test/test_model/bdd.rb +55 -0
- data/test/test_model/bsr.rb +38 -0
- data/test/test_model/delivery.rb +79 -0
- data/test/test_model/delivery_item.rb +52 -0
- data/test/test_model/freetext_container.rb +45 -0
- data/test/test_model/invoice.rb +65 -0
- data/test/test_model/invoice_item.rb +41 -0
- data/test/test_model/name.rb +57 -0
- data/test/test_model/part_info.rb +24 -0
- data/test/test_model/party.rb +96 -0
- data/test/test_model/price.rb +24 -0
- data/test/test_util/application.rb +168 -0
- data/test/test_util/destination.rb +415 -0
- data/test/test_util/invoicer.rb +42 -0
- data/test/test_util/polling_manager.rb +299 -0
- data/test/test_util/transaction.rb +130 -0
- metadata +178 -0
data/test/mock.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# Ruby/Mock version 1.0
|
2
|
+
#
|
3
|
+
# A class for conveniently building mock objects in RUnit test cases.
|
4
|
+
# Copyright (c) 2001 Nat Pryce, all rights reserved
|
5
|
+
#
|
6
|
+
# This program is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
18
|
+
|
19
|
+
require 'runit/error'
|
20
|
+
|
21
|
+
|
22
|
+
class Mock
|
23
|
+
# Creates a new, named mock object. The name is reported in exceptions
|
24
|
+
# thrown by the mock object when method invocations are incorrect.
|
25
|
+
#
|
26
|
+
def initialize( mock_name = self.to_s )
|
27
|
+
@mock_calls = []
|
28
|
+
@next_call = 0
|
29
|
+
@name = mock_name
|
30
|
+
end
|
31
|
+
|
32
|
+
# Mock the next method call to be made to this mock object.
|
33
|
+
#
|
34
|
+
# A mock method is defined by the method name (a symbol) and a block
|
35
|
+
# that defines the arity of the method and the mocked behaviour for
|
36
|
+
# this call. The mocked behaviour should assert preconditions and
|
37
|
+
# return a value. Mocked behaviour should rarely be any more complex
|
38
|
+
# than that. If it is, that's probably an indication that the tests
|
39
|
+
# need some restructuring or that the tested code needs refactoring.
|
40
|
+
#
|
41
|
+
# If no block is given and preconditions have been defined for the named
|
42
|
+
# method, a block is created for the mocked methodthat has the same arity
|
43
|
+
# as the precondition and returns self.
|
44
|
+
#
|
45
|
+
def __next( name, &test )
|
46
|
+
if test == nil
|
47
|
+
if respond_to?( Mock.__pre(name) )
|
48
|
+
test = proc { |*args| self }
|
49
|
+
else
|
50
|
+
raise "no block given for mocked method #{name}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@mock_calls.push( [name,test] )
|
54
|
+
end
|
55
|
+
|
56
|
+
# Call this at the end of a test to ensure that all scheduled calls
|
57
|
+
# have been made to the mock
|
58
|
+
#
|
59
|
+
def __verify
|
60
|
+
if @next_call != @mock_calls.length
|
61
|
+
raise RUNIT::AssertionFailedError,
|
62
|
+
"not all expected method calls were made to #{@name}",
|
63
|
+
caller
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
private
|
69
|
+
# Dispatches aribtrary method calls to the next mocked behaviour
|
70
|
+
#
|
71
|
+
def method_missing( name, *args, &block )
|
72
|
+
__mock_call( name, args, (block_given? ? block : nil) )
|
73
|
+
end
|
74
|
+
|
75
|
+
# Implements a method call using the next mocked behaviour and asserts
|
76
|
+
# that the expected method is called with the expected number of
|
77
|
+
# arguments.
|
78
|
+
#
|
79
|
+
def __mock_call( name, args, block )
|
80
|
+
if @next_call >= @mock_calls.length
|
81
|
+
raise RUNIT::AssertionFailedError,
|
82
|
+
"unexpected call to #{name} method of #{@name}",
|
83
|
+
caller(2)
|
84
|
+
end
|
85
|
+
|
86
|
+
expected_name,body = @mock_calls[@next_call]
|
87
|
+
@next_call += 1
|
88
|
+
|
89
|
+
if name != expected_name
|
90
|
+
raise RUNIT::AssertionFailedError,
|
91
|
+
"wrong method called on #{@name}; " +
|
92
|
+
"expected #{expected_name}, was #{name}",
|
93
|
+
caller(2)
|
94
|
+
end
|
95
|
+
|
96
|
+
args_length = args.length + (block ? 1 : 0)
|
97
|
+
|
98
|
+
if body.arity < 0
|
99
|
+
if (body.arity+1).abs > args_length
|
100
|
+
raise RUNIT::AssertionFailedError,
|
101
|
+
"too few arguments to #{name} method of #{@name}; " +
|
102
|
+
"require #{(body.arity+1).abs}, got #{args.length}",
|
103
|
+
caller(2)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
if body.arity != args_length
|
107
|
+
raise RUNIT::AssertionFailedError,
|
108
|
+
"wrong number of arguments to " +
|
109
|
+
"#{name} method of #{@name}; " +
|
110
|
+
"require #{body.arity}, got #{args.length}",
|
111
|
+
caller(2)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
if respond_to? Mock.__pre(name)
|
116
|
+
if block
|
117
|
+
precondition_ok = __send__( Mock.__pre(name), *args, &block )
|
118
|
+
else
|
119
|
+
precondition_ok = __send__( Mock.__pre(name), *args )
|
120
|
+
end
|
121
|
+
|
122
|
+
if not precondition_ok
|
123
|
+
raise RUNIT::AssertionFailedError,
|
124
|
+
"precondition of #{name} method violated",
|
125
|
+
caller(2)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
if block
|
130
|
+
instance_eval { body.call( block, *args ) }
|
131
|
+
else
|
132
|
+
instance_eval { body.call( *args ) }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# The name of a precondition for a method
|
137
|
+
def Mock.__pre( method )
|
138
|
+
"__pre_#{method.to_i}".intern
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
def Mock.method_added( name )
|
143
|
+
unless(/^__pre_/.match(name.to_s))
|
144
|
+
pre = self.__pre(name)
|
145
|
+
alias_method( pre, name )
|
146
|
+
undef_method(name)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/test/suite.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# TestSuite -- xmlconv2 -- 01.06.2004 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.dirname(File.expand_path(__FILE__))
|
5
|
+
|
6
|
+
current_dir = File.dirname(__FILE__)
|
7
|
+
Dir.foreach(current_dir) { |dirname|
|
8
|
+
dirpath = File.expand_path(dirname, current_dir)
|
9
|
+
if(/^test_/o.match(dirname) && (File.ftype(dirpath) == 'directory'))
|
10
|
+
Dir.foreach(dirpath) { |filename|
|
11
|
+
if(/\.rb$/o.match(filename))
|
12
|
+
require "#{dirname}/#{filename}"
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
16
|
+
}
|
@@ -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('../../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'xmlconv/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,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# I2::TestDate -- xmlconv2 -- 02.06.2004 -- hwyss@ywesee.com
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
$: << File.expand_path('../../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'xmlconv/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_s__order_order
|
19
|
+
date = I2::Date.new(1975, 8, 21)
|
20
|
+
date.level = :order
|
21
|
+
date.code = :order
|
22
|
+
expected = <<-EOS
|
23
|
+
300:4
|
24
|
+
301:19750821
|
25
|
+
EOS
|
26
|
+
assert_equal(expected, date.to_s)
|
27
|
+
end
|
28
|
+
def test_to_s__position_delivery
|
29
|
+
date = I2::Date.new(1975, 8, 21)
|
30
|
+
date.level = :position
|
31
|
+
date.code = :delivery
|
32
|
+
expected = <<-EOS
|
33
|
+
540:2
|
34
|
+
541:19750821
|
35
|
+
EOS
|
36
|
+
assert_equal(expected, date.to_s)
|
37
|
+
end
|
38
|
+
def test_to_s__position_delivery
|
39
|
+
date = I2::Date.new(1975, 8, 21)
|
40
|
+
date.level = :order
|
41
|
+
date.code = :delivery
|
42
|
+
expected = <<-EOS
|
43
|
+
300:2
|
44
|
+
301:19750821
|
45
|
+
EOS
|
46
|
+
assert_equal(expected, date.to_s)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
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('../../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'xmlconv/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('../../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'xmlconv/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('../../lib', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'xmlconv/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
|