Skip to content

#521 Enhanced Kind Validation and Testing for ValidKindConstraintValidator

Type of change

  • Bug Fix
  • Feature

Please provide link to gitlab issue or ADR(Architecture Decision Record)
#521

Does this introduce a change in the core logic?

  • [YES]

Does this introduce a change in the cloud provider implementation, if so which cloud?

  • AWS
  • Azure
  • GCP
  • IBM

Does this introduce a breaking change?

  • [NO]

What is the current behavior?

  • The existing kind id validation is shallow, doesn't cover all validation cases
  • It is possible to try to create a kind cache config with wrong/absent kinds referenced.

What is the new/expected behavior?

This merge request introduces a comprehensive validation mechanism for the Kind structure and entity type identifier in the ValidKindConstraintValidator. The key highlights include:

  • Kind Structure Validation: Implemented validation for the Kind property, ensuring that it conforms to the expected four-part structure. This logic was externalized to a new KindUtil class to keep the validator clean.

  • Entity Type Identifier Validation: The validation to check whether the entity type identifier (third segment) is part of the supported data types was moved to the TransformerConfigurationCacheService. This keeps responsibility aligned and reduces complexity in the validator class.

  • Exception Handling: Incorporated handling for TransformerConfigurationCacheException in the validator logic and corresponding unit tests.

Changes

  1. Kind Structure Validation:

    • Introduced KindUtil to manage kind structure validation and entity type extraction.
  2. Entity Type Identifier Validation:

    • Added isEntityTypeSupported method to TransformerConfigurationCacheService to validate the entity type.
  3. Refactoring of ValidKindConstraintValidator:

    • The validator now uses KindUtil and TransformerConfigurationCacheService to handle kind structure and entity type validation.
  4. Robust Unit Tests:

    • Added unit tests that cover various validation scenarios such as null kind values, unsupported entity types, and invalid kind structure.
    • Mocks dependencies like KindCacheConfigurationCacheService, SchemaService, and TransformerConfigurationCacheService.
    • Unit tests rely on exact text matching in error messages for validation.

How to Test

  • Run the unit tests (ValidKindConstraintValidatorTest) to verify the functionality.
  • Tests cover:
    • Validation of proper and improper Kind structure.
    • Handling of null values based on annotation configuration.
    • Validation of entity type identifier support in transformer configuration.
    • Exception handling in the validator.

Risks and Considerations

  • Message Updates: Tests rely on exact error message text matching, so any changes to error messages in the code will require updates in the test assertions.
  • Scalability: The changes keep the validation logic clean and modular, preparing for future extensions to the kind validation process.

Conclusion

This merge request improves the modularity, maintainability, and robustness of the ValidKindConstraintValidator by externalizing key logic and ensuring thorough unit test coverage.

Any other useful information

Closes #521

Merge request reports

Loading