Skip to content

Commit 2a8a7b4

Browse files
Add camel. extension prefix for route resources supported for hot reload
Fixes #7971
1 parent 673a344 commit 2a8a7b4

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/util/CamelSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@ public static Set<String> getRouteResourceFileExtensions(Capabilities capabiliti
162162
Set<String> extensions = new HashSet<>();
163163
if (capabilities.isPresent(CamelCapabilities.XML_JAXB) || capabilities.isPresent(CamelCapabilities.XML_IO_DSL)) {
164164
extensions.add("xml");
165+
extensions.add("camel.xml");
165166
}
166167

167168
if (capabilities.isPresent(CamelCapabilities.YAML_DSL)) {
168169
extensions.add("yaml");
169-
extensions.add("yml");
170+
extensions.add("camel.yaml");
170171
}
171172

172173
if (capabilities.isPresent(CamelCapabilities.JAVA_JOOR_DSL)) {

integration-tests-jvm/main-devmode/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
<groupId>org.apache.camel.quarkus</groupId>
3636
<artifactId>camel-quarkus-xml-io-dsl</artifactId>
3737
</dependency>
38+
<dependency>
39+
<groupId>org.apache.camel.quarkus</groupId>
40+
<artifactId>camel-quarkus-yaml-dsl</artifactId>
41+
</dependency>
3842
<dependency>
3943
<groupId>org.apache.camel.quarkus</groupId>
4044
<artifactId>camel-quarkus-direct</artifactId>
@@ -171,6 +175,19 @@
171175
</exclusion>
172176
</exclusions>
173177
</dependency>
178+
<dependency>
179+
<groupId>org.apache.camel.quarkus</groupId>
180+
<artifactId>camel-quarkus-yaml-dsl-deployment</artifactId>
181+
<version>${project.version}</version>
182+
<type>pom</type>
183+
<scope>test</scope>
184+
<exclusions>
185+
<exclusion>
186+
<groupId>*</groupId>
187+
<artifactId>*</artifactId>
188+
</exclusion>
189+
</exclusions>
190+
</dependency>
174191
</dependencies>
175192
</profile>
176193
</profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.main;
18+
19+
import java.io.IOException;
20+
import java.io.StringWriter;
21+
import java.io.Writer;
22+
import java.util.Map;
23+
import java.util.Properties;
24+
import java.util.concurrent.TimeUnit;
25+
26+
import io.quarkus.test.QuarkusDevModeTest;
27+
import io.restassured.RestAssured;
28+
import io.restassured.response.Response;
29+
import org.jboss.shrinkwrap.api.ShrinkWrap;
30+
import org.jboss.shrinkwrap.api.asset.Asset;
31+
import org.jboss.shrinkwrap.api.asset.StringAsset;
32+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.RegisterExtension;
35+
36+
import static org.assertj.core.api.Assertions.assertThat;
37+
import static org.awaitility.Awaitility.await;
38+
39+
class CamelMainRoutesIncludePatternWithSupportedFileExtensionsDevModeTest {
40+
static final String ROUTE_ID_BASE = "route";
41+
static final String XML_ROUTE_ID = "xml-" + ROUTE_ID_BASE;
42+
static final String CAMEL_XML_ROUTE_ID = "camel-" + XML_ROUTE_ID;
43+
static final String YAML_ROUTE_ID = "yaml-" + ROUTE_ID_BASE;
44+
static final String CAMEL_YAML_ROUTE_ID = "camel-" + YAML_ROUTE_ID;
45+
46+
@RegisterExtension
47+
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
48+
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
49+
.addClass(CamelSupportResource.class)
50+
.addAsResource(routeXml(XML_ROUTE_ID), "camel/routes.xml")
51+
.addAsResource(routeXml(CAMEL_XML_ROUTE_ID), "camel/routes.camel.xml")
52+
.addAsResource(routeYaml(YAML_ROUTE_ID), "camel/routes.yaml")
53+
.addAsResource(routeYaml(CAMEL_YAML_ROUTE_ID), "camel/routes.camel.yaml")
54+
.addAsResource(applicationProperties(), "application.properties"));
55+
56+
public static Asset routeXml(String routeId) {
57+
String xml = """
58+
<?xml version="1.0" encoding="UTF-8"?>
59+
<routes>
60+
<route id="%s">
61+
<from uri="direct:%s"/>
62+
<setBody><constant>Hello World</constant></setBody>
63+
</route>
64+
</routes>""".formatted(routeId, routeId);
65+
return new StringAsset(xml);
66+
}
67+
68+
public static Asset routeYaml(String routeId) {
69+
String yaml = """
70+
- route:
71+
id: "%s"
72+
from:
73+
uri: "direct:%s"
74+
steps:
75+
- setBody:
76+
constant: "Hello World"
77+
""".formatted(routeId, routeId);
78+
return new StringAsset(yaml);
79+
}
80+
81+
public static Asset applicationProperties() {
82+
Writer writer = new StringWriter();
83+
84+
Properties props = new Properties();
85+
props.setProperty("quarkus.banner.enabled", "false");
86+
87+
try {
88+
props.store(writer, "");
89+
} catch (IOException e) {
90+
throw new RuntimeException(e);
91+
}
92+
93+
return new StringAsset(writer.toString());
94+
}
95+
96+
@Test
97+
void routesDiscoveryWithSupportedFileExtensions() {
98+
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
99+
Response res = RestAssured.when().get("/test/describe").thenReturn();
100+
101+
assertThat(res.statusCode()).isEqualTo(200);
102+
assertThat(res.body().jsonPath().getList("routes", String.class)).containsOnly(XML_ROUTE_ID, CAMEL_XML_ROUTE_ID,
103+
YAML_ROUTE_ID, CAMEL_YAML_ROUTE_ID);
104+
});
105+
106+
Map<String, String> fileToRouteIdMappings = Map.of("camel/routes.xml", XML_ROUTE_ID,
107+
"camel/routes.camel.xml", CAMEL_XML_ROUTE_ID,
108+
"camel/routes.yaml", YAML_ROUTE_ID,
109+
"camel/routes.camel.yaml", CAMEL_YAML_ROUTE_ID);
110+
111+
fileToRouteIdMappings.forEach((path, routeId) -> {
112+
TEST.modifyResourceFile(path, route -> route.replaceAll(routeId, routeId + "-updated"));
113+
114+
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
115+
Response res = RestAssured.when().get("/test/describe").thenReturn();
116+
117+
assertThat(res.statusCode()).isEqualTo(200);
118+
assertThat(res.body().jsonPath().getList("routes", String.class)).contains(routeId + "-updated");
119+
});
120+
});
121+
}
122+
}

0 commit comments

Comments
 (0)