Skip to content

SD-3207: Split scenarios between parties for TNT - #537

Merged
pedrocarvalhodcsa merged 5 commits into
devfrom
SD-3207_adjust-TNT-scenarios
Aug 10, 2026
Merged

SD-3207: Split scenarios between parties for TNT#537
pedrocarvalhodcsa merged 5 commits into
devfrom
SD-3207_adjust-TNT-scenarios

Conversation

@pedrocarvalhodcsa

Copy link
Copy Markdown
Collaborator

No description provided.

@pedrocarvalhodcsa pedrocarvalhodcsa self-assigned this Aug 6, 2026
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

SD-3207: Split TNT scenarios by party role (producer/consumer)

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Restructures TNT v3.0.0 scenario builder to assign scenarios per party role instead of a single
 shared list.
• Producer gets POST scenarios plus GET query-parameter and pagination scenarios; consumer gets
 POST/GET-by-type scenarios only.
• Only scenarios for the currently tested party roles (derived from getReportRoleNames) are
 included in the generated conformance report.
• Introduces MapUtils.orderedMap helper to build ordered maps of scenario entries.
 ["enhancement", "refactor"]
Diagram

graph TD
  CF["TntComponentFactory"] --> RN["getReportRoleNames()"] --> SB["TntScenarioListBuilder"]
  SB --> PM["Party Scenario Map"]
  PM --> PR["Producer Scenarios"]
  PM --> CO["Consumer Scenarios"]
  SB --> MU["MapUtils.orderedMap"]
  RN --> SEL["Filtered Scenarios"]
  PR --> SEL
  CO --> SEL
Loading
High-Level Assessment

Partitioning scenarios by role via a nested map and filtering by tested role names is a straightforward, low-risk approach consistent with existing patterns (getReportRoleNames is already used elsewhere in AbstractComponentFactory). No meaningfully better alternative was identified for this scope of change.

Files changed (2) +56 / -52

Enhancement (2) +56 / -52
TntComponentFactory.javaPass tested party role names into scenario list builder +1/-0

Pass tested party role names into scenario list builder

• createModuleScenarioListBuilders now calls getReportRoleNames to compute the set of tested party roles and forwards it into TntScenarioListBuilder.createModuleScenarioListBuilders so scenarios can be filtered per role.

tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntComponentFactory.java

TntScenarioListBuilder.javaSplit scenario list into producer and consumer specific maps +55/-52

Split scenario list into producer and consumer specific maps

• Reworks createModuleScenarioListBuilders to build a nested map of scenarios keyed by party role (producer/consumer) using the new MapUtils.orderedMap helper, then filters the returned scenarios to only the roles present in testedPartyRoleNames. Producer scenarios include POST, GET-by-type, query-parameter filter, and pagination scenarios; consumer scenarios include only POST and GET-by-type scenarios.

tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntScenarioListBuilder.java

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Unknown role causes NPE 🐞 Bug ☼ Reliability
Description
TntScenarioListBuilder.createModuleScenarioListBuilders() calls
scenarios.putAll(partyScenariosMap.get(role)) without handling unknown role names; if a role in
testedPartyRoleNames is not present in partyScenariosMap, this throws a NullPointerException during
scenario generation.
Code

tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntScenarioListBuilder.java[R84-86]

+    Map<String, TntScenarioListBuilder> scenarios = new LinkedHashMap<>();
+    testedPartyRoleNames.forEach(role -> scenarios.putAll(partyScenariosMap.get(role)));
+
Evidence
The scenario builder merges per-role maps using partyScenariosMap.get(role) without a null check,
and the role set is derived from configuration role strings in getReportRoleNames, so an
unsupported role string can reach this lookup and trigger an NPE.

tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntScenarioListBuilder.java[60-87]
tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntComponentFactory.java[103-116]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`TntScenarioListBuilder.createModuleScenarioListBuilders` merges role-specific scenario maps via `scenarios.putAll(partyScenariosMap.get(role))` without guarding for missing keys. If `testedPartyRoleNames` contains any role name other than the two keys present in `partyScenariosMap` (Producer/Consumer), `partyScenariosMap.get(role)` returns `null` and `putAll(null)` throws a `NullPointerException`.

## Issue Context
`testedPartyRoleNames` is passed from `TntComponentFactory.getReportRoleNames(...)`, which derives role names from configuration and does not constrain them to the set of known TNT roles in the non-all-in-one case.

## Fix Focus Areas
- tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntScenarioListBuilder.java[84-86]
- tnt/src/main/java/org/dcsa/conformance/standards/tnt/v300/TntComponentFactory.java[103-116]

## Suggested fix
- Add a null-safe merge:
 - `var roleScenarios = partyScenariosMap.get(role); if (roleScenarios != null) scenarios.putAll(roleScenarios); else throw new IllegalArgumentException("Unsupported role: " + role);`
 - (Or, if silently ignoring is desired: `scenarios.putAll(partyScenariosMap.getOrDefault(role, Map.of()));`)
- Optionally, also filter/validate `testedPartyRoleNames` against `TntRole.values()` in `getReportRoleNames(...)` (or at least ensure the returned set only contains supported role config names).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

@pedrocarvalhodcsa
pedrocarvalhodcsa merged commit 9306b64 into dev Aug 10, 2026
1 check passed
@pedrocarvalhodcsa
pedrocarvalhodcsa deleted the SD-3207_adjust-TNT-scenarios branch August 10, 2026 10:00
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