rcommons 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/COPYING +202 -0
  2. data/Changes.rdoc +4 -0
  3. data/README.rdoc +21 -0
  4. data/Rakefile +277 -0
  5. data/doc/jamis.rb +589 -0
  6. data/lib/commons.rb +44 -0
  7. data/lib/commons/io/filename_utils.rb +54 -0
  8. data/lib/commons/lang/builder/to_s_builder.rb +124 -0
  9. data/lib/commons/lang/builder/to_s_style.rb +493 -0
  10. data/lib/commons/lang/class_loader.rb +77 -0
  11. data/lib/commons/lang/class_utils.rb +50 -0
  12. data/lib/commons/lang/object_utils.rb +61 -0
  13. data/lib/commons/lang/state_error.rb +41 -0
  14. data/lib/commons/lang/system_utils.rb +113 -0
  15. data/lib/commons/lang/time/date_utils.rb +47 -0
  16. data/lib/commons/lang/time/duration_format_utils.rb +279 -0
  17. data/lib/commons/lang/time/stop_watch.rb +207 -0
  18. data/lib/commons/logging/impl/log4r_logger.rb +159 -0
  19. data/lib/commons/logging/impl/log_factory_impl.rb +253 -0
  20. data/lib/commons/logging/impl/no_op_log.rb +59 -0
  21. data/lib/commons/logging/impl/simple_log.rb +251 -0
  22. data/lib/commons/logging/log.rb +106 -0
  23. data/lib/commons/logging/log_configuration_error.rb +40 -0
  24. data/lib/commons/logging/log_factory.rb +177 -0
  25. data/lib/commons/ruby/exception.rb +46 -0
  26. data/lib/commons/ruby/log4r.rb +34 -0
  27. data/lib/commons/ruby/log4r/logger.rb +116 -0
  28. data/lib/commons/ruby/string.rb +55 -0
  29. data/lib/commons/ruby/test/unit.rb +33 -0
  30. data/lib/commons/ruby/test/unit/assertions.rb +50 -0
  31. data/lib/commons/util/properties.rb +84 -0
  32. data/test/commons/io/filename_utils_test.rb +69 -0
  33. data/test/commons/lang/builder/to_s_builder_test.rb +101 -0
  34. data/test/commons/lang/system_utils_test.rb +75 -0
  35. data/test/commons/lang/time/duration_format_utils_test.rb +261 -0
  36. data/test/commons/lang/time/stop_watch_test.rb +232 -0
  37. data/test/commons/logging/impl/log4r_logger_test.rb +133 -0
  38. data/test/commons/logging/log_factory_test.rb +80 -0
  39. data/test/commons/ruby/string_test.rb +64 -0
  40. data/test/commons/util/properties_test.rb +92 -0
  41. data/test/log4r/logger_test.rb +92 -0
  42. metadata +123 -0
