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 9d5301a5 Ref #347: Add camel-kafka integration tests (#348)
9d5301a5 is described below
commit 9d5301a5dd0194be0fceccea216f46dd9030612d
Author: François de Parscau <[email protected]>
AuthorDate: Fri Jun 14 10:33:28 2024 +0200
Ref #347: Add camel-kafka integration tests (#348)
---
tests/features/camel-kafka/pom.xml | 48 ++++++++++++++++
.../karaf/camel/test/CamelKafkaRouteSupplier.java | 64 ++++++++++++++++++++++
.../apache/karaf/camel/itest/CamelKafkaITest.java | 58 ++++++++++++++++++++
tests/features/pom.xml | 1 +
4 files changed, 171 insertions(+)
diff --git a/tests/features/camel-kafka/pom.xml
b/tests/features/camel-kafka/pom.xml
new file mode 100644
index 00000000..f0287417
--- /dev/null
+++ b/tests/features/camel-kafka/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel.karaf</groupId>
+ <artifactId>camel-karaf-features-test</artifactId>
+ <version>4.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-kafka-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Kafka</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-kafka</artifactId>
+ <version>${camel.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>kafka</artifactId>
+ <version>${testcontainers-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git
a/tests/features/camel-kafka/src/main/java/org/apache/karaf/camel/test/CamelKafkaRouteSupplier.java
b/tests/features/camel-kafka/src/main/java/org/apache/karaf/camel/test/CamelKafkaRouteSupplier.java
new file mode 100644
index 00000000..9b199fe5
--- /dev/null
+++
b/tests/features/camel-kafka/src/main/java/org/apache/karaf/camel/test/CamelKafkaRouteSupplier.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.karaf.camel.test;
+
+import java.util.function.Function;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.kafka.KafkaComponent;
+import org.apache.camel.component.kafka.KafkaConfiguration;
+import org.apache.camel.model.RouteDefinition;
+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-kafka-test",
+ immediate = true,
+ service = CamelRouteSupplier.class
+)
+public class CamelKafkaRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ @Override
+ public void configure(CamelContext camelContext) {
+ KafkaComponent kafka = new KafkaComponent();
+ KafkaConfiguration config = new KafkaConfiguration();
+ config.setBreakOnFirstError(true);
+ config.setBrokers(System.getProperty("kafka.server"));
+ kafka.setConfiguration(config);
+ camelContext.addComponent("kafka", kafka);
+ }
+
+ private static final String KAFKA_TOPIC = "testTopic";
+
+ @Override
+ protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+ return builder ->
+ builder.fromF("kafka://%s?autoOffsetReset=earliest",
KAFKA_TOPIC)
+ .log("received kafka message ${body}");
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ producerRoute.log("calling kafka topic")
+ .setBody(builder.constant("OK"))
+ .toF("kafka://%s", KAFKA_TOPIC)
+ .log("kafka topic called");
+ }
+}
+
diff --git
a/tests/features/camel-kafka/src/test/java/org/apache/karaf/camel/itest/CamelKafkaITest.java
b/tests/features/camel-kafka/src/test/java/org/apache/karaf/camel/itest/CamelKafkaITest.java
new file mode 100644
index 00000000..89617f9a
--- /dev/null
+++
b/tests/features/camel-kafka/src/test/java/org/apache/karaf/camel/itest/CamelKafkaITest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed 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.karaf.camel.itest;
+
+import java.util.function.Consumer;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.GenericContainerResource;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.KafkaContainer;
+import org.testcontainers.utility.DockerImageName;
+
+@CamelKarafTestHint(externalResourceProvider =
CamelKafkaITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelKafkaITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived("OK");
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ assertMockEndpointsSatisfied();
+ }
+
+ public static final class ExternalResourceProviders {
+
+ public static GenericContainerResource createKafkaContainer() {
+ final KafkaContainer kafkaContainer =
+ new
KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.6.1"));
+
+ return new GenericContainerResource(kafkaContainer,
(Consumer<GenericContainerResource>) resource -> {
+ resource.setProperty("kafka.server",
kafkaContainer.getBootstrapServers());
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 69f77369..1e09ab69 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -48,6 +48,7 @@
<module>camel-hazelcast</module>
<module>camel-jcache</module>
<module>camel-jetty</module>
+ <module>camel-kafka</module>
<module>camel-netty-http</module>
<module>camel-mail</module>
<module>camel-olingo2</module>