You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2024/04/14 16:18:29 UTC
(camel) 02/02: (chores) camel-core: externalized large strings from tests
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4428fc01f0ae8fa56ae99855231a977589be40f2
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Apr 11 17:11:46 2024 +0200
(chores) camel-core: externalized large strings from tests
---
.../camel/xml/io/util/XmlStreamDetectorTest.java | 61 +++++++---------------
.../camel/xml/io/util/documentFullOfNamespaces.xml | 25 +++++++++
.../camel/xml/io/util/documentWithModeline.xml | 30 +++++++++++
.../org/apache/camel/xml/io/util/simpleRoute.xml | 38 ++++++++++++++
4 files changed, 111 insertions(+), 43 deletions(-)
diff --git a/core/camel-xml-io-util/src/test/java/org/apache/camel/xml/io/util/XmlStreamDetectorTest.java b/core/camel-xml-io-util/src/test/java/org/apache/camel/xml/io/util/XmlStreamDetectorTest.java
index f7deff662e3..adaa245a165 100644
--- a/core/camel-xml-io-util/src/test/java/org/apache/camel/xml/io/util/XmlStreamDetectorTest.java
+++ b/core/camel-xml-io-util/src/test/java/org/apache/camel/xml/io/util/XmlStreamDetectorTest.java
@@ -18,6 +18,8 @@ package org.apache.camel.xml.io.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
@@ -29,6 +31,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class XmlStreamDetectorTest {
+ private String readAllFromFile(String filename) throws IOException {
+ final URL resource = getClass().getResource(filename);
+ assert resource != null : "Cannot open a null resource: " + filename;
+
+ try (final InputStream inputStream = resource.openStream()) {
+ final byte[] bytes = inputStream.readAllBytes();
+ return new String(bytes);
+ }
+ }
+
@Test
public void nonExistingDocument() throws IOException {
XmlStreamDetector detector = new XmlStreamDetector(getClass().getResourceAsStream("non-existing"));
@@ -54,15 +66,8 @@ public class XmlStreamDetectorTest {
@Test
public void documentFullOfNamespaces() throws IOException {
- String xml = """
- <root xmlns="urn:camel"
- xmlns:c="urn:camel:ns1"
- xmlns:d="urn:camel:ns2"
- xmlnS="typo"
- a1="v1"
- c:a1="v2"
- d:a1="v3" />
- """;
+ String xml = readAllFromFile("documentFullOfNamespaces.xml");
+
XmlStreamDetector detector
= new XmlStreamDetector(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
XmlStreamInfo info = detector.information();
@@ -86,19 +91,8 @@ public class XmlStreamDetectorTest {
@Test
public void documentWithModeline() throws IOException {
- String xml = """
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- This is my Camel application and I'm proud of it
- camel-k: dependency=mvn:com.i-heart-camel:best-routes-ever:1.0.0
- camel-k: env=HELLO=world
- -->
- <!--
- camel-k: name=MyApplication
- -->
- <routes xmlns="http://camel.apache.org/schema/spring">
- </routes>
- """;
+ String xml = readAllFromFile("documentWithModeline.xml");
+
XmlStreamDetector detector
= new XmlStreamDetector(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
XmlStreamInfo info = detector.information();
@@ -119,27 +113,8 @@ public class XmlStreamDetectorTest {
@Test
public void simpleRoute() throws IOException {
- String xml = """
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- camel-k: language=xml -->
-
- <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
- http://camel.apache.org/schema/spring
- https://camel.apache.org/schema/spring/camel-spring.xsd">
-
- <!-- Write your routes here, for example: -->
- <route id="xml1">
- <from uri="timer:xml1?period={{time:1000}}"/>
- <setBody>
- <simple>Hello Camel (1) from ${routeId}</simple>
- </setBody>
- <log message="${body}"/>
- </route>
-
- </routes>
- """;
+ String xml = readAllFromFile("simpleRoute.xml");
+
XmlStreamDetector detector
= new XmlStreamDetector(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
XmlStreamInfo info = detector.information();
diff --git a/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/documentFullOfNamespaces.xml b/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/documentFullOfNamespaces.xml
new file mode 100644
index 00000000000..b9a65165a49
--- /dev/null
+++ b/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/documentFullOfNamespaces.xml
@@ -0,0 +1,25 @@
+<!--
+
+ 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.
+
+-->
+<root xmlns="urn:camel"
+ xmlns:c="urn:camel:ns1"
+ xmlns:d="urn:camel:ns2"
+ xmlnS="typo"
+ a1="v1"
+ c:a1="v2"
+ d:a1="v3" />
\ No newline at end of file
diff --git a/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/documentWithModeline.xml b/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/documentWithModeline.xml
new file mode 100644
index 00000000000..744a178cc44
--- /dev/null
+++ b/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/documentWithModeline.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+
+<!--
+ This is my Camel application and I'm proud of it
+ camel-k: dependency=mvn:com.i-heart-camel:best-routes-ever:1.0.0
+ camel-k: env=HELLO=world
+-->
+<!--
+ camel-k: name=MyApplication
+-->
+<routes xmlns="http://camel.apache.org/schema/spring">
+</routes>
\ No newline at end of file
diff --git a/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/simpleRoute.xml b/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/simpleRoute.xml
new file mode 100644
index 00000000000..af0ca2c9b2f
--- /dev/null
+++ b/core/camel-xml-io-util/src/test/resources/org/apache/camel/xml/io/util/simpleRoute.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+
+<!-- camel-k: language=xml -->
+
+<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://camel.apache.org/schema/spring
+ https://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- Write your routes here, for example: -->
+ <route id="xml1">
+ <from uri="timer:xml1?period={{time:1000}}"/>
+ <setBody>
+ <simple>Hello Camel (1) from ${routeId}</simple>
+ </setBody>
+ <log message="${body}"/>
+ </route>
+
+</routes>
\ No newline at end of file