You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/09/28 08:48:28 UTC

[camel] 02/02: CAMEL-15586: camel-http-vertx - Add support for SendDynamicAware

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.git

commit 00bba37a2dec8d1a618f3d1a87f3c6057bff7ce4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Sep 28 10:47:40 2020 +0200

    CAMEL-15586: camel-http-vertx - Add support for SendDynamicAware
---
 .../org/apache/camel/send-dynamic/vertx-http       |  2 +
 .../vertx/http/VertxHttpSendDynamicAware.java}     | 20 ++-----
 .../vertx/http/VertxHttpSendDynamicAwareTest.java  | 64 ++++++++++++++++++++++
 .../component/vertx/http/VertxHttpTestSupport.java |  4 ++
 4 files changed, 74 insertions(+), 16 deletions(-)

diff --git a/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http b/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http
new file mode 100644
index 0000000..3d4bc48
--- /dev/null
+++ b/components/camel-vertx-http/src/generated/resources/META-INF/services/org/apache/camel/send-dynamic/vertx-http
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.vertx.http.VertxHttpSendDynamicAware
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java
similarity index 59%
copy from components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
copy to components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java
index bbb3c6e..f47f46e 100644
--- a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
+++ b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAware.java
@@ -16,22 +16,10 @@
  */
 package org.apache.camel.component.vertx.http;
 
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit5.CamelTestSupport;
+import org.apache.camel.http.base.HttpSendDynamicAware;
+import org.apache.camel.spi.annotations.SendDynamic;
 
-public class VertxHttpTestSupport extends CamelTestSupport {
+@SendDynamic("vertx-http")
+public class VertxHttpSendDynamicAware extends HttpSendDynamicAware {
 
-    protected final int port = AvailablePortFinder.getNextAvailable();
-
-    protected String getTestServerUrl() {
-        return String.format("http://localhost:%d", port);
-    }
-
-    protected String getTestServerUri() {
-        return String.format("undertow:%s", getTestServerUrl());
-    }
-
-    protected String getProducerUri() {
-        return String.format("vertx-http:http://localhost:%d", port);
-    }
 }
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java
new file mode 100644
index 0000000..a040d98
--- /dev/null
+++ b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpSendDynamicAwareTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.component.vertx.http;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class VertxHttpSendDynamicAwareTest extends VertxHttpTestSupport {
+
+    @Test
+    public void testDynamicAware() throws Exception {
+        String out = fluentTemplate.to("direct:moes").withHeader("drink", "beer").request(String.class);
+        assertEquals("Drinking beer", out);
+
+        out = fluentTemplate.to("direct:joes").withHeader("drink", "wine").request(String.class);
+        assertEquals("Drinking wine", out);
+
+        // and there should only be one http endpoint as they are both on same host
+        boolean found = context.getEndpointMap()
+                .containsKey("vertx-http://http://localhost:" + getPort() + "?throwExceptionOnFailure=false");
+        assertTrue(found, "Should find static uri");
+
+        // we only have 2xdirect and 2xVERTX-http
+        assertEquals(4, context.getEndpointMap().size());
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:moes")
+                        .toD("vertx-http:http://localhost:" + getPort()
+                             + "/moes?throwExceptionOnFailure=false&drink=${header.drink}");
+
+                from("direct:joes")
+                        .toD("vertx-http:http://localhost:" + getPort()
+                             + "/joes?throwExceptionOnFailure=false&drink=${header.drink}");
+
+                from("undertow:http://localhost:" + getPort() + "/?matchOnUriPrefix=true")
+                        .transform().simple("Drinking ${header.drink[0]}");
+            }
+        };
+    }
+
+}
diff --git a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
index bbb3c6e..9eee115 100644
--- a/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
+++ b/components/camel-vertx-http/src/test/java/org/apache/camel/component/vertx/http/VertxHttpTestSupport.java
@@ -34,4 +34,8 @@ public class VertxHttpTestSupport extends CamelTestSupport {
     protected String getProducerUri() {
         return String.format("vertx-http:http://localhost:%d", port);
     }
+
+    protected int getPort() {
+        return port;
+    }
 }