@@ -0,0 +1,232 @@
1
+ # = Stop Watch Test Case
2
+ #
3
+ #
4
+ # Ruby version 1.8
5
+ #
6
+ # == Authors
7
+ # * Yomei Komiya
8
+ #
9
+ # == Copyright
10
+ # 2008 the original author or authors.
11
+ #
12
+ # == License
13
+ # Apache License 2.0
14
+ #
15
+ # Licensed under the Apache License, Version 2.0 (the "License");
16
+ # you may not use this file except in compliance with the License.
17
+ # You may obtain a copy of the License at
18
+ #
19
+ # http://www.apache.org/licenses/LICENSE-2.0
20
+ #
21
+ # Unless required by applicable law or agreed to in writing, software
22
+ # distributed under the License is distributed on an "AS IS" BASIS,
23
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ # See the License for the specific language governing permissions and
25
+ # limitations under the License.
26
+ #
27
+ # == Version
28
+ # SVN: $Id: stop_watch_test.rb 68 2008-10-05 05:08:21Z whitestar $
29
+ #
30
+ # == Since
31
+ # File available since Release 0.8.0
32
+
33
+ require 'commons/ruby/test/unit'
34
+
35
+ require 'commons/lang/state_error'
36
+ require 'commons/lang/time/stop_watch'
37
+
38
+ module Commons
39
+ module Lang
40
+ module Time
41
+
42
+ class StopWatchTest < Test::Unit::TestCase
43
+ SLEEP_TIME = 0.005
44
+
45
+
46
+ def setup
47
+ @stop_watch = StopWatch.new
48
+ end
49
+
50
+
51
+ def teardown
52
+ end
53
+
54
+
55
+ def test_initialize
56
+ # no test.
57
+ end
58
+
59
+
60
+ def test_start
61
+ # 1. Exceptional
62
+ assert_raise(StateError) do
63
+ @stop_watch.reset
64
+ @stop_watch.start
65
+ @stop_watch.start
66
+ end
67
+
68
+ assert_raise(StateError) do
69
+ @stop_watch.reset
70
+ @stop_watch.stop
71
+ end
72
+
73
+ # 2. Normal
74
+ @stop_watch.reset
75
+ @stop_watch.start
76
+ sleep(SLEEP_TIME)
77
+ @stop_watch.stop
78
+
79
+ time = @stop_watch.get_time
80
+ assert_true(0 < time && time < 10, "Expected: 0 < time (actual:#{time}) < 10")
81
+ end
82
+
83
+
84
+ def test_stop
85
+ # 1. Exceptional
86
+ assert_raise(StateError) do
87
+ @stop_watch.reset
88
+ @stop_watch.stop
89
+ end
90
+ end
91
+
92
+
93
+ def test_reset
94
+ # no test.
95
+ end
96
+
97
+
98
+ def test_split
99
+ # 1. Exceptional
100
+ assert_raise(StateError) do
101
+ @stop_watch.reset
102
+ @stop_watch.split
103
  end
104
+
105
+ # 2. Normal
106
+ assert_nothing_raised do
107
+ @stop_watch.reset
108
+ @stop_watch.start
109
+ @stop_watch.split
1
110
  end
111
+ end
112
+
113
+
114
+ def test_unsplit
115
+ # 1. Exceptional
116
+ assert_raise(StateError) do
117
+ @stop_watch.reset
118
+ @stop_watch.unsplit
119
+ end
120
+
121
+ # 2. Normal
122
+ assert_nothing_raised do
123
+ @stop_watch.reset
124
+ @stop_watch.start
125
+ @stop_watch.split
126
+ @stop_watch.unsplit
2
127
  end
128
+ end
129
+
130
+
131
+ def test_suspend
132
+ # 1. Exceptional
133
+ assert_raise(StateError) do
134
+ @stop_watch.reset
135
+ @stop_watch.suspend
136
+ end
137
+
138
+ # 2. Normal
139
+ assert_nothing_raised do
140
+ @stop_watch.reset
141
+ @stop_watch.start
142
+ @stop_watch.suspend
3
143
  end
