Class: ODDB::TestPersistencePointer

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_util/persistence.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



206
207
208
209
210
# File 'test/test_util/persistence.rb', line 206

def setup
  ODBA.storage = ODBA::StorageStub.new
  ODBA.cache = ODBA::CacheStub.new
  @pointer = ODDB::Persistence::Pointer.new(:foo, [:bar, '12345'])
end

- (Object) teardown



211
212
213
214
# File 'test/test_util/persistence.rb', line 211

def teardown
  ODBA.storage = nil
  ODBA.cache = nil
end

- (Object) test_ancestors



336
337
338
339
340
341
342
343
344
345
# File 'test/test_util/persistence.rb', line 336

def test_ancestors
  big_pointer = @pointer + [:zap, :frap]
  assert_equal(Array, big_pointer.ancestors.class)
  assert_equal(2, big_pointer.ancestors.size)
  expected = [
    [:foo],
  ]
  assert_equal(expected, big_pointer.ancestors.first.directions)
  assert_equal(@pointer, big_pointer.ancestors.last)
end

- (Object) test_append



222
223
224
225
226
227
228
229
230
231
232
# File 'test/test_util/persistence.rb', line 222

def test_append
  pointer = ODDB::Persistence::Pointer.new(:foo, [:bar])
  pointer.append('12345')
  assert_equal(@pointer, pointer)
  pointer.append('12345')
  assert_equal(@pointer, pointer)
  pointer = ODDB::Persistence::Pointer.new
  assert_nothing_raised {
    pointer.append('12345')
  }
end

- (Object) test_combined_creation_and_update



346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'test/test_util/persistence.rb', line 346

def test_combined_creation_and_update
  app = StubPointerApp2.new
  @pointer.directions[1] = [:car, '12345']
  pointer = ODDB::Persistence::Pointer.new([:create, @pointer])
  values = {
    'zaf' =>  'flop',
    'urks'=>  'bong',
  }
  new_obj = pointer.issue_update(app, values)
  assert_equal(StubPointerBar, new_obj.class)
  assert_equal(@pointer, new_obj.pointer)
  assert_equal(values, new_obj.values)
end

- (Object) test_creator



391
392
393
394
# File 'test/test_util/persistence.rb', line 391

def test_creator
  creator = ODDB::Persistence::Pointer.new([:create, @pointer])
  assert_equal(creator, @pointer.creator)
end

- (Object) test_equal



233
234
235
236
# File 'test/test_util/persistence.rb', line 233

def test_equal
  pointer = ODDB::Persistence::Pointer.new(:foo, [:bar, '12345'])
  assert_equal(@pointer, pointer)
end

- (Object) test_fail_resolve1



258
259
260
261
262
# File 'test/test_util/persistence.rb', line 258

def test_fail_resolve1
  app = StubPointerApp2.new
  @pointer.directions[0] = [:fap, '9']
  assert_raises(ODDB::Persistence::UninitializedPathError) { @pointer.resolve(app) }
end

- (Object) test_fail_resolve2



263
264
265
266
267
# File 'test/test_util/persistence.rb', line 263

def test_fail_resolve2
  app = StubPointerApp2.new
  @pointer.directions[0] = [:frug, '9']
  assert_raises(ODDB::Persistence::InvalidPathError) { @pointer.resolve(app) }
end

- (Object) test_fail_resolve3



268
269
270
271
272
273
# File 'test/test_util/persistence.rb', line 268

def test_fail_resolve3
  app = StubPointerApp2.new
  @pointer.directions[1] = [:bar]
  assert_nothing_raised { @pointer.resolve(app) }
  assert_nil(@pointer.resolve(app))
end

- (Object) test_from_yus_privilege



412
413
414
415
416
417
418
419
# File 'test/test_util/persistence.rb', line 412

def test_from_yus_privilege
  src = 'org.oddb.model.!foo.!bar.1'
  pointer = Persistence::Pointer.new(:foo, [:bar, 1])
  assert_equal(pointer, Persistence::Pointer.from_yus_privilege(src))
  src = 'org.oddb.model.!foo.meep.!bar.1'
  pointer = Persistence::Pointer.new([:foo, 'meep'], [:bar, 1])
  assert_equal(pointer, Persistence::Pointer.from_yus_privilege(src))
end

- (Object) test_hash_key



400
401
402
403
404
405
# File 'test/test_util/persistence.rb', line 400

def test_hash_key
  hash = {}
  hash.store(Persistence::Pointer.new(:foo, [:bar, 1]), 'test')
  assert_equal('test', 
    hash[Persistence::Pointer.new(:foo, [:bar, 1])])
end

- (Object) test_initialize



215
216
217
218
219
220
221
# File 'test/test_util/persistence.rb', line 215

def test_initialize
  expected = [
    [:foo],
    [:bar, '12345'],
  ]
  assert_equal(expected, @pointer.directions)
end

- (Object) test_issue_create1



274
275
276
277
278
279
280
281
282
283
284
285
# File 'test/test_util/persistence.rb', line 274

def test_issue_create1
  app = StubPointerApp.new
  @pointer.directions[1] = [:car, '12345']
  new_obj = @pointer.issue_create(app)
  assert_equal(StubPointerBar, new_obj.class)
  assert_equal('54321', new_obj.bar)
  expected = [
    [:foo],
    [:car, '12345'],
  ]
  assert_equal(expected, new_obj.pointer.directions)
end

- (Object) test_issue_create2



286
287
288
289
290
291
292
# File 'test/test_util/persistence.rb', line 286

def test_issue_create2
  pointer = ODDB::Persistence::Pointer.new([:fap, '12345'])
  app = StubPointerApp2.new
  new_obj = pointer.issue_create(app)
  assert_equal(StubPointerFap, new_obj.class)
  assert_equal(new_obj, pointer.issue_create(app))
end

- (Object) test_issue_delete



293
294
295
296
297
298
# File 'test/test_util/persistence.rb', line 293

def test_issue_delete
  app = StubPointerApp.new
  foo = app.foo
  @pointer.issue_delete(app)
  assert_equal("12345", foo.bar_deleted)
end

- (Object) test_issue_delete_checkout



299
300
301
302
303
304
# File 'test/test_util/persistence.rb', line 299

def test_issue_delete_checkout
  app = StubPointerApp.new
  bar = @pointer.resolve(app)
  @pointer.issue_delete(app)
  assert_equal(true, bar.checkout_called)
end

- (Object) test_issue_delete_robust



305
306
307
308
309
310
311
# File 'test/test_util/persistence.rb', line 305

def test_issue_delete_robust
  pointer = ODDB::Persistence::Pointer.new([:not_available], [:equally_unavailable])
  app = StubPointerApp.new
  assert_nothing_raised { 
    pointer.issue_delete(app)
  }
end

- (Object) test_issue_update



312
313
314
315
316
317
318
319
320
321
322
# File 'test/test_util/persistence.rb', line 312

def test_issue_update
  app = StubPointerApp2.new
  obj = @pointer.issue_create(app)
  assert_equal(nil, obj.values)
  values = {
    'zaf' =>  'flop',
    'urks'=>  'bong',
  }
  @pointer.issue_update(app, values)
  assert_equal(values, obj.values)
end

- (Object) test_marshal_dump



395
396
397
398
399
# File 'test/test_util/persistence.rb', line 395

def test_marshal_dump
  assert_nothing_raised {
    Marshal.dump(@pointer)
  }
end

- (Object) test_parent



323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'test/test_util/persistence.rb', line 323

def test_parent
  parent = @pointer.parent
  assert_equal(ODDB::Persistence::Pointer, parent.class)
  expected = [
    [:foo],
    [:bar, '12345'],
  ]
  assert_equal(expected, @pointer.directions)
  expected = [
    [:foo],
  ]
  assert_equal(expected, parent.directions)
end

- (Object) test_parse1



366
367
368
369
# File 'test/test_util/persistence.rb', line 366

def test_parse1
  pointer = ODDB::Persistence::Pointer.parse(':!foo!bar,12345.')
  assert_equal(@pointer, pointer)
end

- (Object) test_parse2



370
371
372
373
374
# File 'test/test_util/persistence.rb', line 370

def test_parse2
  expected = ODDB::Persistence::Pointer.new([:create, @pointer])
  pointer = ODDB::Persistence::Pointer.parse(':!create,:!foo!bar,12345..')
  assert_equal(expected, pointer)
end

- (Object) test_parse_escape



379
380
381
382
383
# File 'test/test_util/persistence.rb', line 379

def test_parse_escape
  expected = ODDB::Persistence::Pointer.new([:test, 'a!b,c:d.e%f'])
  pointer = ODDB::Persistence::Pointer.parse(':!test,a%!b%,c%:d%.e%%f.')
  assert_equal(expected, pointer)
end

- (Object) test_plus



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'test/test_util/persistence.rb', line 237

def test_plus
  pointer = @pointer + [:baz, '54321']
  expected = [
    [:foo],
    [:bar, '12345'],
    [:baz, '54321'],
  ]
  assert_equal(expected, pointer.directions)
  pointer = @pointer + :baz
  expected = [
    [:foo],
    [:bar, '12345'],
    [:baz],
  ]
  assert_equal(expected, pointer.directions)
end

- (Object) test_resolve



253
254
255
256
257
# File 'test/test_util/persistence.rb', line 253

def test_resolve
  obj = @pointer.resolve(StubPointerApp.new)
  assert_equal(StubPointerBar, obj.class)
  assert_equal('12346', obj.bar)
end

- (Object) test_skeleton



384
385
386
# File 'test/test_util/persistence.rb', line 384

def test_skeleton
  assert_equal([:foo,:bar], @pointer.skeleton)
end

- (Object) test_string_skeleton



387
388
389
390
# File 'test/test_util/persistence.rb', line 387

def test_string_skeleton
  pointer = ODDB::Persistence::Pointer.new(['foo', 1, 2], ['bar'])
  assert_equal([:foo,:bar], pointer.skeleton)
end

- (Object) test_to_s1



359
360
361
# File 'test/test_util/persistence.rb', line 359

def test_to_s1
  assert_equal(':!foo!bar,12345.', @pointer.to_s)
end

- (Object) test_to_s2



362
363
364
365
# File 'test/test_util/persistence.rb', line 362

def test_to_s2
  pointer = ODDB::Persistence::Pointer.new([:create, @pointer])
  assert_equal(':!create,:!foo!bar,12345..', pointer.to_s)
end

- (Object) test_to_s_escape



375
376
377
378
# File 'test/test_util/persistence.rb', line 375

def test_to_s_escape
  pointer = ODDB::Persistence::Pointer.new([:test, 'a!b,c:d.e%f'])
  assert_equal(':!test,a%!b%,c%:d%.e%%f.', pointer.to_s)
end

- (Object) test_to_yus_privilege



406
407
408
409
410
411
# File 'test/test_util/persistence.rb', line 406

def test_to_yus_privilege
  pointer = Persistence::Pointer.new(:foo, [:bar, 1])
  assert_equal('org.oddb.model.!foo.!bar.1', pointer.to_yus_privilege)
  pointer = Persistence::Pointer.new([:foo, 'meep'], [:bar, 1])
  assert_equal('org.oddb.model.!foo.meep.!bar.1', pointer.to_yus_privilege)
end