Skip to content

Commit 7573f7d

Browse files
authored
Merge branch 'develop' into feature/MAT-8023/add-shared-measures-tab
2 parents 78c6a0f + e0656f0 commit 7573f7d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/main/java/cms/gov/madie/measure/utils/JsonUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ public static String enforcePatientId(TestCase testCase, String madieJsonResourc
426426
// update full urls for non-patient resources
427427
public static String updateResourceFullUrls(TestCase testCase, String madieJsonResourcesBaseUri) {
428428
ObjectMapper mapper = new ObjectMapper();
429+
boolean jsonValid = false;
429430
try {
430431
JsonNode rootNode = mapper.readTree(testCase.getJson());
431432
JsonNode entry = rootNode.get("entry");
@@ -441,11 +442,16 @@ public static String updateResourceFullUrls(TestCase testCase, String madieJsonR
441442
String newUrl = buildFullUrl(id, resourceType, madieJsonResourcesBaseUri);
442443
ObjectNode node = (ObjectNode) theNode;
443444
node.put("fullUrl", newUrl);
445+
jsonValid = true;
444446
}
445447
}
446448
}
447449
}
448-
return jsonNodeToString(mapper, rootNode);
450+
if (!jsonValid) {
451+
return testCase.getJson();
452+
} else {
453+
return jsonNodeToString(mapper, rootNode);
454+
}
449455
} catch (JsonProcessingException ex) {
450456
log.error("Error reading testCaseJson testCaseId = " + testCase.getId(), ex);
451457
}

src/test/java/cms/gov/madie/measure/utils/JsonUtilTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,23 @@ void updateResourceFullUrlsIfNoTestResourceAvailable() {
561561
assertFalse(updatedTc1.contains(baseUrl));
562562
}
563563

564+
@Test
565+
void updateResourceFullUrlsIfJsonInvalid() {
566+
final String json = getData("/bundles/qicore_json_util_fullurl.json");
567+
// remove the opening { to make json invalid
568+
String invalidJson = json.substring(1, json.length());
569+
TestCase tc1 =
570+
TestCase.builder()
571+
.id("TC1")
572+
.name("TC1")
573+
.patientId(UUID.randomUUID())
574+
.json(invalidJson)
575+
.build();
576+
String updatedTc1 = JsonUtil.updateResourceFullUrls(tc1, baseUrl);
577+
// original json is returned when json is invalid
578+
assertEquals(updatedTc1, invalidJson);
579+
}
580+
564581
@Test
565582
void updateResourceFullUrlsIfEntryNodeNotAvailable() {
566583
final String json =

0 commit comments

Comments
 (0)