Skip to content

MOSIP-33663: Added common ID validation(UIN,VID,PRID) and test data generation.#1882

Open
SradhaMohanty5899 wants to merge 6 commits intomosip:developfrom
SradhaMohanty5899:MOSIP-33663
Open

MOSIP-33663: Added common ID validation(UIN,VID,PRID) and test data generation.#1882
SradhaMohanty5899 wants to merge 6 commits intomosip:developfrom
SradhaMohanty5899:MOSIP-33663

Conversation

@SradhaMohanty5899
Copy link
Contributor

@SradhaMohanty5899 SradhaMohanty5899 commented Jan 29, 2026

  • Added IdValidator and IdGenerator to handle UIN, VID, and PRID validation/generation.
  • Centralized all ID-related constants and rules in id-filter.properties for easier maintenance.
  • Integrated CheckSumUtil for Verhoeff checksum validation.
  • Updated AdminTestUtil to use IdGenerator for test data generation.
  • Simplified sequence, repeating, cyclic number, and pattern checks.
  • Replaced hardcoded values with configurable properties to improve flexibility and maintainability.

Summary by CodeRabbit

  • New Features
    • Added ID generation for valid and invalid UIN, VID, and PRID to support test automation.
    • Added keyword substitutions in JSON payloads for generated IDs (including valid/invalid and not-in-db variants).
    • Added ID validation framework enforcing configurable rules for UIN, VID, and PRID formats.
    • Enhanced configuration access with new property retrieval helpers (integer and list) and actuator-backed property section.

@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Walkthrough

Adds an ID generation and validation framework: new CheckSumUtil, IdValidator, and IdGenerator classes for UIN/VID/PRID generation and validation; AdminTestUtil integrates dynamic ID keyword replacements; ConfigManager gains actuator-backed int and list property access; GlobalConstants adds an actuator property section constant.

Changes

Cohort / File(s) Summary
ID Validation & Generation Framework
apitest-commons/src/main/java/io/mosip/testrig/apirig/id/CheckSumUtil.java, apitest-commons/src/main/java/io/mosip/testrig/apirig/id/IdValidator.java, apitest-commons/src/main/java/io/mosip/testrig/apirig/id/IdGenerator.java
Added CheckSumUtil (checksum generation/validation using static lookup tables), IdValidator (UIN/VID/PRID validation rules and patterns), and IdGenerator (produces valid/invalid UIN/VID/PRID using random bases, checksum, type checks, retry up to 1000).
Configuration & Constants
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/ConfigManager.java, apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/GlobalConstants.java
ConfigManager: added actuator-backed helpers getIntProperty(String) and getListProperty(String) (uses BaseTestCase actuator endpoint). GlobalConstants: added ACTUATOR_PROPERTY_SECTION constant.
Test Utility Integration
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Imported IdGenerator and extended keyword handling to replace tokens with generated IDs: $INVALID_UIN$, $VALID_UIN_NOTIN_DB$, $INVALID_VID$, $VALID_VID_NOTIN_DB$, $INVALID_PRID$, $VALID_PRID_NOTIN_DB$ (uses IdGenerator methods).

Sequence Diagram

sequenceDiagram
    participant AdminTestUtil
    participant IdGenerator
    participant CheckSumUtil
    participant IdValidator

    AdminTestUtil->>IdGenerator: request generated ID (valid/invalid)
    IdGenerator->>IdGenerator: randomDigits(baseLength)
    IdGenerator->>CheckSumUtil: generateChecksumDigit(base)
    CheckSumUtil->>CheckSumUtil: apply lookup tables (d, p, inv)
    CheckSumUtil-->>IdGenerator: checksum digit
    IdGenerator->>IdGenerator: assemble id = base + checksum
    IdGenerator->>IdValidator: isValid{Type}(id)
    IdValidator->>IdValidator: run pattern/sequence/length checks
    IdValidator-->>IdGenerator: validation result
    alt valid as requested
        IdGenerator-->>AdminTestUtil: return id
    else retry up to MAX_ATTEMPTS
        IdGenerator->>IdGenerator: repeat generation
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Poem

🐰 I hopped through digits, one by one,
I twiddled tables till checksums shone,
I stitched bases and tails with care,
Now IDs bloom from my burrowed lair,
Hop, test, repeat — a bunny's dare.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding ID validation for UIN, VID, PRID and test data generation capabilities, which aligns with the primary additions of IdValidator, IdGenerator, and CheckSumUtil classes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.5)
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Fix all issues with AI agents
In `@apitest-commons/src/main/java/io/mosip/testrig/apirig/id/CheckSumUtil.java`:
- Around line 16-31: The public methods generateChecksumDigit and
validateChecksum currently pass invalid or null strings into
stringToReversedIntArray causing NumberFormatException/NullPointerException; add
input validation at the start of both methods to check for null/empty and ensure
the string contains only digits (e.g., regex or Character.isDigit loop) and if
invalid throw a clear IllegalArgumentException (with message identifying the
method and the bad input) instead of letting
NumberFormatException/NullPointerException propagate; this keeps
stringToReversedIntArray unchanged and centralizes validation in the public
APIs.

