-
Notifications
You must be signed in to change notification settings - Fork 657
[Junie]: fix(codegen): set group delimiter for deeply nested components #1089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jetbrains-junie
wants to merge
3
commits into
master
Choose a base branch
from
jetbrains-junie-issue-1084-run-ae9e97a7-b405-4793-b047-822c86d91d39
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+114
β0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a3e362d
fix(codegen): set group delimiter for deeply nested components
jetbrains-junie[bot] 1564c66
[issue-1089] test(codegen): add unit test for nested group delimiter fix
junie-eap[bot] fc97673
[issue-1089] test(codegen): fix exception handling in NestedGroupDeliβ¦
junie-eap[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ixj-codegenerator/src/test/java/org/quickfixj/codegenerator/NestedGroupDelimiterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.quickfixj.codegenerator; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Verifies that the code generator sets the correct group delimiter when the | ||
| * first element of a repeating group is a component that nests other components | ||
| * before the first concrete field appears. | ||
| * | ||
| * This covers the regression fixed in PR #1089 where the XSL must recurse into | ||
| * deeply nested components to locate the actual first field (delimiter). | ||
| */ | ||
| public class NestedGroupDelimiterTest { | ||
|
|
||
| private final File outputDirectory = new File("./target/test-output/"); | ||
| private final File dictFile = new File("./src/test/resources/NESTED_FIX.xml"); | ||
| private final File schemaDirectory = new File("./src/main/resources/org/quickfixj/codegenerator"); | ||
|
|
||
| @Before | ||
| public void setup() throws IOException { | ||
| if (outputDirectory.exists()) { | ||
| FileUtils.cleanDirectory(outputDirectory); | ||
| } else { | ||
| outputDirectory.mkdirs(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void generatesGroupWithDeeplyNestedDelimiter() throws Exception { | ||
| MessageCodeGenerator generator = new MessageCodeGenerator(); | ||
| MessageCodeGenerator.Task task = new MessageCodeGenerator.Task(); | ||
|
|
||
| task.setSpecification(dictFile); | ||
| task.setName(dictFile.getName()); | ||
| task.setTransformDirectory(schemaDirectory); | ||
| task.setMessagePackage("quickfix.fixZZ"); | ||
| task.setOutputBaseDirectory(outputDirectory); | ||
| task.setFieldPackage("quickfix.field"); | ||
| task.setUtcTimestampPrecision(null); | ||
| task.setOverwrite(true); | ||
| task.setOrderedFields(true); | ||
| task.setDecimalGenerated(true); | ||
|
|
||
| try { | ||
| generator.generate(task); | ||
| } catch (CodeGenerationException e) { | ||
| // Surface with context for easier debugging in CI | ||
| throw new AssertionError("Code generation failed: " + e.getMessage(), e); | ||
| } | ||
|
|
||
| // Read the generated message class and assert the group constructor uses FieldA (1001) as delimiter | ||
| File generated = new File(outputDirectory, "quickfix/fixZZ/NestedGroupTest.java"); | ||
| assertTrue("Expected generated message class not found: " + generated.getAbsolutePath(), generated.exists()); | ||
|
|
||
| String java = FileUtils.readFileToString(generated, StandardCharsets.UTF_8); | ||
|
|
||
| // The group name is NoOuterGrp with counter tag 1000. The delimiter should be FieldA (1001), | ||
| // which is the first field reachable by recursing into components (InnerComponent -> DeepComponent -> FieldA) | ||
| // The generated constructor should therefore look like: super(1000, 1001, ORDER) | ||
| assertTrue( | ||
| "Group constructor should use 1001 as delimiter for NoOuterGrp (deeply nested first field)", | ||
| java.contains("public static class NoOuterGrp") && | ||
| java.contains("super(1000, 1001, ORDER)") | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <fix major="4" type="FIX" minor="4"> | ||
| <header> | ||
| </header> | ||
| <messages> | ||
| <message name="NestedGroupTest" msgtype="ZZ" msgcat="app"> | ||
| <group name="NoOuterGrp" required="N"> | ||
| <component name="InnerComponent" required="N"/> | ||
| </group> | ||
| </message> | ||
| </messages> | ||
| <components> | ||
| <component name="InnerComponent"> | ||
| <component name="DeepComponent"/> | ||
| </component> | ||
| <component name="DeepComponent"> | ||
| <!-- The first concrete field deep inside the component tree --> | ||
| <field name="FieldA" required="N"/> | ||
| <field name="FieldB" required="N"/> | ||
| </component> | ||
| </components> | ||
| <fields> | ||
| <!-- Group counter field --> | ||
| <field number="1000" name="NoOuterGrp" type="NUMINGROUP"/> | ||
| <!-- Deepest first field that should become the group delimiter --> | ||
| <field number="1001" name="FieldA" type="STRING"/> | ||
| <field number="1002" name="FieldB" type="STRING"/> | ||
| </fields> | ||
| <trailer> | ||
| </trailer> | ||
| </fix> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment mentions "no group ancestor needed" but this template will match ANY component in group-delimeter mode, not just those without a group ancestor. The
group//componenttemplate at line 200 is more specific and will take precedence for components that are descendants of groups, so this template will handle components at position 1 that are either:Consider clarifying the comment to: "Recursively process components when they are not direct descendants of a group element in the XML (e.g., when referenced through component definitions)"