Skip to content

Commit

Permalink
Update unit tests for R4.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawalonoski committed Mar 26, 2019
1 parent 1edc985 commit a8ae606
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion fhir_models.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'fhir_models/version'
Gem::Specification.new do |spec|
spec.name = 'fhir_models'
spec.version = FHIR::Models::VERSION
spec.authors = ['Jason Walonoski', 'Andre Quina', "Michael O'Keefe", 'Robert Scanlon']
spec.authors = ['Jason Walonoski', 'Andre Quina', "Michael O'Keefe", 'Robert Scanlon', 'Reece Adamson']
spec.email = ['[email protected]']

spec.summary = %q{A Gem for handling FHIR models in ruby}
Expand All @@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'pry-coolline'
spec.add_development_dependency 'test-unit'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'simplecov'
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/bootstrap/definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

context 'matching expansions' do
it 'returns a matching expansion.contains value' do
expect(FHIR::Definitions.get_display(uri, code)).to eq 'Echography of kidney'
expect(FHIR::Definitions.get_display(uri, code)).to eq 'US kidneys'
end
end

Expand Down
24 changes: 13 additions & 11 deletions test/unit/equality_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class EqualityTest < Test::Unit::TestCase
Dir.glob(example_json_files).each do |example_json_file|
example_name = File.basename(example_json_file, '.json')
example_xml_file = File.join(EXAMPLE_ROOT, 'xml', "#{example_name}.xml")
define_method("test_equality_#{example_name}") do
run_equality_test(example_json_file, example_xml_file, example_name)
if File.exist?(example_xml_file)
define_method("test_equality_#{example_name}") do
run_equality_test(example_json_file, example_xml_file, example_name)
end
end
end

Expand Down Expand Up @@ -90,17 +92,17 @@ def run_xml_equality_test(example_file, example_name)
def run_equality_test(example_json_file, example_xml_file, example_name)
input_json = File.read(example_json_file)
input_xml = File.read(example_xml_file)
instance_a = FHIR::Json.from_json(input_json)
instance_b = FHIR::Xml.from_xml(input_xml)
instance_json = FHIR::Json.from_json(input_json)
instance_xml = FHIR::Xml.from_xml(input_xml)
exclude = ['div']
if !instance_a.equals?(instance_b, exclude) || !instance_b.equals?(instance_a, exclude)
File.open("#{ERROR_DIR}/#{example_name}_A.json", 'w:UTF-8') { |file| file.write(instance_a.to_json) }
File.open("#{ERROR_DIR}/#{example_name}_B.json", 'w:UTF-8') { |file| file.write(instance_b.to_json) }
File.open("#{ERROR_DIR}/#{example_name}_A.xml", 'w:UTF-8') { |file| file.write(instance_a.to_xml) }
File.open("#{ERROR_DIR}/#{example_name}_B.xml", 'w:UTF-8') { |file| file.write(instance_b.to_xml) }
if !instance_json.equals?(instance_xml, exclude) || !instance_xml.equals?(instance_json, exclude)
File.open("#{ERROR_DIR}/#{example_name}_json.json", 'w:UTF-8') { |file| file.write(instance_json.to_json) }
File.open("#{ERROR_DIR}/#{example_name}_xml.json", 'w:UTF-8') { |file| file.write(instance_xml.to_json) }
File.open("#{ERROR_DIR}/#{example_name}_json.xml", 'w:UTF-8') { |file| file.write(instance_json.to_xml) }
File.open("#{ERROR_DIR}/#{example_name}_xml.xml", 'w:UTF-8') { |file| file.write(instance_xml.to_xml) }
end
assert instance_a.equals?(instance_b, exclude), 'Instance A should be equal to instance B.'
assert instance_b.equals?(instance_a, exclude), 'Instance B should be equal to instance A.'
assert instance_json.equals?(instance_xml, exclude), 'Instance JSON should be equal to instance XML.'
assert instance_xml.equals?(instance_json, exclude), 'Instance XML should be equal to instance JSON.'
# check memory
before = check_memory
instance_a = nil
Expand Down
12 changes: 6 additions & 6 deletions test/unit/profile_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProfileValidationTest < Test::Unit::TestCase
Dir.glob(us_core_ig).each do |definition|
json = File.read(definition)
resource = FHIR.from_contents(json)
PROFILES[resource.url] = resource
PROFILES[resource.url] = resource if resource
end

# Create a blank folder for the errors
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_valueset_binding

# first 2 value sets are special cases
element = FHIR::ElementDefinition.new('path' => 'mime', 'type' => [{ 'code' => 'string' }], 'min' => 1, 'max' => '1',
'binding' => { 'valueSetUri' => 'http://hl7.org/fhir/ValueSet/content-type' })
'binding' => { 'valueSet' => 'http://hl7.org/fhir/ValueSet/mimetypes' })
sd.errors = []
sd.send(:check_binding_element, element, 'xml')
assert_empty(sd.errors)
Expand All @@ -420,7 +420,7 @@ def test_valueset_binding
assert_equal("mime has invalid mime-type: 'jpeg'", sd.errors[0])

element = FHIR::ElementDefinition.new('path' => 'lang', 'type' => [{ 'code' => 'string' }], 'min' => 1, 'max' => '1',
'binding' => { 'valueSetUri' => 'http://hl7.org/fhir/ValueSet/languages' })
'binding' => { 'valueSet' => 'http://hl7.org/fhir/ValueSet/languages' })
sd.errors = []
sd.send(:check_binding_element, element, 'en')
assert_empty(sd.errors)
Expand All @@ -435,7 +435,7 @@ def test_valueset_binding

# use a valueset we don't have defined here
element = FHIR::ElementDefinition.new('path' => 'problem', 'type' => [{ 'code' => 'string' }], 'min' => 1, 'max' => '1',
'binding' => { 'valueSetUri' => 'http://standardhealthrecord.org/shr/problem/vs/ProblemCategoryVS' })
'binding' => { 'valueSet' => 'http://standardhealthrecord.org/shr/problem/vs/ProblemCategoryVS' })
sd.errors = []
sd.warnings = []
sd.send(:check_binding_element, element, 'disease')
Expand All @@ -446,7 +446,7 @@ def test_valueset_binding
# regular case, FHIR VS with nothing special about it
# binding strength required => error if wrong
element = FHIR::ElementDefinition.new('path' => 'county', 'type' => [{ 'code' => 'string' }], 'min' => 1, 'max' => '1',
'binding' => { 'valueSetUri' => 'http://hl7.org/fhir/ValueSet/fips-county',
'binding' => { 'valueSet' => 'http://hl7.org/fhir/ValueSet/fips-county',
'strength' => 'required' })
sd.errors = []
sd.warnings = []
Expand All @@ -462,7 +462,7 @@ def test_valueset_binding

# binding strength example => warning if wrong
element = FHIR::ElementDefinition.new('path' => 'county', 'type' => [{ 'code' => 'string' }], 'min' => 1, 'max' => '1',
'binding' => { 'valueSetUri' => 'http://hl7.org/fhir/ValueSet/fips-county',
'binding' => { 'valueSet' => 'http://hl7.org/fhir/ValueSet/fips-county',
'strength' => 'example' })
sd.errors = []
sd.warnings = []
Expand Down

0 comments on commit a8ae606

Please sign in to comment.