Class: ODDB::TestRegistration

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
test/test_model/registration.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



91
92
93
# File 'test/test_model/registration.rb', line 91

def setup
  @registration = ODDB::Registration.new('12345')
end

- (Object) test_active



94
95
96
97
98
99
100
# File 'test/test_model/registration.rb', line 94

def test_active
  assert_equal(true, @registration.active?)
  @registration.inactive_date = (Date.today >> 1)
  assert_equal(true, @registration.active?)
  @registration.inactive_date = Date.today 
  assert_equal(false, @registration.active?)
end

- (Object) test_active__renewal



101
102
103
104
105
106
107
# File 'test/test_model/registration.rb', line 101

def test_active__renewal
  assert_equal(true, @registration.active?)
  @registration.expiration_date = @@two_years_ago - 1 
  assert_equal(nil, @registration.active?)
  @registration.renewal_flag = true
  assert_equal(true, @registration.active?)
end

- (Object) test_active_package_count



116
117
118
119
120
121
122
123
# File 'test/test_model/registration.rb', line 116

def test_active_package_count
  seq1 = flexmock :active_package_count => 2
  seq2 = flexmock :active_package_count => 1
  @registration.sequences.update '01' => seq1, '02' => seq2
  assert_equal 3, @registration.active_package_count
  @registration.expiration_date = @@two_years_ago
  assert_equal 0, @registration.active_package_count
end

- (Object) test_active_packages



108
109
110
111
112
113
114
115
# File 'test/test_model/registration.rb', line 108

def test_active_packages
  seq1 = flexmock :active_packages => ['pac1', 'pac2']
  seq2 = flexmock :active_packages => ['pac3']
  @registration.sequences.update '01' => seq1, '02' => seq2
  assert_equal %w{pac1 pac2 pac3}, @registration.active_packages
  @registration.expiration_date = @@two_years_ago
  assert_equal [], @registration.active_packages
end

- (Object) test_adjust_types1



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'test/test_model/registration.rb', line 124

def test_adjust_types1
  values = {
    :registration_date  => nil,
    :revision_date      => nil,
    :expiration_date    =>  nil,
    :inactive_date      => nil,
    :market_date        =>  nil,
  }
  expected = {
    :registration_date  => nil,
    :revision_date      => nil,
    :expiration_date    =>  nil,
    :inactive_date      => nil,
    :market_date        =>  nil,
  }
  assert_equal(expected, @registration.adjust_types(values))
end

- (Object) test_adjust_types2



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'test/test_model/registration.rb', line 141

def test_adjust_types2
  @registration.registration_date = Date.new(2002,1,1)
  values = {
    :registration_date  => '2002-02-02',
    :revision_date      => Date.new(2003,1,30),
    :expiration_date    =>  '2004-12-20',
    :inactive_date      => '2004-12-20',
  }
  expected = {
    :registration_date  => Date.new(2002,2,2),
    :revision_date      => Date.new(2003,1,30),
    :expiration_date    =>  Date.new(2004,12,20),
    :inactive_date      => Date.new(2004,12,20),
  }
  assert_equal(expected, @registration.adjust_types(values))
end

- (Object) test_atc_classes



168
169
170
171
172
173
174
175
176
# File 'test/test_model/registration.rb', line 168

def test_atc_classes
  seq1 = flexmock :atc_class => 'atc1'
  seq2 = flexmock :atc_class => 'atc2'
  seq3 = flexmock :atc_class => nil
  seq4 = flexmock :atc_class => 'atc1'
  @registration.sequences.update '01' => seq1, '02' => seq2,
                                 '03' => seq3, '04' => seq4
  assert_equal %w{atc1 atc2}, @registration.atc_classes
end

- (Object) test_atcless_sequences



157
158
159
160
161
162
163
164
165
166
167
# File 'test/test_model/registration.rb', line 157

def test_atcless_sequences
  seq1 = StubRegistrationSequence.new('01')
  seq2 = StubRegistrationSequence.new('02')
  seq2.atc_class = 'foo'
  @registration.sequences = {
    '01'  => seq1,
    '02'  => seq2,
  }
  expected = [ seq1 ]
  assert_equal(expected, @registration.atcless_sequences)
end

