source: ruby/branches/0.5/test/unit/open_ehr/rm/support_test.rb@ 191

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

test cases rearrangement

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