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 612144a5 Ref #463: Add couchdb integration test (#464)
612144a5 is described below

commit 612144a514d81a431a51c7a46f1dab69219c665a
Author: Stefan Tataru <[email protected]>
AuthorDate: Fri Jul 26 09:56:19 2024 +0200

    Ref #463: Add couchdb integration test (#464)
---
 features/src/main/feature/camel-features.xml       |  11 ++-
 tests/features/camel-couchdb/pom.xml               |  56 +++++++++++
 .../camel/test/CamelCouchdbRouteSupplier.java      |  62 ++++++++++++
 .../karaf/camel/itest/CamelCouchdbITest.java       | 104 +++++++++++++++++++++
 tests/features/pom.xml                             |   1 +
 5 files changed, 233 insertions(+), 1 deletion(-)

diff --git a/features/src/main/feature/camel-features.xml 
b/features/src/main/feature/camel-features.xml
index bbc5baf3..df294df1 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -831,8 +831,17 @@
         <feature version='${camel-osgi-version-range}'>camel-core</feature>
         <feature version="[4,5)">http-client</feature>
         <bundle 
dependency='true'>wrap:mvn:com.ibm.cloud/cloudant/${cloudant-version}</bundle>
+        <bundle 
dependency='true'>wrap:mvn:com.ibm.cloud/cloudant-common/${cloudant-version}</bundle>
         <bundle 
dependency='true'>wrap:mvn:com.ibm.cloud/sdk-core/${auto-detect-version}</bundle>
-        <bundle 
dependency='true'>mvn:com.google.code.gson/gson/${auto-detect-version}</bundle>
+        <!-- 'sdk-core' requires 'com.google.gson.internal*', which is not 
exported by the original bundle -->
+        <bundle 
dependency='true'>wrap:mvn:com.google.code.gson/gson/${gson-version}$overwrite=merge&amp;Export-Package=com.google.gson*;version=${gson-version}</bundle>
+        <bundle 
dependency='true'>wrap:mvn:com.squareup.okio/okio/${squareup-okio-version}</bundle>
+        <!-- both 'okhttp' and 'okhttp-urlconnection' export 'okhttp3',
+        the fragmented host option will enforce both bundles to share the same 
class loader,
+        'okhttp' was chosen as the host because 'okhttp-urlconnection' 
contains only one package with 2 classes -->
+        <bundle 
dependency='true'>wrap:mvn:com.squareup.okhttp3/okhttp/${squareup-okhttp-version}$Bundle-SymbolicName=com.squareup.okhttp3.okhttp</bundle>
+        <bundle 
dependency='true'>wrap:mvn:com.squareup.okhttp3/okhttp-urlconnection/${squareup-okhttp-version}$Fragment-Host=com.squareup.okhttp3.okhttp;bundle-version=${squareup-okhttp-version}</bundle>
+        <bundle 
dependency='true'>mvn:org.apache.commons/commons-lang3/${commons-lang3-version}</bundle>
         
<bundle>mvn:org.apache.camel.karaf/camel-couchdb/${project.version}</bundle>
     </feature>
     <feature name="camel-cron" version="${project.version}" start-level="50">
