apupier commented on code in PR #23305:
URL: https://github.com/apache/camel/pull/23305#discussion_r3261434924


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IOHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DefaultDumpRoutesStrategyXmlTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.setDumpRoutes("xml");
+
+        DefaultDumpRoutesStrategy drd = new DefaultDumpRoutesStrategy();
+        drd.setInclude("routes,routeTemplates");
+        drd.setLog(false);
+        drd.setOutput(testDirectory().toString());
+        drd.setResolvePlaceholders(false);
+        context.addService(drd);
+
+        return context;
+    }
+
+    @Test
+    public void testDumpXmlHasCorrectStructure() throws Exception {
+        File dir = testDirectory().toFile();
+        File[] files = dir.listFiles();
+        assertNotNull(files, "Expected dump files in " + dir);
+
+        StringBuilder all = new StringBuilder();
+        for (File f : files) {
+            if (f.getName().endsWith(".xml")) {
+                all.append(IOHelper.loadText(new FileInputStream(f)));
+            }
+        }
+        String xml = all.toString();
+
+        // the dump wraps output in <camel> and strips the outer container 
elements
+        assertTrue(xml.contains("<camel>"), "Expected <camel> root wrapper");
+        assertTrue(xml.contains("</camel>"), "Expected </camel> root wrapper 
closing tag");
+
+        // outer container tags must be stripped entirely (both opening and 
closing) - CAMEL-23521
+        assertFalse(xml.contains("<routes"), "Outer <routes> wrapper must be 
stripped");
+        assertFalse(xml.contains("<routeTemplates"), "Outer <routeTemplates> 
wrapper must be stripped");
+
+        // individual route elements must be present and properly closed
+        assertTrue(xml.contains("<route "), "Expected individual <route> 
elements");
+        assertTrue(xml.contains("</route>"), "Expected </route> closing tag");
+        assertTrue(xml.contains("<routeTemplate "), "Expected individual 
<routeTemplate> elements");
+        assertTrue(xml.contains("</routeTemplate>"), "Expected 
</routeTemplate> closing tag");

Review Comment:
   using AssertJ/XMLUnit,  it would help to have better readability when the 
test is failing. For instance to show what is current content of `xml`



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to