This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new a8bac24 Fix #259 The User guide should refer to the rest-json example (#261) a8bac24 is described below commit a8bac2456bf27b39091fe674655fe87e89444ae2 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Fri Oct 11 21:45:07 2019 +0200 Fix #259 The User guide should refer to the rest-json example (#261) * Do not use ${project.version} in the BOMs * Comment and simplify the rest-json example * Fix #259 The User guide should refer to the rest-json example rather than the servlet itest --- docs/modules/ROOT/pages/user-guide.adoc | 57 ++++++++++------------ examples/rest-json/pom.xml | 20 +------- .../src/main/java/org/acme/rest/json/Fruit.java | 5 +- .../src/main/java/org/acme/rest/json/Legume.java | 6 ++- .../src/main/java/org/acme/rest/json/Routes.java | 22 +++++---- .../java/org/acme/rest/json/LegumeResourceIT.java | 23 --------- .../org/acme/rest/json/LegumeResourceTest.java | 39 --------------- .../json/{FruitResourceIT.java => RestJsonIT.java} | 6 ++- .../{FruitResourceTest.java => RestJsonTest.java} | 26 ++++++++-- extensions/pom.xml | 3 ++ poms/bom-deployment/pom.xml | 10 ++-- poms/bom/pom.xml | 12 ++--- 12 files changed, 91 insertions(+), 138 deletions(-) diff --git a/docs/modules/ROOT/pages/user-guide.adoc b/docs/modules/ROOT/pages/user-guide.adoc index e79c397..4806330 100644 --- a/docs/modules/ROOT/pages/user-guide.adoc +++ b/docs/modules/ROOT/pages/user-guide.adoc @@ -13,14 +13,11 @@ xref:list-of-camel-quarkus-extensions.adoc[complete list]. == Your first application -As long as we do not have self-contained examples, we can only offer some of the Camel Quarkus integration tests as a -replacement. Only a few manual steps are needed to turn e.g. the servlet integration test into a standalone application -that can further serve as a base for your real world project. +We recommend you to choose an example from our https://github.com/apache/camel-quarkus/tree/master/examples[source tree] +as a base for your real world project. === Prerequisites -To transform one of our integration tests to a standalone example, you need: - * A `git` client * An IDE * JDK 1.8+ with JAVA_HOME configured appropriately @@ -29,7 +26,7 @@ To transform one of our integration tests to a standalone example, you need: https://quarkus.io/guides/building-native-image-guide[Building a native executable] section of the Quarkus documentation. -=== Turn the servlet integration test into a standalone application +=== Step by step with the `rest-json` example 1. Clone Camel Quarkus and checkout the latest release tag + @@ -41,13 +38,13 @@ cd camel-quarkus git checkout $(git describe --abbrev=0) ---- -2. Copy the servlet integration test out of the Camel Quarkus source tree. +2. Copy the `rest-json` example out of the Camel Quarkus source tree. + [source,shell] ---- cd .. -cp -r camel-quarkus/integration-tests/servlet/ . -cd servlet +cp -r camel-quarkus/examples/rest-json . +cd rest-json ---- 3. Open the `pom.xml` file in your IDE. @@ -87,24 +84,24 @@ The application has just two compile dependencies: ---- <dependency> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-servlet</artifactId> + <artifactId>camel-quarkus-platform-http</artifactId> </dependency> <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-rest</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jackson</artifactId> </dependency> ---- -They are managed in `camel-quarkus-bom` that we use as the Maven parent. `camel-quarkus-bom` also manages plugins -necessary for a typical Camel Quarkus application. +They are managed in `camel-quarkus-bom` that we use as the Maven parent. `camel-quarkus-bom` and its ancestors also +manage plugins necessary for a typical Camel Quarkus application. In case you cannot use `camel-quarkus-bom` as a +parent of your application, make sure that you add those plugins manually. -There are only two classes in the application: `CamelRoute` defining the Camel routes and -`CustomServlet`. +There are only three classes in the application: `Routes` defining the Camel routes and a couple of entity classes +(`Fruit` and `Legume`). -`src/main/resources/application.properties` configure the application. E.g. the `CustomServlet` is set -there to serve the requests for the path `/my-named-folder/*`. +`src/main/resources/application.properties` configure the application. E.g. the `camel.context.name` is set there. -There are two test classes there: `CamelServletTest` is for the JVM mode while `CamelServletIT` is there for the native +There are two test classes there: `RestJsonTest` is for the JVM mode while `RestJsonIT` is there for the native mode. The JVM mode tests are run by `maven-surefire-plugin` in the `test` Maven phase: @@ -114,17 +111,17 @@ The JVM mode tests are run by `maven-surefire-plugin` in the `test` Maven phase: mvn clean test ---- -This should take about half a minute. +This should take about 15 seconds. The native mode tests are verified by `maven-failsafe-plugin` in the `verify` phase. Pass the `native` property to activate the profile that runs them: [source,shell] ---- -mvn clean verify -Dnative -Dnative-image.docker-build=true -Dnative-image.xmx=5g +mvn clean verify -Dnative -Dnative-image.docker-build=true ---- -This takes about three minutes. +This takes about 2.5 minutes (once you have all dependencies cached). === Run the application @@ -137,7 +134,7 @@ This takes about three minutes. mvn clean package ls -lh target ... --rw-r--r--. 1 ppalaga ppalaga 157K Aug 9 18:55 my-app-0.0.1-SNAPSHOT-runner.jar +-rw-r--r--. 1 ppalaga ppalaga 238K Oct 11 18:55 my-app-0.0.1-SNAPSHOT-runner.jar ... ---- @@ -147,10 +144,10 @@ You can run it as follows: ---- java -jar target/*-runner.jar ... -[io.quarkus] (main) Quarkus 0.20.0 started in 0.805s. Listening on: http://[::]:8080 +[io.quarkus] (main) Quarkus 0.23.2 started in 1.163s. Listening on: http://[::]:8080 ---- -Notice the boot time under a second. +Notice the boot time around a second. The thin `jar` contains just the application code. To run it, the dependencies in `target/lib` are required too. @@ -160,10 +157,10 @@ To prepare a native executable using GraalVM, run the following command: [source,shell] ---- -mvn clean package -Dnative -Dnative-image.docker-build=true -Dnative-image.xmx=5g +mvn clean package -Dnative -Dnative-image.docker-build=true ls -lh target ... --rwxr-xr-x. 1 ppalaga ppalaga 32M Aug 9 18:57 my-app-0.0.1-SNAPSHOT-runner +-rwxr-xr-x. 1 ppalaga ppalaga 46M Oct 11 18:57 my-app-0.0.1-SNAPSHOT-runner ... ---- @@ -174,7 +171,7 @@ it can be run directly: ---- ./target/*-runner ... -[io.quarkus] (main) Quarkus 0.20.0 started in 0.017s. Listening on: http://[::]:8080 +[io.quarkus] (main) Quarkus 0.23.2 started in 0.013s. Listening on: http://[::]:8080 ... ---- @@ -184,7 +181,7 @@ Check how fast it started and check how little memory it consumes: ---- ps -o rss,command -p $(pgrep my-app) RSS COMMAND -21932 ./target/my-app-0.0.1-SNAPSHOT-runner +34916 ./target/my-app-0.0.1-SNAPSHOT-runner ---- -That's under 22 MB of RAM! +That's under 35 MB of RAM! diff --git a/examples/rest-json/pom.xml b/examples/rest-json/pom.xml index 1420885..bd1e4c4 100644 --- a/examples/rest-json/pom.xml +++ b/examples/rest-json/pom.xml @@ -20,8 +20,9 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-examples</artifactId> + <artifactId>camel-quarkus-bom</artifactId> <version>0.2.1-SNAPSHOT</version> + <relativePath>../../poms/bom/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> @@ -41,18 +42,6 @@ <native-image.container-runtime>docker</native-image.container-runtime> </properties> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-bom</artifactId> - <version>${project.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -63,11 +52,6 @@ <artifactId>camel-jackson</artifactId> </dependency> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-resteasy</artifactId> - </dependency> - <!-- test dependencies --> <dependency> <groupId>io.quarkus</groupId> diff --git a/examples/rest-json/src/main/java/org/acme/rest/json/Fruit.java b/examples/rest-json/src/main/java/org/acme/rest/json/Fruit.java index 29349f0..b86a36c 100644 --- a/examples/rest-json/src/main/java/org/acme/rest/json/Fruit.java +++ b/examples/rest-json/src/main/java/org/acme/rest/json/Fruit.java @@ -20,7 +20,10 @@ import java.util.Objects; import io.quarkus.runtime.annotations.RegisterForReflection; -@RegisterForReflection +/** + * A REST entity representing a fruit. + */ +@RegisterForReflection // Lets Quarkus register this class for reflection during the native build public class Fruit { private String name; private String description; diff --git a/examples/rest-json/src/main/java/org/acme/rest/json/Legume.java b/examples/rest-json/src/main/java/org/acme/rest/json/Legume.java index b72a880..e9f4f0e 100644 --- a/examples/rest-json/src/main/java/org/acme/rest/json/Legume.java +++ b/examples/rest-json/src/main/java/org/acme/rest/json/Legume.java @@ -20,7 +20,11 @@ import java.util.Objects; import io.quarkus.runtime.annotations.RegisterForReflection; -@RegisterForReflection + +/** + * A REST entity representing a legume. + */ +@RegisterForReflection // Lets Quarkus register this class for reflection during the native build public class Legume { private String name; private String description; diff --git a/examples/rest-json/src/main/java/org/acme/rest/json/Routes.java b/examples/rest-json/src/main/java/org/acme/rest/json/Routes.java index cc39afe..ace624c 100644 --- a/examples/rest-json/src/main/java/org/acme/rest/json/Routes.java +++ b/examples/rest-json/src/main/java/org/acme/rest/json/Routes.java @@ -17,33 +17,32 @@ package org.acme.rest.json; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Set; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.dataformat.JsonLibrary; +/** + * Camel route definitions. + */ public class Routes extends RouteBuilder { - private final Set<Fruit> fruits; - private final Set<Legume> legumes; + private final Set<Fruit> fruits = Collections.synchronizedSet(new LinkedHashSet<>()); + private final Set<Legume> legumes = Collections.synchronizedSet(new LinkedHashSet<>()); public Routes() { - this.fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>())); + + /* Let's add some initial fruits */ this.fruits.add(new Fruit("Apple", "Winter fruit")); this.fruits.add(new Fruit("Pineapple", "Tropical fruit")); - this.legumes = Collections.synchronizedSet(new LinkedHashSet<>()); + /* Let's add some initial legumes */ this.legumes.add(new Legume("Carrot", "Root vegetable, usually orange")); this.legumes.add(new Legume("Zucchini", "Summer squash")); } @Override public void configure() throws Exception { - from("platform-http:/legumes?httpMethodRestrict=GET") - .setBody().constant(legumes) - .marshal().json(); - from("platform-http:/fruits?httpMethodRestrict=GET,POST") .choice() .when(simple("${header.CamelHttpMethod} == 'GET'")) @@ -60,5 +59,10 @@ public class Routes extends RouteBuilder { .endChoice() .end() .marshal().json(); + + from("platform-http:/legumes?httpMethodRestrict=GET") + .setBody().constant(legumes) + .marshal().json(); + } } diff --git a/examples/rest-json/src/test/java/org/acme/rest/json/LegumeResourceIT.java b/examples/rest-json/src/test/java/org/acme/rest/json/LegumeResourceIT.java deleted file mode 100644 index ce0b3c8..0000000 --- a/examples/rest-json/src/test/java/org/acme/rest/json/LegumeResourceIT.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.acme.rest.json; - -import io.quarkus.test.junit.SubstrateTest; - -@SubstrateTest -public class LegumeResourceIT extends LegumeResourceTest { -} \ No newline at end of file diff --git a/examples/rest-json/src/test/java/org/acme/rest/json/LegumeResourceTest.java b/examples/rest-json/src/test/java/org/acme/rest/json/LegumeResourceTest.java deleted file mode 100644 index c0b5eb0..0000000 --- a/examples/rest-json/src/test/java/org/acme/rest/json/LegumeResourceTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.acme.rest.json; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.Matchers.containsInAnyOrder; - -@QuarkusTest -public class LegumeResourceTest { - - @Test - public void testList() { - given() - .when().get("/legumes") - .then() - .statusCode(200) - .body("$.size()", is(2), - "name", containsInAnyOrder("Carrot", "Zucchini"), - "description", containsInAnyOrder("Root vegetable, usually orange", "Summer squash")); - } -} diff --git a/examples/rest-json/src/test/java/org/acme/rest/json/FruitResourceIT.java b/examples/rest-json/src/test/java/org/acme/rest/json/RestJsonIT.java similarity index 81% rename from examples/rest-json/src/test/java/org/acme/rest/json/FruitResourceIT.java rename to examples/rest-json/src/test/java/org/acme/rest/json/RestJsonIT.java index d36cb4b..c32a4fb 100644 --- a/examples/rest-json/src/test/java/org/acme/rest/json/FruitResourceIT.java +++ b/examples/rest-json/src/test/java/org/acme/rest/json/RestJsonIT.java @@ -18,6 +18,10 @@ package org.acme.rest.json; import io.quarkus.test.junit.SubstrateTest; +/** + * Native mode tests. In the native mode, the same tests will be executed as in the JVM mode because this class extends + * {@link RestJsonTest}. + */ @SubstrateTest -public class FruitResourceIT extends FruitResourceTest { +public class RestJsonIT extends RestJsonTest { } \ No newline at end of file diff --git a/examples/rest-json/src/test/java/org/acme/rest/json/FruitResourceTest.java b/examples/rest-json/src/test/java/org/acme/rest/json/RestJsonTest.java similarity index 76% rename from examples/rest-json/src/test/java/org/acme/rest/json/FruitResourceTest.java rename to examples/rest-json/src/test/java/org/acme/rest/json/RestJsonTest.java index fdd17fb..24f1e76 100644 --- a/examples/rest-json/src/test/java/org/acme/rest/json/FruitResourceTest.java +++ b/examples/rest-json/src/test/java/org/acme/rest/json/RestJsonTest.java @@ -16,8 +16,6 @@ */ package org.acme.rest.json; -import javax.ws.rs.core.MediaType; - import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; @@ -25,11 +23,16 @@ import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.containsInAnyOrder; +/** + * JVM mode tests. + */ @QuarkusTest -public class FruitResourceTest { +public class RestJsonTest { @Test - public void test() { + public void fruits() { + + /* Assert the initial fruits are there */ given() .when().get("/fruits") .then() @@ -40,9 +43,10 @@ public class FruitResourceTest { "description", containsInAnyOrder("Winter fruit", "Tropical fruit") ); + /* Add a new fruit */ given() .body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}") - .header("Content-Type", MediaType.APPLICATION_JSON) + .header("Content-Type", "application/json") .when() .post("/fruits") .then() @@ -53,4 +57,16 @@ public class FruitResourceTest { "description", containsInAnyOrder("Winter fruit", "Tropical fruit", "Winter fruit") ); } + + @Test + public void legumes() { + given() + .when().get("/legumes") + .then() + .statusCode(200) + .body("$.size()", is(2), + "name", containsInAnyOrder("Carrot", "Zucchini"), + "description", containsInAnyOrder("Root vegetable, usually orange", "Summer squash")); + } + } diff --git a/extensions/pom.xml b/extensions/pom.xml index 3ba3193..4c3906d 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -83,6 +83,9 @@ <templatesUriBase>file:///${project.basedir}/../build/create-extension-templates</templatesUriBase> <runtimeBomPath>../poms/bom/pom.xml</runtimeBomPath> <deploymentBomPath>../poms/bom-deployment/pom.xml</deploymentBomPath> + <!-- The bomEntryVersion should come with the upgrade to Quarkus 0.25 + see https://github.com/quarkusio/quarkus/pull/4514 + <bomEntryVersion>%{camel-quarkus.version}</bomEntryVersion> --> <itestParentPath>../integration-tests/pom.xml</itestParentPath> </configuration> </plugin> diff --git a/poms/bom-deployment/pom.xml b/poms/bom-deployment/pom.xml index 35c0d8f..f962574 100644 --- a/poms/bom-deployment/pom.xml +++ b/poms/bom-deployment/pom.xml @@ -118,7 +118,7 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-csv-deployment</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -153,7 +153,7 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-microprofile-metrics-deployment</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -203,17 +203,17 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-zipfile-deployment</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-paho-deployment</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-platform-http-deployment</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> </dependencies> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 1cecddf..cd1f2fc 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -305,7 +305,7 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-csv</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -330,7 +330,7 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-microprofile-metrics</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -375,7 +375,7 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-zipfile</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <!-- Other third party dependencies (in alphabetical order by groupId:artifactId) --> @@ -392,17 +392,17 @@ <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-paho</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-platform-http</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-platform-http-component</artifactId> - <version>${project.version}</version> + <version>${camel-quarkus.version}</version> </dependency> </dependencies>