sbsm 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/COPYING +515 -0
  2. data/History.txt +5 -0
  3. data/Manifest.txt +49 -0
  4. data/README.txt +41 -0
  5. data/Rakefile +28 -0
  6. data/data/_flavored_uri.grammar +24 -0
  7. data/data/_uri.grammar +22 -0
  8. data/data/_zone_uri.grammar +24 -0
  9. data/data/flavored_uri.grammar +24 -0
  10. data/data/uri.grammar +22 -0
  11. data/data/zone_uri.grammar +24 -0
  12. data/install.rb +1098 -0
  13. data/lib/cgi/drbsession.rb +37 -0
  14. data/lib/sbsm/cgi.rb +79 -0
  15. data/lib/sbsm/drb.rb +19 -0
  16. data/lib/sbsm/drbserver.rb +162 -0
  17. data/lib/sbsm/exception.rb +28 -0
  18. data/lib/sbsm/flavored_uri_parser.rb +47 -0
  19. data/lib/sbsm/index.rb +66 -0
  20. data/lib/sbsm/lookandfeel.rb +176 -0
  21. data/lib/sbsm/lookandfeelfactory.rb +50 -0
  22. data/lib/sbsm/lookandfeelwrapper.rb +109 -0
  23. data/lib/sbsm/redefine_19_cookie.rb +4 -0
  24. data/lib/sbsm/redirector.rb +37 -0
  25. data/lib/sbsm/request.rb +162 -0
  26. data/lib/sbsm/session.rb +542 -0
  27. data/lib/sbsm/state.rb +301 -0
  28. data/lib/sbsm/time.rb +29 -0
  29. data/lib/sbsm/trans_handler.rb +119 -0
  30. data/lib/sbsm/turing.rb +25 -0
  31. data/lib/sbsm/uri_parser.rb +45 -0
  32. data/lib/sbsm/user.rb +47 -0
  33. data/lib/sbsm/validator.rb +256 -0
  34. data/lib/sbsm/viralstate.rb +47 -0
  35. data/lib/sbsm/zone_uri_parser.rb +48 -0
  36. data/test/data/dos_file.txt +2 -0
  37. data/test/data/lnf_file.txt +2 -0
  38. data/test/data/mac_file.txt +1 -0
  39. data/test/stub/cgi.rb +35 -0
  40. data/test/suite.rb +29 -0
  41. data/test/test_drbserver.rb +83 -0
  42. data/test/test_index.rb +90 -0
  43. data/test/test_lookandfeel.rb +230 -0
  44. data/test/test_session.rb +372 -0
  45. data/test/test_state.rb +176 -0
  46. data/test/test_trans_handler.rb +447 -0
  47. data/test/test_user.rb +44 -0
  48. data/test/test_validator.rb +126 -0
  49. data/usage-en.txt +112 -0
  50. metadata +142 -0
