arrow 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/ChangeLog +1590 -0
  2. data/LICENSE +28 -0
  3. data/README +75 -0
  4. data/Rakefile +366 -0
  5. data/Rakefile.local +63 -0
  6. data/data/arrow/applets/TEMPLATE.rb.tpl +53 -0
  7. data/data/arrow/applets/args.rb +50 -0
  8. data/data/arrow/applets/config.rb +55 -0
  9. data/data/arrow/applets/error.rb +63 -0
  10. data/data/arrow/applets/files.rb +46 -0
  11. data/data/arrow/applets/inspect.rb +46 -0
  12. data/data/arrow/applets/nosuchapplet.rb +31 -0
  13. data/data/arrow/applets/status.rb +92 -0
  14. data/data/arrow/applets/test.rb +133 -0
  15. data/data/arrow/applets/tutorial/counter.rb +96 -0
  16. data/data/arrow/applets/tutorial/dingus.rb +67 -0
  17. data/data/arrow/applets/tutorial/hello.rb +34 -0
  18. data/data/arrow/applets/tutorial/hello2.rb +73 -0
  19. data/data/arrow/applets/tutorial/imgtext.rb +90 -0
  20. data/data/arrow/applets/tutorial/imgtext2.rb +286 -0
  21. data/data/arrow/applets/tutorial/index.rb +36 -0
  22. data/data/arrow/applets/tutorial/logo.rb +98 -0
  23. data/data/arrow/applets/tutorial/memcache.rb +61 -0
  24. data/data/arrow/applets/tutorial/missing.rb +37 -0
  25. data/data/arrow/applets/tutorial/protected.rb +100 -0
  26. data/data/arrow/applets/tutorial/redirector.rb +52 -0
  27. data/data/arrow/applets/tutorial/rndimages.rb +159 -0
  28. data/data/arrow/applets/tutorial/sharenotes.rb +83 -0
  29. data/data/arrow/applets/tutorial/subclassed-hello.rb +32 -0
  30. data/data/arrow/applets/tutorial/superhello.rb +72 -0
  31. data/data/arrow/applets/tutorial/timeclock.rb +78 -0
  32. data/data/arrow/applets/view-applet.rb +123 -0
  33. data/data/arrow/applets/view-template.rb +85 -0
  34. data/data/arrow/applets/wiki.rb +274 -0
  35. data/data/arrow/templates/TEMPLATE.tmpl.tpl +36 -0
  36. data/data/arrow/templates/applet-status.tmpl +153 -0
  37. data/data/arrow/templates/args-display.tmpl +120 -0
  38. data/data/arrow/templates/config/display-table.tmpl +36 -0
  39. data/data/arrow/templates/config/display.tmpl +36 -0
  40. data/data/arrow/templates/counter-deleted.tmpl +33 -0
  41. data/data/arrow/templates/counter.tmpl +59 -0
  42. data/data/arrow/templates/dingus.tmpl +55 -0
  43. data/data/arrow/templates/enumtable.tmpl +8 -0
  44. data/data/arrow/templates/error-display.tmpl +92 -0
  45. data/data/arrow/templates/filemap.tmpl +89 -0
  46. data/data/arrow/templates/hello-world-src.tmpl +34 -0
  47. data/data/arrow/templates/hello-world.tmpl +60 -0
  48. data/data/arrow/templates/imgtext/fontlist.tmpl +46 -0
  49. data/data/arrow/templates/imgtext/form.tmpl +70 -0
  50. data/data/arrow/templates/imgtext/reload-error.tmpl +40 -0
  51. data/data/arrow/templates/imgtext/reload.tmpl +55 -0
  52. data/data/arrow/templates/inspect/display.tmpl +80 -0
  53. data/data/arrow/templates/loginform.tmpl +64 -0
  54. data/data/arrow/templates/logout.tmpl +32 -0
  55. data/data/arrow/templates/memcache/display.tmpl +41 -0
  56. data/data/arrow/templates/navbar.incl +27 -0
  57. data/data/arrow/templates/nosuchapplet.tmpl +32 -0
  58. data/data/arrow/templates/printsource.tmpl +35 -0
  59. data/data/arrow/templates/protected.tmpl +36 -0
  60. data/data/arrow/templates/rndimages.tmpl +38 -0
  61. data/data/arrow/templates/service-response.tmpl +13 -0
  62. data/data/arrow/templates/sharenotes/display.tmpl +38 -0
  63. data/data/arrow/templates/status.tmpl +120 -0
  64. data/data/arrow/templates/templateviewer.tmpl +43 -0
  65. data/data/arrow/templates/test/harness.tmpl +57 -0
  66. data/data/arrow/templates/test/list.tmpl +48 -0
  67. data/data/arrow/templates/test/problem.tmpl +42 -0
  68. data/data/arrow/templates/tutorial/index.tmpl +37 -0
  69. data/data/arrow/templates/tutorial/missingapplet.tmpl +29 -0
  70. data/data/arrow/templates/view-applet-nosuch.tmpl +32 -0
  71. data/data/arrow/templates/view-applet.tmpl +40 -0
  72. data/data/arrow/templates/view-template.tmpl +83 -0
  73. data/data/arrow/templates/wiki/formerror.tmpl +47 -0
  74. data/data/arrow/templates/wiki/markup_help.incl +6 -0
  75. data/data/arrow/templates/wiki/new.tmpl +56 -0
  76. data/data/arrow/templates/wiki/new_system.tmpl +122 -0
  77. data/data/arrow/templates/wiki/sectionlist.tmpl +43 -0
  78. data/data/arrow/templates/wiki/show.tmpl +34 -0
  79. data/docs/manual/layouts/default.page +43 -0
  80. data/docs/manual/lib/api-filter.rb +81 -0
  81. data/docs/manual/lib/editorial-filter.rb +64 -0
  82. data/docs/manual/lib/examples-filter.rb +244 -0
  83. data/docs/manual/lib/links-filter.rb +117 -0
  84. data/lib/apache/fakerequest.rb +448 -0
  85. data/lib/apache/logger.rb +33 -0
  86. data/lib/arrow.rb +51 -0
  87. data/lib/arrow/acceptparam.rb +207 -0
  88. data/lib/arrow/applet.rb +725 -0
  89. data/lib/arrow/appletmixins.rb +218 -0
  90. data/lib/arrow/appletregistry.rb +590 -0
  91. data/lib/arrow/applettestcase.rb +503 -0
  92. data/lib/arrow/broker.rb +255 -0
  93. data/lib/arrow/cache.rb +176 -0
  94. data/lib/arrow/config-loaders/yaml.rb +75 -0
  95. data/lib/arrow/config.rb +615 -0
  96. data/lib/arrow/constants.rb +24 -0
  97. data/lib/arrow/cookie.rb +359 -0
  98. data/lib/arrow/cookieset.rb +108 -0
  99. data/lib/arrow/dispatcher.rb +368 -0
  100. data/lib/arrow/dispatcherloader.rb +50 -0
  101. data/lib/arrow/exceptions.rb +61 -0
  102. data/lib/arrow/fallbackhandler.rb +48 -0
  103. data/lib/arrow/formvalidator.rb +631 -0
  104. data/lib/arrow/htmltokenizer.rb +343 -0
  105. data/lib/arrow/logger.rb +488 -0
  106. data/lib/arrow/logger/apacheoutputter.rb +69 -0
  107. data/lib/arrow/logger/arrayoutputter.rb +63 -0
  108. data/lib/arrow/logger/coloroutputter.rb +111 -0
  109. data/lib/arrow/logger/fileoutputter.rb +96 -0
  110. data/lib/arrow/logger/htmloutputter.rb +54 -0
  111. data/lib/arrow/logger/outputter.rb +123 -0
  112. data/lib/arrow/mixins.rb +425 -0
  113. data/lib/arrow/monkeypatches.rb +94 -0
  114. data/lib/arrow/object.rb +117 -0
  115. data/lib/arrow/path.rb +196 -0
  116. data/lib/arrow/service.rb +447 -0
  117. data/lib/arrow/session.rb +289 -0
  118. data/lib/arrow/session/dbstore.rb +100 -0
  119. data/lib/arrow/session/filelock.rb +160 -0
  120. data/lib/arrow/session/filestore.rb +132 -0
  121. data/lib/arrow/session/id.rb +98 -0
  122. data/lib/arrow/session/lock.rb +253 -0
  123. data/lib/arrow/session/md5id.rb +42 -0
  124. data/lib/arrow/session/nulllock.rb +42 -0
  125. data/lib/arrow/session/posixlock.rb +166 -0
  126. data/lib/arrow/session/sha1id.rb +54 -0
  127. data/lib/arrow/session/store.rb +366 -0
  128. data/lib/arrow/session/usertrackid.rb +52 -0
  129. data/lib/arrow/spechelpers.rb +73 -0
  130. data/lib/arrow/template.rb +713 -0
  131. data/lib/arrow/template/attr.rb +31 -0
  132. data/lib/arrow/template/call.rb +31 -0
  133. data/lib/arrow/template/comment.rb +33 -0
  134. data/lib/arrow/template/container.rb +118 -0
  135. data/lib/arrow/template/else.rb +41 -0
  136. data/lib/arrow/template/elsif.rb +44 -0
  137. data/lib/arrow/template/escape.rb +53 -0
  138. data/lib/arrow/template/export.rb +87 -0
  139. data/lib/arrow/template/for.rb +145 -0
  140. data/lib/arrow/template/if.rb +78 -0
  141. data/lib/arrow/template/import.rb +119 -0
  142. data/lib/arrow/template/include.rb +206 -0
  143. data/lib/arrow/template/iterator.rb +208 -0
  144. data/lib/arrow/template/nodes.rb +734 -0
  145. data/lib/arrow/template/parser.rb +571 -0
  146. data/lib/arrow/template/prettyprint.rb +53 -0
  147. data/lib/arrow/template/render.rb +191 -0
  148. data/lib/arrow/template/selectlist.rb +94 -0
  149. data/lib/arrow/template/set.rb +87 -0
  150. data/lib/arrow/template/timedelta.rb +81 -0
  151. data/lib/arrow/template/unless.rb +78 -0
  152. data/lib/arrow/template/urlencode.rb +51 -0
  153. data/lib/arrow/template/yield.rb +139 -0
  154. data/lib/arrow/templatefactory.rb +125 -0
  155. data/lib/arrow/testcase.rb +567 -0
  156. data/lib/arrow/transaction.rb +608 -0
  157. data/rake/191_compat.rb +26 -0
  158. data/rake/dependencies.rb +76 -0
  159. data/rake/documentation.rb +114 -0
  160. data/rake/helpers.rb +502 -0
  161. data/rake/hg.rb +282 -0
  162. data/rake/manual.rb +787 -0
  163. data/rake/packaging.rb +129 -0
  164. data/rake/publishing.rb +278 -0
  165. data/rake/style.rb +62 -0
  166. data/rake/svn.rb +668 -0
  167. data/rake/testing.rb +187 -0
  168. data/rake/verifytask.rb +64 -0
  169. data/spec/arrow/acceptparam_spec.rb +157 -0
  170. data/spec/arrow/applet_spec.rb +575 -0
  171. data/spec/arrow/appletmixins_spec.rb +409 -0
  172. data/spec/arrow/appletregistry_spec.rb +294 -0
  173. data/spec/arrow/broker_spec.rb +153 -0
  174. data/spec/arrow/config_spec.rb +224 -0
  175. data/spec/arrow/cookieset_spec.rb +164 -0
  176. data/spec/arrow/dispatcher_spec.rb +137 -0
  177. data/spec/arrow/dispatcherloader_spec.rb +65 -0
  178. data/spec/arrow/formvalidator_spec.rb +781 -0
  179. data/spec/arrow/logger_spec.rb +346 -0
  180. data/spec/arrow/mixins_spec.rb +120 -0
  181. data/spec/arrow/service_spec.rb +645 -0
  182. data/spec/arrow/session_spec.rb +121 -0
  183. data/spec/arrow/template/iterator_spec.rb +222 -0
  184. data/spec/arrow/templatefactory_spec.rb +185 -0
  185. data/spec/arrow/transaction_spec.rb +319 -0
  186. data/spec/arrow_spec.rb +37 -0
  187. data/spec/lib/appletmatchers.rb +281 -0
  188. data/spec/lib/constants.rb +77 -0
  189. data/spec/lib/helpers.rb +41 -0
  190. data/spec/lib/matchers.rb +44 -0
  191. data/tests/cookie.tests.rb +310 -0
  192. data/tests/path.tests.rb +157 -0
  193. data/tests/session.tests.rb +111 -0
  194. data/tests/session_id.tests.rb +82 -0
  195. data/tests/session_lock.tests.rb +191 -0
  196. data/tests/session_store.tests.rb +53 -0
  197. data/tests/template.tests.rb +1360 -0
  198. metadata +339 -0
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env ruby -w
2
+ #
3
+ # Unit test for the Arrow::Config::Path class
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2003 RubyCrafters, LLC. Most rights reserved.
7
+ #
8
+ # This work is licensed under the Creative Commons Attribution-ShareAlike
9
+ # License. To view a copy of this license, visit
10
+ # http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative
11
+ # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12
+ #
13
+
14
+ unless defined? Arrow::TestCase
15
+ testsdir = File.dirname( File.expand_path(__FILE__) )
16
+ basedir = File.dirname( testsdir )
17
+ $LOAD_PATH.unshift "#{basedir}/lib" unless
18
+ $LOAD_PATH.include?( "#{basedir}/lib" )
19
+ $LOAD_PATH.unshift "#{basedir}/tests/lib" unless
20
+ $LOAD_PATH.include?( "#{basedir}/tests/lib" )
21
+
22
+ require 'arrow/testcase'
23
+ end
24
+
25
+ require 'arrow/path'
26
+
27
+ ### This test suite tests the stage1 (static) parser and the metagrammar it
28
+ ### parses in which the actual parser-generator's behaviour is defined.
29
+ class Arrow::PathTestCase < Arrow::TestCase
30
+
31
+ TestArrayPath = %w{/etc /bin /shouldnt/exist} +
32
+ [ Dir.pwd, File.dirname(Dir.pwd) ]
33
+ TestStringPath = TestArrayPath.join( File::PATH_SEPARATOR )
34
+ ExtantDirs = TestArrayPath.find_all {|dir|
35
+ File.directory?(dir) && File.readable?(dir)
36
+ }.uniq
37
+ warn "No extant directories in the array of test paths." if ExtantDirs.empty?
38
+
39
+
40
+ #################################################################
41
+ ### T E S T S
42
+ #################################################################
43
+
44
+ ### Instance test
45
+ def test_00_Instance
46
+ printTestHeader "Arrow::Path: Instantiation"
47
+ path = nil
48
+
49
+ assert_instance_of Class, Arrow::Path
50
+ assert_nothing_raised { path = Arrow::Path.new }
51
+ assert_instance_of Arrow::Path, path
52
+ assert_equal 0, path.dirs.length
53
+ end
54
+
55
+ ### Test instantiation with a String
56
+ def test_01_InstanceWithString
57
+ printTestHeader "Arrow::Path: Instantiation with String"
58
+ path, rval = nil, nil
59
+
60
+ assert_nothing_raised {
61
+ path = Arrow::Path.new( TestStringPath )
62
+ }
63
+
64
+ assert_instance_of Arrow::Path, path
65
+ assert_instance_of Array, path.dirs
66
+ assert_equal TestArrayPath.length, path.dirs.length
67
+
68
+ TestArrayPath.each_with_index {|dir, i|
69
+ assert_equal dir, path.dirs[i]
70
+ }
71
+ end
72
+
73
+ ### Test instantiation with a Array
74
+ def test_02_InstanceWithArray
75
+ printTestHeader "Arrow::Path: Instantiation with Array"
76
+ path, rval = nil, nil
77
+
78
+ assert_nothing_raised {
79
+ path = Arrow::Path.new( TestArrayPath )
80
+ }
81
+
82
+ assert_instance_of Arrow::Path, path
83
+ assert_instance_of Array, path.dirs
84
+ assert_equal TestArrayPath.length, path.dirs.length
85
+
86
+ TestArrayPath.each_with_index {|dir, i|
87
+ assert_equal dir, path.dirs[i]
88
+ }
89
+
90
+ self.class.addSetupBlock {
91
+ @path = Arrow::Path.new( TestArrayPath )
92
+ }
93
+ self.class.addTeardownBlock {
94
+ @path = nil
95
+ }
96
+ end
97
+
98
+ ### Test the valid_dirs method
99
+ def test_05_ValidDirs
100
+ printTestHeader "Arrow::Path: Valid Dirs"
101
+ rval = nil
102
+
103
+ assert_nothing_raised {
104
+ rval = @path.valid_dirs
105
+ }
106
+
107
+ assert_equal ExtantDirs, rval
108
+ end
109
+
110
+ ### Test Enumerable interface 'each'
111
+ def test_10_Enumerable
112
+ printTestHeader "Arrow::Path: Each Iterator"
113
+ rval = []
114
+ assert_nothing_raised {
115
+ @path.each {|dir| rval << dir}
116
+ }
117
+ assert_equal ExtantDirs, rval
118
+ end
119
+
120
+ ### Test Enumerable mixin method #collect
121
+ def test_11_EnumerableCollect
122
+ printTestHeader "Arrow::Path: Collect Iterator"
123
+ rval = nil
124
+ assert_nothing_raised {
125
+ rval = @path.collect {|dir| dir.reverse }
126
+ }
127
+ assert_equal ExtantDirs.collect {|dir| dir.reverse}, rval
128
+ end
129
+
130
+ ### Test Array method delegation for #push
131
+ def test_14_PushArrayDelegate
132
+ printTestHeader "Arrow::Path: Array Delegate: Push"
133
+
134
+ assert_nothing_raised do
135
+ @path.push Dir.pwd
136
+ end
137
+
138
+ newpath = ExtantDirs | [Dir.pwd]
139
+ assert_equal newpath.sort, @path.valid_dirs.sort
140
+ end
141
+
142
+ ### Test Array method delegation for #unshift
143
+ def test_15_UnshiftArrayDelegate
144
+ printTestHeader "Arrow::Path: Array Delegate: Unshift"
145
+
146
+ assert_nothing_raised {
147
+ @path.unshift( Dir.pwd, File.dirname(Dir.pwd) )
148
+ }
149
+
150
+ newpath = [Dir.pwd, File.dirname(Dir.pwd)] | ExtantDirs
151
+ assert_equal newpath.sort, @path.valid_dirs.sort
152
+ end
153
+
154
+
155
+
156
+ end
157
+
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby -w
2
+ #
3
+ # Unit test for the Arrow::Session class
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2003 RubyCrafters, LLC. Most rights reserved.
7
+ #
8
+ # This work is licensed under the Creative Commons Attribution-ShareAlike
9
+ # License. To view a copy of this license, visit
10
+ # http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative
11
+ # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12
+ #
13
+ #
14
+
15
+ unless defined? Arrow::TestCase
16
+ testsdir = File.dirname( File.expand_path(__FILE__) )
17
+ basedir = File.dirname( testsdir )
18
+ $LOAD_PATH.unshift "#{basedir}/lib" unless
19
+ $LOAD_PATH.include?( "#{basedir}/lib" )
20
+ $LOAD_PATH.unshift "#{basedir}/tests/lib" unless
21
+ $LOAD_PATH.include?( "#{basedir}/tests/lib" )
22
+
23
+ require 'arrow/testcase'
24
+ end
25
+
26
+ require 'arrow/session'
27
+ require 'arrow/config'
28
+ require 'arrow/transaction'
29
+
30
+
31
+ ### Collection of tests for the Arrow::Session class.
32
+ class Arrow::SessionTestCase < Arrow::TestCase
33
+
34
+ ### Configuration
35
+ SessionDir = File.dirname( File.expand_path(__FILE__) ) + "/sessions"
36
+
37
+ DefaultIdUri = "md5:."
38
+ DefaultIdType = 'Arrow::Session::MD5Id'
39
+ DefaultLockUri = "file:#{SessionDir}"
40
+ DefaultLockType = 'Arrow::Session::FileLock'
41
+ DefaultStoreUri = "file:#{SessionDir}"
42
+ DefaultStoreType = 'Arrow::Session::YamlStore'
43
+
44
+ TestSessionId = "6bfb3f041cf9204c3a2ea4611bd5c9d1"
45
+
46
+ DefaultConfigHash = {
47
+ :idType => DefaultIdUri,
48
+ :idName => "test_id",
49
+ :lockType => DefaultLockUri,
50
+ :storeType => DefaultStoreUri,
51
+ }
52
+
53
+
54
+
55
+ #################################################################
56
+ ### T E S T S
57
+ #################################################################
58
+
59
+ def test_create_id_should_use_id_from_cookie_if_present
60
+ rval = nil
61
+
62
+ FlexMock.use( "config", "txn", "request", "cookie" ) do |config, txn, request, cookie|
63
+ txn.should_receive( :request_cookies ).
64
+ and_return({ "test_id" => cookie }).at_least.twice
65
+ txn.should_receive( :request ).and_return( request )
66
+
67
+ config.should_receive( :idName ).and_return( "test_id" ).at_least.once
68
+ cookie.should_receive( :value ).and_return( TestSessionId ).once
69
+ config.should_receive( :idType ).and_return( DefaultIdUri )
70
+
71
+ rval = Arrow::Session.create_id( config, txn )
72
+ end
73
+
74
+ assert_kind_of Arrow::Session::Id, rval
75
+ assert_equal TestSessionId, rval.to_s
76
+ end
77
+
78
+ def test_the_session_class_should_know_what_the_session_cookie_name_is
79
+ rval = nil
80
+
81
+ FlexMock.use( "config" ) do |config|
82
+ config.should_receive( :idName ).and_return( 'cookie-name' )
83
+ Arrow::Session.configure( config )
84
+ rval = Arrow::Session.session_cookie_name
85
+ end
86
+
87
+ assert_equal 'cookie-name', rval
88
+ end
89
+
90
+ def test_saving_should_add_the_session_cookie_to_the_request_via_the_transaction
91
+ cookieset = Arrow::CookieSet.new
92
+ config = Arrow::Config.new
93
+ config.session.idName = 'cookie-name'
94
+ Arrow::Session.configure( config.session )
95
+
96
+ FlexMock.use( "config", "store", "txn", "lock" ) do |config, store, txn, lock|
97
+ store.should_receive( :[]= ).with( :_session_id, 'id' )
98
+ store.should_receive( :save )
99
+
100
+ lock.should_receive( :release_all_locks )
101
+ txn.should_receive( :cookies ).and_return( cookieset )
102
+
103
+ session = Arrow::Session.new( :id, lock, store, txn )
104
+ session.save
105
+ end
106
+
107
+ assert cookieset.include?( 'cookie-name' )
108
+ end
109
+
110
+ end
111
+
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby -w
2
+ #
3
+ # Unit test for the Arrow::Session::Id class
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2003 RubyCrafters, LLC. Most rights reserved.
7
+ #
8
+ # This work is licensed under the Creative Commons Attribution-ShareAlike
9
+ # License. To view a copy of this license, visit
10
+ # http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative
11
+ # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12
+ #
13
+ #
14
+
15
+ unless defined? Arrow::TestCase
16
+ testsdir = File.dirname( File.expand_path(__FILE__) )
17
+ basedir = File.dirname( testsdir )
18
+ $LOAD_PATH.unshift "#{basedir}/lib" unless
19
+ $LOAD_PATH.include?( "#{basedir}/lib" )
20
+ $LOAD_PATH.unshift "#{basedir}/tests/lib" unless
21
+ $LOAD_PATH.include?( "#{basedir}/tests/lib" )
22
+
23
+ require 'arrow/testcase'
24
+ end
25
+
26
+
27
+ ### Collection of tests for the Arrow::Session::Id class.
28
+ class Arrow::SessionIdTestCase < Arrow::TestCase
29
+
30
+ DefaultIdUri = "md5:."
31
+ DefaultIdType = 'Arrow::Session::MD5Id'
32
+
33
+
34
+ def setup
35
+ @id = Arrow::Session::Id.create( DefaultIdUri, @req )
36
+ end
37
+
38
+ def teardown
39
+ @id = nil
40
+ end
41
+
42
+
43
+ #################################################################
44
+ ### T E S T S
45
+ #################################################################
46
+
47
+ ### Test to make sure the Id class is defined
48
+ def test_session_id_class_should_exist_and_be_a_class
49
+ assert_block( "Arrow::Session::Id defined?" ) { defined? Arrow::Session::Id }
50
+ assert_instance_of Class, Arrow::Session::Id
51
+ end
52
+
53
+
54
+ ### Test the id component.
55
+ def test_creating_an_id_should_determine_the_id_class_from_the_uri
56
+ assert_equal DefaultIdType, @id.class.name
57
+ end
58
+
59
+
60
+ ### Test to be sure the id object passes its own validation
61
+ def test_11_IdValidate
62
+ printTestHeader "Session::Id: Validation"
63
+ rval = nil
64
+
65
+ assert_nothing_raised {
66
+ rval = @id.class.validate( DefaultIdUri, @id.to_s )
67
+ }
68
+ assert_equal @id.to_s, rval,
69
+ "return value from .validate should be the same as its string value"
70
+
71
+ assert_nothing_raised {
72
+ str = @id.to_s
73
+ str.taint
74
+ rval = @id.class.validate( DefaultIdUri, str )
75
+ }
76
+ assert_not_tainted rval,
77
+ "return value from .validate should be untainted"
78
+ end
79
+
80
+
81
+ end
82
+
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env ruby -w
2
+ #
3
+ # Unit test for the Arrow::Session::Lock class
4
+ # $Id$
5
+ #
6
+ # Copyright (c) 2003, 2004 RubyCrafters, LLC. Most rights reserved.
7
+ #
8
+ # This work is licensed under the Creative Commons Attribution-ShareAlike
9
+ # License. To view a copy of this license, visit
10
+ # http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative
11
+ # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12
+ #
13
+ #
14
+
15
+ unless defined? Arrow::TestCase
16
+ testsdir = File.dirname( File.expand_path(__FILE__) )
17
+ basedir = File.dirname( testsdir )
18
+ $LOAD_PATH.unshift "#{basedir}/lib" unless
19
+ $LOAD_PATH.include?( "#{basedir}/lib" )
20
+ $LOAD_PATH.unshift "#{basedir}/tests/lib" unless
21
+ $LOAD_PATH.include?( "#{basedir}/tests/lib" )
22
+
23
+ require 'arrow/testcase'
24
+ end
25
+
26
+ require 'digest/md5'
27
+
28
+
29
+ ### Collection of tests for the Arrow::Session::Lock class.
30
+ class Arrow::SessionLockTestCase < Arrow::TestCase
31
+
32
+ SessionDir = File.dirname( File.expand_path(__FILE__) ) + "/sessions"
33
+
34
+ LockTypes = {
35
+ "file:#{SessionDir}" => 'Arrow::Session::FileLock',
36
+ }
37
+
38
+ # If 'posixlock' is installed, test the posix lock type
39
+ begin
40
+ require 'posixlock'
41
+ LockTypes["posix:#{SessionDir}"] = 'Arrow::Session::PosixLock'
42
+ rescue ::Exception => err
43
+ end
44
+
45
+
46
+ def initialize( *args )
47
+ super
48
+
49
+ ctx = Digest::MD5.new
50
+ ctx << Process.pid.to_s
51
+ ctx << Time.now.to_s
52
+
53
+ @id = ctx.hexdigest
54
+ end
55
+
56
+
57
+ #################################################################
58
+ ### T E S T S
59
+ #################################################################
60
+
61
+ ### Instance test
62
+ def test_00_Instantiate
63
+ assert_block( "Arrow::Session::Lock defined?" ) { defined? Arrow::Session::Lock }
64
+ assert_instance_of Class, Arrow::Session::Lock
65
+ end
66
+
67
+
68
+ ### Test the lock component.
69
+ def test_10_LockCreate
70
+ printTestHeader "Session::Lock: Create"
71
+ rval = nil
72
+
73
+ LockTypes.each {|uri, type|
74
+
75
+ # Should be able to a lock
76
+ assert_nothing_raised do
77
+ rval = Arrow::Session::Lock.create( uri, @id )
78
+ end
79
+
80
+ # Lock should support locking/unlocking/predicate methods
81
+ assert_equal type, rval.class.name
82
+
83
+ [
84
+ :read_lock, :write_lock,
85
+ :with_read_lock, :with_write_lock,
86
+ :locked?, :read_locked?, :write_locked?,
87
+ :read_unlock, :write_unlock, :finish
88
+ ].each do |meth|
89
+ assert_respond_to rval, meth
90
+ end
91
+ }
92
+
93
+ addSetupBlock {
94
+ @locks = LockTypes.keys.collect {|uri|
95
+ Arrow::Session::Lock.create( uri, @id )
96
+ }
97
+ }
98
+ addTeardownBlock {
99
+ unless @locks.nil?
100
+ @locks.each do |lock|
101
+ lock.finish
102
+ end
103
+ @locks = nil
104
+ end
105
+ }
106
+ end
107
+
108
+
109
+ ### Test lock state before any locking
110
+ def test_11_LockBeforeLocking
111
+ printTestHeader "Session::Lock: Before locking"
112
+ rval = nil
113
+
114
+ # Locks should start out unlocked
115
+ @locks.each do |lock|
116
+ locktype = lock.class.name
117
+
118
+ assert_nothing_raised { rval = lock.locked? }
119
+ assert !rval, "locked? should be false, ie., unlocked (#{locktype})"
120
+ assert_nothing_raised { rval = lock.read_locked? }
121
+ assert !rval, "read_locked? should be false, ie., unlocked (#{locktype})"
122
+ assert_nothing_raised { rval = lock.write_locked? }
123
+ assert !rval, "write_locked? should be false, ie., unlocked (#{locktype})"
124
+
125
+ # Lock should raise errors when unlocked without first being locked.
126
+ assert_raises( Arrow::LockingError, locktype ) { lock.read_unlock }
127
+ assert_raises( Arrow::LockingError, locktype ) { lock.write_unlock }
128
+ end
129
+ end
130
+
131
+
132
+ ### Test read lock functionality
133
+ def test_12_LockReadLocking
134
+ printTestHeader "Session::Lock: Read locking"
135
+ rval = nil
136
+
137
+ # Read lock should work
138
+ @locks.each do |lock|
139
+ locktype = lock.class.name
140
+
141
+ assert_nothing_raised( locktype ) { lock.read_lock }
142
+ assert_nothing_raised( locktype ) { rval = lock.read_locked? }
143
+ assert rval, "read_locked? should be true, ie., read locked (#{locktype})"
144
+ assert_nothing_raised( locktype ) { rval = lock.locked? }
145
+ assert rval, "locked? should be true, ie., either read or write locked (#{locktype})"
146
+ assert_nothing_raised( locktype ) { rval = lock.write_locked? }
147
+ assert !rval, "write_locked? should be false, ie., not write locked (#{locktype})"
148
+
149
+ # read_unlock should work and leave it unlocked
150
+ assert_nothing_raised( locktype ) { lock.read_unlock }
151
+ assert_nothing_raised( locktype ) { rval = lock.read_locked? }
152
+ assert !rval, "read_locked? should be false, ie., not locked (#{locktype})"
153
+ assert_nothing_raised( locktype ) { rval = lock.locked? }
154
+ assert !rval, "locked? should be false, ie., not read nor write locked (#{locktype})"
155
+ assert_nothing_raised( locktype ) { rval = lock.write_locked? }
156
+ assert !rval, "write_locked? should be false, ie., not write locked (#{locktype})"
157
+ end
158
+ end
159
+
160
+
161
+ ### Test write lock functionality
162
+ def test_13_LockWriteLocking
163
+ printTestHeader "Session::Lock: Read locking"
164
+ rval = nil
165
+
166
+ @locks.each do |lock|
167
+ locktype = lock.class.name
168
+
169
+ # Write lock should work
170
+ assert_nothing_raised( locktype ) { lock.write_lock }
171
+ assert_nothing_raised( locktype ) { rval = lock.write_locked? }
172
+ assert rval, "write_locked? should be true, ie., write locked (#{locktype})"
173
+ assert_nothing_raised( locktype ) { rval = lock.locked? }
174
+ assert rval, "locked? should be true, ie., either write or read locked (#{locktype})"
175
+ assert_nothing_raised( locktype ) { rval = lock.read_locked? }
176
+ assert !rval, "read_locked? should be false, ie., not read locked (#{locktype})"
177
+
178
+ # write_unlock should work and leave it unlocked
179
+ assert_nothing_raised( locktype ) { lock.write_unlock }
180
+ assert_nothing_raised( locktype ) { rval = lock.write_locked? }
181
+ assert !rval, "write_locked? should be false, ie., not locked (#{locktype})"
182
+ assert_nothing_raised( locktype ) { rval = lock.locked? }
183
+ assert !rval, "locked? should be false, ie., not write nor read locked (#{locktype})"
184
+ assert_nothing_raised( locktype ) { rval = lock.read_locked? }
185
+ assert !rval, "read_locked? should be false, ie., not read locked (#{locktype})"
186
+ end
187
+
188
+ end
189
+
190
+ end
191
+