Skip to content

Commit 266b253

Browse files
authored
Enforcing strict error handling while converting json tests (#1013)
* tests for enforcing strict error handling while converting json * checkstyle * using text block instead of concatenation
1 parent 79031e7 commit 266b253

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

service/src/main/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public String encodeToJson(IBaseResource resource) {
2626

2727
private IParser prepareParser() {
2828
FhirContext ctx = FhirContext.forDstu3();
29-
ctx.newJsonParser();
3029
ctx.setParserErrorHandler(new StrictErrorHandler());
3130
return ctx.newJsonParser();
3231
}

service/src/test/java/uk/nhs/adaptors/gp2gp/common/service/FhirParseServiceTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ void setUp() {
4444
fhirParseService = new FhirParseService();
4545
}
4646

47+
@Test
48+
void shouldThrowValidationExceptionForInvalidJsonDiagnosticsField() {
49+
50+
String invalidJson = """
51+
{
52+
"resourceType": "OperationOutcome",
53+
"meta": {
54+
"profile": ["https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-OperationOutcome-1"]
55+
},
56+
"issue": [ {
57+
"severity": "error",
58+
"code": "value",
59+
"details": {
60+
"coding": [ {
61+
"system": "http://fhir.nhs.net/ValueSet/gpconnect-error-or-warning-code-1",
62+
"code": "INVALID_IDENTIFIER_VALUE"
63+
} ]
64+
},
65+
"diagnosticos": "Provide a conversationId that exists and retry the operation"
66+
} ]
67+
}
68+
""";
69+
70+
assertThrows(FhirValidationException.class, () -> {
71+
fhirParseService.parseResource(invalidJson, OperationOutcome.class);
72+
});
73+
}
74+
4775
@Test
4876
void ableToEncodeOperationOutcomeToJson() throws JsonProcessingException {
4977

0 commit comments

Comments
 (0)