Skip to content

Commit

Permalink
Enforcing strict error handling while converting json tests (#1013)
Browse files Browse the repository at this point in the history
* tests for enforcing strict error handling while converting json

* checkstyle

* using text block instead of concatenation
  • Loading branch information
ole4ryb authored Nov 27, 2024
1 parent 79031e7 commit 266b253
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public String encodeToJson(IBaseResource resource) {

private IParser prepareParser() {
FhirContext ctx = FhirContext.forDstu3();
ctx.newJsonParser();
ctx.setParserErrorHandler(new StrictErrorHandler());
return ctx.newJsonParser();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ void setUp() {
fhirParseService = new FhirParseService();
}

@Test
void shouldThrowValidationExceptionForInvalidJsonDiagnosticsField() {

String invalidJson = """
{
"resourceType": "OperationOutcome",
"meta": {
"profile": ["https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-OperationOutcome-1"]
},
"issue": [ {
"severity": "error",
"code": "value",
"details": {
"coding": [ {
"system": "http://fhir.nhs.net/ValueSet/gpconnect-error-or-warning-code-1",
"code": "INVALID_IDENTIFIER_VALUE"
} ]
},
"diagnosticos": "Provide a conversationId that exists and retry the operation"
} ]
}
""";

assertThrows(FhirValidationException.class, () -> {
fhirParseService.parseResource(invalidJson, OperationOutcome.class);
});
}

@Test
void ableToEncodeOperationOutcomeToJson() throws JsonProcessingException {

Expand Down

0 comments on commit 266b253

Please sign in to comment.