You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/01/05 07:32:47 UTC

Re: [PR] [incubator-kie-issues#2182] Make xmlReportRemainsSameAfterReadWrite deterministic [incubator-kie-optaplanner]

Copilot commented on code in PR #3188:
URL: https://github.com/apache/incubator-kie-optaplanner/pull/3188#discussion_r2660541781


##########
optaplanner-benchmark/src/test/java/org/optaplanner/benchmark/impl/result/PlannerBenchmarkResultTest.java:
##########
@@ -152,7 +152,11 @@ void xmlReportRemainsSameAfterReadWrite() throws IOException {
         String originalXml = IOUtils.toString(
                 PlannerBenchmarkResultTest.class.getResourceAsStream(TEST_PLANNER_BENCHMARK_RESULT), StandardCharsets.UTF_8);
 
-        assertThat(jaxbString.trim()).isXmlEqualTo(originalXml.trim());
+        org.xmlunit.assertj3.XmlAssert.assertThat(jaxbString)
+                .and(originalXml)
+                .ignoreWhitespace()
+                .ignoreChildNodesOrder()
+                .areSimilar();

Review Comment:
   The XMLUnit assertion here uses `areSimilar()` which allows for some differences in the XML structure. However, for a round-trip test that verifies XML remains the same after read/write, consider using `areIdentical()` instead. The `areSimilar()` method is more lenient and may not catch certain XML serialization issues. If the intention is to be lenient about child node order and whitespace but strict about everything else, `areIdentical()` combined with the ignore options would be more appropriate.
   ```suggestion
                   .areIdentical();
   ```



##########
optaplanner-benchmark/src/test/java/org/optaplanner/benchmark/impl/result/PlannerBenchmarkResultTest.java:
##########
@@ -152,7 +152,11 @@ void xmlReportRemainsSameAfterReadWrite() throws IOException {
         String originalXml = IOUtils.toString(
                 PlannerBenchmarkResultTest.class.getResourceAsStream(TEST_PLANNER_BENCHMARK_RESULT), StandardCharsets.UTF_8);
 
-        assertThat(jaxbString.trim()).isXmlEqualTo(originalXml.trim());
+        org.xmlunit.assertj3.XmlAssert.assertThat(jaxbString)
+                .and(originalXml)
+                .ignoreWhitespace()
+                .ignoreChildNodesOrder()
+                .areSimilar();

Review Comment:
   The same flaky test issue likely affects other similar XML round-trip tests in the codebase. The test `xmlConfigFileRemainsSameAfterReadWrite` in `PlannerBenchmarkConfigTest.java` also uses `isXmlEqualTo()` and may suffer from the same non-deterministic behavior with child node ordering. Consider applying the same XMLUnit fix to that test for consistency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org