This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch 2.16.x in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 25a814735a077efc7401b175abe909a6313342d7 Author: Nicolas Filotto <nfilo...@talend.com> AuthorDate: Mon Apr 3 15:44:10 2023 +0200 Ref #4447: java-joor-dsl - Improve the test coverage --- integration-tests/java-joor-dsl/pom.xml | 51 ++++++++++++++++++++++ .../quarkus/dsl/java/joor/JavaJoorDslResource.java | 21 +++++++++ .../src/main/resources/application.properties | 2 +- .../src/main/resources/routes/MyBar.java | 29 ++++++++++++ .../src/main/resources/routes/MyBarEcho.java | 30 +++++++++++++ .../src/main/resources/routes/MyBarRoute.java | 28 ++++++++++++ .../main/resources/routes/MyRoutesWithBeans.java | 38 ++++++++++++++++ .../main/resources/routes/MyRoutesWithModel.java | 36 +++++++++++++++ .../resources/routes/MyRoutesWithNestedClass.java | 40 +++++++++++++++++ .../src/main/resources/routes/MyUser.java | 46 +++++++++++++++++++ .../quarkus/dsl/java/joor/JavaJoorDslTest.java | 21 ++++++++- 11 files changed, 340 insertions(+), 2 deletions(-) diff --git a/integration-tests/java-joor-dsl/pom.xml b/integration-tests/java-joor-dsl/pom.xml index 905f083e95..1ca826a316 100644 --- a/integration-tests/java-joor-dsl/pom.xml +++ b/integration-tests/java-joor-dsl/pom.xml @@ -39,6 +39,18 @@ <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-direct</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jackson</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bean</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-rest</artifactId> + </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> @@ -72,6 +84,19 @@ </activation> <dependencies> <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bean-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-direct-deployment</artifactId> @@ -98,6 +123,32 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jackson-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-rest-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> </profile> <profile> diff --git a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java index 5f08ccbeea..f780863002 100644 --- a/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java +++ b/integration-tests/java-joor-dsl/src/main/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslResource.java @@ -16,6 +16,7 @@ */ package org.apache.camel.quarkus.dsl.java.joor; +import java.util.Set; import java.util.stream.Collectors; import javax.enterprise.context.ApplicationScoped; @@ -27,13 +28,16 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import io.quarkus.runtime.annotations.RegisterForReflection; import org.apache.camel.ExtendedCamelContext; import org.apache.camel.ProducerTemplate; import org.apache.camel.Route; +import org.apache.camel.component.direct.DirectEndpoint; import org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader; import org.apache.camel.quarkus.main.CamelMain; import org.apache.camel.spi.RoutesBuilderLoader; +@RegisterForReflection(targets = String.class) @Path("/java-joor-dsl") @ApplicationScoped public class JavaJoorDslResource { @@ -72,6 +76,23 @@ public class JavaJoorDslResource { .collect(Collectors.joining(",")); } + @GET + @Path("/main/successful/routes") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public int successfulRoutes() { + int successful = 0; + Set<String> excluded = Set.of("my-java-route", "reflection-route", "inner-classes-route", "routes-with-rest"); + for (Route route : main.getCamelContext().getRoutes()) { + String name = route.getRouteId(); + if (route.getEndpoint() instanceof DirectEndpoint && !excluded.contains(name) + && Boolean.TRUE.equals(producerTemplate.requestBody(route.getEndpoint(), "", Boolean.class))) { + successful++; + } + } + return successful; + } + @POST @Path("/hello") @Consumes(MediaType.TEXT_PLAIN) diff --git a/integration-tests/java-joor-dsl/src/main/resources/application.properties b/integration-tests/java-joor-dsl/src/main/resources/application.properties index 0b17e9e265..e03850aeee 100644 --- a/integration-tests/java-joor-dsl/src/main/resources/application.properties +++ b/integration-tests/java-joor-dsl/src/main/resources/application.properties @@ -18,4 +18,4 @@ # # Main # -camel.main.routes-include-pattern = classpath:routes/MyRoutes.java +camel.main.routes-include-pattern = classpath:routes/*.java diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.java new file mode 100644 index 0000000000..2bf03dcf76 --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBar.java @@ -0,0 +1,29 @@ +/* + * 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. + */ + +public class MyBar { + + private String name; + + public MyBar(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarEcho.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarEcho.java new file mode 100644 index 0000000000..f2efc91170 --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarEcho.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +import io.quarkus.runtime.annotations.RegisterForReflection; +import org.apache.camel.BindToRegistry; + +@RegisterForReflection +@BindToRegistry("myBarEcho") +public class MyBarEcho { + + private MyBar bar = new MyBar("Moes Bar"); + + public String echo(String s) { + return s + " is at " + bar.getName(); + } + +} \ No newline at end of file diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java new file mode 100644 index 0000000000..202f18d0fb --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyBarRoute.java @@ -0,0 +1,28 @@ +/* + * 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. + */ +import org.apache.camel.builder.RouteBuilder; + +public class MyBarRoute extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("direct:routes-with-bean") + .id("routes-with-bean") + .bean("myBarEcho") + .setBody().simple("${body.endsWith(' is at Moes Bar')}"); + } +} \ No newline at end of file diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java new file mode 100644 index 0000000000..3896398a32 --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithBeans.java @@ -0,0 +1,38 @@ +/* + * 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. + */ +import io.quarkus.runtime.annotations.RegisterForReflection; +import org.apache.camel.BindToRegistry; +import org.apache.camel.builder.RouteBuilder; + +@RegisterForReflection(ignoreNested = false) +public class MyRoutesWithBeans extends RouteBuilder { + @Override + public void configure() throws Exception { + from("direct:routes-with-inner-bean") + .id("routes-with-inner-bean") + .bean("myBean") + .setBody().simple("${body.endsWith('John!')}"); + } + + @BindToRegistry("myBean") + public static class MyBean { + + public String hi() { + return "Hi John!"; + } + } +} \ No newline at end of file diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java new file mode 100644 index 0000000000..c5997b823b --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithModel.java @@ -0,0 +1,36 @@ +/* + * 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. + */ + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.JsonLibrary; + +public class MyRoutesWithModel extends RouteBuilder { + @Override + public void configure() throws Exception { + rest("/say") + .get("/emp/{id}") + .id("routes-with-rest-get") + .produces("application/json") + .outType(MyUser.class) + .to("direct:routes-with-rest"); + + from("direct:routes-with-rest") + .id("routes-with-rest") + .process(exchange -> exchange.getMessage().setBody(new MyUser("Bruce", 68))) + .marshal().json(JsonLibrary.Jackson); + } +} \ No newline at end of file diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.java new file mode 100644 index 0000000000..aaac2f15e9 --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyRoutesWithNestedClass.java @@ -0,0 +1,40 @@ +/* + * 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. + */ +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; + +public class MyRoutesWithNestedClass extends RouteBuilder { + @Override + public void configure() throws Exception { + Processor toUpper = new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + body = body.toUpperCase(); + + exchange.getMessage().setBody(body); + } + }; + + from("direct:routes-with-nested-class") + .id("routes-with-nested-class") + .setBody().constant("Some Content") + .process(toUpper) + .setBody().simple("${body.endsWith('CONTENT')}"); + } +} \ No newline at end of file diff --git a/integration-tests/java-joor-dsl/src/main/resources/routes/MyUser.java b/integration-tests/java-joor-dsl/src/main/resources/routes/MyUser.java new file mode 100644 index 0000000000..104791b080 --- /dev/null +++ b/integration-tests/java-joor-dsl/src/main/resources/routes/MyUser.java @@ -0,0 +1,46 @@ +/* + * 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. + */ + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class MyUser { + + private String name; + private int age; + + public MyUser(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public void setName(String name) { + this.name = name; + } + + public void setAge(int age) { + this.age = age; + } +} diff --git a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java index 52bfde5bbd..38998a3cb5 100644 --- a/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java +++ b/integration-tests/java-joor-dsl/src/test/java/org/apache/camel/quarkus/dsl/java/joor/JavaJoorDslTest.java @@ -22,6 +22,8 @@ import org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader; import org.hamcrest.CoreMatchers; import org.junit.jupiter.api.Test; +import static org.hamcrest.CoreMatchers.equalTo; + @QuarkusTest class JavaJoorDslTest { @@ -73,6 +75,23 @@ class JavaJoorDslTest { .get("/java-joor-dsl/main/routes") .then() .statusCode(200) - .body(CoreMatchers.is("inner-classes-route,my-java-route,reflection-route")); + .body(CoreMatchers.is( + "inner-classes-route,my-java-route,reflection-route,routes-with-bean,routes-with-inner-bean,routes-with-nested-class,routes-with-rest,routes-with-rest-get")); + + RestAssured.given() + .get("/java-joor-dsl/main/successful/routes") + .then() + .statusCode(200) + .body(CoreMatchers.is("3")); + } + + @Test + void testRestEndpoints() { + RestAssured.given() + .get("/say/emp/123") + .then() + .log().ifValidationFails() + .statusCode(200) + .body("name", equalTo("Bruce"), "age", equalTo(68)); } }