Repository: camel Updated Branches: refs/heads/master ce9f8f973 -> 5bb5014e7
CAMEL-11756: Prepare unit tests of camel-spring to work with Spring 5.x Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5bb5014e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5bb5014e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5bb5014e Branch: refs/heads/master Commit: 5bb5014e78aca696f91d1fc6c9deef1747bcabe5 Parents: ce9f8f9 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Sep 11 13:49:28 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Sep 11 14:01:14 2017 +0200 ---------------------------------------------------------------------- components/camel-spring/pom.xml | 5 -- .../spring/processor/idempotent/MyCache.java | 49 ++++++++++++++++++++ .../MySpringIdempotentCacheManager.java | 39 ++++++++++++++++ .../idempotent/SpringCacheIdempotentTest.xml | 3 +- 4 files changed, 90 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5bb5014e/components/camel-spring/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml index d18f3c0..d460bfb 100644 --- a/components/camel-spring/pom.xml +++ b/components/camel-spring/pom.xml @@ -173,11 +173,6 @@ <version>${xmlunit-version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <scope>test</scope> - </dependency> <!-- for testing Spring AOP at class level --> <dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/5bb5014e/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MyCache.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MyCache.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MyCache.java new file mode 100644 index 0000000..3168c35 --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MyCache.java @@ -0,0 +1,49 @@ +/** + * 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.camel.spring.processor.idempotent; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.springframework.cache.support.NoOpCache; +import org.springframework.cache.support.SimpleValueWrapper; + +public class MyCache extends NoOpCache { + + private final ConcurrentMap<Object, Object> cache = new ConcurrentHashMap<>(); + + public MyCache(String name) { + super(name); + } + + @Override + public void put(Object key, Object value) { + cache.put(key, value); + } + + @Override + public ValueWrapper putIfAbsent(Object key, Object value) { + Object answer = cache.putIfAbsent(key, value); + return answer != null ? new SimpleValueWrapper(answer) : null; + } + + @Override + public ValueWrapper get(Object key) { + Object answer = cache.get(key); + return answer != null ? new SimpleValueWrapper(answer) : null; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/5bb5014e/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MySpringIdempotentCacheManager.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MySpringIdempotentCacheManager.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MySpringIdempotentCacheManager.java new file mode 100644 index 0000000..c5082e3 --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/MySpringIdempotentCacheManager.java @@ -0,0 +1,39 @@ +/** + * 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.camel.spring.processor.idempotent; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.cache.Cache; +import org.springframework.cache.support.AbstractCacheManager; + +public class MySpringIdempotentCacheManager extends AbstractCacheManager { + + private final Collection<Cache> cache = new ArrayList<>(1); + + public MySpringIdempotentCacheManager() { + super(); + } + + @Override + protected Collection<? extends Cache> loadCaches() { + cache.add(new MyCache("idempotent")); + return cache; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/5bb5014e/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentTest.xml index b66ec41..4f0a338 100644 --- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentTest.xml +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentTest.xml @@ -27,7 +27,7 @@ <!-- START SNIPPET: example --> <bean id="repo" class="org.apache.camel.spring.processor.idempotent.SpringCacheIdempotentRepository"> <constructor-arg> - <bean class="org.springframework.cache.guava.GuavaCacheManager"/> + <bean class="org.apache.camel.spring.processor.idempotent.MySpringIdempotentCacheManager"/> </constructor-arg> <constructor-arg value="idempotent"/> </bean> @@ -35,6 +35,7 @@ <camelContext xmlns="http://camel.apache.org/schema/spring"> <route id="idempotent-cache"> <from uri="direct:start" /> + <log message="Message id: ${header.MessageId}"/> <idempotentConsumer messageIdRepositoryRef="repo" skipDuplicate="true"> <header>MessageId</header> <to uri="log:org.apache.camel.spring.processor.idempotent?level=INFO&showAll=true&multiline=true" />