This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new c711e1eff Ref #322: Add camel netty http test with rest (#323)
c711e1eff is described below

commit c711e1eff012ff7fde357bf420ed16b70810228b
Author: François de Parscau <116000379+f2p...@users.noreply.github.com>
AuthorDate: Wed Jun 5 18:00:57 2024 +0200

    Ref #322: Add camel netty http test with rest (#323)
    
    * Add camel netty http test with rest
    
    * Update 
tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSuppliedRouteLauncher.java
    
    ---------
    
    Co-authored-by: Nicolas Filotto <essob...@users.noreply.github.com>
---
 .../camel/itests/CamelSuppliedRouteLauncher.java   |  7 ++-
 .../test/CamelRestNettyHttpRouteSupplier.java      | 56 ++++++++++++++++++++++
 .../karaf/camel/itest/CamelNettyHttpITest.java     |  4 +-
 ...HttpITest.java => CamelRestNettyHttpITest.java} | 23 +++++++--
 4 files changed, 84 insertions(+), 6 deletions(-)

diff --git 
a/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSuppliedRouteLauncher.java
 
b/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSuppliedRouteLauncher.java
index e2de01603..479d05975 100644
--- 
a/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSuppliedRouteLauncher.java
+++ 
b/tests/camel-integration-test/src/main/java/org/apache/karaf/camel/itests/CamelSuppliedRouteLauncher.java
@@ -70,7 +70,12 @@ public class CamelSuppliedRouteLauncher extends 
AbstractCamelRouteLauncher imple
 
     @SuppressWarnings("SuspiciousMethodCalls")
     private boolean ignore(ServiceReference<?> serviceReference) {
-        return !suppliers.isEmpty() && 
!suppliers.contains(serviceReference.getProperty("component.name"));
+        boolean result = false;
+        if (!suppliers.isEmpty()) {
+            Object componentName = 
serviceReference.getProperty("component.name");
+            result = componentName != null && 
!suppliers.contains(componentName);
+        }
+        return result;
     }
 
     @Override
diff --git 
a/tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelRestNettyHttpRouteSupplier.java
 
b/tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelRestNettyHttpRouteSupplier.java
new file mode 100644
index 000000000..fbbd6c90c
--- /dev/null
+++ 
b/tests/features/camel-netty-http/src/main/java/org/apache/karaf/camel/test/CamelRestNettyHttpRouteSupplier.java
@@ -0,0 +1,56 @@
+package org.apache.karaf.camel.test;
+
+import java.util.function.Function;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.RestConfiguration;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+        name = "karaf-camel-rest-netty-http-test",
+        immediate = true,
+        service = CamelRouteSupplier.class
+)
+public class CamelRestNettyHttpRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    private static final String REST_PORT = "rest.port";
+
+    @Override
+    protected String getResultMockName() {
+        return "camel-netty-http-test";
+    }
+
+    @Override
+    public String getTestComponentName() {
+        return "camel-netty-http-test";
+    }
+
+    @Override
+    public void configure(CamelContext camelContext) {
+        RestConfiguration config = new RestConfiguration();
+        config.setComponent("netty-http");
+        config.setHost("127.0.0.1");
+        config.setPort(Integer.parseInt(System.getProperty(REST_PORT)));
+        camelContext.setRestConfiguration(config);
+    }
+
+    @Override
+    protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+        return builder ->
+                builder.fromF("rest:get:testRestNetty")
+                        .log("receiving rest http request")
+                        .setBody(builder.constant("OK"));
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        producerRoute.log("calling http endpoint")
+                .setBody(builder.constant("OK"))
+                .log("sending rest http request")
+                .toF("rest:get:testRestNetty?host=127.0.0.1:%s", 
System.getProperty(REST_PORT));
+    }
+}
diff --git 
a/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
 
b/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
index 216d56faf..59dc64be5 100644
--- 
a/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
+++ 
b/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
@@ -22,7 +22,9 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
-@CamelKarafTestHint(externalResourceProvider = 
CamelNettyHttpITest.ExternalResourceProviders.class)
+@CamelKarafTestHint(
+        externalResourceProvider = 
CamelNettyHttpITest.ExternalResourceProviders.class,
+        camelRouteSuppliers = "karaf-camel-netty-http-test")
 @RunWith(PaxExamWithExternalResource.class)
 @ExamReactorStrategy(PerClass.class)
 public class CamelNettyHttpITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
diff --git 
a/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
 
b/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelRestNettyHttpITest.java
similarity index 60%
copy from 
tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
copy to 
tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelRestNettyHttpITest.java
index 216d56faf..ae4055554 100644
--- 
a/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelNettyHttpITest.java
+++ 
b/tests/features/camel-netty-http/src/test/java/org/apache/karaf/camel/itest/CamelRestNettyHttpITest.java
@@ -14,19 +14,34 @@
 package org.apache.karaf.camel.itest;
 
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.karaf.camel.itests.*;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.AvailablePortProvider;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
-@CamelKarafTestHint(externalResourceProvider = 
CamelNettyHttpITest.ExternalResourceProviders.class)
+@CamelKarafTestHint(
+        externalResourceProvider = 
CamelRestNettyHttpITest.ExternalResourceProviders.class,
+        camelRouteSuppliers = "karaf-camel-rest-netty-http-test")
 @RunWith(PaxExamWithExternalResource.class)
 @ExamReactorStrategy(PerClass.class)
-public class CamelNettyHttpITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+public class CamelRestNettyHttpITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
 
+    @Override
+    public String getTestComponentName() {
+        return "camel-netty-http-test";
+    }
+
+    @Override
+    public String getCamelFeatureName() {
+        return "camel-netty-http";
+    }
 
     @Override
     public void configureMock(MockEndpoint mock) {
@@ -40,7 +55,7 @@ public class CamelNettyHttpITest extends 
AbstractCamelSingleFeatureResultMockBas
 
     public static final class ExternalResourceProviders {
         public static AvailablePortProvider createAvailablePortProvider() {
-            return new AvailablePortProvider(List.of("http.port"));
+            return new AvailablePortProvider(List.of("rest.port"));
         }
 
     }

Reply via email to