torquebox-vfs 1.0.0.CR1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/gem_hook.rb +18 -0
  2. data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
  3. data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
  4. data/lib/jboss-logging-spi-2.2.0.CR1.jar +0 -0
  5. data/lib/jboss-logmanager-1.2.0.CR9.jar +0 -0
  6. data/lib/jboss-logmanager-log4j-1.0.0.CR3.jar +0 -0
  7. data/lib/jboss-vfs-3.0.0.GA.jar +0 -0
  8. data/lib/log4j-1.2.14.jar +0 -0
  9. data/lib/org.torquebox.vfs.rb +20 -0
  10. data/lib/torquebox/vfs/debug_filter.rb +37 -0
  11. data/lib/torquebox/vfs/dir.rb +78 -0
  12. data/lib/torquebox/vfs/ext/dir.rb +188 -0
  13. data/lib/torquebox/vfs/ext/file.rb +278 -0
  14. data/lib/torquebox/vfs/ext/file_test.rb +48 -0
  15. data/lib/torquebox/vfs/ext/io.rb +158 -0
  16. data/lib/torquebox/vfs/ext/jdbc.rb +65 -0
  17. data/lib/torquebox/vfs/ext/kernel.rb +30 -0
  18. data/lib/torquebox/vfs/ext/pathname.rb +31 -0
  19. data/lib/torquebox/vfs/ext/tempfile.rb +31 -0
  20. data/lib/torquebox/vfs/ext/vfs.rb +24 -0
  21. data/lib/torquebox/vfs/ext/virtual_file.rb +72 -0
  22. data/lib/torquebox/vfs/file.rb +188 -0
  23. data/lib/torquebox/vfs/glob_filter.rb +46 -0
  24. data/lib/torquebox/vfs/glob_translator.rb +204 -0
  25. data/lib/torquebox/vfs.rb +100 -0
  26. data/lib/torquebox-vfs.jar +0 -0
  27. data/lib/torquebox-vfs.rb +20 -0
  28. data/lib/vfs.rb +20 -0
  29. data/licenses/lgpl-2.1.txt +504 -0
  30. data/spec/dir_spec.rb +259 -0
  31. data/spec/file_spec.rb +451 -0
  32. data/spec/file_test_spec.rb +34 -0
  33. data/spec/io_spec.rb +82 -0
  34. data/spec/jdbc_spec.rb +68 -0
  35. data/spec/pathname_spec.rb +20 -0
  36. data/spec/spec_helper.rb +171 -0
  37. data/spec/vfs_dir_spec.rb +23 -0
  38. data/spec/vfs_spec.rb +36 -0
  39. metadata +121 -0
