You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2023/02/03 12:03:21 UTC

[GitHub] [camel] gnodet opened a new pull request, #9295: Generated xml writer

gnodet opened a new pull request, #9295:
URL: https://github.com/apache/camel/pull/9295

   - Remove deprecated XmlRoutesDefinitionLoader
   - Ensure the resource is read (and closed) once
   - Add missing namespace (or no-namespace) calls
   - Generate a lightweight xml writer
   
   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--  
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I formatted the code using `mvn -Pformat,fastinstall install && mvn -Psourcecheck`
   
   <!-- 
   You can run the aforementioned command in your module so that the build auto-formats your code and the source check verifies that is complies with our coding style. This will also be verified as part of the checks and your PR may be rejected if the checkstyle does not pass.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
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@camel.apache.org

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


[GitHub] [camel] oscerd commented on a diff in pull request #9295: Generated xml writer

Posted by "oscerd (via GitHub)" <gi...@apache.org>.
oscerd commented on code in PR #9295:
URL: https://github.com/apache/camel/pull/9295#discussion_r1095728579


##########
components/camel-openapi-java/src/main/java/org/apache/camel/openapi/jmx/JmxRestDefinitionsResolver.java:
##########
@@ -16,11 +16,8 @@
  */
 package org.apache.camel.openapi.jmx;
 
-import java.io.InputStream;
 import java.lang.management.ManagementFactory;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;

Review Comment:
   This will fail with sourcecheck profile.



-- 
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@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9295: Generated xml writer

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9295:
URL: https://github.com/apache/camel/pull/9295#issuecomment-1420514581

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 0 | 2 |


-- 
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@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9295: Generated xml writer

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9295:
URL: https://github.com/apache/camel/pull/9295#issuecomment-1420550417

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 0 | 2 |


-- 
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@camel.apache.org

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


[GitHub] [camel] orpiske commented on a diff in pull request #9295: Generated xml writer

Posted by "orpiske (via GitHub)" <gi...@apache.org>.
orpiske commented on code in PR #9295:
URL: https://github.com/apache/camel/pull/9295#discussion_r1095936475


##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/out/ModelWriterTest.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.out;
+
+import java.io.*;

Review Comment:
   This may fail the checkstyle check