144
+ end
145
+
146
+
147
+ def test_resume
148
+ # 1. Exceptional
149
+ assert_raise(StateError) do
150
+ @stop_watch.reset
151
+ @stop_watch.resume
152
+ end
153
+
154
+ # 2. Normal
155
+ assert_nothing_raised do
156
+ @stop_watch.reset
157
+ @stop_watch.start
158
+ @stop_watch.suspend
159
+ @stop_watch.resume
160
+ end
161
+ end
162
+
163
+
164
+ def test_get_time
165
+ # normal
166
+ @stop_watch.reset
167
+ @stop_watch.start
168
+ sleep(SLEEP_TIME)
169
+ @stop_watch.stop
170
+ time = @stop_watch.get_time
171
+ assert_true(0 < time && time < 10, "Expected: 0 < time (actual:#{time}) < 10")
172
+
173
+ # suspented
174
+ @stop_watch.reset
175
+ @stop_watch.start
176
+ sleep(SLEEP_TIME)
177
+ @stop_watch.suspend
178
+ time = @stop_watch.get_time
179
+ assert_true(0 < time && time < 10, "Expected: 0 < time (actual:#{time}) < 10")
180
+
181
+ # not started.
182
+ @stop_watch.reset
183
+ time = @stop_watch.get_time
184
+ assert_equal(0, time, "Expected: 0 < time (actual:#{time}) < 10")
185
+
186
+ # running
187
+ @stop_watch.reset
188
+ @stop_watch.start
189
+ sleep(SLEEP_TIME)
190
+ time = @stop_watch.get_time
191
+ assert_true(0 < time && time < 10, "Expected: 0 < time (actual:#{time}) < 10")
192
+ end
193
+
194
+
195
+ def test_get_split_time
196
+ # 1. Exceptional
197
+ assert_raise(StateError) do
198
+ @stop_watch.reset
199
+ @stop_watch.start
200
+ @stop_watch.stop
201
+ @stop_watch.get_split_time
202
+ end
203
+
204
+ # 2. Normal
205
+ assert_nothing_raised do
206
+ @stop_watch.reset
207
+ @stop_watch.start
208
+ sleep(SLEEP_TIME)
209
+ @stop_watch.split
210
+ time = @stop_watch.get_split_time
211
+ assert_true(0 < time && time < 10, "Expected: 0 < time (actual:#{time}) < 10")
212
+ end
213
+ end
214
+
215
+
216
+ def test_to_s
217
+ @stop_watch.reset
218
+ @stop_watch.start
219
+ sleep(SLEEP_TIME)
220
+ @stop_watch.stop
221
+ p 'Expected (about 5 msec): ' + @stop_watch.to_s
222
+ end
223
+
224
+
225
+ def test_to_split_s
226
+ @stop_watch.reset
227
+ @stop_watch.start
228
+ sleep(SLEEP_TIME)
229
+ @stop_watch.split
230
+ p 'Expected (about 5 msec): ' + @stop_watch.to_split_s
231
+ end
232
+ end
233
+
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,133 @@
1
+ # = Log4r Logger Test Case
2
+ #
3
+ #--
4
+ # Ruby version 1.8
5
+ #
6
+ # == Authors
7
+ # * Yomei Komiya
8
+ #
9
+ # == Copyright
10
+ # 2008 the original author or authors.
11
+ #
12
+ # == License
13
+ # Apache License 2.0
14
+ #
15
+ # Licensed under the Apache License, Version 2.0 (the "License");
16
+ # you may not use this file except in compliance with the License.
17
+ # You may obtain a copy of the License at
18
+ #
19
+ # http://www.apache.org/licenses/LICENSE-2.0
20
+ #
21
+ # Unless required by applicable law or agreed to in writing, software
22
+ # distributed under the License is distributed on an "AS IS" BASIS,
23
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ # See the License for the specific language governing permissions and
25
+ # limitations under the License.
26
+ #++
27
+ # == Version
28
+ # SVN: $Id: log4r_logger_test.rb 76 2008-10-12 11:45:33Z whitestar $
29
+ #
30
+ # == Since
31
+ # File available since Release 0.8.0
32
+
33
+ require 'commons/ruby/test/unit'
34
+
35
+ require 'commons/logging/impl/log4r_logger'
36
+
37
+ module Commons
38
+ module Logging
39
+ module Impl
40
+
41
+ class Log4rLoggerTest < Test::Unit::TestCase
42
+
43
+ def setup
44
+ @logger = Log4rLogger.new(self.class.name)
45
+ end
46
+
47
+
48
+ def teardown
49
+ end
50
+
51
+
52
+ def test_initialize
53
+ # TODO:
54
+ end
55
+
56
+
57
+ def test_get_logger
58
+ logger = @logger.get_logger
59
+ assert_not_nil(logger)
60
+ assert_kind_of(Log4r::Logger, logger)
61
+ assert_equal(self.class.name, logger.fullname)
62
+ end
63
+
64
+
65
+ def test_trace
66
+ @logger.trace('This is TRACE log.')
67
+ @logger.trace('This is TRACE log.', Exception.new('trace!'))
68
+ end
69
+
70
+
71
+ def test_debug
72
+ @logger.debug('This is DEBUG log.')
73
+ @logger.debug('This is DEBUG log.', Exception.new('debug!'))
74
+ end
75
+
76
+
77
+ def test_info
78
+ @logger.info('This is INFO log.')
79
+ @logger.info('This is INFO log.', Exception.new('info!'))
80
+ end
81
+
82
+
83
+ def test_warn
84
+ @logger.warn('This is WARN log.')
85
+ @logger.warn('This is WARN log.', Exception.new('warn!'))
86
+ end
87
+
88
+
89
+ def test_error
90
+ @logger.error('This is ERROR log.')
91
+ @logger.error('This is ERROR log.', Exception.new('error!'))
92
+ end
93
+
94
+
95
+ def test_fatal
96
+ @logger.fatal('This is FATAL log.')
97
+ @logger.fatal('This is FATAL log.', Exception.new('fatal!'))
98
+ end
99
+
100
+
101
+ def test_trace?
102
+ assert_true(@logger.trace?)
103
+ end
104
+
105
+
106
+ def test_debug?
107
+ assert_true(@logger.debug?)
108
+ end
109
+
110
+
111
+ def test_info?
112
+ assert_true(@logger.info?)
113
+ end
114
+
115
+
116
+ def test_warn?
117
+ assert_true(@logger.warn?)
118
+ end
119
+
120
+
121
+ def test_error?
122
+ assert_true(@logger.error?)
123
+ end
124
+
125
+
126
+ def test_fatal?
127
+ assert_true(@logger.fatal?)
128
+ end
129
+ end
130
+
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,80 @@
1
+ # = Log Factory Test Case
2
+ #
3
+ #--
4
+ # Ruby version 1.8
5
+ #
6
+ # == Authors
7
+ # * Yomei Komiya
8
+ #
9
+ # == Copyright
10
+ # 2008 the original author or authors.
11
+ #
12
+ # == License
13
+ # Apache License 2.0
14
+ #
15
+ # Licensed under the Apache License, Version 2.0 (the "License");
16
+ # you may not use this file except in compliance with the License.
17
+ # You may obtain a copy of the License at
18
+ #
19
+ # http://www.apache.org/licenses/LICENSE-2.0
20
+ #
21
+ # Unless required by applicable law or agreed to in writing, software
22
+ # distributed under the License is distributed on an "AS IS" BASIS,
23
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ # See the License for the specific language governing permissions and
25
+ # limitations under the License.
26
+ #++
27
+ # == Version
28
+ # SVN: $Id: log_factory_test.rb 76 2008-10-12 11:45:33Z whitestar $
29
+ #
30
+ # == Since
31
+ # File available since Release 0.8.0
32
+
33
+ require 'commons/ruby/test/unit'
34
+
35
+ require 'commons/logging/log_factory'
36
+
37
+ module Commons
38
+ module Logging
39
+
40
+ class LogFactoryTest < Test::Unit::TestCase
41
+
42
+ def setup
43
+ end
44
+
45
+
46
+ def teardown
47
+ end
48
+
49
+
50
+ def test_initialize
51
+ # no test.
52
+ end
53
+
54
+
55
+ def test_get_factory
56
+ assert_kind_of(LogFactory, LogFactory.get_factory)
57
+ end
58
+
59
+
60
+ def test_get_log
61
+ log = LogFactory.get_log(self.class.name)
62
+
63
+ e = Exception.new('exception message!')
64
+ log.trace('trace message.') if log.trace?
65
+ log.trace('trace message.', e) if log.trace?
66
+ log.debug('debug message.') if log.debug?
67
+ log.debug('debug message.', e) if log.debug?
68
+ log.info('info message.') if log.info?
69
+ log.info('info message.', e) if log.info?
70
+ log.warn('warn message.') if log.warn?
71
+ log.warn('warn message.', e) if log.warn?
72
+ log.error('error message.') if log.error?
73
+ log.error('error message.', e) if log.error?
74
+ log.fatal('fatal message.') if log.fatal?
75
+ log.fatal('fatal message.', e) if log.fatal?
76
+ end
77
+ end
78
+
79
+ end
80
+ end