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 b7c208f2e Ref #329: Add camel-ehcache integration test (#330) b7c208f2e is described below commit b7c208f2e0d07383d0c6f2065096ffd23e1680e8 Author: François de Parscau <116000379+f2p...@users.noreply.github.com> AuthorDate: Fri Jun 7 18:50:57 2024 +0200 Ref #329: Add camel-ehcache integration test (#330) --- features/src/main/feature/camel-features.xml | 3 +- tests/features/camel-ehcache/pom.xml | 41 ++++++++++++ .../camel/test/CamelEhcacheRouteSupplier.java | 74 ++++++++++++++++++++++ .../karaf/camel/itest/CamelEhcacheITest.java | 37 +++++++++++ tests/features/pom.xml | 1 + 5 files changed, 155 insertions(+), 1 deletion(-) diff --git a/features/src/main/feature/camel-features.xml b/features/src/main/feature/camel-features.xml index 482e59fb7..cf9a3ab25 100644 --- a/features/src/main/feature/camel-features.xml +++ b/features/src/main/feature/camel-features.xml @@ -838,6 +838,7 @@ <feature>scr</feature> <feature version='${camel.osgi.version.range}'>camel-core</feature> <bundle dependency="true">mvn:org.ehcache/ehcache/${ehcache3-version}</bundle> + <bundle dependency="true">mvn:javax.cache/cache-api/${jcache-version}</bundle> <bundle>mvn:org.apache.camel.karaf/camel-ehcache/${project.version}</bundle> </feature> <feature name='camel-elasticsearch' version='${project.version}' start-level='50'> @@ -1333,7 +1334,7 @@ </feature> <feature name='camel-jcache' version='${project.version}' start-level='50'> <feature version='${camel.osgi.version.range}'>camel-core</feature> - <bundle dependency='true'>mvn:javax.cache/cache-api/1.1.1</bundle> + <bundle dependency='true'>mvn:javax.cache/cache-api/${jcache-version}</bundle> <bundle>mvn:org.apache.camel.karaf/camel-jcache/${project.version}</bundle> </feature> <feature name='camel-jcr' version='${project.version}' start-level='50'> diff --git a/tests/features/camel-ehcache/pom.xml b/tests/features/camel-ehcache/pom.xml new file mode 100644 index 000000000..dd98a728e --- /dev/null +++ b/tests/features/camel-ehcache/pom.xml @@ -0,0 +1,41 @@ +<?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-ehcache-test</artifactId> + <name>Apache Camel :: Karaf :: Tests :: Features :: EhCache</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-ehcache</artifactId> + <version>${camel.version}</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/tests/features/camel-ehcache/src/main/java/org/apache/karaf/camel/test/CamelEhcacheRouteSupplier.java b/tests/features/camel-ehcache/src/main/java/org/apache/karaf/camel/test/CamelEhcacheRouteSupplier.java new file mode 100644 index 000000000..08abb3c53 --- /dev/null +++ b/tests/features/camel-ehcache/src/main/java/org/apache/karaf/camel/test/CamelEhcacheRouteSupplier.java @@ -0,0 +1,74 @@ +/* + * 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.ehcache.EhcacheConstants; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.apache.karaf.camel.itests.CamelRouteSupplier; +import org.ehcache.CacheManager; +import org.ehcache.config.builders.CacheConfigurationBuilder; +import org.ehcache.config.builders.CacheManagerBuilder; +import org.ehcache.config.builders.ResourcePoolsBuilder; +import org.ehcache.config.units.EntryUnit; +import org.ehcache.expiry.ExpiryPolicy; +import org.osgi.service.component.annotations.Component; + + +@Component( + name = "karaf-camel-ehcache-test", + immediate = true, + service = CamelRouteSupplier.class +) +public class CamelEhcacheRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + public static final String TEST_CACHE_NAME = "mycache"; + + @Override + public void configure(CamelContext camelContext) { + CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() + .withCache(TEST_CACHE_NAME, CacheConfigurationBuilder.newCacheConfigurationBuilder( + Object.class, Object.class, ResourcePoolsBuilder.newResourcePoolsBuilder() + .heap(100, EntryUnit.ENTRIES)) + .withExpiry(ExpiryPolicy.NO_EXPIRY) + ) + .build(true); + + camelContext.getRegistry().bind("cacheManager",cacheManager); + } + + @Override + protected Function<RouteBuilder, RouteDefinition> consumerRoute() { + return builder -> + builder.fromF("ehcache://%s?cacheManager=#cacheManager", TEST_CACHE_NAME) + .log("received message ${body}"); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute.log("Storing in cache") + .setBody(builder.constant("OK")) + .setHeader(EhcacheConstants.ACTION).constant(EhcacheConstants.ACTION_PUT) + .setHeader(EhcacheConstants.KEY).constant("OK") + .toF("ehcache://%s?cacheManager=#cacheManager", TEST_CACHE_NAME) + .log("Cached value: ${body}"); + } +} + diff --git a/tests/features/camel-ehcache/src/test/java/org/apache/karaf/camel/itest/CamelEhcacheITest.java b/tests/features/camel-ehcache/src/test/java/org/apache/karaf/camel/itest/CamelEhcacheITest.java new file mode 100644 index 000000000..1678fecec --- /dev/null +++ b/tests/features/camel-ehcache/src/test/java/org/apache/karaf/camel/itest/CamelEhcacheITest.java @@ -0,0 +1,37 @@ +/* + * 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 org.apache.camel.component.mock.MockEndpoint; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest; +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; + +@RunWith(PaxExamWithExternalResource.class) +@ExamReactorStrategy(PerClass.class) +public class CamelEhcacheITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest { + + @Override + public void configureMock(MockEndpoint mock) { + mock.expectedBodiesReceived("OK"); + } + + @Test + public void testResultMock() throws Exception { + assertMockEndpointsSatisfied(); + } +} \ No newline at end of file diff --git a/tests/features/pom.xml b/tests/features/pom.xml index 28fdce07f..171968a90 100644 --- a/tests/features/pom.xml +++ b/tests/features/pom.xml @@ -42,6 +42,7 @@ <module>camel-aws2-sns</module> <module>camel-aws2-sqs</module> <module>camel-core</module> + <module>camel-ehcache</module> <module>camel-elasticsearch</module> <module>camel-jetty</module> <module>camel-netty-http</module>