This is an automated email from the ASF dual-hosted git repository. fmariani pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push: new ef979632725 [CAMEL-20577] Test for avoid rest dupes ef979632725 is described below commit ef979632725bbd83e9045c32d4abb6d5941fc000 Author: Croway <federico.mariani.1...@gmail.com> AuthorDate: Tue Mar 19 15:32:44 2024 +0100 [CAMEL-20577] Test for avoid rest dupes --- core/camel-spring-boot-xml/pom.xml | 5 ++ .../camel/spring/boot/xml/MixedRestDslTest.java | 74 ++++++++++++++++++++++ .../src/test/resources/camel-xml-io-dsl.xml | 27 ++++++++ .../src/test/resources/spring-camel-context.xml | 46 ++++++++++++++ 4 files changed, 152 insertions(+) diff --git a/core/camel-spring-boot-xml/pom.xml b/core/camel-spring-boot-xml/pom.xml index 6fa2756f4b9..fe1833f2577 100644 --- a/core/camel-spring-boot-xml/pom.xml +++ b/core/camel-spring-boot-xml/pom.xml @@ -92,6 +92,11 @@ <version>${spring-boot-version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel.springboot</groupId> + <artifactId>camel-jetty-starter</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> <build> diff --git a/core/camel-spring-boot-xml/src/test/java/org/apache/camel/spring/boot/xml/MixedRestDslTest.java b/core/camel-spring-boot-xml/src/test/java/org/apache/camel/spring/boot/xml/MixedRestDslTest.java new file mode 100644 index 00000000000..c683303835b --- /dev/null +++ b/core/camel-spring-boot-xml/src/test/java/org/apache/camel/spring/boot/xml/MixedRestDslTest.java @@ -0,0 +1,74 @@ +/* + * 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.spring.boot.xml; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.rest.RestEndpoint; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.test.annotation.DirtiesContext; + +@DirtiesContext +@CamelSpringBootTest +@SpringBootTest( + properties = { + "camel.springboot.routes-include-pattern=classpath:camel-xml-io-dsl.xml", + "spring.main.allow-circular-references=true" + }) +public class MixedRestDslTest { + + @Autowired + CamelContext camelContext; + + @Test + public void testMultipleRestDslDefinition() { + Assertions.assertThat(camelContext.getRoutes()) + .filteredOn( + route -> route.getEndpoint() instanceof RestEndpoint + ) + .map(route -> ((RestEndpoint) route.getEndpoint()).getPath()) + .containsExactlyInAnyOrder( + "java", + "xml-io", + "spring"); + } + + @Configuration + @EnableAutoConfiguration + @ImportResource(value = { "classpath:spring-camel-context.xml" }) + public static class TestConfiguration { + + @Bean + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + rest("java").get().to("direct:test"); + } + }; + } + } +} diff --git a/core/camel-spring-boot-xml/src/test/resources/camel-xml-io-dsl.xml b/core/camel-spring-boot-xml/src/test/resources/camel-xml-io-dsl.xml new file mode 100644 index 00000000000..c96156752ae --- /dev/null +++ b/core/camel-spring-boot-xml/src/test/resources/camel-xml-io-dsl.xml @@ -0,0 +1,27 @@ +<?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. + +--> + +<rests xmlns="http://camel.apache.org/schema/spring"> + <rest path="xml-io"> + <get consumes="application/json" produces="application/json"> + <to uri="direct:createUser"/> + </get> + </rest> +</rests> \ No newline at end of file diff --git a/core/camel-spring-boot-xml/src/test/resources/spring-camel-context.xml b/core/camel-spring-boot-xml/src/test/resources/spring-camel-context.xml new file mode 100644 index 00000000000..91105c6e92f --- /dev/null +++ b/core/camel-spring-boot-xml/src/test/resources/spring-camel-context.xml @@ -0,0 +1,46 @@ +<?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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <camelContext xmlns="http://camel.apache.org/schema/spring" + id="camel" useMDCLogging="true"> + + <restConfiguration component="jetty" bindingMode="json" enableCORS="true"> + <apiProperty key="api.description" value="Desc"/> + </restConfiguration> + <rest path="spring"> + <get consumes="application/json" produces="application/json"> + <to uri="direct:sample"/> + </get> + </rest> + <route> + <from uri="direct:sample" /> + <to uri="direct:test"/> + </route> + <route> + <from uri="direct:test" /> + <log message="logged"/> + </route> + </camelContext> + +</beans> \ No newline at end of file