feat(jans-fido2): add JUnit 5 coverage for UserMetricsUpdateRequest DTO#14138
feat(jans-fido2): add JUnit 5 coverage for UserMetricsUpdateRequest DTO#14138imran-ishaq wants to merge 1 commit into
Conversation
Signed-off-by: imran <imranishaq7071@gmail.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Prepare
Description
Adds JUnit 5 test coverage for
UserMetricsUpdateRequest, the parameter-object DTO passed intoFido2UserMetricsServicefor every user registration, authentication, or fallback event that updates per-user adoption/engagement statistics. The new test class locks the 3-argument constructor's argument order (userId,username,success), theisSuccess()boolean-getter naming convention (reflectively, including a negative check thatgetSuccess()does NOT exist), and theSerializable+serialVersionUID = 1Linvariant. Test-only change; no production code orpom.xmlchanges. Step 4 of the FIDO2 metrics test rollout.Target issue
UserMetricsUpdateRequest(jans-fido2/model/src/main/java/io/jans/fido2/model/metric/UserMetricsUpdateRequest.java) is the parameter-object DTO passed from the recording code path intoFido2UserMetricsServicewhenever a user registration, authentication, or fallback event needs to update per-user adoption/engagement statistics. It carries 12 fields covering user identity, success flag, authenticator/device/browser/OS metadata, duration, network info, and fallback details. It exposes a default constructor and a 3-argument convenience constructor(userId, username, success), and uses theisSuccess()boolean-getter naming convention.None of this is tested today. Two specific regressions would be silent failures:
Stringparameters (userId,username) are the most likely to get accidentally swapped during a refactor — without a test, every user-metrics record would be written with the values transposed and no compile-time signal would fire.isSuccess()→getSuccess()would break Jackson default introspection, JavaBeansIntrospector, and MapStruct, but compile fine — silently corrupting serialized payloads and downstream service contracts.This PR is step 4 of the FIDO2 metrics test rollout.
closes #14120
Implementation Details
Adds a single new JUnit 5 test class —
jans-fido2/model/src/test/java/io/jans/fido2/model/metric/UserMetricsUpdateRequestTest.java— with 5 grouped@Testmethods, one per spec'd behavior:testDefaultConstructorLeavesFieldsUnsettestThreeArgConstructorWiresUserIdAndUsernameAndSuccesstestGetterSetterRoundTripCoversEachValueTypeisSuccess()boolean-getter naming locked reflectivelytestIsSuccessUsesBooleanGetterNamingConventionSerializablecontract +serialVersionUID = 1Llocked reflectivelytestSerializableContractIsIntactDesign choices worth flagging:
authenticatorTypeforString,successforboolean,durationMsforLong). Catches the same wiring class of bugs as testing all 12 individually without ~24 near-identical methods.("u-123", "alice", true)and asserts each field landed in the right slot, then asserts the remaining 9 fields stayednull. This is the load-bearing test against the most likely refactor regression in this DTO.isSuccess(). The test reflectively confirmsisSuccess()exists and returns primitiveboolean, and thatgetSuccess()does NOT exist. A direct call wouldn't catch the rename; the negative reflective check is what locks the convention.Serializableinvariant. The test asserts the class still implementsSerializableand thatserialVersionUIDisprivate static final long = 1L. Bumping the UID silently breaks deserialization of in-flight queued payloads — exactly the kind of regression that surfaces only at runtime, in production, far from the change. A full Java native serialization round-trip was considered and rejected as out of scope; the reflective invariant covers the actual production failure mode.Scope:
src/test.src/main.pom.xmlchanges (the JUnit 5 test-scope dependencies were already declared from step 3).Local verification:
mvn -pl model -am testfromjans-fido2/— 5 tests, 0 failures, 0 errors, runtime ~0.075s.Test and Document the changes
Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with
docs:to indicate documentation changes or if the below checklist is not selected.