diff --git a/tests/features/camel-couchdb/pom.xml 
b/tests/features/camel-couchdb/pom.xml
new file mode 100644
index 00000000..f0e3f9dc
--- /dev/null
+++ b/tests/features/camel-couchdb/pom.xml
@@ -0,0 +1,56 @@
+<?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.7.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-couchdb-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: Couchdb</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-couchdb</artifactId>
+            <version>${camel-version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${gson-version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <version>${testcontainers-version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-couchdb/src/main/java/org/apache/karaf/camel/test/CamelCouchdbRouteSupplier.java
 
b/tests/features/camel-couchdb/src/main/java/org/apache/karaf/camel/test/CamelCouchdbRouteSupplier.java
new file mode 100644
index 00000000..1bf5f01a
--- /dev/null
+++ 
b/tests/features/camel-couchdb/src/main/java/org/apache/karaf/camel/test/CamelCouchdbRouteSupplier.java
@@ -0,0 +1,62 @@
+/*
+ * 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 static org.apache.camel.builder.Builder.constant;
+
+import java.util.function.Function;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.couchdb.CouchDbConstants;
+import org.apache.camel.component.couchdb.CouchDbOperations;
+import org.apache.camel.model.RouteDefinition;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+        name = "karaf-camel-couchdb-test",
+        immediate = true,
+        service = CamelCouchdbRouteSupplier.class
+)
+public class CamelCouchdbRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    private static final String COUCHDB_BASE_URI = 
"couchdb:http://%s:%s/%s?username=%s&password=%s".formatted(
+            System.getProperty("couchdb.host"),
+            System.getProperty("couchdb.port"),
+            "testdb",
+            System.getProperty("couchdb.user"),
+            System.getProperty("couchdb.pass"));
+
+    @Override
+    protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+        return builder -> builder.from(COUCHDB_BASE_URI + 
"&deletes=true&updates=false")
+                                .log("Received: ${body}");
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        producerRoute.log("Will save as document: ${body}")
+                    .to(COUCHDB_BASE_URI + "&createDatabase=true")
+                    .log("Document saved with id: 
${header.%s}".formatted(CouchDbConstants.HEADER_DOC_ID))
+                    .log("Will get document: 
${header.%s}".formatted(CouchDbConstants.HEADER_DOC_ID))
+                    .setHeader(CouchDbConstants.HEADER_METHOD, 
constant(CouchDbOperations.GET.toString()))
+                    .to(COUCHDB_BASE_URI)
+                    .log("Get document: ${body}")
+                    .log("Will delete document")
+                    .setHeader(CouchDbConstants.HEADER_METHOD, 
constant(CouchDbOperations.DELETE.toString()))
+                    .to(COUCHDB_BASE_URI);
+    }
+}
\ No newline at end of file
diff --git 
a/tests/features/camel-couchdb/src/test/java/org/apache/karaf/camel/itest/CamelCouchdbITest.java
 
b/tests/features/camel-couchdb/src/test/java/org/apache/karaf/camel/itest/CamelCouchdbITest.java
new file mode 100644
index 00000000..5d040bc0
--- /dev/null
+++ 
b/tests/features/camel-couchdb/src/test/java/org/apache/karaf/camel/itest/CamelCouchdbITest.java
@@ -0,0 +1,104 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.couchdb.CouchDbConstants;
+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.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+import com.google.gson.JsonObject;
+
+@CamelKarafTestHint(externalResourceProvider = 
CamelCouchdbITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelCouchdbITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    private static final int DB_ORIGINAL_PORT = 5984;
+    private static final String COUCHDB_USER = "admin";
+    private static final String COUCHDB_PASSWORD = "password";
+
+    @Override
+    public String getBodyToSend() {
+        return """
+            {
+                "user": "Bob99", 
+                "registered": "2009-09-03T09:13:18 -01:00",
+                "status": "active"
+            }
+        """;
+    }
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedMessageCount(1);
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+
+        MockEndpoint endpoint = getMockEndpoint();
+        List<Exchange> exchanges = endpoint.getExchanges();
+        assertNotNull(exchanges);
+        assertEquals(1, exchanges.size());
+        Exchange ex = exchanges.get(0);
+
+        JsonObject event = ex.getIn().getBody(JsonObject.class);
+        assertNotNull(event);
+        assertEquals(event.get("id").getAsString(), 
ex.getIn().getHeader(CouchDbConstants.HEADER_DOC_ID, String.class));
+        assertTrue(event.get("deleted").getAsBoolean());
+    }
+
+    public static final class ExternalResourceProviders {
+        public static GenericContainerResource<CouchdbContainer> 
createCouchdbContainer() {
+
+            CouchdbContainer couchdbContainer = new 
CouchdbContainer("couchdb:3.3.3");
+            return new GenericContainerResource<>(couchdbContainer, resource 
-> {
+                resource.setProperty("couchdb.host", 
couchdbContainer.getHost());
+                resource.setProperty("couchdb.port",
+                        
Integer.toString(couchdbContainer.getMappedPort(DB_ORIGINAL_PORT)));
+                resource.setProperty("couchdb.user", COUCHDB_USER);
+                resource.setProperty("couchdb.pass", COUCHDB_PASSWORD);
+            });
+        }
+    }
+
+    public static class CouchdbContainer extends 
GenericContainer<CouchdbContainer> {
+
+        public CouchdbContainer(final String containerName) {
+            super(containerName);
+
+            withExposedPorts(DB_ORIGINAL_PORT)
+                .waitingFor(Wait.forListeningPort())
+                .withEnv("COUCHDB_USER", COUCHDB_USER)
+                .withEnv("COUCHDB_PASSWORD", COUCHDB_PASSWORD);
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index f6f0f1e6..50435e92 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -59,6 +59,7 @@
         <module>camel-cbor</module>
         <module>camel-coap</module>
         <module>camel-core</module>
+        <module>camel-couchdb</module>
         <module>camel-crypto</module>
         <module>camel-csv</module>
         <module>camel-disruptor</module>

Reply via email to