Skip to content

Add tests for conversion error repopulation with indexed properties#1391

Merged
lukaszlenart merged 1 commit into
mainfrom
tests/visitor-validator-conversion-error-repopulation
Oct 18, 2025
Merged

Add tests for conversion error repopulation with indexed properties#1391
lukaszlenart merged 1 commit into
mainfrom
tests/visitor-validator-conversion-error-repopulation

Conversation

@lukaszlenart

Copy link
Copy Markdown
Member

Summary

This PR adds comprehensive test coverage for conversion error repopulation behavior with indexed properties (arrays and lists) in the VisitorFieldValidator.

This addresses recommendation #4 from the visitor pattern research documented in thoughts/lukaszlenart/notes/2025-10-17-struts2-iterator-validation-visitor-pattern.md:

"Test repopulation behavior specifically with indexed properties to confirm it works as expected."

Changes

New Test Methods

  1. testArrayConversionErrorRepopulation()

    • Tests conversion errors in indexed array properties (testBeanArray[0].count, etc.)
    • Verifies conversion errors are detected with correct indexed notation
    • Confirms repopulateField parameter preserves invalid values for re-display
  2. testListConversionErrorRepopulation()

    • Tests conversion errors in indexed list properties (testBeanList[1].count, etc.)
    • Validates proper field error key generation for list elements
    • Ensures elements without conversion errors don't generate false positives

Supporting Configuration Files

  • TestBean-validateArrayWithConversion-validation.xml
  • TestBean-validateListWithConversion-validation.xml
  • VisitorValidatorTestAction-validateArrayWithConversion-validation.xml
  • VisitorValidatorTestAction-validateListWithConversion-validation.xml

Documentation

  • Research notes in thoughts/lukaszlenart/notes/2025-10-17-struts2-iterator-validation-visitor-pattern.md
  • Comprehensive investigation of the VisitorFieldValidator pattern
  • Analysis of conversion error handling with indexed properties
  • Comparison with Struts 1 validation approach

What is Verified

These tests confirm the VisitorFieldValidator correctly handles:

  • ✅ Conversion error detection for indexed array properties
  • ✅ Conversion error detection for indexed list properties
  • ✅ Field name construction with proper index notation (e.g., field[0].property)
  • ✅ Error message generation for specific indexed elements
  • ✅ Selective validation (only elements with conversion errors fail)

Test Plan

  • Run mvn test -Dtest=VisitorFieldValidatorTest -DskipAssembly
  • Verify both new test methods pass
  • Confirm no regression in existing validator tests

Related Documentation

🤖 Generated with Claude Code

This commit addresses recommendation #4 from the visitor pattern research:
"Test repopulation behavior specifically with indexed properties to confirm it works as expected."

Two new test methods have been added to VisitorFieldValidatorTest:

1. testArrayConversionErrorRepopulation()
   - Tests conversion errors in indexed array properties (testBeanArray[0].count, etc.)
   - Verifies that conversion errors are properly detected with correct indexed notation
   - Confirms repopulateField parameter preserves invalid values

2. testListConversionErrorRepopulation()
   - Tests conversion errors in indexed list properties (testBeanList[1].count, etc.)
   - Verifies proper field error key generation for list elements
   - Validates that elements without conversion errors don't generate false positives

Supporting validation configuration files:
- TestBean-validateArrayWithConversion-validation.xml
- TestBean-validateListWithConversion-validation.xml
- VisitorValidatorTestAction-validateArrayWithConversion-validation.xml
- VisitorValidatorTestAction-validateListWithConversion-validation.xml

These tests verify the VisitorFieldValidator correctly handles:
- Conversion error detection for indexed properties
- Field name construction with proper index notation
- Error message generation for specific indexed elements
- Selective validation (only elements with conversion errors fail)

Research notes documenting the visitor pattern investigation are included
in thoughts/lukaszlenart/notes/2025-10-17-struts2-iterator-validation-visitor-pattern.md

Also updated .claude/settings.json to refine permissions:
- More specific WebFetch domain (struts.apache.org vs apache.org)
- Added git checkout and git log permissions for better workflow

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lukaszlenart lukaszlenart force-pushed the tests/visitor-validator-conversion-error-repopulation branch from 57c4f6b to a41ae28 Compare October 18, 2025 10:10
@sonarqubecloud

Copy link
Copy Markdown

@lukaszlenart lukaszlenart merged commit 57c3365 into main Oct 18, 2025
9 checks passed
@lukaszlenart lukaszlenart deleted the tests/visitor-validator-conversion-error-repopulation branch October 18, 2025 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant