source: ruby/trunk/lib/models/tests/rm/test_support.rb@ 292

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

adjust some conflict

File size: 16.8 KB
Line 
1require 'test/unit'
2require 'set'
3require 'rm'
4
5class RM_Support_Definition_Test < Test::Unit::TestCase
6 def test_constant
7 assert_equal("\r", OpenEhr::RM::Support::Definition::OpenEHRDefinitions::CR)
8 assert_equal("\n", OpenEhr::RM::Support::Definition::OpenEHRDefinitions::LF)
9 end
10end
11
12
13class RM_Support_Identification_Test < Test::Unit::TestCase
14 def setup
15 assert_nothing_raised(Exception){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new("0.0.3")}
16 assert_nothing_raised(Exception){@object_ref = OpenEhr::RM::Support::Identification::ObjectRef.new('local', 'ANY', @object_id)}
17 assert_nothing_raised(Exception){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
18 assert_nothing_raised(Exception){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('ICD10(2003)')}
19 assert_nothing_raised(Exception){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", "openehr")}
20 assert_nothing_raised(Exception){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.3')}
21 assert_nothing_raised(Exception){@hier_object_id = OpenEhr::RM::Support::Identification::HierObjectId.new('0.0.4')}
22 assert_nothing_raised(Exception){@locatable_ref = OpenEhr::RM::Support::Identification::LocatableRef.new('unknown', 'PERSON', @uid_based_id, 'data/event[at0001, standing]')}
23 assert_nothing_raised(Exception){@party_ref = OpenEhr::RM::Support::Identification::PartyRef.new('unknown', 'ORGANISATION', @object_id)}
24 assert_nothing_raised(Exception){@access_group_ref = OpenEhr::RM::Support::Identification::AccessGroupRef.new('unknown', 'ACCESS_GROUP', @object_id)}
25 assert_nothing_raised(Exception){@version_tree_id = OpenEhr::RM::Support::Identification::VersionTreeId.new('1.2.3')}
26 assert_nothing_raised(Exception){@object_version_id = OpenEhr::RM::Support::Identification::ObjectVersionId.new('ABC::DEF::1.2.3')}
27 end
28
29 def test_init
30 assert_instance_of OpenEhr::RM::Support::Identification::ObjectId, @object_id
31 assert_instance_of OpenEhr::RM::Support::Identification::ObjectRef, @object_ref
32 assert_instance_of OpenEhr::RM::Support::Identification::ArchetypeId, @archetype_id
33 assert_instance_of OpenEhr::RM::Support::Identification::TerminologyId, @terminology_id
34 assert_instance_of OpenEhr::RM::Support::Identification::ObjectId, @object_id
35 assert_instance_of OpenEhr::RM::Support::Identification::GenericId, @generic_id
36 assert_instance_of OpenEhr::RM::Support::Identification::UidBasedId, @uid_based_id
37 assert_instance_of OpenEhr::RM::Support::Identification::HierObjectId, @hier_object_id
38 assert_instance_of OpenEhr::RM::Support::Identification::LocatableRef, @locatable_ref
39 assert_instance_of OpenEhr::RM::Support::Identification::PartyRef, @party_ref
40 assert_instance_of OpenEhr::RM::Support::Identification::AccessGroupRef, @access_group_ref
41 assert_instance_of OpenEhr::RM::Support::Identification::VersionTreeId, @version_tree_id
42 assert_instance_of OpenEhr::RM::Support::Identification::ObjectVersionId, @object_version_id
43 end
44
45 def test_object_id
46 assert_equal "0.0.3", @object_id.value
47 assert_nothing_raised(Exception){@object_id.value = "0.0.4"}
48 assert_equal "0.0.4", @object_id.value
49 assert_raise(ArgumentError){@object_id.value=nil}
50 assert_raise(ArgumentError){@object_id.value=""}
51 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new}
52 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new(nil)}
53 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ObjectId.new("")}
54 assert_equal @object_id, OpenEhr::RM::Support::Identification::ObjectId.new("0.0.4")
55 end
56
57 def test_object_refs
58 assert_equal 'local', @object_ref.namespace
59 assert_equal 'ANY', @object_ref.type
60 assert_equal @object_id, @object_ref.id
61
62 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new}
63 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new(nil, 'ANY', @object_id)}
64 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('', 'ANY', @object_id)}
65 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', nil, @object_id)}
66 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', '', @object_id)}
67 assert_raise(ArgumentError){@object_ref = OpenEhr::RM::Support::Identification::ArchetypeId.new('local', 'ANY', nil)}
68
69 assert_nothing_raised(Exception){@object_ref.namespace = 'terminology'}
70 assert_equal 'terminology', @object_ref.namespace
71 assert_raise(ArgumentError){@object_ref.namespace = nil}
72 assert_raise(ArgumentError){@object_ref.namespace = ''}
73 assert_raise(ArgumentError){@object_ref.namespace = '?&&'}
74 assert_raise(ArgumentError){@object_ref.namespace = '843'}
75
76 assert_nothing_raised(Exception){@object_ref.type = 'GUIDELINE'}
77 assert_equal 'GUIDELINE', @object_ref.type
78 assert_raise(ArgumentError){@object_ref.type = nil}
79 assert_raise(ArgumentError){@object_ref.type = ''}
80
81 assert_nothing_raised(Exception){@object_ref.id = OpenEhr::RM::Support::Identification::ObjectId.new("0.0.5")}
82 assert_equal OpenEhr::RM::Support::Identification::ObjectId.new("0.0.5"), @object_ref.id
83 assert_raise(ArgumentError){@object_ref.id = nil}
84 end
85
86 def test_archetype_id
87 assert_equal "0.0.5", @archetype_id.value
88 assert_nothing_raised(Exception){@archetype_id.value = "0.0.6"}
89 assert_equal "0.0.6", @archetype_id.value
90 assert_raise(ArgumentError){@archetype_id.value=nil}
91 assert_raise(ArgumentError){@archetype_id.value=""}
92 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new}
93 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new(nil, "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
94 assert_raise(ArgumentError){@object_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
95 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", nil, "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
96 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "", "entry", "ehr_rm", "openehr","cholesterol","0.0.3")}
97 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", nil, "ehr_rm", "openehr","cholesterol","0.0.3")}
98 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "", "ehr_rm", "openehr","cholesterol","0.0.3")}
99 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", nil, "openehr","cholesterol","0.0.3")}
100 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "", "openehr","cholesterol","0.0.3")}
101 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", nil,"cholesterol","0.0.3")}
102 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "","cholesterol","0.0.3")}
103 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr",nil ,"0.0.3")}
104 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","","0.0.3")}
105 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol", nil)}
106 assert_raise(ArgumentError){@archetype_id = OpenEhr::RM::Support::Identification::ArchetypeId.new("0.0.5", "biochemistry result_cholesterol", "entry", "ehr_rm", "openehr","cholesterol","")}
107
108 assert_equal "biochemistry result_cholesterol", @archetype_id.domain_concept
109 assert_nothing_raised(Exception){(@archetype_id.domain_concept = "biochemistry result_triglyceride")}
110 assert_equal "biochemistry result_triglyceride", @archetype_id.domain_concept
111 assert_raise(ArgumentError){@archetype_id.domain_concept = nil}
112 assert_raise(ArgumentError){@archetype_id.domain_concept = ""}
113
114 assert_equal "entry", @archetype_id.rm_name
115 assert_nothing_raised(Exception){@archetype_id.rm_name = "section"}
116 assert_equal "section", @archetype_id.rm_name
117 assert_raise(ArgumentError){@archetype_id.rm_name = nil}
118 assert_raise(ArgumentError){@archetype_id.rm_name = ""}
119
120 assert_equal "ehr_rm", @archetype_id.rm_entity
121 assert_nothing_raised(Exception){@archetype_id.rm_entity = "13606"}
122 assert_equal "13606", @archetype_id.rm_entity
123 assert_raise(ArgumentError){@archetype_id.rm_entity = nil}
124 assert_raise(ArgumentError){@archetype_id.rm_entity = ""}
125
126 assert_equal "openehr", @archetype_id.rm_originator
127 assert_nothing_raised(Exception){@archetype_id.rm_originator = "cen"}
128 assert_equal "cen", @archetype_id.rm_originator
129 assert_raise(ArgumentError){@archetype_id.rm_originator = nil}
130 assert_raise(ArgumentError){@archetype_id.rm_originator = ""}
131
132 assert_equal "cholesterol", @archetype_id.specialisation
133 assert_nothing_raised(Exception){@archetype_id.specialisation = "triglyceride"}
134 assert_equal "triglyceride", @archetype_id.specialisation
135 assert_raise(ArgumentError){@archetype_id.specialisation = nil}
136 assert_raise(ArgumentError){@archetype_id.specialisation = ""}
137
138 assert_equal "0.0.3", @archetype_id.version_id
139 assert_nothing_raised(Exception){@archetype_id.version_id = "0.0.7"}
140 assert_equal "0.0.7", @archetype_id.version_id
141 assert_raise(ArgumentError){@archetype_id.version_id = nil}
142 assert_raise(ArgumentError){@archetype_id.version_id = ""}
143 end
144
145 def test_terminology_id
146 assert_equal "ICD10(2003)", @terminology_id.value
147 assert_nothing_raised(Exception){@terminology_id.value = "ICD9(1999)"}
148 assert_equal "ICD9", @terminology_id.name
149 assert_equal "1999", @terminology_id.version_id
150 assert_raise(ArgumentError){@terminology_id.value = nil}
151 assert_raise(ArgumentError){@terminology_id.value = ""}
152
153 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new}
154 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new(nil,'2008')}
155 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new('','02008')}
156 assert_raise(ArgumentError){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new("SNOMED", nil)}
157 assert_nothing_raised(Exception){@terminology_id = OpenEhr::RM::Support::Identification::TerminologyId.new("SNOMED")}
158
159 assert_equal "SNOMED", @terminology_id.name
160 assert_nothing_raised(Exception){@terminology_id.name = "LOINC"}
161 assert_equal "LOINC", @terminology_id.name
162 assert_raise(ArgumentError){@terminology_id.name = nil}
163 assert_raise(ArgumentError){@terminology_id.name = ""}
164
165 assert_equal "", @terminology_id.version_id
166 assert_nothing_raised(Exception){@terminology_id.version_id = "2008"}
167 assert_equal "2008", @terminology_id.version_id
168 assert_equal 'LOINC(2008)', @terminology_id.value
169 assert_raise(ArgumentError){@terminology_id.version_id = nil}
170 assert_nothing_raised(Exception){@terminology_id.version_id = ''}
171 end
172
173 def test_generic_id
174 assert_equal "0.0.3", @generic_id.value
175 assert_equal "openehr", @generic_id.scheme
176
177 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new(nil, "openehr")}
178 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("", "openehr")}
179 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", nil)}
180 assert_raise(ArgumentError){@generic_id = OpenEhr::RM::Support::Identification::GenericId.new("0.0.3", "")}
181
182 assert_raise(ArgumentError){@generic_id.value = nil}
183 assert_raise(ArgumentError){@generic_id.value = ""}
184 assert_nothing_raised(Exception){@generic_id.value = "0.0.5"}
185 assert_equal "0.0.5", @generic_id.value
186
187 assert_raise(ArgumentError){@generic_id.scheme = nil}
188 assert_raise(ArgumentError){@generic_id.scheme = ""}
189 assert_nothing_raised(Exception){@generic_id.scheme = "cen"}
190 assert_equal "cen", @generic_id.scheme
191 end
192
193 def test_uid_based_id
194 assert_equal "rrip::0.0.3", @uid_based_id.value
195 assert_equal "rrip", @uid_based_id.root
196 assert_equal '0.0.3', @uid_based_id.extension
197 assert @uid_based_id.has_extension?
198
199 assert_raise(ArgumentError){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new(nil)}
200 assert_raise(ArgumentError){@uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('')}
201 assert_raise(ArgumentError){@uid_based_id.value = nil}
202 assert_raise(ArgumentError){@uid_based_id.value = ''}
203
204 assert_nothing_raised(Exception){@uid_based_id.value = 'rrip'}
205 assert_equal 'rrip', @uid_based_id.value
206 assert_equal 'rrip', @uid_based_id.root
207 assert_equal '', @uid_based_id.extension
208 end
209
210 def test_hier_object_id
211 assert_equal '0.0.4', @hier_object_id.value
212 assert !@hier_object_id.root.nil?
213 assert !@hier_object_id.has_extension?
214# in the specification 1.0.1 has_extension? xor extention != Void void is not nil?
215 assert @hier_object_id.extension.empty?
216 assert_nothing_raised(Exception){@hier_object_id.value = "ehr::test"}
217 assert !@hier_object_id.root.nil?
218 assert @hier_object_id.has_extension?
219 assert !@hier_object_id.extension.empty?
220 end
221
222 def test_object_version_id
223 assert_equal 'ABC::DEF::1.2.3', @object_version_id.value
224 assert_equal 'ABC', @object_version_id.object_id.value
225 assert_equal 'DEF', @object_version_id.creating_system_id.value
226 assert_equal '1', @object_version_id.version_tree_id.trunk_version
227 end
228
229 def test_locatable_ref
230# test constructor
231 assert_equal 'unknown', @locatable_ref.namespace
232 assert_equal 'PERSON', @locatable_ref.type
233 assert_equal @uid_based_id, @locatable_ref.id
234 assert_equal 'data/event[at0001, standing]', @locatable_ref.path
235 assert_equal 'ehr://rrip::0.0.3/data/event[at0001, standing]', @locatable_ref.as_uri
236#test path
237 assert_nothing_raised(Exception){@locatable_ref.path = 'data/event[at0002, tilting]'}
238 assert_equal 'data/event[at0002, tilting]', @locatable_ref.path
239 assert_equal 'ehr://rrip::0.0.3/data/event[at0002, tilting]', @locatable_ref.as_uri
240 end
241
242 def test_party_ref
243# test constructor
244 assert_equal 'unknown', @party_ref.namespace
245 assert_equal 'ORGANISATION', @party_ref.type
246 assert_equal @object_id, @party_ref.id
247# test type validation
248 assert_raise(ArgumentError){@party_ref.type = 'GUIDELINE'}
249 assert_nothing_raised(Exception){@party_ref.type = 'PERSON'}
250 assert_equal 'PERSON', @party_ref.type
251 assert_nothing_raised(Exception){@party_ref.type = 'GROUP'}
252 assert_nothing_raised(Exception){@party_ref.type = 'AGENT'}
253 assert_nothing_raised(Exception){@party_ref.type = 'ROLE'}
254 assert_nothing_raised(Exception){@party_ref.type = 'PARTY'}
255 assert_nothing_raised(Exception){@party_ref.type = 'ACTOR'}
256 end
257
258 def test_access_group_ref
259# test constructor
260 assert_equal 'unknown', @access_group_ref.namespace
261 assert_equal 'ACCESS_GROUP', @access_group_ref.type
262 assert_equal @object_id, @access_group_ref.id
263# test type validation
264 assert_raise(ArgumentError){@access_group_ref.type = 'PERSON'}
265 assert_nothing_raised(Exception){@access_group_ref.type = 'ACCESS_GROUP'}
266 end
267
268 def test_version_tree_id
269 assert_equal '1.2.3', @version_tree_id.value
270 assert_equal '1', @version_tree_id.trunk_version
271 assert_equal '2', @version_tree_id.branch_number
272 assert_equal '3', @version_tree_id.branch_version
273 assert @version_tree_id.is_first?
274 assert @version_tree_id.is_branch?
275 assert_nothing_raised(Exception){@version_tree_id.value = '2'}
276 assert_equal '2', @version_tree_id.trunk_version
277 assert !@version_tree_id.is_first?
278 assert !@version_tree_id.is_branch?
279 assert_nil @version_tree_id.branch_number
280 assert_nil @version_tree_id.branch_version
281 assert_raise(ArgumentError){@version_tree_id.branch_version = '5'}
282 end
283end
Note: See TracBrowser for help on using the repository browser.