data/spec/file_spec.rb ADDED
@@ -0,0 +1,451 @@
1
+
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+ require 'tempfile'
4
+ require 'pathname'
5
+
6
+ describe "File extensions for VFS" do
7
+
8
+ extend TestDataCopyHelper
9
+
10
+ it "should report writable-ness for VFS urls" do
11
+ prefix = test_copy_base_path( :relative )
12
+ url = vfs_path( "#{prefix}/home/larry/file1.txt" )
13
+ File.exists?( url ).should be_true
14
+ File.exist?( url ).should be_true
15
+ File.writable?( url ).should be_true
16
+ end
17
+
18
+ it "should not loop infinitely" do
19
+ File.exists?("/nothingtoseehere").should be_false
20
+ File.exists?(vfs_path("/nothingtoseehere")).should be_false
21
+ end
22
+
23
+ describe "expand_path" do
24
+ it "should handle relative non-vfs path" do
25
+ File.expand_path("../foo", "/tmp/bar").should == "#{absolute_prefix}/tmp/foo"
26
+ end
27
+
28
+ it "should handle relative to vfs path" do
29
+ File.expand_path("../foo", vfs_path("/tmp/bar") ).should == vfs_path("#{absolute_prefix}/tmp/foo")
30
+ end
31
+
32
+ it "should expand paths relative to VFS urls as VFS" do
33
+ absolute = File.expand_path("db/development.sqlite3", vfs_path("/path/to/app") )
34
+ absolute.should eql( vfs_path("#{absolute_prefix}/path/to/app/db/development.sqlite3") )
35
+ end
36
+
37
+ it "should expand paths relative to VFS pathnames as VFS" do
38
+ absolute = File.expand_path("db/development.sqlite3", Pathname.new( vfs_path( "/path/to/app" ) ) )
39
+ absolute.should eql( vfs_path("#{absolute_prefix}/path/to/app/db/development.sqlite3") )
40
+ end
41
+
42
+ it "should expand absolute Pathname objects correctly" do
43
+ File.expand_path( vfs_path("/foo") ).should eql( vfs_path("/foo") )
44
+ File.expand_path(Pathname.new( vfs_path("/foo"))).should eql( vfs_path("/foo") )
45
+ end
46
+
47
+ it "should return first path when given two vfs paths" do
48
+ File.expand_path( vfs_path("/tmp/foo"), vfs_path("/tmp/bar")).should == vfs_path("/tmp/foo")
49
+ end
50
+ end
51
+
52
+ it "should handle vfs urls as readable" do
53
+ File.readable?( __FILE__ ).should be_true
54
+ File.readable?( vfs_path(__FILE__) ).should be_true
55
+ end
56
+
57
+ it "should report readable-ness for files inside vfs archives" do
58
+ path = "#{archive1_vfs_path}/web.xml"
59
+ File.readable?( path ).should be_true
60
+ end
61
+
62
+ it "should report readable-ness for non-existent files inside vfs archives" do
63
+ path = "#{archive1_vfs_path}/file_that_does_not_exist.txt"
64
+ File.readable?( path ).should be_false
65
+ end
66
+
67
+ it "should handle #'s in filenames properly" do
68
+ prefix = test_copy_base_path( :absolute )
69
+ File.file?( "#{prefix}/#bad-uri#" ).should be_true
70
+ File.file?( vfs_path( "#{prefix}/#bad-uri#" ) ).should be_true
71
+ File.file?( vfs_path( "#{prefix}/#missing#" ) ).should be_false
72
+ end
73
+
74
+ it "should handle spaces in filenames properly" do
75
+ prefix = test_copy_base_path( :absolute )
76
+ File.file?( "#{prefix}/sound of music/flibbity jibbit" ).should be_true
77
+ File.file?( vfs_path("#{prefix}/sound of music/flibbity jibbit" ) ).should be_true
78
+ File.file?( vfs_path("#{prefix}/sound of music/flibberty gibbet" ) ).should be_false
79
+ end
80
+
81
+ it "should handle percent-encoded filenames" do
82
+ prefix = test_copy_base_path( :absolute )
83
+ File.file?( "#{prefix}/views%2Flocalhost%3A8080%2Fposts" ).should be_true
84
+ File.file?( vfs_path("#{prefix}/views%2Flocalhost%3A8080%2Fposts" ) ).should be_true
85
+ File.file?( vfs_path("#{prefix}/views%2Flocalhost%3A8080%2Fmissing" ) ).should be_false
86
+ end
87
+
88
+ it "should handle backslashes in filenames even though there's no good reason to use them regardless of platform" do
89
+ filename = __FILE__.gsub("/","\\")
90
+ File.readable?( filename ).should be_true
91
+ File.readable?( vfs_path( filename ) ).should be_true
92
+ end
93
+
94
+ it "should be able to chmod real files with vfs urls" do
95
+ path = File.expand_path("foo")
96
+ begin
97
+ f = File.new(path, "w")
98
+ FileUtils.chmod( 0666, vfs_path( path ) )
99
+ m1 = f.stat.mode
100
+ FileUtils.chmod( 0644, vfs_path( path ) )
101
+ m2 = f.stat.mode
102
+ m1.should_not eql(m2) unless TESTING_ON_WINDOWS
103
+ ensure
104
+ File.delete(path) rescue nil
105
+ end
106
+ end
107
+
108
+ it "should be able to read file after chmod from a stat" do
109
+ # Similar to what Rails' File.atomic_write does (TORQUE-174)
110
+ p1 = vfs_path( File.expand_path("p1") )
111
+ p2 = vfs_path( File.expand_path("p2") )
112
+ begin
113
+ File.open(p1, "w") { }
114
+ File.open(p2, "w") { }
115
+ File.chmod(File.stat(p1).mode, p2)
116
+ File.read(p2)
117
+ ensure
118
+ File.unlink(p1, p2) rescue nil
119
+ end
120
+ end
121
+
122
+ it "should chmod inside vfs archive when directory mounted on filesystem" do
123
+ FileUtils.rm_rf "target/mnt"
124
+ archive = org.jboss.vfs::VFS.child( @archive1_path )
125
+ logical = archive.getChild( "lib" )
126
+ physical = java.io::File.new( "target/mnt" )
127
+ physical.mkdirs
128
+ mount = org.jboss.vfs::VFS.mountReal( physical, logical )
129
+ path = "#{@archive1_path}/lib/chmod_test"
130
+ begin
131
+ lambda {
132
+ f = File.new("target/mnt/chmod_test", "w" )
133
+ FileUtils.chmod( 0666, path )
134
+ m1 = f.stat.mode
135
+ FileUtils.chmod( 0755, path )
136
+ m2 = f.stat.mode
137
+ m1.should_not eql(m2) unless TESTING_ON_WINDOWS
138
+ }.should_not raise_error
139
+ ensure
140
+ mount.close
141
+ end
142
+ end
143
+
144
+ it "should be able to create new files with vfs urls" do
145
+ lambda {
146
+ File.new( vfs_path( __FILE__ ), 'r')
147
+ }.should_not raise_error
148
+ end
149
+
150
+ it "should allow rm_rf and mkdir_p of vfs path" do
151
+ parent = Dir.tmpdir
152
+ workdir = parent + '/vfs-test'
153
+ child = workdir + "/b/c"
154
+ FileUtils.rm_rf vfs_path( workdir )
155
+ File.exist?( vfs_path( child ) ).should be_false
156
+ FileUtils.mkdir_p( vfs_path( child ) )
157
+ File.exist?( vfs_path( child ) ).should be_true
158
+ FileUtils.rm_rf vfs_path( workdir )
159
+ File.exist?( vfs_path( workdir ) ).should be_false
160
+ File.exist?( vfs_path( parent ) ).should be_true
161
+ end
162
+
163
+ describe "Tempfiles" do
164
+ it "should be created in default dir" do
165
+ lambda {
166
+ t = Tempfile.new("temp_file_test")
167
+ File.exist?(t.path).should be_true
168
+ }.should_not raise_error
169
+ end
170
+
171
+ it "should be created in a non-vfs directory" do
172
+ lambda {
173
+ t = Tempfile.new("temp_file_test", Dir.tmpdir)
174
+ File.exist?(t.path).should be_true
175
+ }.should_not raise_error
176
+ end
177
+
178
+ it "should be created in a vfs directory" do
179
+ lambda {
180
+ t = Tempfile.new("temp_file_test", "vfs:#{Dir.tmpdir}")
181
+ File.exist?(t.path).should be_true
182
+ }.should_not raise_error
183
+ end
184
+ end
185
+
186
+ describe "open" do
187
+ it "should return File when called on File with VFS url" do
188
+ f = File.open( archive1_vfs_path, 'r')
189
+ f.should be_an_instance_of(File)
190
+ f.close
191
+ end
192
+
193
+ it "should return File when called on File without VFS url" do
194
+ f = File.open(archive1_path, 'r')
195
+ f.should be_an_instance_of(File)
196
+ f.close
197
+ end
198
+
199
+ it "should find files by pathnames" do
200
+ lambda {
201
+ f = File.open(Pathname.new(archive1_path), 'r')
202
+ f.close
203
+ }.should_not raise_error
204
+ end
205
+ end
206
+
207
+ describe "new" do
208
+ it "should return File when called on File with VFS url" do
209
+ f = File.new( archive1_vfs_path, 'r')
210
+ f.should be_an_instance_of(File)
211
+ f.close
212
+ end
213
+
214
+ it "should return File when called on File without VFS url" do
215
+ f = File.new( archive1_path, 'r')
216
+ f.should be_an_instance_of(File)
217
+ f.close
218
+ end
219
+
220
+ it "should create objects that respond to lstat for files in an archive" do
221
+ f = File.new( "#{archive1_vfs_path}/web.xml")
222
+ f.lstat.should_not be_nil
223
+ f.close
224
+ end
225
+ end
226
+
227
+ [ :absolute, :relative, :vfs ].each do |style|
228
+ describe "with #{style} paths" do
229
+ case ( style )
230
+ when :relative
231
+ prefix = test_copy_base_path( :relative )
232
+ when :absolute
233
+ prefix = test_copy_base_path( :absolute )
234
+ when :vfs
235
+ prefix = test_copy_base_path( :vfs )
236
+ end
237
+
238
+ unless TESTING_ON_WINDOWS && ( style == :absolute ) # WTF?
239
+ it "should provide size for normal files" do
240
+ path = "#{prefix}/home/larry/file1.txt"
241
+ s = File.size( path )
242
+ s.should_not be_nil
243
+ s.should be > 0
244
+ end
245
+ end
246
+
247
+ it "should throw NOENT for size of non-existant files" do
248
+ lambda {
249
+ File.size( "#{prefix}/home/larry/NOT_REALLY_file1.txt" )
250
+ }.should raise_error
251
+ end
252
+
253
+
254
+ unless TESTING_ON_WINDOWS && ( style == :absolute ) # WTF?
255
+ it "should provide size? for normal files" do
256
+ s = File.size?( "#{prefix}/home/larry/file1.txt" )
257
+ s.should_not be_nil
258
+ s.should be > 0
259
+ end
260
+ end
261
+
262
+ it "should not throw NOENT for size? of non-existant files" do
263
+ lambda {
264
+ s = File.size?( "#{prefix}/home/larry/NOT_REALLY_file1.txt" )
265
+ s.should be_nil
266
+ }.should_not raise_error
267
+ end
268
+
269
+ it "should provide mtime for normal files" do
270
+ mtime = File.mtime( "#{prefix}/home/larry/file1.txt" )
271
+ mtime.should_not be_nil
272
+ end
273
+
274
+ it "should report writeable-ness for normal files" do
275
+ File.writable?( "#{prefix}/home/larry/file1.txt" ).should be_true
276
+ end
277
+
278
+ # move to kernel_spec
279
+ it "should allow writing with truncation via open()" do
280
+ open( "#{prefix}/home/larry/file1.txt", (File::WRONLY | File::TRUNC | File::CREAT) ) do |file|
281
+ file.puts "howdy"
282
+ end
283
+ contents = File.read( "#{prefix}/home/larry/file1.txt" )
284
+ contents.should eql( "howdy\n" )
285
+ end
286
+
287
+ # move to kernel_spec
288
+ it "should allow writing with appending via open()" do
289
+ open( "#{prefix}/home/larry/file1.txt", (File::WRONLY | File::APPEND | File::CREAT) ) do |file|
290
+ file.puts "howdy"
291
+ end
292
+ contents = File.read( "#{prefix}/home/larry/file1.txt" )
293
+ contents.should eql( "This is file 1\nhowdy\n" )
294
+
295
+ fs_file = File.join( "#{test_copy_base_path(:relative)}/home/larry/file1.txt" )
296
+ fs_contents = File.read( fs_file )
297
+ fs_contents.should eql( "This is file 1\nhowdy\n" )
298
+ end
299
+
300
+ it "should allow writing new files via File.open" do
301
+ File.open( "#{prefix}/home/larry/new_file.txt", 'w' ) do |file|
302
+ file.puts "howdy"
303
+ end
304
+ contents = File.read( "#{prefix}/home/larry/new_file.txt" )
305
+ contents.should eql( "howdy\n")
306
+ end
307
+
308
+ it "should allow stat for normal files" do
309
+ file = "#{prefix}/home/larry/file1.txt"
310
+ stat = File.stat( file )
311
+ stat.should_not be_nil
312
+ stat.mtime.to_s.should eql( File.mtime( file ).to_s )
313
+ end
314
+
315
+ it "should not return a stat for missing files" do
316
+ lambda {
317
+ stat = File.stat( "missing file" )
318
+ }.should raise_error(Errno::ENOENT)
319
+ lambda {
320
+ stat = File.stat( vfs_path("/missing/file") )
321
+ }.should raise_error(Errno::ENOENT)
322
+ end
323
+
324
+ it "should provide mtime for files in an archive" do
325
+ mtime = File.mtime( "#{prefix}/home/larry/archive1.jar/web.xml" )
326
+ mtime.should_not be_nil
327
+ end
328
+
329
+ it "should allow stat for files in an archive" do
330
+ file = "#{prefix}/home/larry/archive1.jar/web.xml"
331
+ stat = File.stat( file )
332
+ stat.should_not be_nil
333
+ stat.mtime.should eql( File.mtime( file ) )
334
+ end
335
+
336
+ it "should provide mtime for files in a nested archive" do
337
+ mtime = File.mtime( "#{prefix}/home/larry/archive1.jar/lib/archive2.jar/manifest.txt" )
338
+ mtime.should_not be_nil
339
+ end
340
+
341
+ it "should test existance of normal files" do
342
+ File.exist?( "#{prefix}/home/larry/file1.txt" ).should be_true
343
+ File.exist?( "#{prefix}/home/larry/file42.txt" ).should be_false
344
+ end
345
+
346
+ it "should test existance of files in an archive" do
347
+ File.exist?( "#{prefix}/home/larry/archive1.jar/web.xml" ).should be_true
348
+ end
349
+
350
+ it "should test directoryness for normal files" do
351
+ File.directory?( "#{prefix}/home/larry" ).should be_true
352
+ File.directory?( "#{prefix}/home/larry/file1.txt" ).should be_false
353
+ end
354
+
355
+ it "should test directoryness for files within an archive" do
356
+ File.directory?( "#{prefix}/home/larry/archive1.jar/lib" ).should be_true
357
+ File.directory?( "#{prefix}/home/larry/archive1.jar/web.xml" ).should be_false
358
+ end
359
+
360
+ it "should test directoryness for non-existant files" do
361
+ File.directory?( "#{prefix}/home/larry/archive1.jar/fib" ).should be_false
362
+ File.directory?( "#{prefix}/home/larry/archive1.jar/tacos" ).should be_false
363
+ File.directory?( "#{prefix}/tacos" ).should be_false
364
+ end
365
+
366
+ it "should test fileness for normal files" do
367
+ File.file?( "#{prefix}/home/larry" ).should be_false
368
+ File.file?( "#{prefix}/home/larry/file1.txt" ).should be_true
369
+ end
370
+
371
+ it "should test fileness for files within an archive" do
372
+ File.file?( "#{prefix}/home/larry/archive1.jar/lib" ).should be_false
373
+ File.file?( "#{prefix}/home/larry/archive1.jar/web.xml" ).should be_true
374
+ end
375
+
376
+ end
377
+ end
378
+
379
+ describe 'path joinage' do
380
+ it "should work for relative paths" do
381
+ File.join("", "./foo").should == "/./foo"
382
+ File.join("/", "./foo").should == "/./foo"
383
+ File.join("vfs:", "./foo").should == "vfs:/./foo"
384
+ File.join("vfs:/", "./foo").should == "vfs:/./foo"
385
+ end
386
+ it "should work for absolute paths" do
387
+ File.join("", "/foo").should == "/foo"
388
+ File.join("/", "/foo").should == "/foo"
389
+ File.join("vfs:", "/foo").should == "vfs:/foo"
390
+ File.join("vfs:/", "/foo").should == "vfs:/foo"
391
+ end
392
+ it "should work for vfs paths" do
393
+ File.join("", "vfs:/foo").should == "/foo"
394
+ File.join("/", "vfs:/foo").should == "/foo"
395
+ File.join("vfs:", "vfs:/foo").should == "vfs:/foo"
396
+ File.join("vfs:/", "vfs:/foo").should == "vfs:/foo"
397
+ end
398
+ it "should handle a subset of vfs params" do
399
+ File.join('a', 'b', 'c', 'vfs:/d', 'e').should == 'a/b/c/d/e'
400
+ File.join('vfs:a', 'b', 'c', 'vfs:/d', 'e').should == 'vfs:a/b/c/d/e'
401
+ File.join('vfs:/a', 'b', 'c', 'vfs:/d', 'e').should == 'vfs:/a/b/c/d/e'
402
+ end
403
+ end
404
+
405
+ describe 'dirname' do
406
+ it "should properly handle non-vfs paths" do
407
+ File.dirname('/').should == '/'
408
+ File.dirname('/a').should == '/'
409
+ File.dirname('/a/b').should == '/a'
410
+ end
411
+
412
+ it "should return vfs paths when given a vfs path" do
413
+ File.dirname('vfs:/').should == 'vfs:/'
414
+ File.dirname('vfs:/a').should == 'vfs:/'
415
+ File.dirname('vfs:/a/b').should == 'vfs:/a'
416
+ end
417
+ end
418
+
419
+ describe 'chown' do
420
+ it "should handle vfs paths" do
421
+ path = archive1_vfs_path
422
+ stat = File.stat(path)
423
+ File.chown( stat.uid, stat.gid, path )
424
+ end
425
+ end
426
+
427
+ describe 'utime' do
428
+ it "should handle vfs paths" do
429
+ path = File.expand_path("foo")
430
+ begin
431
+ File.new(path, "w")
432
+ vpath = vfs_path( path )
433
+ mtime = File.mtime(vpath)
434
+ File.utime( Time.now, mtime+1, vpath )
435
+ mtime.should be < File.mtime(vpath)
436
+ ensure
437
+ File.delete(path) rescue nil
438
+ end
439
+ end
440
+ end
441
+
442
+ describe 'subclasses' do
443
+ it "should open an instance of the subclass" do
444
+ class MyFile < File
445
+ def new_method; 'hello'; end
446
+ end
447
+ MyFile.open(__FILE__).new_method.should == 'hello'
448
+ end
449
+ end
450
+
451
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "File extensions for VFS" do
4
+
5
+ it "should delegate to File.directory?" do
6
+ delegate_to_file(:directory?, 'file')
7
+ end
8
+
9
+ it "should delegate to File.exist?" do
10
+ delegate_to_file(:exist?, 'file')
11
+ end
12
+
13
+ it "should delegate to File.exists?" do
14
+ delegate_to_file(:exists?, 'file')
15
+ end
16
+
17
+ it "should delegate to File.file?" do
18
+ delegate_to_file(:file?, 'file')
19
+ end
20
+
21
+ it "should delegate to File.readable?" do
22
+ delegate_to_file(:readable?, 'file')
23
+ end
24
+
25
+ it "should delegate to File.writable?" do
26
+ delegate_to_file(:writable?, 'file')
27
+ end
28
+
29
+ def delegate_to_file(*args)
30
+ method = args.shift
31
+ File.should_receive(method).with(*args).and_return('value')
32
+ FileTest.send(method, *args).should == 'value'
33
+ end
34
+ end
data/spec/io_spec.rb ADDED
@@ -0,0 +1,82 @@
1
+
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+
4
+ describe "IO extensions for VFS" do
5
+
6
+ extend TestDataHelper
7
+
8
+ [ :absolute, :relative ].each do |style|
9
+ [ :vfs, :normal ].each do |vfs_style|
10
+ describe "with #{vfs_style} #{style} paths" do
11
+
12
+ prefix = test_data_base_path( style )
13
+ prefix = vfs_path( prefix ) if vfs_style == :vfs
14
+
15
+ describe 'read' do
16
+
17
+ it "should allow reading of regular files" do
18
+ content = IO.read( "#{prefix}/home/larry/file1.txt" ).chomp
19
+ content.should_not be_nil
20
+ content.should_not be_empty
21
+ content.should eql( "This is file 1" )
22
+ end
23
+
24
+ it "should allow reading of files within an archive" do
25
+ content = IO.read( "#{prefix}/home/larry/archive1.jar/web.xml" ).chomp
26
+ content.should_not be_nil
27
+ content.should_not be_empty
28
+ content.should eql( "This is web.xml" )
29
+ end
30
+
31
+ it "should allow reading of files within a nested archive" do
32
+ content = IO.read( "#{prefix}/home/larry/archive1.jar/lib/archive2.jar/manifest.txt" ).chomp
33
+ content.should_not be_nil
34
+ content.should_not be_empty
35
+ content.should eql( "This is manifest.txt" )
36
+ end
37
+
38
+ it "should honor the length argument" do
39
+ content = IO.read( "#{prefix}/home/larry/file1.txt", 1 ).chomp
40
+ content.should_not be_nil
41
+ content.should_not be_empty
42
+ content.should eql( "T" )
43
+ end
44
+
45
+ it "should honor the offset argument" do
46
+ content = IO.read( "#{prefix}/home/larry/file1.txt", 1, 1 ).chomp
47
+ content.should_not be_nil
48
+ content.should_not be_empty
49
+ content.should eql( "h" )
50
+ end
51
+
52
+ end
53
+
54
+ describe 'readline' do
55
+
56
+ it "should allow reading a regular file" do
57
+ content = IO.readlines( "#{prefix}/home/larry/file1.txt" )
58
+ content.should_not be_nil
59
+ content.should_not be_empty
60
+ content.first.chomp.should eql( "This is file 1" )
61
+ end
62
+
63
+ it "should allow reading of files within an archive" do
64
+ content = IO.readlines( "#{prefix}/home/larry/archive1.jar/web.xml" )
65
+ content.should_not be_nil
66
+ content.should_not be_empty
67
+ content.first.chomp.should eql( "This is web.xml" )
68
+ end
69
+
70
+ it "should allow reading of files within a nested archive" do
71
+ content = IO.readlines( "#{prefix}/home/larry/archive1.jar/lib/archive2.jar/manifest.txt" )
72
+ content.should_not be_nil
73
+ content.should_not be_empty
74
+ content.first.chomp.should eql( "This is manifest.txt" )
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+ end
data/spec/jdbc_spec.rb ADDED
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ java_import java.util.Properties
3
+
4
+ describe "JDBC Extensions for VFS" do
5
+
6
+ describe "DriverManager" do
7
+
8
+ before(:each) do
9
+ @driver_manager = java.sql.DriverManager
10
+ end
11
+
12
+ describe "getConnection" do
13
+
14
+ it "should call get_connection_with_properties if passed two arguments" do
15
+ properties = Properties.new
16
+ @driver_manager.should_receive(:get_connection_with_properties).
17
+ with("url", properties)
18
+ @driver_manager.getConnection("url", properties)
19
+ end
20
+
21
+ it "should call get_connection_with_username_password if passed three arguments" do
22
+ @driver_manager.should_receive(:get_connection_with_username_password).
23
+ with("url", "user", "password")
24
+ @driver_manager.getConnection("url", "user", "password")
25
+ end
26
+
27
+ end
28
+
29
+ describe "get_connection_with_properties" do
30
+
31
+ it "should delegate to original method" do
32
+ properties = Properties.new
33
+ @driver_manager.should_receive(:get_connection_without_vfs).
34
+ with("url", properties)
35
+ @driver_manager.send(:get_connection_with_properties, "url", properties)
36
+ end
37
+
38
+ it "should fall back to connect directly" do
39
+ properties = Properties.new
40
+ driver = mock('driver')
41
+ driver.should_receive(:connect).with("url", properties)
42
+ @driver_manager.registerDriver(driver)
43
+ @driver_manager.send(:get_connection_with_properties, "url", properties)
44
+ end
45
+
46
+ end
47
+
48
+ describe "get_connection_with_username_password" do
49
+
50
+ it "should delegate to original method" do
51
+ @driver_manager.should_receive(:get_connection_without_vfs).
52
+ with("url", "user", "password")
53
+ @driver_manager.send(:get_connection_with_username_password,
54
+ "url", "user", "password")
55
+ end
56
+
57
+ it "should fall back to connect directly" do
58
+ driver = mock('driver')
59
+ driver.should_receive(:connect).with("url",an_instance_of(Properties))
60
+ @driver_manager.registerDriver(driver)
61
+ @driver_manager.send(:get_connection_with_username_password,
62
+ "url", "user", "password")
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,20 @@
1
+
2
+ require File.dirname(__FILE__) + '/spec_helper.rb'
3
+ require 'pathname'
4
+
5
+ describe "Pathname extensions for VFS" do
6
+
7
+ describe "realpath" do
8
+ it "should expand VFS paths" do
9
+ pathname = Pathname.new("vfs:/tmp/test")
10
+ pathname.should_receive(:expand_path).and_return(Pathname.new("/expanded/path"))
11
+ pathname.realpath.to_s.should == "/expanded/path"
12
+ end
13
+
14
+ it "should find real path for non-VFS paths" do
15
+ pathname = Pathname.new("/tmp/test")
16
+ pathname.should_receive(:realpath_without_vfs).and_return(Pathname.new("/real/path"))
17
+ pathname.realpath.to_s.should == "/real/path"
18
+ end
19
+ end
20
+ end