@@ -0,0 +1,2 @@
1
+ This dos text looked up from File
2
+ With a newline
@@ -0,0 +1,2 @@
1
+ This text looked up from File
2
+ With a newline
@@ -0,0 +1 @@
1
+ This mac text looked up from File
data/test/stub/cgi.rb ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # State Based Session Management
4
+ # Copyright (C) 2004 Hannes Wyss
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # CGI -- oddb -- 18.11.2002 -- hwyss@ywesee.com
24
+
25
+ require 'sbsm/cgi'
26
+
27
+ class CGI
28
+ STUB_VALUES = {}
29
+ def initialize throwaway=nil
30
+ extend Html4Tr
31
+ element_init()
32
+ extend HtmlExtension
33
+ @params = STUB_VALUES.dup
34
+ end
35
+ end
data/test/suite.rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # State Based Session Management
4
+ # Copyright (C) 2004 Hannes Wyss
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # suite.rb -- oddb -- 20.11.2002 -- hwyss@ywesee.com
24
+
25
+ $: << File.expand_path(File.dirname(__FILE__))
26
+
27
+ Dir.foreach(File.dirname(__FILE__)) { |file|
28
+ require file if /^test_.*\.rb$/o.match(file)
29
+ }
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # State Based Session Management
4
+ # Copyright (C) 2004 Hannes Wyss
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # TestDRbServer -- ODDB -- 27.11.2003 -- hwyss@ywesee.com
24
+
25
+
26
+ $: << File.dirname(__FILE__)
27
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
28
+
29
+ require 'test/unit'
30
+ require 'sbsm/drbserver'
31
+
32
+ class TestDRbServer < Test::Unit::TestCase
33
+ class DRbServer < ::SBSM::DRbServer
34
+ attr_reader :sessions
35
+ CAP_MAX_THRESHOLD = 3
36
+ MAX_SESSIONS = 3
37
+ end
38
+ def setup
39
+ @server = DRbServer.new
40
+ end
41
+ def test_session
42
+ ses1 = @server['test1']
43
+ assert_instance_of(SBSM::Session, ses1)
44
+ assert_equal({'test1'=>ses1}, @server.sessions)
45
+ ses2 = @server['test2']
46
+ assert_instance_of(SBSM::Session, ses2)
47
+ assert_not_equal(ses1, ses2)
48
+ expected = {
49
+ 'test1' => ses1,
50
+ 'test2' => ses2,
51
+ }
52
+ assert_equal(expected, @server.sessions)
53
+ ses3 = @server['test3']
54
+ assert_instance_of(SBSM::Session, ses3)
55
+ assert_not_equal(ses1, ses3)
56
+ assert_not_equal(ses2, ses3)
57
+ expected = {
58
+ 'test1' => ses1,
59
+ 'test2' => ses2,
60
+ 'test3' => ses3,
61
+ }
62
+ assert_equal(expected, @server.sessions)
63
+ ses4 = @server['test4']
64
+ assert_instance_of(SBSM::Session, ses4)
65
+ assert_not_equal(ses1, ses4)
66
+ assert_not_equal(ses2, ses4)
67
+ expected = {
68
+ 'test2' => ses2,
69
+ 'test3' => ses3,
70
+ 'test4' => ses4,
71
+ }
72
+ @server.cap_max_sessions
73
+ assert_equal(expected, @server.sessions)
74
+ ses2.touch
75
+ ses5 = @server['test5']
76
+ assert_instance_of(SBSM::Session, ses5)
77
+ expected = {
78
+ 'test2' => ses2,
79
+ 'test4' => ses4,
80
+ 'test5' => ses5,
81
+ }
82
+ end
83
+ end
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # State Based Session Management
4
+ # Copyright (C) 2004 Hannes Wyss
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # TestIndex -- sbsm -- 04.03.2003 -- hwyss@ywesee.com
24
+
25
+ $: << File.dirname(__FILE__)
26
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
27
+
28
+ require 'test/unit'
29
+ require 'sbsm/index'
30
+
31
+ module SBSM
32
+ class Index
33
+ attr_accessor :values, :children
34
+ end
35
+ end
36
+
37
+ class TestIndex < Test::Unit::TestCase
38
+ def setup
39
+ @index = SBSM::Index.new
40
+ o2 = SBSM::Index.new
41
+ o2.values = ['bar']
42
+ o1 = SBSM::Index.new
43
+ o1.children[?o] = o2
44
+ f = SBSM::Index.new
45
+ f.children[?o] = o1
46
+ r = SBSM::Index.new
47
+ r.values = ['foo']
48
+ a = SBSM::Index.new
49
+ a.children[?r] = r
50
+ b = SBSM::Index.new
51
+ b.children[?a] = a
52
+ @index.children[?b] = b
53
+ @index.children[?f] = f
54
+ end
55
+ def test_to_a
56
+ assert_equal(['foo', 'bar'], @index.to_a)
57
+ end
58
+ def test_fetch1
59
+ assert_equal(['bar'], @index.fetch('foo'))
60
+ end
61
+ def test_fetch2
62
+ assert_equal([], @index.fetch('Foo'))
63
+ end
64
+ def test_fetch3
65
+ @index.store('bar', ['foobar', 'babar'])
66
+ assert_equal(['foo', ['foobar', 'babar']], @index['ba'])
67
+ end
68
+ def test_store1
69
+ @index.store('bar', 'babar')
70
+ assert_equal(['foo', 'babar'], @index.children[?b].children[?a].children[?r].values)
71
+ assert_equal(['foo', 'babar'], @index['ba'])
72
+ end
73
+ def test_store2
74
+ @index.store('bar', 'foobar', 'babar')
75
+ assert_equal(['foo', 'foobar', 'babar'], @index.children[?b].children[?a].children[?r].values)
76
+ assert_equal(['foo', 'foobar', 'babar'], @index['ba'])
77
+ end
78
+ def test_store3
79
+ @index.store('bar', ['foobar', 'babar'])
80
+ assert_equal(['foo', ['foobar', 'babar']], @index.children[?b].children[?a].children[?r].values)
81
+ end
82
+ def test_replace
83
+ @index.replace('foo', 'muh', 'bar')
84
+ assert_equal(['bar'], @index.children[?m].children[?u].children[?h].values)
85
+ end
86
+ def test_delete
87
+ @index.delete('foo', 'bar')
88
+ assert_equal([], @index.children[?f].children[?o].children[?o].values)
89
+ end
90
+ end
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # State Based Session Management
4
+ # Copyright (C) 2004 Hannes Wyss
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # TestLookandfeel -- sbsm -- 15.11.2002 -- hwyss@ywesee.com
24
+
25
+ require 'test/unit'
26
+ require 'sbsm/lookandfeel'
27
+ require 'date'
28
+ require 'sbsm/lookandfeelwrapper'
29
+
30
+ class StubLookandfeelState
31
+ attr_reader :direct_event
32
+ def initialize(direct_event)
33
+ @direct_event = direct_event
34
+ end
35
+ end
36
+ class StubLookandfeelSession
37
+ attr_accessor :persistent_user_input, :user_input, :state,
38
+ :is_crawler
39
+ DEFAULT_LANGUAGE = "de"
40
+ def initialize(*args)
41
+ @persistent_user_input = {}
42
+ @user_input = nil
43
+ end
44
+ def default_language
45
+ "de"
46
+ end
47
+ def is_crawler?
48
+ !!@is_crawler
49
+ end
50
+ def language
51
+ persistent_user_input(:language) \
52
+ || self::class::DEFAULT_LANGUAGE
53
+ end
54
+ def navigation
55
+ [
56
+ StubLookandfeelState.new(:foo),
57
+ StubLookandfeelState.new(:bar),
58
+ StubLookandfeelState.new(:baz),
59
+ ]
60
+ end
61
+ def persistent_user_input(key)
62
+ if (value = @user_input)
63
+ @persistent_user_input.store(key, value)
64
+ else
65
+ @persistent_user_input[key]
66
+ end
67
+ end
68
+ def flavor
69
+ "gcc"
70
+ end
71
+ def server_name
72
+ "test.com"
73
+ end
74
+ def http_protocol
75
+ "http"
76
+ end
77
+ end
78
+ class StubNotBuiltIn
79
+ end
80
+
81
+ class LookandfeelBase < SBSM::Lookandfeel
82
+ HTML_ATTRIBUTES = {
83
+ :stub => {:foo=>"Bar", :baz=>123, :rof=>StubNotBuiltIn},
84
+ }
85
+ RESOURCES = {
86
+ :foo => 'bar'
87
+ }
88
+
89
+ DICTIONARIES = {
90
+ "de" => {
91
+ :date_format=> '%d.%m.%Y',
92
+ :foo => "dictbar",
93
+ :from_file => txt_file('lnf_file.txt'),
94
+ :from_file_mac => txt_file('mac_file.txt'),
95
+ :from_file_dos => txt_file('dos_file.txt'),
96
+ },
97
+ "fr" => {
98
+ :foo => "frabar",
99
+ },
100
+ }
101
+ TXT_RESOURCES = File.expand_path('data', File.dirname(__FILE__))
102
+ end
103
+ class LookandfeelWrapper1 < SBSM::LookandfeelWrapper
104
+ HTML_ATTRIBUTES = {
105
+ :stub => {:foo=>'baz'}
106
+ }
107
+ ENABLED = [:foo, :bar, :bof]
108
+ RESOURCES = {
109
+ :foo => 'foo',
110
+ }
111
+ end
112
+ class LookandfeelWrapper2 < SBSM::LookandfeelWrapper
113
+ ENABLED = [:baz]
114
+ end
115
+
116
+ class TestLookandfeel < Test::Unit::TestCase
117
+ def setup
118
+ @session = StubLookandfeelSession.new
119
+ @lookandfeel = LookandfeelBase.new(@session)
120
+ end
121
+ def test_attributes
122
+ expected = {:foo=>"Bar", :baz=>123, :rof=>StubNotBuiltIn}
123
+ assert_equal(expected, @lookandfeel.attributes(:stub))
124
+ end
125
+ def test_no_attributes
126
+ assert_equal({}, @lookandfeel.attributes(:undefined))
127
+ end
128
+ def test_resource
129
+ assert_equal('http://test.com/resources/gcc/bar', @lookandfeel.resource(:foo))
130
+ end
131
+ def test_lookup
132
+ assert_equal('dictbar', @lookandfeel.lookup(:foo))
133
+ end
134
+ def test_lookup2
135
+ assert_equal("This text looked up from File<br>With a newline", @lookandfeel.lookup(:from_file))
136
+ end
137
+ def test_lookup3
138
+ assert_equal("This mac text looked up from File<br>With a newline", @lookandfeel.lookup(:from_file_mac))
139
+ end
140
+ def test_lookup4
141
+ assert_equal("This dos text looked up from File<br>With a newline", @lookandfeel.lookup(:from_file_dos))
142
+ end
143
+ def test_lookup5
144
+ session = StubLookandfeelSession.new
145
+ session.user_input = "fr"
146
+ lookandfeel2 = LookandfeelBase.new(session)
147
+ assert_equal("frabar", lookandfeel2.lookup(:foo))
148
+ end
149
+ def test_lookup6
150
+ session = StubLookandfeelSession.new
151
+ session.user_input = "fr"
152
+ lookandfeel2 = LookandfeelBase.new(session)
153
+ assert_equal("%d.%m.%Y", lookandfeel2.lookup(:date_format))
154
+ end
155
+ def test_rfc1123
156
+ time = Time.local(2002,11,20,9,45,23)
157
+ expected = 'Wed, 20 Nov 2002 08:45:23 GMT'
158
+ assert_equal(expected, time.rfc1123)
159
+ end
160
+ def test_base_url
161
+ assert_equal("http://test.com/de/gcc", @lookandfeel.base_url)
162
+ end
163
+ def test_event_url
164
+ # state_id is 4, because @session.state = nil
165
+ assert_equal("http://test.com/de/gcc/foo/state_id/4/bar/baz",
166
+ @lookandfeel.event_url(:foo, {:bar => 'baz'}))
167
+ end
168
+ def test_event_url__crawler
169
+ @session.is_crawler = true
170
+ assert_equal("http://test.com/de/gcc/foo/bar/baz",
171
+ @lookandfeel.event_url(:foo, {:bar => 'baz'}))
172
+ end
173
+ def test_event_url__state_id_given
174
+ assert_equal("http://test.com/de/gcc/foo/bar/baz/state_id/mine",
175
+ @lookandfeel.event_url(:foo, [:bar, 'baz', :state_id, 'mine']))
176
+ end
177
+ def test_format_price
178
+ assert_equal('123.45', @lookandfeel.format_price(12345))
179
+ assert_equal(nil, @lookandfeel.format_price(nil))
180
+ assert_equal(nil, @lookandfeel.format_price(0))
181
+ end
182
+ def test_format_date
183
+ hannesgeburtstag = Date.new(1975,8,21)
184
+ expected = '21.08.1975'
185
+ assert_equal(expected, @lookandfeel.format_date(hannesgeburtstag))
186
+ end
187
+ def test_languages
188
+ assert_equal(['de', 'fr'], @lookandfeel.languages)
189
+ end
190
+ end
191
+ class TestLookandfeelWrapper < Test::Unit::TestCase
192
+ def setup
193
+ @lookandfeel = LookandfeelBase.new(StubLookandfeelSession.new)
194
+ @wrapped = LookandfeelWrapper1.new(@lookandfeel)
195
+ end
196
+ def test_navigation1
197
+ lnf = SBSM::LookandfeelWrapper.new(@lookandfeel)
198
+ assert_equal([], lnf.navigation)
199
+ end
200
+ def test_navigation2
201
+ nav = @wrapped.navigation
202
+ result = nav.collect { |st| st.direct_event }
203
+ assert_equal([:foo, :bar], result)
204
+ end
205
+ def test_navigation3
206
+ lnf = LookandfeelWrapper2.new(@wrapped)
207
+ nav = lnf.navigation
208
+ result = nav.collect { |st| st.direct_event }
209
+ assert_equal([:foo, :bar, :baz], result)
210
+ end
211
+ def test_flavor
212
+ assert_equal('gcc', @wrapped.flavor)
213
+ end
214
+ def test_resource1
215
+ lnf = SBSM::LookandfeelWrapper.new(@lookandfeel)
216
+ assert_equal('http://test.com/resources/gcc/bar', lnf.resource(:foo))
217
+ end
218
+ def test_resource2
219
+ assert_equal('http://test.com/resources/gcc/foo', @wrapped.resource(:foo))
220
+ end
221
+ def test_attributes1
222
+ lnf = SBSM::LookandfeelWrapper.new(@lookandfeel)
223
+ expected = {:foo=>"Bar", :baz=>123, :rof=>StubNotBuiltIn}
224
+ assert_equal(expected, lnf.attributes(:stub))
225
+ end
226
+ def test_attributes2
227
+ expected = {:foo=>"baz"}
228
+ assert_equal(expected, @wrapped.attributes(:stub))
229
+ end
230
+ end