- (Object) test_checkout



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'test/test_model/registration.rb', line 177

def test_checkout
  seq1 = flexmock('Sequence1')
  seq2 = flexmock('Sequence2')
  sequences = {
    "01"  => seq1,
    "02"  => seq2,
  }
  @registration.instance_variable_set('@sequences', sequences)
  seq1.should_receive(:checkout).and_return { 
    assert(true)  
  }
  seq1.should_receive(:odba_delete).and_return { 
    assert(true)  
  }
  seq2.should_receive(:checkout).and_return { 
    assert(true)  
  }
  seq2.should_receive(:odba_delete).and_return { 
    assert(true)  
  }
  @registration.checkout
end

- (Object) test_company_name



199
200
201
202
203
# File 'test/test_model/registration.rb', line 199

def test_company_name
  assert_nil @registration.company_name
  @registration.company = flexmock :name => 'Company Name'
  assert_equal 'Company Name', @registration.company_name
end

- (Object) test_complementary_type



204
205
206
207
208
209
210
# File 'test/test_model/registration.rb', line 204

def test_complementary_type
  assert_nil @registration.complementary_type
  @registration.company = flexmock :complementary_type => :original
  assert_equal :original, @registration.complementary_type
  @registration.complementary_type = :generic
  assert_equal :generic, @registration.complementary_type
end

- (Object) test_compositions



211
212
213
214
215
216
# File 'test/test_model/registration.rb', line 211

def test_compositions
  seq1 = flexmock :compositions => ['cmp1', 'cmp2']
  seq2 = flexmock :compositions => ['cmp3']
  @registration.sequences.update '01' => seq1, '02' => seq2
  assert_equal %w{cmp1 cmp2 cmp3}, @registration.compositions
end

- (Object) test_create_patent



217
218
219
220
221
# File 'test/test_model/registration.rb', line 217

def test_create_patent
  assert_nil @registration.patent
  @registration.create_patent
  assert_instance_of Patent, @registration.patent
end

- (Object) test_create_sequence



222
223
224
225
226
227
228
229
# File 'test/test_model/registration.rb', line 222

def test_create_sequence
  @registration.sequences = {}
  seq = @registration.create_sequence('01')
  assert_equal(seq, @registration.sequences['01'])
  assert_equal(@registration, seq.registration)
  seq1 = @registration.create_sequence(2)
  assert_equal(seq1, @registration.sequences['02'])
end

- (Object) test_delete_patent



230
231
232
233
234
# File 'test/test_model/registration.rb', line 230

def test_delete_patent
  @registration.instance_variable_set '@patent', 'A Patent'
  @registration.delete_patent
  assert_nil @registration.patent
end

- (Object) test_diff



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'test/test_model/registration.rb', line 235

def test_diff
  values = {
    :registration_date  => '12.04.2002',
    :generic_type     =>  :generic,
  }
  expected = {
    :registration_date  => Date.new(2002,4,12),
    :generic_type     =>  :generic,
  }
  diff = @registration.diff(values)
  assert_equal(expected, diff)
  @registration.update_values(diff)
  assert_equal({}, @registration.diff(values))
end

- (Object) test_each_package



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'test/test_model/registration.rb', line 249

def test_each_package
  seq1 = StubRegistrationSequence.new(1)
  seq2 = StubRegistrationSequence.new(2)
  seq3 = StubRegistrationSequence.new(3)
  @registration.sequences = {
    1 => seq1,
    2 => seq2,
    3 => seq3,
  }
  @registration.each_package { |seq|
    seq*seq
  }
  assert_equal(1, seq1.block_result)
  assert_equal(4, seq2.block_result)
  assert_equal(9, seq3.block_result)
end

- (Object) test_fachinfo_writer



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'test/test_model/registration.rb', line 265

def test_fachinfo_writer
  fachinfo1 = StubRegistrationIndication.new
  fachinfo1.oid = 2
  fachinfo2 = StubRegistrationIndication.new
  fachinfo2.oid = 3
  @registration.fachinfo = fachinfo1
  assert_equal(@registration, fachinfo1.added)
  assert_nil(fachinfo1.removed)
  @registration.fachinfo = fachinfo2
  assert_equal(@registration, fachinfo1.removed)
  assert_equal(@registration, fachinfo2.added)
  assert_equal(@registration.fachinfo.oid, 3)
  assert_nil(fachinfo2.removed)
  @registration.fachinfo = nil
  assert_equal(@registration, fachinfo2.removed)
