source: ruby/trunk/lib/models/tests/rm/test_common.rb@ 155

Last change on this file since 155 was 155, checked in by KOBAYASHI, Shinji, 15 years ago

refs #62

File size: 10.9 KB
Line 
1require 'test/unit'
2require 'set'
3require 'rm'
4
5include OpenEHR::RM::Data_Types::Text
6include OpenEHR::RM::Common::Resource
7include OpenEHR::RM::Common::Archetyped
8include OpenEHR::RM::Common::Generic
9include OpenEHR::RM::Support::Identification
10include OpenEHR::RM::Data_Types::Basic
11
12class RM_Common_Resource_Test < Test::Unit::TestCase
13 def setup
14 @authored_resource = OpenEHR::RM::Common::Resource::AUTHORED_RESOURCE.new(:original_language => "ja",
15 :translations => "en",
16 :description => "test")
17 @translation_details = OpenEHR::RM::Common::Resource::TRANSLATION_DETAILS.new(nil,nil,nil,nil,nil)
18 end
19 def test_init
20 assert_instance_of OpenEHR::RM::Common::Resource::AUTHORED_RESOURCE, @authored_resource
21 assert_instance_of OpenEHR::RM::Common::Resource::TRANSLATION_DETAILS, @translation_details
22 end
23
24 def test_authoured_resource
25 assert_equal 'ja', @authored_resource.original_language
26 end
27end
28
29
30class RM_Common_Archetyped_Test < Test::Unit::TestCase
31 def setup
32 @dv_text = OpenEHR::RM::Data_Types::Text::DV_Text.new('Test')
33 @uid_based_id = OpenEHR::RM::Support::Identification::UID_Based_ID.new('rrip::0.0.5')
34 @archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")
35 @template_id = OpenEHR::RM::Support::Identification::Template_ID.new('1.0.1')
36 assert_nothing_raised(Exception){@archetyped = OpenEHR::RM::Common::Archetyped::Archetyped.new(@archetype_id, '1.0.1')}
37 assert_nothing_raised(Exception){@link = OpenEHR::RM::Common::Archetyped::Link.new(OpenEHR::RM::Data_Types::Text::DV_Text.new("generic"), OpenEHR::RM::Data_Types::URI::DV_EHR_URI.new("ehr://test/"),OpenEHR::RM::Data_Types::Text::DV_Text.new("problem"))}
38 assert_nothing_raised(Exception){
39 @pathable = OpenEHR::RM::Common::Archetyped::Pathable.new }
40 name = OpenEHR::RM::Data_Types::Text::DV_Text.new('blood')
41 links = Set.new([@uid_based_id])
42 assert_nothing_raised(Exception){
43 @locatable = OpenEHR::RM::Common::Archetyped::Locatable.new('at0001',name,links)}
44 provider = Party_Identified.new(:name => 'NERV')
45 location = Party_Identified.new(:name => 'GEOFRONT')
46 object_id = Object_ID.new('0.0.4')
47 party_ref = Party_Ref.new('local', 'ORGANISATION', object_id)
48 assert_nothing_raised(Exception){
49 @feeder_audit_details = Feeder_Audit_Details.new(:system_id => 'MAGI',
50 :provider => provider,
51 :location => location,
52 :time => DV_Date_Time.new('2009-07-03T12:16:31'),
53 :subject => Party_Proxy.new(:external_ref => party_ref),
54 :version_id => '0.0.4')}
55 feeder_audit_details = Feeder_Audit_Details.new(:system_id => 'AKAGI')
56 dv_identifier = DV_Identifier.new('NERV', 'MELCHIOR', 'RITSUKO', 'COMPUTER')
57 feeder_audit_details2 = Feeder_Audit_Details.new(:system_id => 'KATSURAGI')
58 dv_identifier2 = DV_Identifier.new('NERV', 'SHOGOUKI', 'MISATO', 'EVANGELION')
59 charset = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('UTF-8','character-sets')
60 language = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('ja', 'languages')
61
62 dv_encapsulated = OpenEHR::RM::Data_Types::Encapsulated::DV_Encapsulated.new(charset, language, 10)
63 assert_nothing_raised(Exception){
64 @feeder_audit = Feeder_Audit.new(:originating_system_audit => feeder_audit_details,
65 :originating_system_item_ids => [dv_identifier],
66 :feeder_system_audit => feeder_audit_details2,
67 :feeder_system_item_ids => [dv_identifier2],
68 :original_content => dv_encapsulated)}
69 end
70
71 def test_init
72 assert_instance_of OpenEHR::RM::Common::Archetyped::Archetyped, @archetyped
73 assert_instance_of OpenEHR::RM::Common::Archetyped::Link, @link
74 assert_instance_of OpenEHR::RM::Common::Archetyped::Pathable, @pathable
75 assert_instance_of OpenEHR::RM::Common::Archetyped::Locatable, @locatable
76 assert_instance_of Feeder_Audit_Details, @feeder_audit_details
77 assert_instance_of Feeder_Audit, @feeder_audit
78 end
79
80 def test_archetyped
81 assert_equal @archetype_id, @archetyped.archetype_id
82 assert_equal '1.0.1', @archetyped.rm_version
83 assert_raise(ArgumentError){@archetyped.archetype_id = nil}
84 assert_raise(ArgumentError){@archetyped.rm_version = nil}
85 assert_raise(ArgumentError){@archetyped.rm_version = ''}
86 assert_nothing_raised(Exception){@archetyped.template_id = @template_id}
87 assert_equal @template_id, @archetyped.template_id
88 archetype_id2 = OpenEHR::RM::Support::Identification::Archetype_ID.new("1.0.2", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")
89 assert_nothing_raised(ArgumentError){@archetyped.archetype_id = archetype_id2}
90 assert_equal archetype_id2, @archetyped.archetype_id
91 assert_nothing_raised(ArgumentError){@archetyped.rm_version = '1.0.2'}
92 assert_equal '1.0.2', @archetyped.rm_version
93 end
94
95 def test_link
96 # test constructor
97 assert_equal 'generic', @link.meaning.value
98 assert_equal 'ehr://test/', @link.target.value
99 assert_equal 'problem', @link.type.value
100 # test meaning
101 assert_nothing_raised(Exception){@link.meaning = OpenEHR::RM::Data_Types::Text::DV_Text.new('clinical')}
102 assert_equal 'clinical', @link.meaning.value
103 assert_raise(ArgumentError){@link.meaning = nil}
104 # test target
105 assert_nothing_raised(Exception){@link.target = OpenEHR::RM::Data_Types::URI::DV_EHR_URI.new("ehr://try/")}
106 assert_equal 'ehr://try/', @link.target.value
107 assert_raise(ArgumentError){@link.target = nil}
108 # test type
109 assert_nothing_raised(Exception){@link.type = OpenEHR::RM::Data_Types::Text::DV_Text.new("issue")}
110 assert_equal 'issue', @link.type.value
111 assert_raise(ArgumentError){@link.type = nil}
112 end
113
114 def test_feeder_audit
115 assert_equal 'AKAGI', @feeder_audit.originating_system_audit.system_id
116 assert_equal 'RITSUKO', @feeder_audit.originating_system_item_ids[0].issuer
117 assert_equal 'KATSURAGI', @feeder_audit.feeder_system_audit.system_id
118 assert_equal 'MISATO', @feeder_audit.feeder_system_item_ids[0].issuer
119 assert_equal 'UTF-8', @feeder_audit.original_content.charset.code_string
120 end
121
122 def test_feeder_audit_detail
123 assert_equal 'MAGI', @feeder_audit_details.system_id
124 assert_equal 'NERV', @feeder_audit_details.provider.name
125 assert_equal 'GEOFRONT', @feeder_audit_details.location.name
126 assert_equal 2009, @feeder_audit_details.time.year
127 assert_equal 'local', @feeder_audit_details.subject.external_ref.namespace
128 assert_equal '0.0.4', @feeder_audit_details.version_id
129 end
130end
131
132class RM_Common_Generic_Test < Test::Unit::TestCase
133 def setup
134 assert_nothing_raised(Exception){party_proxy = Party_Proxy.new}
135 object_id = Object_ID.new('0.0.4')
136 party_ref = Party_Ref.new('unknown', 'ORGANISATION', object_id)
137 assert_nothing_raised(Exception){
138 @party_proxy = Party_Proxy.new(:external_ref => party_ref)}
139 assert_nothing_raised(Exception){party_self = Party_Self.new}
140 assert_nothing_raised(Exception){
141 @party_self = Party_Self.new(:external_ref => party_ref)}
142 assert_raise(ArgumentError){
143 party_identified = Party_Identified.new}
144 identifiers = []
145 identifiers << DV_Identifier.new('NERV', 'MELCHIOR', 'GENDO', 'COMPUTER')
146 identifiers << DV_Identifier.new('NERV', 'CASPER', 'GENDO', 'COMPUTER')
147 identifiers << DV_Identifier.new('NERV', 'BALTHAZAR', 'GENDO', 'COMPUTER')
148 assert_nothing_raised(Exception){
149 @party_identified = Party_Identified.new(:name => 'NERV',
150 :external_ref => party_ref,
151 :identifier => identifiers)}
152 terminology_id = Terminology_ID.new('test','0.04')
153 code_phrase = Code_Phrase.new('self', terminology_id)
154 dv_coded_text = DV_Coded_Text.new('Seele',terminology_id)
155 assert_nothing_raised(Exception){
156 @party_related = Party_Related.new(:name => 'GEHIRN',
157 :relationship => dv_coded_text)}
158
159
160# change_type = OpenEHR::RM::Data_Types::Text::DV_Text.new('audit_type')
161# time_committed = OpenEHR::RM::Data_Types::Quantity::Date_Time::DV_Date_Time.new(2008)
162# assert_nothing_raised(Exception){@audit_details = OpenEHR::RM::Common::Generic::Audit_Details.new('rails',@party_proxy, change_type, time_committed)}
163 end
164
165 def test_init
166 assert_instance_of Party_Proxy, @party_proxy
167 assert_instance_of Party_Self, @party_self
168 assert_instance_of Party_Identified, @party_identified
169 end
170
171 def test_party_proxy
172 assert_equal 'unknown', @party_proxy.external_ref.namespace
173 end
174
175 def test_party_self
176 assert_equal 'ORGANISATION', @party_self.external_ref.type
177 end
178
179 def test_party_identified
180 assert_equal 'NERV', @party_identified.name
181 assert_equal '0.0.4', @party_identified.external_ref.id.value
182 identifiers = @party_identified.identifier
183 ids = [ ]
184 identifiers.each do |id|
185 ids << id.id
186 end
187 assert_equal %w[MELCHIOR CASPER BALTHAZAR], ids
188 end
189
190 def test_party_related
191 assert_equal 'GEHIRN', @party_related.name
192 end
193end
194
195class RM_Common_Directory_Test < Test::Unit::TestCase
196 def setup
197 dv_text = OpenEHR::RM::Data_Types::Text::DV_Text.new('root')
198 assert_nothing_raised(Exception){@folder = OpenEHR::RM::Common::Directory::Folder.new('at0000', dv_text, nil)}
199 end
200
201 def test_init
202 assert_instance_of OpenEHR::RM::Common::Directory::Folder, @folder
203 end
204
205 def test_folder
206 assert_equal 'at0000', @folder.archetype_node_id
207 assert_equal 'root', @folder.name.value
208 end
209end
210
211class RM_Common_Change_Control_Test < Test::Unit::TestCase
212 def setup
213 hier_object_id = OpenEHR::RM::Support::Identification::Hier_Object_ID.new('0.0.4')
214 object_id = OpenEHR::RM::Support::Identification::Object_ID.new("0.0.3")
215 object_ref = OpenEHR::RM::Support::Identification::Object_Ref.new('local', 'ANY', object_id)
216 versions = Set.new [object_ref]
217# audit_detail = OpenEHR::RM::Generic::Audit_Detail.new()
218# assert_nothing_raised(Exception){@version = OpenEHR::RM::Common::Change_Control::Version.new(hier_object_id, versions)}
219# assert_nothing_raised(Exception){@contribution = OpenEHR::RM::Common::Change_Control::Contribution.new(hier_object_id, versions, audit_detail)}
220 end
221 def test_init
222# assert_instace_of OpenEHR::RM::Common::Change_Control::Contribution @contribution
223# assert_instace_of OpenEHR::RM::Common::Change_Control::Version @version
224 end
225 def test_version
226 end
227 def test_contribution
228# assert_equal @contribution.uid
229 end
230end
Note: See TracBrowser for help on using the repository browser.