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 013f5d23 Ref #470: Add camel-consul integration test (#471) 013f5d23 is described below commit 013f5d23982ebe478c65b5c9ca0ae05db2d17863 Author: François de Parscau <116000379+f2p...@users.noreply.github.com> AuthorDate: Wed Jul 31 09:27:45 2024 +0200 Ref #470: Add camel-consul integration test (#471) --- features/src/main/feature/camel-features.xml | 11 ++++ pom.xml | 9 +-- tests/features/camel-consul/pom.xml | 52 ++++++++++++++++ .../karaf/camel/test/CamelConsulRouteSupplier.java | 69 ++++++++++++++++++++++ .../apache/karaf/camel/itest/CamelConsulITest.java | 61 +++++++++++++++++++ tests/features/pom.xml | 1 + 6 files changed, 199 insertions(+), 4 deletions(-) diff --git a/features/src/main/feature/camel-features.xml b/features/src/main/feature/camel-features.xml index 5cada3a7..59087f61 100644 --- a/features/src/main/feature/camel-features.xml +++ b/features/src/main/feature/camel-features.xml @@ -818,7 +818,18 @@ </feature> <feature name='camel-consul' version='${project.version}' start-level='50'> <feature version='${camel-osgi-version-range}'>camel-core</feature> + <feature version='${camel-osgi-jackson2-version}'>jackson</feature> + <feature version='[33,34)'>guava</feature> <bundle dependency='true'>wrap:mvn:org.kiwiproject/consul-client/${consul-client-version}</bundle> + <bundle dependency='true'>wrap:mvn:com.squareup.okhttp3/okhttp/${consul-okhttp3-version}</bundle> + <bundle dependency='true'>wrap:mvn:org.jetbrains.kotlin/kotlin-stdlib/${consul-kotlin-version}</bundle> + <bundle dependency='true'>wrap:mvn:com.squareup.retrofit2/retrofit/${auto-detect-version}</bundle> + <bundle dependency='true'>wrap:mvn:com.squareup.retrofit2/converter-jackson/${auto-detect-version}</bundle> + <bundle dependency='true'>wrap:mvn:com.squareup.okio/okio/${consul-okio-version}</bundle> + <bundle dependency='true'>wrap:mvn:com.squareup.okio/okio-jvm/${consul-okio-version}</bundle> + <bundle dependency='true'>mvn:com.fasterxml.jackson.datatype/jackson-datatype-jdk8/${jackson2-version}</bundle> + <bundle dependency='true'>mvn:com.fasterxml.jackson.datatype/jackson-datatype-guava/${jackson2-version}</bundle> + <bundle dependency='true'>mvn:org.apache.commons/commons-lang3/${commons-lang3-version}</bundle> <bundle>mvn:org.apache.camel.karaf/camel-consul/${project.version}</bundle> </feature> <feature name='camel-couchbase' version='${project.version}' start-level='50'> diff --git a/pom.xml b/pom.xml index 02a6e30c..c960782c 100644 --- a/pom.xml +++ b/pom.xml @@ -534,11 +534,13 @@ <aries-version>1.10.3</aries-version> <azure-core-version>1.49.1</azure-core-version> <azure-identity-version>1.13.0</azure-identity-version> - <azure-messaging-eventhubs-checkpointstore-blob-version>1.19.5 - </azure-messaging-eventhubs-checkpointstore-blob-version> + <azure-messaging-eventhubs-checkpointstore-blob-version>1.19.5</azure-messaging-eventhubs-checkpointstore-blob-version> <azure-messaging-eventhubs-version>5.18.5</azure-messaging-eventhubs-version> <azure-storage-common-version>12.25.1</azure-storage-common-version> <azure-storage-blob-version>12.26.1</azure-storage-blob-version> + <consul-kotlin-version>1.8.21</consul-kotlin-version> + <consul-okhttp3-version>4.12.0</consul-okhttp3-version> + <consul-okio-version>3.6.0</consul-okio-version> <geronimo-atinject-version>1.2</geronimo-atinject-version> <guava32-version>32.1.3-jre</guava32-version> <harmcrest-version>1.3_1</harmcrest-version> @@ -557,8 +559,7 @@ <jaxb3-osgi-version>3.0.2</jaxb3-osgi-version> <jetty11-version>11.0.21</jetty11-version> <karaf-version>4.4.6</karaf-version> - <netty-incubator-transport-classes-io_uring-version>0.0.25.Final - </netty-incubator-transport-classes-io_uring-version> + <netty-incubator-transport-classes-io_uring-version>0.0.25.Final</netty-incubator-transport-classes-io_uring-version> <osgi-cmpn-version>7.0.0</osgi-cmpn-version> <osgi-resource-locator-version>2.5.0-b42</osgi-resource-locator-version> <osgi-service-event-version>1.4.1</osgi-service-event-version> diff --git a/tests/features/camel-consul/pom.xml b/tests/features/camel-consul/pom.xml new file mode 100644 index 00000000..fbd89110 --- /dev/null +++ b/tests/features/camel-consul/pom.xml @@ -0,0 +1,52 @@ +<?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-consul-test</artifactId> + <name>Apache Camel :: Karaf :: Tests :: Features :: Consul</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-consul</artifactId> + <version>${camel-version}</version> + </dependency> + <dependency> + <groupId>com.orbitz.consul</groupId> + <artifactId>consul-client</artifactId> + <version>${consul-client-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-consul/src/main/java/org/apache/karaf/camel/test/CamelConsulRouteSupplier.java b/tests/features/camel-consul/src/main/java/org/apache/karaf/camel/test/CamelConsulRouteSupplier.java new file mode 100644 index 00000000..ae658cd6 --- /dev/null +++ b/tests/features/camel-consul/src/main/java/org/apache/karaf/camel/test/CamelConsulRouteSupplier.java @@ -0,0 +1,69 @@ +/* + * 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.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.consul.ConsulComponent; +import org.apache.camel.component.consul.ConsulConstants; +import org.apache.camel.component.consul.endpoint.ConsulHealthActions; +import org.apache.camel.component.consul.endpoint.ConsulKeyValueActions; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.osgi.service.component.annotations.Component; + +@Component( + name = "karaf-camel-consul-test", + immediate = true, + service = CamelConsulRouteSupplier.class +) +public class CamelConsulRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + private static final String KEY= "consulKey"; + + @Override + public void configure(CamelContext context) { + ConsulComponent component = new ConsulComponent(context); + component.getConfiguration().setUrl("http://localhost:%s".formatted(System.getProperty("consul.port"))); + context.addComponent("consul", component); + } + + @Override + protected Function<RouteBuilder, RouteDefinition> consumerRoute() { + return builder -> + builder.fromF("consul:kv?key=%s&valueAsString=true", KEY) + .log("received message ${body}"); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute + .setHeader(ConsulConstants.CONSUL_ACTION, constant(ConsulHealthActions.SERVICE_INSTANCES)) + .setHeader(ConsulConstants.CONSUL_SERVICE, constant("service")) + .to("consul:health") + .log("Consul health check: ${body}") + .setHeader(ConsulConstants.CONSUL_ACTION, constant(ConsulKeyValueActions.PUT)) + .setHeader(ConsulConstants.CONSUL_KEY, constant(KEY)) + .setBody(constant("OK")) + .log("sending message") + .to("consul:kv") + .log("message sent to consul : ${body}"); + } +} + diff --git a/tests/features/camel-consul/src/test/java/org/apache/karaf/camel/itest/CamelConsulITest.java b/tests/features/camel-consul/src/test/java/org/apache/karaf/camel/itest/CamelConsulITest.java new file mode 100644 index 00000000..e369b5ea --- /dev/null +++ b/tests/features/camel-consul/src/test/java/org/apache/karaf/camel/itest/CamelConsulITest.java @@ -0,0 +1,61 @@ +/* + * 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.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +import com.orbitz.consul.Consul; + +@CamelKarafTestHint(externalResourceProvider = CamelConsulITest.ExternalResourceProviders.class) +@RunWith(PaxExamWithExternalResource.class) +@ExamReactorStrategy(PerClass.class) +public class CamelConsulITest 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 createConsulContainer() { + final GenericContainer<?> consulContainer = + new GenericContainer<>("hashicorp/consul:1.19") + .withExposedPorts(Consul.DEFAULT_HTTP_PORT) + .waitingFor(Wait.forLogMessage(".*Synced node info.*", 1)) + .withCommand("agent", "-dev", "-server", "-bootstrap", "-client", "0.0.0.0", "-log-level", "trace"); + + return new GenericContainerResource(consulContainer, (Consumer<GenericContainerResource>) resource -> { + resource.setProperty("consul.port", Integer.toString(consulContainer.getMappedPort(Consul.DEFAULT_HTTP_PORT))); + }); + } + } +} \ No newline at end of file diff --git a/tests/features/pom.xml b/tests/features/pom.xml index a445df26..d6ba49ed 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-cometd</module> + <module>camel-consul</module> <module>camel-core</module> <module>camel-couchdb</module> <module>camel-crypto</module>