end

- (Object) test_generic_type



281
282
283
284
285
286
287
288
# File 'test/test_model/registration.rb', line 281

def test_generic_type
  company = flexmock "company"
  @registration.company = company 
  company.should_receive(:generic_type).and_return { "complementary" }  
  assert_equal("complementary", @registration.generic_type)
  @registration.generic_type = "generic"
  assert_equal("generic", @registration.generic_type)
end

- (Object) test_iksnr



289
290
291
292
# File 'test/test_model/registration.rb', line 289

def test_iksnr
  assert_respond_to(@registration, :iksnr)
  assert_equal('12345', @registration.iksnr)
end

- (Object) test_indication_writer



293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'test/test_model/registration.rb', line 293

def test_indication_writer
  indication1 = StubRegistrationIndication.new
  indication2 = StubRegistrationIndication.new
  @registration.indication = indication1
  assert_equal(indication1, @registration.indication)
  assert_equal(@registration, indication1.added)
  assert_nil(indication1.removed)
  @registration.indication = indication2
  assert_equal(@registration, indication1.removed)
  assert_equal(@registration, indication2.added)
  assert_nil(indication2.removed)
  @registration.indication = nil
  assert_equal(@registration, indication2.removed)
end

- (Object) test_limitation_text_count



307
308
309
310
311
312
# File 'test/test_model/registration.rb', line 307

def test_limitation_text_count
  seq1 = flexmock :limitation_text_count => 2
  seq2 = flexmock :limitation_text_count => 1
  @registration.sequences.update '01' => seq1, '02' => seq2
  assert_equal 3, @registration.limitation_text_count
end

- (Object) test_localized_name



313
314
315
316
317
318
319
320
# File 'test/test_model/registration.rb', line 313

def test_localized_name
  @registration.sequences = {}
  assert_nothing_raised { @registration.localized_name(:de) }
  seq = flexmock :name_base => 'A Name'
  seq.should_receive(:localized_name).with(:de).and_return 'Localized Name'
  @registration.sequences.update '02' => seq
  assert_equal 'Localized Name', @registration.localized_name(:de)
end

- (Object) test_may_violate_patent



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'test/test_model/registration.rb', line 321

def test_may_violate_patent
  assert_equal nil, @registration.may_violate_patent?
  @registration.registration_date = @@today
  assert_equal true, @registration.may_violate_patent?
  @registration.registration_date = @@one_year_ago
  assert_equal false, @registration.may_violate_patent?
  @registration.registration_date = @@one_year_ago + 1
  assert_equal true, @registration.may_violate_patent?
  @registration.comarketing_with = 'something'
  assert_equal false, @registration.may_violate_patent?
  @registration.comarketing_with = nil
  @registration.generic_type = :original
  assert_equal false, @registration.may_violate_patent?
  @registration.generic_type = :generic
  assert_equal true, @registration.may_violate_patent?
end

- (Object) test_name_base



337
338
339
340
341
342
343
# File 'test/test_model/registration.rb', line 337

def test_name_base
  @registration.sequences = {}
  assert_nothing_raised { @registration.name_base }
  seq = flexmock :name_base => 'A Name'
  @registration.sequences.store '02', seq
  assert_equal 'A Name', @registration.name_base
end

- (Object) test_original



344
345
346
347
348
349
350
# File 'test/test_model/registration.rb', line 344

def test_original
  assert_equal false, @registration.original?
  @registration.generic_type = :original
  assert_equal true, @registration.original?
  @registration.generic_type = :generic
  assert_equal false, @registration.original?
end

- (Object) test_out_of_trade



351
352
353
354
355
356
357
358
359
360
361
# File 'test/test_model/registration.rb', line 351

def test_out_of_trade
  assert_equal true, @registration.out_of_trade
  seq1 = flexmock :out_of_trade => true
  @registration.sequences.store '01', seq1
  assert_equal true, @registration.out_of_trade
  seq2 = flexmock :out_of_trade => false
  @registration.sequences.store '02', seq2
  assert_equal false, @registration.out_of_trade

  seq2 = flexmock :out_of_trade => false
