ValidationReportUtils { public static String getOverallValidationResult(final String reportJSON) { if (!isJSONValid(reportJSON)) { LOGGER.warn("Report JSON is: invalid"); return ERROR_VALIDATION; } try { final Integer validSignatureCount = JsonPath.read(reportJSON, "$.validationReport.validationConclusion.validSignaturesCount"); final Integer totalSignatureCount = JsonPath.read(reportJSON, "$.validationReport.validationConclusion.signaturesCount"); if (validSignatureCount == null || totalSignatureCount == null) { LOGGER.warn("No validSignatureCount or totalSignatureCount present in response JSON"); return ERROR_VALIDATION; } return validSignatureCount.equals(totalSignatureCount) && totalSignatureCount > 0 ? VALID_CONTAINER : INVALID_CONTAINER; } catch (final PathNotFoundException ex) { LOGGER.warn("JSON parsing failed when validating overall validation result: ", ex); return INVALID_CONTAINER; } }  static String getValidateFilename(final String reportJSON); static List<String> getValidationWarnings(final String jsonValidationResult); static String getOverallValidationResult(final String reportJSON); static String handleMissingJSON(); static boolean isJSONValid(String json);  }
@Test public void overallValidationRequiredJsonKeysArePresentReturnsValid() throws Exception { final String json = "{\"validationReport\":{\"validationConclusion\":{\"validSignaturesCount\": 1, \"signaturesCount\": 1}}}"; assertEquals("VALID", ValidationReportUtils.getOverallValidationResult(json)); }
@Test public void overallValidationRequiredJsonKeysPresentReturnsInvalid() throws Exception { final String json = "{\"validSignaturesCount\": 0, \"signaturesCount\": 1}"; assertEquals("INVALID", ValidationReportUtils.getOverallValidationResult(json)); }
@Test public void overallValidationRequiredJsonKeysWithValuesZeroReturnsInvalid() throws Exception { final String json = "{\"validationReport\":{\"validationConclusion\":{\"validSignaturesCount\": 0, \"signaturesCount\": 0}}}"; assertEquals("INVALID", ValidationReportUtils.getOverallValidationResult(json)); }
@Test public void overallValidationRequiredKeysPresentValuesNullReturnsInvalid() throws Exception { final String json = "{\"validationReport\":{\"validationConclusion\":{\"validSignaturesCount\": null, \"signaturesCount\": null}}}"; assertEquals("ERROR", ValidationReportUtils.getOverallValidationResult(json)); }
@Test public void overallValidationRequiredKeysNotPresentReturnsInvalid() throws Exception { final String json = "{\"randomKey\": \"randomValue\"}"; assertEquals("INVALID", ValidationReportUtils.getOverallValidationResult(json)); }
@Test public void givenNullJSONToOverallValidationResultWillReturnERROR() throws Exception { assertThat(ValidationReportUtils.getOverallValidationResult(null)).isEqualTo("ERROR"); }