#!/usr/bin/env ruby # ODDB::OdbaExporter::TestTable, TestLine -- oddb -- 03.02.2011 -- mhatakeyama@ywesee.com $: << File.expand_path('../src', File.dirname(__FILE__)) $: << File.expand_path('../../../src', File.dirname(__FILE__)) $: << File.expand_path('../../..', File.dirname(__FILE__)) $: << File.expand_path('../../../test', File.dirname(__FILE__)) require 'stub/odba' require 'test/unit' require 'flexmock' require 'oddbdat' require 'model/package' require 'date' module ODDB module OdbaExporter DATE = Date.today.strftime("%Y%m%d%H%M%S") class TestTable < Test::Unit::TestCase Table::FILENAME = 'table' def test_filename table = Table.new assert_equal('table', table.filename) end end class TestLine < Test::Unit::TestCase Line::LENGTH = 3 def setup @line = Line.new end def test_content assert_equal([], @line.content(nil)) structure = {1=>"1", 2=>"2", 3=>"3"} assert_equal(["1", "2", "3"], @line.content(structure)) end def test_empty? assert_equal(true, @line.empty?) end def test_structure assert_equal(nil, @line.structure) end def test_to_s assert_equal('', @line.to_s) end end class TestAcLine < Test::Unit::TestCase include FlexMock::TestCase def setup @package = ODDB::Package.new('12') @registration = flexmock('registration') do |mock| mock.should_receive(:generic_type).and_return(:generic) #mock.should_receive(:registration_date).and_return(Date.today) mock.should_receive(:registration_date).and_return(Date.new(2011,2,3)) end @package.sequence = flexmock('sequence') do |seq| seq.should_receive(:registration).and_return @registration seq.should_receive(:iksnr).and_return('12345') end @package.create_sl_entry @package.sl_entry.limitation = 'limitation' @package.sl_entry.limitation_points = 5 flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @acline = AcLine.new(@package) end def test_generic_code assert_equal('Y', @acline.generic_code(@registration)) end def test_iks_date expected = '20110203' assert_equal(expected, @acline.iks_date(@registration)) end def test_ikskey assert_equal('12345012', @acline.ikskey) end def test_inscode assert_equal('1', @acline.inscode) end def test_limitation assert_equal('Y', @acline.limitation) end def test_limitation_points assert_equal(5, @acline.limitation_points) end def test_structure expected = { 1 =>"01", 2 =>"20110203000000", 3 =>"1", 4 =>@package.oid, 5 =>"4", 7 =>"12345012", 14=>nil, 20=>"Y", 22=>"20110203", 29=>"3", 32=>nil, 39=>"1", 40=>"Y", 41=>5, 47=>nil, } # test assert_equal(expected.sort, @acline.structure.sort) end end class TestAccompLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure package = ODDB::Package.new('12') registration = flexmock('registration') do |mock| mock.should_receive(:company).and_return(flexmock('compay') do |comp| comp.should_receive(:oid).and_return(111) end) end package.sequence = flexmock('sequence') do |seq| seq.should_receive(:registration).and_return registration seq.should_receive(:iksnr).and_return('12345') end flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @accompline = AccompLine.new(package) expected = { 1=>"19", 2=>"20110203000000", 3=>package.oid, 4=>111, 5=>"H", 6=>"4", } assert_equal(expected.sort, @accompline.structure.sort) end end class TestAcLimLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @aclimline = AcLimLine.new(111, 222, 333) expected = { 1=>"09", 2=>"20110203000000", 3=>111, 4=>333, 5=>222, 6=>"4", } assert_equal(expected.sort, @aclimline.structure.sort) end end class TestAcnamLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure # assert(false) end end class TestAcmedLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure # assert(false) end end class TestAcOddbLine < Test::Unit::TestCase def test_structure package = ODDB::Package.new('12') package.pharmacode = 123 @acoddbline = AcOddbLine.new(package) expected = { 1 => package.oid, 2 => "123" } assert_equal(expected.sort, @acoddbline.structure.sort) end end class TestAcpricealgPublicLine < Test::Unit::TestCase include FlexMock::TestCase def setup @package = ODDB::Package.new('12') @package.price_public = 123.45 flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @acpriceline = AcpricealgPublicLine.new(@package) end def test_price_public_type assert_equal('PPUB', @acpriceline.price_public_type) @package.create_sl_entry assert_equal('PSL2', @acpriceline.price_public_type) end def test_structure expected = { 1=>"07", 2=>"20110203000000", 3=>@package.oid, 4=>"PPUB", 5=>"4", 6=>"123.45", } assert_equal(expected.sort, @acpriceline.structure.sort) end end class TestAcpricealgExfactoryLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure package = ODDB::Package.new('12') package.price_exfactory = 123.45 flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @acpriceline = AcpricealgExfactoryLine.new(package) expected = { 1=>"07", 2=>"20110203000000", 3=>package.oid, 4=>"PSL1", 5=>"4", 6=>"123.45", } assert_equal(expected.sort, @acpriceline.structure.sort) end end class TestAcscLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure # test nil case package = ODDB::Package.new('12') @acscline = AcscLine.new(package, nil, 'count') assert_equal(nil, @acscline.structure) # test not nil case active_agent = flexmock('active_agent') do |act| act.should_receive(:dose).and_return(flexmock('dose') do |dose| dose.should_receive(:is_a?).and_return(true) dose.should_receive(:qty).and_return('qty') dose.should_receive(:unit).and_return('unit') end) act.should_receive(:substance).and_return(flexmock('oid') do |oid| oid.should_receive(:oid).and_return('oid') end) end flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @acscline =AcscLine.new(package, active_agent, 123) expected = { 1=>"41", 2=>"20110203000000", 3=>21, 4=>123, 5=>"4", 6=>"oid", 7=>"qty", 8=>"unit", 9=>"W", } assert_equal(expected.sort, @acscline.structure.sort) end end class TestAtcLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure # test nil case @atcline = AtcLine.new(nil) assert_equal(nil, @atcline.structure) # test not nil case atcclass = flexmock('atcclass') do |atc| atc.should_receive(:code).and_return('code') atc.should_receive(:description).and_return('description') end flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @atcline = AtcLine.new(atcclass) expected = { 1=>"11", 2=>"20110203000000", 3=>"8", 4=>"code", 5=>"D", 6=>"4", 7=>"description", } assert_equal(expected, @atcline.structure) end end class TestCompLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure company = flexmock('company') do |comp| comp.should_receive(:oid).and_return('oid') comp.should_receive(:ean13).and_return('ean13') comp.should_receive(:name).and_return('name') comp.should_receive(:address_email).and_return('address_email') comp.should_receive(:url).and_return('url') comp.should_receive(:address).and_return(flexmock('addr') do |addr| addr.should_receive(:address).and_return('address') addr.should_receive(:plz).and_return('plz') addr.should_receive(:city).and_return('city') addr.should_receive(:"fon.first").and_return('fon.first') addr.should_receive(:"fax.first").and_return('fax.first') end) end flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @compline = CompLine.new(company) expected = { 1=>"12", 2=>"20110203000000", 3=>"oid", 4=>"4", 5=>"ean13", 7=>"name", 8=>"address", 9=>"CH", 10=>"plz", 11=>"city", 13=>"fon.first", 15=>"fax.first", 16=>"address_email", 17=>"url", } assert_equal(expected.sort, @compline.structure.sort) end end class TestEanLine < Test::Unit::TestCase include FlexMock::TestCase def setup packclass = flexmock('package') do |pack| pack.should_receive(:new).and_return(flexmock do |mock| mock.should_receive(:oid).and_return('oid') mock.should_receive(:barcode).and_return('barcode') end) end @package = packclass.new flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') end def test_barcode @eanline = EanLine.new(@package) assert_equal('barcode', @eanline.barcode) end def test_structure @eanline = EanLine.new(@package) expected = { 1=>"06", 2=>"20110203000000", 3=>"oid", 4=>"E13", 5=>"barcode", 6=>"4", } assert_equal(expected, @eanline.structure) end end class TestGalenicFormLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure galenic_form = flexmock('galenic_form') do |gal| gal.should_receive(:oid).and_return('oid') gal.should_receive(:to_s).and_return('to_s') end @galenicline = GalenicFormLine.new(galenic_form) expected = { 1=>"11", 2=>DATE, 3=>"5", 4=>"oid", 5=>"D", 6=>"4", 7=>"to_s", } assert_equal(expected.sort, @galenicline.structure.sort) end end class TestScLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure package = ODDB::Package.new('12') substance = flexmock('substance') do |sub| sub.should_receive(:oid).and_return('oid') end flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @scline = ScLine.new(package, substance) expected = { 1=>"40", 2=>"20110203000000", 3=>"oid", 4=>"L", 5=>"4", 6=>substance, } assert_equal(expected.sort, @scline.structure.sort) end end class TestLimitationLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @limitationline = LimitationLine.new('lim_oid') expected = { 1=>"16", 2=>"20110203000000", 3=>"lim_oid", 5=>"4", 6=>"COM", } assert_equal(expected.sort, @limitationline.structure.sort) end end class TestLimTxtLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @limtxtline = LimTxtLine.new('lim_oid', 'language', 'txt') expected = { 1=>"10", 2=>"20110203000000", 3=>"lim_oid", 4=>"language", 5=>"4", 6=>"txt", } assert_equal(expected.sort, @limtxtline.structure.sort) end end class TestMCMLine < Test::Unit::TestCase include FlexMock::TestCase def test_structure flexstub(Date).should_receive(:"today.strftime").and_return('20110203000000') @mcmline = MCMLine.new('fi_oid', 'line_nr', 'language', 'text') expected = { 1=>"31", 7=>"text", 2=>"20110203000000", 3=>"fi_oid", 4=>"L", 5=>"line_nr", 6=>"4", } assert_equal(expected.sort, @mcmline.structure.sort) end end end end