end

- (Object) test_package



371
372
373
374
375
376
377
378
379
# File 'test/test_model/registration.rb', line 371

def test_package
  assert_nil @registration.package('001')
  seq1 = flexmock 'sequence'
  seq1.should_receive(:package).with('001').and_return 'package'
  @registration.sequences.store '01', seq1
  assert_equal 'package', @registration.package('001')
  seq1.should_receive(:package).with('002').and_return nil
  assert_nil @registration.package('002')
end

- (Object) test_package_count



362
363
364
365
366
367
368
369
370
# File 'test/test_model/registration.rb', line 362

def test_package_count
  @registration.sequences = {
    'seq1'  => StubRegistrationSequence.new(1),
    'seq2'  => StubRegistrationSequence.new(2),
    'seq3'  => StubRegistrationSequence.new(3),
  }
  result = @registration.package_count
  assert_equal(12, result)
end

- (Object) test_packages



380
381
382
383
384
385
386
387
# File 'test/test_model/registration.rb', line 380

def test_packages
  seq1 = flexmock :packages => {'001' => 'pac1', '002' => 'pac2'}
  seq2 = flexmock :packages => {'003' => 'pac3'}
  @registration.sequences.update '01' => seq1, '02' => seq2
  assert_equal %w{pac1 pac2 pac3}, @registration.packages
  @registration.expiration_date = @@two_years_ago
  assert_equal %w{pac1 pac2 pac3}, @registration.packages
end

- (Object) test_patent_protected



388
389
390
391
392
393
394
395
396
# File 'test/test_model/registration.rb', line 388

def test_patent_protected
  assert_equal nil, @registration.patent_protected?
  pat1 = flexmock :protected? => false
  @registration.instance_variable_set '@patent', pat1
  assert_equal false, @registration.patent_protected?
  pat2 = flexmock :protected? => true
  @registration.instance_variable_set '@patent', pat2
  assert_equal true, @registration.patent_protected?
end

- (Object) test_public



397
398
399
400
401
# File 'test/test_model/registration.rb', line 397

def test_public
  assert_equal true, @registration.public?
  @registration.export_flag = true
  assert_equal false, @registration.public?
end

- (Object) test_public_package_count



402
403
404
405
406
407
408
409
# File 'test/test_model/registration.rb', line 402

def test_public_package_count
  seq1 = flexmock :public_package_count => 2
  seq2 = flexmock :public_package_count => 1
  @registration.sequences.update '01' => seq1, '02' => seq2
  assert_equal 3, @registration.public_package_count
  @registration.expiration_date = @@two_years_ago
  assert_equal 0, @registration.public_package_count
end

- (Object) test_sequence



410
411
412
413
414
# File 'test/test_model/registration.rb', line 410

def test_sequence
  seq = StubRegistrationSequence.new('01')
  @registration.sequences = {'01'=>seq }
  assert_equal(seq, @registration.sequence('01'))
end

- (Object) test_substance_names



415
416
417
418
419
420
421
422
423
# File 'test/test_model/registration.rb', line 415

def test_substance_names
  sequence = StubRegistrationSequence.new(1)
  expected = ["Milch", "Rahm"]
  sequence.substance_names = expected
  @registration.sequences = {
    '3434' => sequence,
  }
  assert_equal(expected, @registration.substance_names)
end

- (Object) test_update_values



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'test/test_model/registration.rb', line 424

def test_update_values
  assert_nil(@registration.registration_date)
  values = {
    :registration_date  => '12.04.2002',
    :company            =>  'Bayer (Schweiz) AG',
    :generic_type       => :generic,
  }
  app = StubRegistrationApp.new
  @registration.update_values(@registration.diff(values, app))
  assert_equal(Date.new(2002,4,12), @registration.registration_date)
  company = @registration.company
  assert_equal(app.company('Bayer (Schweiz) AG'), company)
  assert_equal(:generic, @registration.generic_type)
  assert_equal(@registration, company.registrations.first)
  values[:company] = 'Jansen Cilag AG'
  @registration.update_values(@registration.diff(values, app))
  assert_equal([], company.registrations)
end