You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2021/07/26 10:46:53 UTC
[camel-quarkus] branch main updated: Test Quarkus and Camel
ElasticSearch REST client configuration
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new e56a3d2 Test Quarkus and Camel ElasticSearch REST client configuration
e56a3d2 is described below
commit e56a3d235bef0d82407ca1fb9747c275e83c798b
Author: James Netherton <ja...@gmail.com>
AuthorDate: Fri Jul 23 14:49:11 2021 +0100
Test Quarkus and Camel ElasticSearch REST client configuration
Fixes #2714
---
integration-tests/elasticsearch-rest/pom.xml | 17 ++++++++
.../rest/it/ElasticsearchRestResource.java | 23 +++++-----
.../rest/it/ElasticsearchRestRoutes.java | 49 ++++++++++++++++++++++
.../rest/it/ElasticSearchTestResource.java | 12 +++++-
.../rest/it/ElasticsearchRestTest.java | 18 ++++++--
5 files changed, 102 insertions(+), 17 deletions(-)
diff --git a/integration-tests/elasticsearch-rest/pom.xml b/integration-tests/elasticsearch-rest/pom.xml
index e4d6a02..e14527f 100644
--- a/integration-tests/elasticsearch-rest/pom.xml
+++ b/integration-tests/elasticsearch-rest/pom.xml
@@ -32,6 +32,10 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-elasticsearch-rest</artifactId>
</dependency>
<dependency>
@@ -59,6 +63,19 @@
<!-- 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-direct-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-elasticsearch-rest-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
diff --git a/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestResource.java b/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestResource.java
index 9d2b1b3..a88976e 100644
--- a/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestResource.java
+++ b/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestResource.java
@@ -46,10 +46,9 @@ public class ElasticsearchRestResource {
@Path("/get")
@GET
@Produces(MediaType.TEXT_PLAIN)
- public Response getData(@QueryParam("indexId") String indexId) throws Exception {
- GetResponse response = producerTemplate
- .requestBody("elasticsearch-rest://elasticsearch?operation=GetById&indexName=test", indexId, GetResponse.class);
-
+ public Response getData(@QueryParam("component") String component, @QueryParam("indexId") String indexId) {
+ GetResponse response = producerTemplate.requestBodyAndHeader("direct:get", indexId, "component", component,
+ GetResponse.class);
if (response.getSource() == null) {
return Response.status(404).build();
}
@@ -59,10 +58,9 @@ public class ElasticsearchRestResource {
@Path("/index")
@POST
@Produces(MediaType.TEXT_PLAIN)
- public Response indexData(String indexValue) throws Exception {
+ public Response indexData(@QueryParam("component") String component, String indexValue) throws Exception {
Map<String, String> data = createIndexedData(indexValue);
- String indexId = producerTemplate.requestBody("elasticsearch-rest://elasticsearch?operation=Index&indexName=test", data,
- String.class);
+ String indexId = producerTemplate.requestBodyAndHeader("direct:index", data, "component", component, String.class);
return Response
.created(new URI("https://camel.apache.org/"))
.entity(indexId)
@@ -72,21 +70,22 @@ public class ElasticsearchRestResource {
@Path("/update")
@PATCH
@Produces(MediaType.TEXT_PLAIN)
- public Response updateData(@QueryParam("indexId") String indexId, String indexValue) throws Exception {
+ public Response updateData(@QueryParam("component") String component, @QueryParam("indexId") String indexId,
+ String indexValue) {
Map<String, String> data = createIndexedData(indexValue);
Map<String, Object> headers = new HashMap<>();
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, indexId);
+ headers.put("component", component);
- producerTemplate.requestBodyAndHeaders("elasticsearch-rest://elasticsearch?operation=Update&indexName=test", data,
- headers);
+ producerTemplate.requestBodyAndHeaders("direct:update", data, headers);
return Response.ok().build();
}
@Path("/delete")
@DELETE
@Produces(MediaType.TEXT_PLAIN)
- public Response deleteData(@QueryParam("indexId") String indexId) throws Exception {
- producerTemplate.requestBody("elasticsearch-rest://elasticsearch?operation=Delete&indexName=test", indexId);
+ public Response deleteData(@QueryParam("component") String component, @QueryParam("indexId") String indexId) {
+ producerTemplate.requestBodyAndHeader("direct:delete", indexId, "component", component);
return Response.noContent().build();
}
diff --git a/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestRoutes.java b/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestRoutes.java
new file mode 100644
index 0000000..bd2fcc2
--- /dev/null
+++ b/integration-tests/elasticsearch-rest/src/main/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestRoutes.java
@@ -0,0 +1,49 @@
+/*
+ * 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.quarkus.component.elasticsearch.rest.it;
+
+import javax.inject.Named;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.elasticsearch.ElasticsearchComponent;
+import org.elasticsearch.client.RestClient;
+
+public class ElasticsearchRestRoutes extends RouteBuilder {
+
+ @Override
+ public void configure() {
+ from("direct:index")
+ .toD("${header.component}://elasticsearch?operation=Index&indexName=test");
+
+ from("direct:get")
+ .toD("${header.component}://elasticsearch?operation=GetById&indexName=test");
+
+ from("direct:update")
+ .toD("${header.component}://elasticsearch?operation=Update&indexName=test");
+
+ from("direct:delete")
+ .toD("${header.component}://elasticsearch?operation=Delete&indexName=test");
+ }
+
+ @Named("elasticsearch-rest-quarkus")
+ public ElasticsearchComponent elasticsearchQuarkus(RestClient client) {
+ // Use the RestClient bean created by the Quarkus ElasticSearch extension
+ ElasticsearchComponent component = new ElasticsearchComponent();
+ component.setClient(client);
+ return component;
+ }
+}
diff --git a/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticSearchTestResource.java b/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticSearchTestResource.java
index d826e4e..6c05588 100644
--- a/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticSearchTestResource.java
+++ b/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticSearchTestResource.java
@@ -48,9 +48,17 @@ public class ElasticSearchTestResource implements QuarkusTestResourceLifecycleMa
container.start();
+ String hostAddresses = String.format("localhost:%s", container.getMappedPort(ELASTICSEARCH_PORT));
+
+ // Create 2 sets of configuration to test scenarios:
+ // - Quarkus ElasticSearch REST client bean being autowired into the Camel ElasticSearch REST component
+ // - Component configuration where the ElasticSearch REST client is managed by Camel (E.g autowiring disabled)
return CollectionHelper.mapOf(
- "quarkus.elasticsearch.hosts",
- String.format("localhost:%s", container.getMappedPort(ELASTICSEARCH_PORT)));
+ // quarkus
+ "quarkus.elasticsearch.hosts", hostAddresses,
+ // camel
+ "camel.component.elasticsearch-rest.autowired-enabled", "false",
+ "camel.component.elasticsearch-rest.host-addresses", hostAddresses);
} catch (Exception e) {
throw new RuntimeException(e);
diff --git a/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestTest.java b/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestTest.java
index 43da5bb..23cdd64 100644
--- a/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestTest.java
+++ b/integration-tests/elasticsearch-rest/src/test/java/org/apache/camel/quarkus/component/elasticsearch/rest/it/ElasticsearchRestTest.java
@@ -20,7 +20,8 @@ import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import static org.hamcrest.Matchers.is;
@@ -28,12 +29,14 @@ import static org.hamcrest.Matchers.is;
@QuarkusTestResource(ElasticSearchTestResource.class)
class ElasticsearchRestTest {
- @Test
- public void testElasticsearchRestComponent() {
+ @ParameterizedTest
+ @MethodSource("componentNames")
+ public void testElasticsearchRestComponent(String component) {
String message = "Hello Camel Quarkus Elasticsearch";
// Index data
String indexId = RestAssured.given()
+ .queryParam("component", component)
.contentType(ContentType.TEXT)
.body(message)
.post("/elasticsearch-rest/index")
@@ -45,6 +48,7 @@ class ElasticsearchRestTest {
// Retrieve indexed data
RestAssured.given()
+ .queryParam("component", component)
.queryParam("indexId", indexId)
.get("/elasticsearch-rest/get")
.then()
@@ -55,6 +59,7 @@ class ElasticsearchRestTest {
String updatedMessage = message + " Updated";
RestAssured.given()
.contentType(ContentType.TEXT)
+ .queryParam("component", component)
.queryParam("indexId", indexId)
.body(updatedMessage)
.patch("/elasticsearch-rest/update")
@@ -63,6 +68,7 @@ class ElasticsearchRestTest {
// Verify updated data
RestAssured.given()
+ .queryParam("component", component)
.queryParam("indexId", indexId)
.get("/elasticsearch-rest/get")
.then()
@@ -71,6 +77,7 @@ class ElasticsearchRestTest {
// Delete indexed data
RestAssured.given()
+ .queryParam("component", component)
.queryParam("indexId", indexId)
.delete("/elasticsearch-rest/delete")
.then()
@@ -78,9 +85,14 @@ class ElasticsearchRestTest {
// Verify data deleted
RestAssured.given()
+ .queryParam("component", component)
.queryParam("indexId", indexId)
.get("/elasticsearch-rest/get")
.then()
.statusCode(404);
}
+
+ private static String[] componentNames() {
+ return new String[] { "elasticsearch-rest", "elasticsearch-rest-quarkus" };
+ }
}