##########
core/camel-xml-io/src/main/java/org/apache/camel/xml/io/PrettyPrintXMLWriter.java:
##########
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.io;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implementation of XMLWriter which emits nicely formatted documents.
+ */
+public class PrettyPrintXMLWriter {
+    /**
+     * Line separator ("\n" on UNIX)
+     */
+    protected static final String LS = System.getProperty("line.separator");

Review Comment:
   Minor thing, but `System.lineSeparator()` is a bit clearer



##########
core/camel-xml-io/src/main/java/org/apache/camel/xml/io/PrettyPrintXMLWriter.java:
##########
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.io;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implementation of XMLWriter which emits nicely formatted documents.
+ */
+public class PrettyPrintXMLWriter {
+    /**
+     * Line separator ("\n" on UNIX)
+     */
+    protected static final String LS = System.getProperty("line.separator");
+
+    private final Writer writer;
+    private final String lineIndenter;
+    private final String lineSeparator;
+    private final String encoding;
+    private final String docType;
+    private final LinkedList<String> elementStack = new LinkedList<>();

Review Comment:
   Maybe it would be better to use a List here, so to give more flexibility.



##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/out/ModelWriterTest.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.out;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Stream;
+
+import jakarta.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.TemplatedRoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.xml.in.ModelParser;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class ModelWriterTest {
+
+    public static final String NAMESPACE = "http://camel.apache.org/schema/spring";
+
+    @ParameterizedTest
+    @MethodSource("routes")
+    void testRoutes(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RoutesDefinition expected = new ModelParser(is, NAMESPACE).parseRoutesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRoutesDefinition(expected);
+            RoutesDefinition actual = new ModelParser(new StringReader(sw.toString()), ns).parseRoutesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("rests")
+    void testRests(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RestsDefinition expected = new ModelParser(is, NAMESPACE).parseRestsDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRestsDefinition(expected);
+            RestsDefinition actual = new ModelParser(new StringReader(sw.toString()), ns).parseRestsDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("routeTemplates")
+    void testRouteTemplates(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RouteTemplatesDefinition expected = new ModelParser(is, NAMESPACE).parseRouteTemplatesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRouteTemplatesDefinition(expected);
+            RouteTemplatesDefinition actual
+                    = new ModelParser(new StringReader(sw.toString()), ns).parseRouteTemplatesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("templatedRoutes")
+    void testTemplatedRoutes(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            TemplatedRoutesDefinition expected = new ModelParser(is, NAMESPACE).parseTemplatedRoutesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeTemplatedRoutesDefinition(expected);
+            TemplatedRoutesDefinition actual
+                    = new ModelParser(new StringReader(sw.toString()), ns).parseTemplatedRoutesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    private static Stream<Arguments> routes() {
+        return definitions("routes");
+    }
+
+    private static Stream<Arguments> rests() {
+        return definitions("rests");
+    }
+
+    private static Stream<Arguments> routeTemplates() {
+        return definitions("routeTemplates");
+    }
+
+    private static Stream<Arguments> templatedRoutes() {
+        return definitions("templatedRoutes");
+    }
+
+    private static Stream<Arguments> definitions(String xml) {
+        try {
+            return Files.list(Paths.get("src/test/resources"))
+                    .filter(p -> {
+                        try {
+                            return Files.isRegularFile(p)
+                                    && p.getFileName().toString().endsWith(".xml")
+                                    && Files.readString(p).contains("<" + xml);
+                        } catch (IOException e) {
+                            throw new IOError(e);
+                        }
+                    })
+                    .map(p -> p.getFileName().toString())
+                    .flatMap(p -> Stream.of(Arguments.of(p, ""), Arguments.of(p, NAMESPACE)));
+        } catch (IOException e) {
+            throw new IOError(e);
+        }
+    }
+
+    private static void assertDeepEquals(Object expected, Object actual, String message) {
+        try {
+            try {
+                deepEquals(expected, actual, "");
+            } catch (AssertionError e) {
+                assertionFailure() //
+                        .cause(e)
+                        .message(message) //
+                        .expected(expected) //
+                        .actual(actual) //
+                        .buildAndThrow();
+            }
+        } catch (IllegalAccessException e) {
+            assertionFailure().cause(e).buildAndThrow();
+        }
+    }
+
+    private static void deepEquals(Object expected, Object actual, String path) throws IllegalAccessException {
+        if (expected == null || actual == null) {
+            assertSame(expected, actual, path);
+        } else if (expected.getClass() != actual.getClass()) {
+            fail("Not equals at " + path);
+        } else if (expected instanceof Collection) {
+            Iterator<?> ie = ((Collection) expected).iterator();
+            Iterator<?> ia = ((Collection) actual).iterator();
+            int i = 0;
+            while (ie.hasNext() && ia.hasNext()) {
+                deepEquals(ie.next(), ia.next(), path + "[" + (i++) + "]");
+            }
+            assertEquals(ie.hasNext(), ia.hasNext(), path);
+        } else if (expected.getClass() == AtomicBoolean.class) {
+            assertEquals(((AtomicBoolean) expected).get(), ((AtomicBoolean) actual).get(), path);
+        } else if (expected.getClass().isEnum()) {
+            assertEquals(((Enum) expected).name(), ((Enum) actual).name(), path);
+        } else if (expected.getClass().getName().startsWith("java.")) {
+            assertEquals(expected, actual, path);
+        } else {
+            for (Class<?> clazz = expected.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
+                for (Field field : clazz.getDeclaredFields()) {
+                    if (isTransient(field)) {
+                        continue;
+                    }
+                    field.setAccessible(true);
+                    Object fe = field.get(expected);
+                    Object fa = field.get(actual);
+                    deepEquals(fe, fa, (path.length() > 0 ? path + "." : path) + field.getName());
+                }
+            }
+        }
+    }
+
+    private static Map<Field, Boolean> TRANSIENT = new ConcurrentHashMap<>();
+
+    private static boolean isTransient(Field field) {
+        return TRANSIENT.computeIfAbsent(field, ModelWriterTest::checkIsTransient);
+    }
+
+    private static boolean checkIsTransient(Field field) {
+        if (Modifier.isStatic(field.getModifiers())) {
+            return true;
+        }
+        if (field.getAnnotation(XmlTransient.class) != null) {
+            return true;
+        }
+        String name = field.getName();
+        try {
+            Method method = field.getDeclaringClass().getDeclaredMethod(
+                    "get" + name.substring(0, 1).toUpperCase() + name.substring(1));
+            if (method.getAnnotation(XmlTransient.class) != null) {
+                return true;
+            }
+        } catch (Throwable t) {
+            // ignore
+        }
+        try {
+            Method method = field.getDeclaringClass().getDeclaredMethod(
+                    "set" + name.substring(0, 1).toUpperCase() + name.substring(1),
+                    field.getType());
+            if (method.getAnnotation(XmlTransient.class) != null) {
+                return true;
+            }
+        } catch (Throwable t) {

Review Comment:
   Same note about catching `Throwable`



##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/out/ModelWriterTest.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.out;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Stream;
+
+import jakarta.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.TemplatedRoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.xml.in.ModelParser;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class ModelWriterTest {
+
+    public static final String NAMESPACE = "http://camel.apache.org/schema/spring";
+
+    @ParameterizedTest
+    @MethodSource("routes")
+    void testRoutes(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RoutesDefinition expected = new ModelParser(is, NAMESPACE).parseRoutesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRoutesDefinition(expected);
+            RoutesDefinition actual = new ModelParser(new StringReader(sw.toString()), ns).parseRoutesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("rests")
+    void testRests(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RestsDefinition expected = new ModelParser(is, NAMESPACE).parseRestsDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRestsDefinition(expected);
+            RestsDefinition actual = new ModelParser(new StringReader(sw.toString()), ns).parseRestsDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("routeTemplates")
+    void testRouteTemplates(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RouteTemplatesDefinition expected = new ModelParser(is, NAMESPACE).parseRouteTemplatesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRouteTemplatesDefinition(expected);
+            RouteTemplatesDefinition actual
+                    = new ModelParser(new StringReader(sw.toString()), ns).parseRouteTemplatesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("templatedRoutes")
+    void testTemplatedRoutes(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            TemplatedRoutesDefinition expected = new ModelParser(is, NAMESPACE).parseTemplatedRoutesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeTemplatedRoutesDefinition(expected);
+            TemplatedRoutesDefinition actual
+                    = new ModelParser(new StringReader(sw.toString()), ns).parseTemplatedRoutesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    private static Stream<Arguments> routes() {
+        return definitions("routes");
+    }
+
+    private static Stream<Arguments> rests() {
+        return definitions("rests");
+    }
+
+    private static Stream<Arguments> routeTemplates() {
+        return definitions("routeTemplates");
+    }
+
+    private static Stream<Arguments> templatedRoutes() {
+        return definitions("templatedRoutes");
+    }
+
+    private static Stream<Arguments> definitions(String xml) {
+        try {
+            return Files.list(Paths.get("src/test/resources"))
+                    .filter(p -> {
+                        try {
+                            return Files.isRegularFile(p)
+                                    && p.getFileName().toString().endsWith(".xml")
+                                    && Files.readString(p).contains("<" + xml);
+                        } catch (IOException e) {
+                            throw new IOError(e);
+                        }
+                    })
+                    .map(p -> p.getFileName().toString())
+                    .flatMap(p -> Stream.of(Arguments.of(p, ""), Arguments.of(p, NAMESPACE)));
+        } catch (IOException e) {
+            throw new IOError(e);
+        }
+    }
+
+    private static void assertDeepEquals(Object expected, Object actual, String message) {
+        try {
+            try {
+                deepEquals(expected, actual, "");
+            } catch (AssertionError e) {
+                assertionFailure() //
+                        .cause(e)
+                        .message(message) //
+                        .expected(expected) //
+                        .actual(actual) //
+                        .buildAndThrow();
+            }
+        } catch (IllegalAccessException e) {
+            assertionFailure().cause(e).buildAndThrow();
+        }
+    }
+
+    private static void deepEquals(Object expected, Object actual, String path) throws IllegalAccessException {
+        if (expected == null || actual == null) {
+            assertSame(expected, actual, path);
+        } else if (expected.getClass() != actual.getClass()) {
+            fail("Not equals at " + path);
+        } else if (expected instanceof Collection) {
+            Iterator<?> ie = ((Collection) expected).iterator();
+            Iterator<?> ia = ((Collection) actual).iterator();
+            int i = 0;
+            while (ie.hasNext() && ia.hasNext()) {
+                deepEquals(ie.next(), ia.next(), path + "[" + (i++) + "]");
+            }
+            assertEquals(ie.hasNext(), ia.hasNext(), path);
+        } else if (expected.getClass() == AtomicBoolean.class) {
+            assertEquals(((AtomicBoolean) expected).get(), ((AtomicBoolean) actual).get(), path);
+        } else if (expected.getClass().isEnum()) {
+            assertEquals(((Enum) expected).name(), ((Enum) actual).name(), path);
+        } else if (expected.getClass().getName().startsWith("java.")) {
+            assertEquals(expected, actual, path);
+        } else {
+            for (Class<?> clazz = expected.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
+                for (Field field : clazz.getDeclaredFields()) {
+                    if (isTransient(field)) {
+                        continue;
+                    }
+                    field.setAccessible(true);
+                    Object fe = field.get(expected);
+                    Object fa = field.get(actual);
+                    deepEquals(fe, fa, (path.length() > 0 ? path + "." : path) + field.getName());
+                }
+            }
+        }
+    }
+
+    private static Map<Field, Boolean> TRANSIENT = new ConcurrentHashMap<>();
+
+    private static boolean isTransient(Field field) {
+        return TRANSIENT.computeIfAbsent(field, ModelWriterTest::checkIsTransient);
+    }
+
+    private static boolean checkIsTransient(Field field) {
+        if (Modifier.isStatic(field.getModifiers())) {
+            return true;
+        }
+        if (field.getAnnotation(XmlTransient.class) != null) {
+            return true;
+        }
+        String name = field.getName();
+        try {
+            Method method = field.getDeclaringClass().getDeclaredMethod(
+                    "get" + name.substring(0, 1).toUpperCase() + name.substring(1));
+            if (method.getAnnotation(XmlTransient.class) != null) {
+                return true;
+            }
+        } catch (Throwable t) {
+            // ignore
+        }

Review Comment:
   We should not catch `Throwable`. This would also catch JVM errors (such as OOME) and could hide some serious problems. In general, catching just Exception should be fine. 



##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/out/ModelWriterTest.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.out;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Stream;
+
+import jakarta.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.TemplatedRoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.xml.in.ModelParser;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class ModelWriterTest {
+
+    public static final String NAMESPACE = "http://camel.apache.org/schema/spring";
+
+    @ParameterizedTest
+    @MethodSource("routes")
+    void testRoutes(String xml, String ns) throws Exception {
+        try (InputStream is = getClass().getClassLoader().getResourceAsStream(xml)) {
+            RoutesDefinition expected = new ModelParser(is, NAMESPACE).parseRoutesDefinition().get();
+            StringWriter sw = new StringWriter();
+            new ModelWriter(sw, ns).writeRoutesDefinition(expected);
+            RoutesDefinition actual = new ModelParser(new StringReader(sw.toString()), ns).parseRoutesDefinition().get();
+            assertDeepEquals(expected, actual, sw.toString());
+        }
+    }
+
+    @ParameterizedTest
+    @MethodSource("rests")

Review Comment:
   Same suggestion about `@Display` here and on the other tests.



##########
core/camel-xml-io/src/test/java/org/apache/camel/xml/out/ModelWriterTest.java:
##########
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.xml.out;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Stream;
+
+import jakarta.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.model.RouteTemplatesDefinition;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.TemplatedRoutesDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.xml.in.ModelParser;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.AssertionFailureBuilder.assertionFailure;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class ModelWriterTest {
+
+    public static final String NAMESPACE = "http://camel.apache.org/schema/spring";
+
+    @ParameterizedTest
+    @MethodSource("routes")

Review Comment:
   Given that this code is doing something complex, I think it would be good to annotate it with `@Display` describing the expectations (i.e.: `@Display("Tests that given an XML file containing X, will generate/process/something Y")`)



-- 
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@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9295: Generated xml writer

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9295:
URL: https://github.com/apache/camel/pull/9295#issuecomment-1422894056

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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@camel.apache.org

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


[GitHub] [camel] gnodet merged pull request #9295: Generated xml writer

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet merged PR #9295:
URL: https://github.com/apache/camel/pull/9295


-- 
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@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9295: Generated xml writer

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9295:
URL: https://github.com/apache/camel/pull/9295#issuecomment-1415777828

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :warning: Please note that the changes on this PR may be **tested automatically**. 
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
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@camel.apache.org

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


[GitHub] [camel] github-actions[bot] commented on pull request #9295: Generated xml writer

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9295:
URL: https://github.com/apache/camel/pull/9295#issuecomment-1420557663

   :no_entry_sign: There are (likely) no components to be tested in this PR


-- 
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@camel.apache.org

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