@Test public void givenComplexArchiveUnitProfileAndInvalidUnitThenValidationKO() throws Exception { JsonNode schemaMail = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream(SCHEMA_JSON_MAIL_FILE)); CachedArchiveUnitProfileLoader archiveUnitProfileLoader = mock(CachedArchiveUnitProfileLoader.class); doReturn(Optional.of( new ArchiveUnitProfileModel() .setControlSchema(JsonHandler.unprettyPrint(schemaMail)) .setStatus(ArchiveUnitProfileStatus.ACTIVE) )).when(archiveUnitProfileLoader).loadArchiveUnitProfile("AUP-000001"); CachedSchemaValidatorLoader schemaValidatorLoader = new CachedSchemaValidatorLoader(10, 6); UnitValidator unitValidator = new UnitValidator(archiveUnitProfileLoader, schemaValidatorLoader); JsonNode unitJson = JsonHandler.getFromInputStream(PropertiesUtils.getResourceAsStream(AU_JSON_MAIL_FILE)); ((ObjectNode) unitJson).put("randomAddedField", "This field will be rejected"); assertThatThrownBy(() -> unitValidator.validateUnit((ObjectNode) unitJson)) .isInstanceOf(MetadataValidationException.class) .extracting(e -> ((MetadataValidationException) e).getErrorCode()) .isEqualTo(MetadataValidationErrorCode.ARCHIVE_UNIT_PROFILE_SCHEMA_VALIDATION_FAILURE); }
public void validateUnit(ObjectNode unitJson) throws MetadataValidationException { validateStartAndEndDates(unitJson); validateInternalSchema(unitJson); validateArchiveUnitProfile(unitJson); }
UnitValidator { public void validateUnit(ObjectNode unitJson) throws MetadataValidationException { validateStartAndEndDates(unitJson); validateInternalSchema(unitJson); validateArchiveUnitProfile(unitJson); } }
UnitValidator { public void validateUnit(ObjectNode unitJson) throws MetadataValidationException { validateStartAndEndDates(unitJson); validateInternalSchema(unitJson); validateArchiveUnitProfile(unitJson); } UnitValidator(CachedArchiveUnitProfileLoader archiveUnitProfileLoader,
        CachedSchemaValidatorLoader schemaValidatorLoader); }
UnitValidator { public void validateUnit(ObjectNode unitJson) throws MetadataValidationException { validateStartAndEndDates(unitJson); validateInternalSchema(unitJson); validateArchiveUnitProfile(unitJson); } UnitValidator(CachedArchiveUnitProfileLoader archiveUnitProfileLoader,
        CachedSchemaValidatorLoader schemaValidatorLoader); void validateUnit(ObjectNode unitJson); void validateInternalSchema(ObjectNode archiveUnit); void validateArchiveUnitProfile(ObjectNode archiveUnit); void validateStartAndEndDates(JsonNode archiveUnit); }
UnitValidator { public void validateUnit(ObjectNode unitJson) throws MetadataValidationException { validateStartAndEndDates(unitJson); validateInternalSchema(unitJson); validateArchiveUnitProfile(unitJson); } UnitValidator(CachedArchiveUnitProfileLoader archiveUnitProfileLoader,
        CachedSchemaValidatorLoader schemaValidatorLoader); void validateUnit(ObjectNode unitJson); void validateInternalSchema(ObjectNode archiveUnit); void validateArchiveUnitProfile(ObjectNode archiveUnit); void validateStartAndEndDates(JsonNode archiveUnit);  }