Stream: implementers
Topic: Writing automated test in Java that validates FHIR
Simon Kågedal Reimer (Nov 14 2020 at 21:05):
Hello! I am writing a FHIR-compatible API for a service and would like to have automated tests in my test JUnit 5 suite that validate that the responses are valid FHIR JSON. Is there a tool that will let me do this? I have found this: https://github.com/hapifhir/org.hl7.fhir.core/ – but I'm not sure if it can be used emvedded in Java, or only as a standalone tool?
Simon Kågedal Reimer (Nov 14 2020 at 21:19):
This post seems to say that you can do exactly this... https://medium.com/@kevin.mayfield/testing-care-connect-resources-hl7-fhir-3680421dda23
Simon Kågedal Reimer (Nov 14 2020 at 21:57):
Yup, I got something working with ValidationEngine.validate :) Super nice! If there's some kind of wrapper that makes it even more ready-made for using with JUnit, I'd love to know!
Lloyd McKenzie (Nov 14 2020 at 21:58):
We use it with JUnit - org.hl7.fhir.validation. All of the test cases are here: https://github.com/FHIR/fhir-test-cases
Simon Kågedal Reimer (Nov 15 2020 at 10:22):
Thanks! So, hmm – where is the actual Java code for running the test cases in junit?
Grahame Grieve (Nov 15 2020 at 10:39):
@Mark Iantorno is working on packaging the validator now, but in the meantime, ValidationHostServices is the least worst package, or else maybe you could look at HAPI full
Simon Kågedal Reimer (Nov 15 2020 at 18:11):
Where do i find that? (ValidationHostServices)
Simon Kågedal Reimer (Nov 15 2020 at 18:30):
So what i tried was basically creating a ValidationEngine and run "validate" on my JSON, and it seems to work, but I'm a bit confused as to how to use the OperationOutcome. I first thought that I could "assertFalse(outcome.hasIssue())" but it appears also the "all ok" state is an "issue"...
Simon Kågedal Reimer (Nov 15 2020 at 18:39):
I guess using the Json Schema is more on the right level for what I need to do?
Grahame Grieve (Nov 15 2020 at 21:32):
you certainly don't want to use Json Schema if you can avoid it - there are many problems with it, and many things it doesn't do anyway
Grahame Grieve (Nov 15 2020 at 21:40):
it's true that the operation outcome explicitly includes an issue for all ok. We've found that's confusing either way - some people are confused when it says nothing, and others are confused when it says 'all 'ok'
anyway, if the only issues present have level = information and type = information, there's no issues to report (and there'll only be one)
Simon Kågedal Reimer (Nov 16 2020 at 08:12):
Thank you! Will not use Json Schema then, and use that method of checking the outcome. Just to check – when you said "ValidationHostServices is the least worst package" – did you mean the thing I am using now or something else?
Simon Kågedal Reimer (Nov 16 2020 at 08:13):
Also, what's the best outlet (RSS feed or such) to follow for updates in this area (as the thing you mentioned that @Mark Iantorno is working on)?
Grahame Grieve (Nov 16 2020 at 08:31):
probably #hapi. Turns out I renamed ValidationHostServices to NativeHostServices
Simon Kågedal Reimer (Nov 16 2020 at 08:57):
Ah nice, found it. So the benefit of using NativeHostServices instead of ValidationEngine would be that it operates locally, is that correct?
Grahame Grieve (Nov 16 2020 at 09:07):
well, it just hosts ValidationEngine for re-use
Grahame Grieve (Nov 16 2020 at 09:08):
without reinitialising it every time
Mark Iantorno (Nov 16 2020 at 14:29):
For updates regarding what I'm working on, you can always check the documentation on the project website:
Mark Iantorno (Nov 16 2020 at 14:29):
https://github.com/hapifhir/org.hl7.fhir.validator-wrapper
Mark Iantorno (Nov 16 2020 at 14:30):
I'm actively working on the project
Simon Kågedal Reimer (Nov 16 2020 at 18:28):
Ok, I think I'm missing the benefit of NativeHostServices. :) Can't I just hold on to the ValidationEngine object instead and call validate repeatedly if needed? From looking at the code, it seems that NativeHostServices just wraps ValidationEngine in a less nice Java interface.
Grahame Grieve (Nov 16 2020 at 21:14):
Yeah that's true. It's just that we reserve the right to make breaking changes to ValidationEngine
Last updated: Apr 12 2022 at 19:14 UTC