In `@apitest-commons/src/main/java/io/mosip/testrig/apirig/id/IdGenerator.java`:
- Around line 37-64: The generateValid and generateInvalid methods use unbounded
while(true) loops and need a max-attempts guard to avoid hangs; introduce a
MAX_ATTEMPTS constant and increment an attempt counter inside both
generateValid(int baseLength, Type type) and generateInvalid(int baseLength,
Type type), break/return when successful as now, and after exceeding
MAX_ATTEMPTS throw an IllegalStateException (or similar) with a clear message
referencing the method, baseLength and type so callers know why generation
failed; ensure both methods use the same guard and exception behavior for
consistency.
- Around line 3-33: IdGenerator currently uses hard-coded base lengths in
methods like generateValidUin(), generateValidVid(), generateValidPrid(),
generateInvalidUin(), generateInvalidVid(), and generateInvalidPrid(); change
these to read the configured lengths via ConfigManager (same keys used by
IdValidator, e.g., mosip.uin.length, mosip.vid.length, mosip.prid.length) at
class init or lazily and use those values when calling generateValid(...) and
generateInvalid(...); ensure you reference ConfigManager once (cache the values
in private static finals) and fall back to current defaults only if the config
lookup returns invalid.

In `@apitest-commons/src/main/java/io/mosip/testrig/apirig/id/IdValidator.java`:
- Around line 77-81: commonValidation currently calls id.matches("\\d+") which
will NPE on a null id; update commonValidation to first check for null or blank
inputs (e.g., id == null || id.trim().isEmpty()) and return false before
performing the regex or other validations so callers like isValidUin, isValidVid
and isValidPrid remain safe with null/blank inputs.
- Around line 11-54: IdValidator currently initializes many static config fields
(e.g., SEQUENCE_LIMIT, UIN_LENGTH, SEQ_ASC, CYCLIC_NUM) at class load using
ConfigManager, and its commonValidation() method has no null check for the id
parameter; if ConfigManager.init(...) hasn't run or properties are missing this
can cause NumberFormatException and commonValidation() can throw NPE. Fix by
making config access lazy and null-safe: replace eager static reads with
lazily-initialized getters (or validate ConfigManager.isInitialized() at start)
that return defaults or throw clear configuration exceptions if properties are
absent, and add a null check at the start of commonValidation(id) to return
false or throw IllegalArgumentException for null id; update references to
SEQUENCE_LIMIT/SEQ_ASC/etc. to use the new getters so class loading no longer
depends on ConfigManager.init().

In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/ConfigManager.java`:
- Around line 305-315: The typed accessors don't guard against missing/blank
values from getproperty (which returns ""), so update getIntProperty,
getListProperty and getArrayProperty to first fetch the raw value via
getproperty(key), trim it and fail fast if it's null/empty by throwing an
IllegalArgumentException with a clear message including the key; for
getIntProperty pass the trimmed value to Integer.parseInt; for getListProperty
and getArrayProperty split on "," then trim each token and filter out empty
tokens before returning (return an empty list/empty array if no valid tokens
remain).
🧹 Nitpick comments (1)
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java (1)

3917-3947: Avoid duplicate $BIOVALUE$ handling.
There’s already a $BIOVALUE$ replacement later in the same method, so this new block is redundant and can drift over time. Consider keeping a single handler.

🧹 Suggested cleanup
-		if (jsonString.contains("$BIOVALUE$")) {
-			jsonString = replaceKeywordWithValue(jsonString, "$BIOVALUE$",
-					BiometricDataProvider.getFromBiometricMap("BioValue"));
-		}
-		

Signed-off-by: SradhaMohanty5899 <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java`:
- Around line 3917-3942: The placeholders $VALID_UIN_NOTIN_DB$,
$VALID_VID_NOTIN_DB$, and $VALID_PRID_NOTIN_DB` in AdminTestUtil are misleading
because IdGenerator.generateValid*() only validates format and does not ensure
DB uniqueness; update the code that handles these keywords (the jsonString
contains checks and calls to replaceKeywordWithValue /
IdGenerator.generateValidUin(), generateValidVid(), generateValidPrid()) to
guarantee non-existence by either: (A) query the DB to verify the candidate ID
is absent and retry generation until it is unique, (B) maintain a run-level
in-memory cache of generated IDs and regenerate on collision, or (C) change the
keyword semantics/name to remove the “NOTIN_DB” claim; implement one approach
consistently for UIN, VID and PRID generation and ensure replaceKeywordWithValue
uses the chosen uniqueness check before replacing the token.

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.

2 participants