Class: TestOddbValidator

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



12
13
14
# File 'test/test_util/validator.rb', line 12

def setup
  @validator = ODDB::Validator.new
end

- (Object) test_atc_code



15
16
17
18
19
20
21
22
# File 'test/test_util/validator.rb', line 15

def test_atc_code
  assert_equal('N', @validator.validate(:code, 'N'))
  assert_equal('N01', @validator.validate(:code, 'N01'))
  assert_equal('N01A', @validator.validate(:code, 'N01A'))
  assert_equal('N01AB', @validator.validate(:code, 'N01AB'))
  assert_equal('N01AB02', @validator.validate(:code, 'N01AB02'))
  assert_equal(SBSM::InvalidDataError, @validator.validate(:code, 'N1AB02').class)
end

- (Object) test_description



23
24
25
# File 'test/test_util/validator.rb', line 23

def test_description
  assert_equal('Eine Beschreibung', @validator.validate(:de, 'Eine Beschreibung'))
end

- (Object) test_dose



26
27
28
29
30
31
32
33
# File 'test/test_util/validator.rb', line 26

def test_dose
  assert_equal([10.0,'mg'], @validator.validate(:dose, '10 mg'))
  assert_equal([10.0,'mg'], @validator.validate(:dose, '10mg'))
  assert_equal([20.0, 'mg/ml'], @validator.validate(:dose, '20mg/ml'))
  assert_equal([20.0, 'mg/5ml'], @validator.validate(:dose, '20mg/5ml'))
  assert_equal([62.5, 'mg/g'], @validator.validate(:dose, '62.5mg/g'))
  assert_equal([62.5, 'mg/g'], @validator.validate(:dose, '62,5mg/g'))
end

- (Object) test_filename



90
91
92
93
94
# File 'test/test_util/validator.rb', line 90

def test_filename
  assert_equal('oddb.yaml.gz', @validator.validate(:filename, "oddb.yaml.gz"))
  assert_equal(nil, @validator.validate(:filename, "/etc/passwd"))

end

- (Object) test_ikscd



34
35
36
37
38
39
40
41
# File 'test/test_util/validator.rb', line 34

def test_ikscd
  assert_equal('123', @validator.validate(:ikscd, '123'))
  assert_equal('003', @validator.validate(:ikscd, '3'))
  assert_equal(nil, @validator.validate(:ikscd, nil))
  assert_equal('', @validator.validate(:ikscd, ''))
  assert_equal(SBSM::InvalidDataError, @validator.validate(:ikscd, '123456').class)
  assert_equal(SBSM::InvalidDataError, @validator.validate(:ikscd, '1a34').class)
end

- (Object) test_iksnr



42
43
44
45
46
47
48
# File 'test/test_util/validator.rb', line 42

def test_iksnr
  assert_equal('12345', @validator.validate(:iksnr, '12345'))
  assert_equal(nil, @validator.validate(:iksnr, nil))
  assert_equal(SBSM::InvalidDataError, @validator.validate(:iksnr, '123').class)
  assert_equal(SBSM::InvalidDataError, @validator.validate(:iksnr, '123456').class)
  assert_equal(SBSM::InvalidDataError, @validator.validate(:iksnr, '1a345').class)
end

- (Object) test_page



84
85
86
87
88
89
# File 'test/test_util/validator.rb', line 84

def test_page
  assert_equal(0, @validator.validate(:page, "1"))
  assert_equal(1, @validator.validate(:page, "2"))
  #assert_equal(0, @validator.validate(:page, "0"))
  #assert_equal(-1, @validator.validate(:page, "-1"))
end

- (Object) test_pointer1



49
50
51
52
# File 'test/test_util/validator.rb', line 49

def test_pointer1
  error = @validator.validate(:pointer, ':!foo!bar,12345.')
  assert_instance_of(SBSM::InvalidDataError, error)
end

- (Object) test_pointer2



53
54
55
56
# File 'test/test_util/validator.rb', line 53

def test_pointer2
  pointer = ODDB::Persistence::Pointer.new([:registration, '49390'])
  assert_equal(pointer, @validator.validate(:pointer, ':!registration,49390.'))
end

- (Object) test_pointer3



57
58
59
60
# File 'test/test_util/validator.rb', line 57

def test_pointer3
  pointer = ODDB::Persistence::Pointer.new([:registration, '49391'], [:sequence, '02'])
  assert_equal(pointer, @validator.validate(:pointer, ':!registration,49391!sequence,02.'))
end

- (Object) test_pointer4



61
62
63
64
65
# File 'test/test_util/validator.rb', line 61

def test_pointer4
  assert_nothing_raised {
    @validator.validate(:pointer, ':,arg,nocommand') 
  }
end

- (Object) test_search_query



66
67
68
# File 'test/test_util/validator.rb', line 66

def test_search_query
  assert_equal('Ponstan', @validator.validate(:search_query, 'Ponstan'))
end

- (Object) test_search_query_shorter_than_3



69
70
71
# File 'test/test_util/validator.rb', line 69

def test_search_query_shorter_than_3
  assert_equal(SBSM::InvalidDataError, @validator.validate(:search_query, 'Po').class)
end

- (Object) test_seqnr



72
73
74
75
76
77
78
# File 'test/test_util/validator.rb', line 72

def test_seqnr
  assert_equal('12', @validator.validate(:seqnr, '12'))
  assert_equal(nil, @validator.validate(:seqnr, nil))
  assert_equal('', @validator.validate(:seqnr, ''))
  assert_equal(SBSM::InvalidDataError, @validator.validate(:seqnr, '123').class)
  assert_equal(SBSM::InvalidDataError, @validator.validate(:seqnr, '1a3').class)
end

- (Object) test_set_pass



79
80
81
82
83
# File 'test/test_util/validator.rb', line 79

def test_set_pass
  expected = Digest::MD5.hexdigest('test')
  assert_equal(expected, @validator.validate(:set_pass_1, 'test'))
  assert_equal(expected, @validator.validate(:set_pass_2, 'test'))
end