You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bi...@apache.org on 2012/12/04 12:39:03 UTC
svn commit: r1416896 [2/2] - in /camel/trunk: apache-camel/
apache-camel/src/main/descriptors/ components/ components/camel-redis/
components/camel-redis/src/ components/camel-redis/src/main/
components/camel-redis/src/main/java/ components/camel-redis...
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerIntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerIntegrationTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerIntegrationTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerIntegrationTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,78 @@
+/**
+ * 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.component.redis;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.listener.RedisMessageListenerContainer;
+
+@Ignore
+public class RedisConsumerIntegrationTest extends RedisTestSupport {
+ private static final JedisConnectionFactory CONNECTION_FACTORY = new JedisConnectionFactory();
+ private static final RedisMessageListenerContainer LISTENER_CONTAINER = new RedisMessageListenerContainer();
+
+ static {
+ CONNECTION_FACTORY.afterPropertiesSet();
+ LISTENER_CONTAINER.setConnectionFactory(CONNECTION_FACTORY);
+ LISTENER_CONTAINER.afterPropertiesSet();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+
+ redisTemplate = new RedisTemplate();
+ redisTemplate.setConnectionFactory(CONNECTION_FACTORY);
+ redisTemplate.afterPropertiesSet();
+
+ registry.bind("redisTemplate", redisTemplate);
+ registry.bind("listenerContainer", LISTENER_CONTAINER);
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("redis://localhost:6379?command=SUBSCRIBE&channels=one,two&listenerContainer=#listenerContainer&redisTemplate=#redisTemplate")
+ .to("mock:result");
+
+ from("direct:start")
+ .to("redis://localhost:6379?redisTemplate=#redisTemplate");
+ }
+ };
+ }
+
+ @Test
+ public void consumerReceivesMessages() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ mock.expectedBodiesReceived("message");
+
+ sendHeaders(
+ RedisConstants.COMMAND, "PUBLISH",
+ RedisConstants.CHANNEL, "two",
+ RedisConstants.MESSAGE, "message");
+ mock.assertIsSatisfied();
+ }
+}
+
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerIntegrationTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,94 @@
+/**
+ * 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.component.redis;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.springframework.data.redis.connection.DefaultMessage;
+import org.springframework.data.redis.connection.MessageListener;
+import org.springframework.data.redis.listener.ChannelTopic;
+import org.springframework.data.redis.listener.RedisMessageListenerContainer;
+import org.springframework.data.redis.listener.Topic;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class RedisConsumerTest extends CamelTestSupport {
+ private RedisMessageListenerContainer listenerContainer;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("listenerContainer", listenerContainer);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ listenerContainer = mock(RedisMessageListenerContainer.class);
+ super.setUp();
+ }
+
+ @Test
+ public void registerConsumerForTwoChannelTopics() throws Exception {
+ ArgumentCaptor<Collection> collectionCaptor = ArgumentCaptor.forClass(Collection.class);
+ verify(listenerContainer).addMessageListener(any(MessageListener.class), collectionCaptor.capture());
+
+ Collection<ChannelTopic> topics = collectionCaptor.getValue();
+ Iterator<ChannelTopic> topicIterator = topics.iterator();
+
+ Topic firstTopic = topicIterator.next();
+ Topic twoTopic = topicIterator.next();
+ assertThat(firstTopic.getTopic(), is("one"));
+ assertThat(twoTopic.getTopic(), is("two"));
+ }
+
+ @Test
+ public void consumerReceivesMessages() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(2);
+
+ ArgumentCaptor<MessageListener> messageListenerCaptor = ArgumentCaptor
+ .forClass(MessageListener.class);
+ verify(listenerContainer).addMessageListener(messageListenerCaptor.capture(), any(Collection.class));
+
+ MessageListener messageListener = messageListenerCaptor.getValue();
+ messageListener.onMessage(new DefaultMessage(null, null), null);
+ messageListener.onMessage(new DefaultMessage(null, null), null);
+
+ mock.assertIsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("redis://localhost:6379?command=SUBSCRIBE&channels=one,two&listenerContainer=#listenerContainer")
+ .to("mock:result");
+ }
+ };
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisConsumerTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisHashTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisHashTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisHashTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisHashTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,220 @@
+/**
+ * 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.component.redis;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.HashOperations;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisHashTest extends RedisTestSupport {
+ private RedisTemplate redisTemplate;
+ private HashOperations hashOperations;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ when(redisTemplate.opsForHash()).thenReturn(hashOperations);
+
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ hashOperations = mock(HashOperations.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteHDEL() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HDEL",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELD, "field");
+
+ verify(hashOperations).delete("key", "field");
+ }
+
+ @Test
+ public void shouldExecuteHEXISTS() throws Exception {
+ when(hashOperations.hasKey(anyString(), anyString())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HEXISTS",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELD, "field");
+
+ verify(hashOperations).hasKey("key", "field");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteHINCRBY() throws Exception {
+ when(hashOperations.increment(anyString(), anyString(), anyLong())).thenReturn(1L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HINCRBY",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELD, "field",
+ RedisConstants.VALUE, "1");
+
+ verify(hashOperations).increment("key", "field", 1L);
+ assertEquals(1L, result);
+ }
+
+ @Test
+ public void shouldExecuteHKEYS() throws Exception {
+ Set<String> fields = new HashSet<String>(Arrays.asList(new String[] {"field1, field2"}));
+ when(hashOperations.keys(anyString())).thenReturn(fields);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HKEYS",
+ RedisConstants.KEY, "key");
+
+ verify(hashOperations).keys("key");
+ assertEquals(fields, result);
+ }
+
+
+ @Test
+ public void shouldExecuteHMSET() throws Exception {
+ HashMap<String, String> values = new HashMap<String, String>();
+ values.put("field1", "value1");
+ values.put("field2", "value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HMSET",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUES, values);
+
+ verify(hashOperations).putAll("key", values);
+ }
+
+ @Test
+ public void shouldExecuteHVALS() throws Exception {
+ List<String> values = new ArrayList<String>();
+ values.add("val1");
+ values.add("val2");
+
+ when(hashOperations.values(anyString())).thenReturn(values);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HVALS",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUES, values);
+
+ verify(hashOperations).values("key");
+ assertEquals(values, result);
+ }
+
+ @Test
+ public void shouldExecuteHLEN() throws Exception {
+ when(hashOperations.size(anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HLEN",
+ RedisConstants.KEY, "key");
+
+ verify(hashOperations).size("key");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldSetHashValue() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HSET",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELD, "field",
+ RedisConstants.VALUE, "value");
+
+ verify(hashOperations).put("key", "field", "value");
+ }
+
+ @Test
+ public void shouldExecuteHSETNX() throws Exception {
+ when(hashOperations.putIfAbsent(anyString(), anyString(), anyString())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HSETNX",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELD, "field",
+ RedisConstants.VALUE, "value");
+
+ verify(hashOperations).putIfAbsent("key", "field", "value");
+ assertEquals(true, result);
+ }
+
+
+ @Test
+ public void shouldExecuteHGET() throws Exception {
+ when(hashOperations.get(anyString(), anyString())).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HGET",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELD, "field");
+
+ verify(hashOperations).get("key", "field");
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteHGETALL() throws Exception {
+ HashMap<String, String> values = new HashMap<String, String>();
+ values.put("field1", "valu1");
+ when(hashOperations.entries(anyString())).thenReturn(values);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HGETALL",
+ RedisConstants.KEY, "key");
+
+ verify(hashOperations).entries("key");
+ assertEquals(values, result);
+ }
+
+ @Test
+ public void shouldExecuteHMGET() throws Exception {
+ List<String> fields = new ArrayList<String>();
+ fields.add("field1");
+ when(hashOperations.multiGet(anyString(), anyCollection())).thenReturn(fields);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "HMGET",
+ RedisConstants.KEY, "key",
+ RedisConstants.FIELDS, fields);
+
+ verify(hashOperations).multiGet("key", fields);
+ assertEquals(fields, result);
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisHashTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisKeyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisKeyTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisKeyTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisKeyTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,248 @@
+/**
+ * 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.component.redis;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.connection.DataType;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.query.SortQuery;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisKeyTest extends RedisTestSupport {
+ private RedisTemplate redisTemplate;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteDEL() throws Exception {
+ Collection<String> keys = new HashSet<String>();
+ keys.add("key1");
+ keys.add("key2");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "DEL",
+ RedisConstants.KEYS, keys);
+
+ verify(redisTemplate).delete(keys);
+ }
+
+ @Test
+ public void shouldExecuteEXISTS() throws Exception {
+ when(redisTemplate.hasKey(anyString())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "EXISTS",
+ RedisConstants.KEY, "key");
+
+ verify(redisTemplate).hasKey("key");
+ assertEquals(true, result);
+
+ }
+
+ @Test
+ public void shouldExecuteEXPIRE() throws Exception {
+ when(redisTemplate.expire(anyString(), anyLong(), any(TimeUnit.class))).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "EXPIRE",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMEOUT, "10");
+
+ verify(redisTemplate).expire("key", 10L, TimeUnit.SECONDS);
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteEXPIREAT() throws Exception {
+ when(redisTemplate.expireAt(anyString(), any(Date.class))).thenReturn(true);
+ long unixTime = System.currentTimeMillis() / 1000L;
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "EXPIREAT",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMESTAMP, unixTime);
+
+ verify(redisTemplate).expireAt("key", new Date(unixTime * 1000L));
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteKEYS() throws Exception {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key1");
+ keys.add("key2");
+ when(redisTemplate.keys(anyString())).thenReturn(keys);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "KEYS",
+ RedisConstants.PATTERN, "key*");
+
+ verify(redisTemplate).keys("key*");
+ assertEquals(keys, result);
+ }
+
+ @Test
+ public void shouldExecuteMOVE() throws Exception {
+ when(redisTemplate.move(anyString(), anyInt())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "MOVE",
+ RedisConstants.KEY, "key",
+ RedisConstants.DB, "2");
+
+ verify(redisTemplate).move("key", 2);
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecutePERSIST() throws Exception {
+ when(redisTemplate.persist(anyString())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "PERSIST",
+ RedisConstants.KEY, "key");
+
+ verify(redisTemplate).persist("key");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecutePEXPIRE() throws Exception {
+ when(redisTemplate.expire(anyString(), anyLong(), any(TimeUnit.class))).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "PEXPIRE",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMEOUT, "10");
+
+ verify(redisTemplate).expire("key", 10L, TimeUnit.MILLISECONDS);
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecutePEXPIREAT() throws Exception {
+ when(redisTemplate.expireAt(anyString(), any(Date.class))).thenReturn(true);
+
+ long millis = System.currentTimeMillis();
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "PEXPIREAT",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMESTAMP, millis);
+
+ verify(redisTemplate).expireAt("key", new Date(millis));
+ assertEquals(true, result);
+
+ }
+
+ @Test
+ public void shouldExecuteRANDOMKEY() throws Exception {
+ when(redisTemplate.randomKey()).thenReturn("key");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RANDOMKEY");
+
+ verify(redisTemplate).randomKey();
+ assertEquals("key", result);
+ }
+
+ @Test
+ public void shouldExecuteRENAME() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RENAME",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "newkey");
+
+ verify(redisTemplate).rename("key", "newkey");
+ }
+
+ @Test
+ public void shouldExecuteRENAMENX() throws Exception {
+ when(redisTemplate.renameIfAbsent(anyString(), anyString())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RENAMENX",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "newkey");
+
+ verify(redisTemplate).renameIfAbsent("key", "newkey");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteSORT() throws Exception {
+ ArrayList<Integer> list = new ArrayList<Integer>();
+ list.add(5);
+ when(redisTemplate.sort(any(SortQuery.class))).thenReturn(list);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SORT",
+ RedisConstants.KEY, "key");
+
+ verify(redisTemplate).sort(any(SortQuery.class));
+ assertEquals(list, result);
+ }
+
+ @Test
+ public void shouldExecuteTTL() throws Exception {
+ when(redisTemplate.getExpire(anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "TTL",
+ RedisConstants.KEY, "key");
+
+ verify(redisTemplate).getExpire("key");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteTYPE() throws Exception {
+ when(redisTemplate.type(anyString())).thenReturn(DataType.STRING);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "TYPE",
+ RedisConstants.KEY, "key");
+
+ verify(redisTemplate).type("key");
+ assertEquals(DataType.STRING, result);
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisKeyTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisListTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisListTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisListTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisListTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,285 @@
+/**
+ * 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.component.redis;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.ListOperations;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisListTest extends RedisTestSupport {
+ private RedisTemplate redisTemplate;
+ private ListOperations listOperations;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ when(redisTemplate.opsForList()).thenReturn(listOperations);
+
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ listOperations = mock(ListOperations.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteLPOP() throws Exception {
+ when(listOperations.leftPop(anyString())).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LPOP",
+ RedisConstants.KEY, "key");
+
+ verify(listOperations).leftPop("key");
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteBLPOP() throws Exception {
+ when(listOperations.leftPop(anyString(), anyLong(), any(TimeUnit.class))).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "BLPOP",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMEOUT, "10");
+
+ verify(listOperations).leftPop("key", 10, TimeUnit.SECONDS);
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteBRPOP() throws Exception {
+ when(listOperations.rightPop(anyString(), anyLong(), any(TimeUnit.class))).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "BRPOP",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMEOUT, "10");
+
+ verify(listOperations).rightPop("key", 10, TimeUnit.SECONDS);
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteRPOP() throws Exception {
+ when(listOperations.rightPop(anyString())).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RPOP",
+ RedisConstants.KEY, "key");
+
+ verify(listOperations).rightPop("key");
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteRPOPLPUSH() throws Exception {
+ when(listOperations.rightPopAndLeftPush(anyString(), anyString())).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RPOPLPUSH",
+ RedisConstants.KEY, "key",
+ RedisConstants.DESTINATION, "destination");
+
+ verify(listOperations).rightPopAndLeftPush("key", "destination");
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteBRPOPLPUSH() throws Exception {
+ when(listOperations.rightPopAndLeftPush(anyString(), anyString(), anyLong(), any(TimeUnit.class)))
+ .thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "BRPOPLPUSH",
+ RedisConstants.KEY, "key",
+ RedisConstants.DESTINATION, "destination",
+ RedisConstants.TIMEOUT, "10");
+
+ verify(listOperations).rightPopAndLeftPush("key", "destination", 10, TimeUnit.SECONDS);
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteLINDEX() throws Exception {
+ when(listOperations.index(anyString(), anyLong()))
+ .thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LINDEX",
+ RedisConstants.KEY, "key",
+ RedisConstants.INDEX, "2");
+
+ verify(listOperations).index("key", 2);
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteLINSERTBEFORE() throws Exception {
+ when(listOperations.leftPush(anyString(), anyString(), anyString()))
+ .thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LINSERT",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.PIVOT, "pivot",
+ RedisConstants.POSITION, "BEFORE");
+
+ verify(listOperations).leftPush("key", "pivot", "value");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteLINSERTAFTER() throws Exception {
+ when(listOperations.rightPush(anyString(), anyString(), anyString()))
+ .thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LINSERT",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.PIVOT, "pivot",
+ RedisConstants.POSITION, "AFTER");
+
+ verify(listOperations).rightPush("key", "pivot", "value");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteLLEN() throws Exception {
+ when(listOperations.size(anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LLEN",
+ RedisConstants.KEY, "key");
+
+ verify(listOperations).size("key");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteLPUSH() throws Exception {
+ when(listOperations.leftPush(anyString(), anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LPUSH",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(listOperations).leftPush("key", "value");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteLRANGE() throws Exception {
+ List<String> values = new ArrayList<String>();
+ values.add("value");
+
+ when(listOperations.range(anyString(), anyLong(), anyLong()))
+ .thenReturn(values);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, "0",
+ RedisConstants.END, "1");
+
+ verify(listOperations).range("key", 0, 1);
+ assertEquals(values, result);
+ }
+
+ @Test
+ public void shouldExecuteLREM() throws Exception {
+ when(listOperations.remove(anyString(), anyLong(), anyString()))
+ .thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LREM",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.COUNT, "1");
+
+ verify(listOperations).remove("key", 1, "value");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteLSET() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LSET",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.INDEX, "1");
+
+ verify(listOperations).set("key", 1, "value");
+ }
+
+ @Test
+ public void shouldExecuteLTRIM() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "LTRIM",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, "1",
+ RedisConstants.END, "2");
+
+ verify(listOperations).trim("key", 1, 2);
+ }
+
+ @Test
+ public void shouldExecuteRPUSH() throws Exception {
+ when(listOperations.rightPush(anyString(), anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RPUSH",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(listOperations).rightPush("key", "value");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteRPUSHX() throws Exception {
+ when(listOperations.rightPushIfPresent(anyString(), anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "RPUSHX",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(listOperations).rightPushIfPresent("key", "value");
+ assertEquals(2L, result);
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisListTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisProducerIntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisProducerIntegrationTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisProducerIntegrationTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisProducerIntegrationTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,61 @@
+/**
+ * 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.component.redis;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+
+@Ignore
+public class RedisProducerIntegrationTest extends RedisTestSupport {
+ private static final JedisConnectionFactory CONNECTION_FACTORY = new JedisConnectionFactory();
+
+ static {
+ CONNECTION_FACTORY.afterPropertiesSet();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ redisTemplate = new RedisTemplate();
+ redisTemplate.setConnectionFactory(CONNECTION_FACTORY);
+ redisTemplate.afterPropertiesSet();
+
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Test
+ public void shouldSetAString() throws Exception {
+ sendHeaders(
+ RedisConstants.COMMAND, "SET",
+ RedisConstants.KEY, "key1",
+ RedisConstants.VALUE, "value");
+
+ assertEquals("value", redisTemplate.opsForValue().get("key1"));
+ }
+
+ @Test
+ public void shouldGetAString() throws Exception {
+ redisTemplate.opsForValue().set("key2", "value");
+ Object result = sendHeaders(RedisConstants.KEY, "key2", RedisConstants.COMMAND, "GET");
+
+ assertEquals("value", result);
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisProducerIntegrationTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSetTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSetTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSetTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,261 @@
+/**
+ * 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.component.redis;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.SetOperations;
+
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisSetTest extends RedisTestSupport {
+ private RedisTemplate redisTemplate;
+ private SetOperations setOperations;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ when(redisTemplate.opsForSet()).thenReturn(setOperations);
+
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ setOperations = mock(SetOperations.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteSADD() throws Exception {
+ when(setOperations.add(anyString(), anyObject())).thenReturn(false);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SADD",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(setOperations).add("key", "value");
+ assertEquals(false, result);
+
+ }
+
+ @Test
+ public void shouldExecuteSCARD() throws Exception {
+ when(setOperations.size(anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SCARD",
+ RedisConstants.KEY, "key");
+
+ verify(setOperations).size("key");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteSDIFF() throws Exception {
+ Set<String> difference = new HashSet<String>();
+ difference.add("a");
+ difference.add("b");
+ when(setOperations.difference(anyString(), anyCollection())).thenReturn(difference);
+
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SDIFF",
+ RedisConstants.KEY, "key",
+ RedisConstants.KEYS, keys);
+
+ verify(setOperations).difference("key", keys);
+ assertEquals(difference, result);
+ }
+
+ @Test
+ public void shouldExecuteSDIFFSTORE() throws Exception {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SDIFFSTORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.KEYS, keys,
+ RedisConstants.DESTINATION, "destination");
+
+ verify(setOperations).differenceAndStore("key", keys, "destination");
+ }
+
+ @Test
+ public void shouldExecuteSINTER() throws Exception {
+ Set<String> difference = new HashSet<String>();
+ difference.add("a");
+ difference.add("b");
+ when(setOperations.intersect(anyString(), anyCollection())).thenReturn(difference);
+
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SINTER",
+ RedisConstants.KEY, "key",
+ RedisConstants.KEYS, keys);
+
+ verify(setOperations).intersect("key", keys);
+ assertEquals(difference, result);
+ }
+
+ @Test
+ public void shouldExecuteSINTERSTORE() throws Exception {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SINTERSTORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.DESTINATION, "destination",
+ RedisConstants.KEYS, keys);
+
+ verify(setOperations).intersectAndStore("key", keys, "destination");
+ }
+
+ @Test
+ public void shouldExecuteSISMEMBER() throws Exception {
+ when(setOperations.isMember(anyString(), anyObject())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SISMEMBER",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "set");
+
+ verify(setOperations).isMember("key", "set");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteSMEMBERS() throws Exception {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+
+ when(setOperations.members(anyString())).thenReturn(keys);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SMEMBERS",
+ RedisConstants.KEY, "key");
+
+ verify(setOperations).members("key");
+ assertEquals(keys, result);
+ }
+
+ @Test
+ public void shouldExecuteSMOVE() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SMOVE",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.DESTINATION, "destination");
+
+ verify(setOperations).move("key", "value", "destination");
+ }
+
+ @Test
+ public void shouldExecuteSPOP() throws Exception {
+ String field = "value";
+ when(setOperations.pop(anyString())).thenReturn(field);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SPOP",
+ RedisConstants.KEY, "key");
+
+ verify(setOperations).pop("key");
+ assertEquals(field, result);
+ }
+
+ @Test
+ public void shouldExecuteSRANDMEMBER() throws Exception {
+ String field = "value";
+ when(setOperations.randomMember(anyString())).thenReturn(field);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SRANDMEMBER",
+ RedisConstants.KEY, "key");
+
+ verify(setOperations).randomMember("key");
+ assertEquals(field, result);
+ }
+
+ @Test
+ public void shouldExecuteSREM() throws Exception {
+ when(setOperations.remove(anyString(), anyObject())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SREM",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(setOperations).remove("key", "value");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteSUNION() throws Exception {
+ Set<String> resultKeys = new HashSet<String>();
+ resultKeys.add("key2");
+ resultKeys.add("key3");
+
+ when(setOperations.union(anyString(), anyCollection())).thenReturn(resultKeys);
+
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key4");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SUNION",
+ RedisConstants.KEY, "key",
+ RedisConstants.KEYS, keys);
+
+ verify(setOperations).union("key", keys);
+ assertEquals(resultKeys, result);
+ }
+
+ @Test
+ public void shouldExecuteSUNIONSTORE() throws Exception {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key4");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SUNIONSTORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.KEYS, keys,
+ RedisConstants.DESTINATION, "destination");
+
+ verify(setOperations).unionAndStore("key", keys, "destination");
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSetTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSortedSetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSortedSetTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSortedSetTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSortedSetTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,306 @@
+/**
+ * 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.component.redis;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ZSetOperations;
+
+import static org.mockito.Matchers.anyDouble;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisSortedSetTest extends RedisTestSupport {
+ private RedisTemplate redisTemplate;
+ private ZSetOperations zSetOperations;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ when(redisTemplate.opsForZSet()).thenReturn(zSetOperations);
+
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ zSetOperations = mock(ZSetOperations.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteZADD() {
+ when(zSetOperations.add(anyString(), anyObject(), anyDouble())).thenReturn(false);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZADD",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.SCORE, 1.0);
+
+ verify(zSetOperations).add("key", "value", 1.0);
+ assertEquals(false, result);
+
+ }
+
+ @Test
+ public void shouldExecuteZCARD() {
+ when(zSetOperations.size(anyString())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZCARD",
+ RedisConstants.KEY, "key");
+
+ verify(zSetOperations).size("key");
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteZCOUNT() {
+ when(zSetOperations.count(anyString(), anyDouble(), anyDouble())).thenReturn(3L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZCOUNT",
+ RedisConstants.KEY, "key",
+ RedisConstants.MIN, 1.0,
+ RedisConstants.MAX, 2.0);
+
+ verify(zSetOperations).count("key", 1.0, 2.0);
+ assertEquals(3L, result);
+ }
+
+ @Test
+ public void shouldExecuteZINCRBY() {
+ when(zSetOperations.incrementScore(anyString(), anyString(), anyDouble())).thenReturn(3.0);
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZINCRBY",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value",
+ RedisConstants.INCREMENT, 2.0);
+
+ verify(zSetOperations).incrementScore("key", "value", 2.0);
+ assertEquals(3.0, result);
+
+ }
+
+ @Test
+ public void shouldExecuteZINTERSTORE() {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZINTERSTORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.DESTINATION, "destination",
+ RedisConstants.KEYS, keys);
+
+ verify(zSetOperations).intersectAndStore("key", keys, "destination");
+ }
+
+ @Test
+ public void shouldExecuteZRANGE() {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ when(zSetOperations.range(anyString(), anyLong(), anyLong())).thenReturn(keys);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, 1,
+ RedisConstants.END, 3);
+
+ verify(zSetOperations).range("key", 1, 3);
+ assertEquals(keys, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZRANGEWithScores() {
+ when(zSetOperations.rangeWithScores(anyString(), anyLong(), anyLong())).thenReturn(null);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.WITHSCORE, true,
+ RedisConstants.START, 1,
+ RedisConstants.END, 3);
+
+ verify(zSetOperations).rangeWithScores("key", 1, 3);
+ assertEquals(null, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZRANGEBYSCORE() {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ when(zSetOperations.rangeByScore(anyString(), anyDouble(), anyDouble())).thenReturn(keys);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZRANGEBYSCORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.MIN, 1.0,
+ RedisConstants.MAX, 2.0);
+
+ verify(zSetOperations).rangeByScore("key", 1.0, 2.0);
+ assertEquals(keys, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZRANK() {
+ when(zSetOperations.rank(anyString(), anyString())).thenReturn(1L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZRANK",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(zSetOperations).rank("key", "value");
+ assertEquals(1L, result);
+ }
+
+ @Test
+ public void shouldExecuteZREM() {
+ when(zSetOperations.remove(anyString(), anyString())).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREM",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(zSetOperations).remove("key", "value");
+ assertEquals(true, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZREMRANGEBYRANK() {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREMRANGEBYRANK",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, 1,
+ RedisConstants.END, 2);
+
+ verify(zSetOperations).removeRange("key", 1, 2);
+ }
+
+ @Test
+ public void shouldExecuteZREMRANGEBYSCORE() {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREMRANGEBYSCORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, 1,
+ RedisConstants.END, 2);
+
+ verify(zSetOperations).removeRangeByScore("key", 1.0, 2.0);
+ }
+
+
+ @Test
+ public void shouldExecuteZREVRANGE() {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ when(zSetOperations.reverseRange(anyString(), anyLong(), anyLong())).thenReturn(keys);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREVRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, 1,
+ RedisConstants.END, 3);
+
+ verify(zSetOperations).reverseRange("key", 1, 3);
+ assertEquals(keys, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZREVRANGEWithScores() {
+ when(zSetOperations.reverseRangeWithScores(anyString(), anyLong(), anyLong())).thenReturn(null);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREVRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.WITHSCORE, true,
+ RedisConstants.START, 1,
+ RedisConstants.END, 3);
+
+ verify(zSetOperations).reverseRangeWithScores("key", 1, 3);
+ assertEquals(null, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZREVRANGEBYSCORE() {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ when(zSetOperations.reverseRangeByScore(anyString(), anyDouble(), anyDouble())).thenReturn(keys);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREVRANGEBYSCORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.MIN, 1.0,
+ RedisConstants.MAX, 2.0);
+
+ verify(zSetOperations).reverseRangeByScore("key", 1.0, 2.0);
+ assertEquals(keys, result);
+ }
+
+
+ @Test
+ public void shouldExecuteZREVRANK() {
+ when(zSetOperations.reverseRank(anyString(), anyString())).thenReturn(1L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZREVRANK",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(zSetOperations).reverseRank("key", "value");
+ assertEquals(1L, result);
+ }
+
+ @Test
+ public void shouldExecuteZUNIONSTORE() {
+ Set<String> keys = new HashSet<String>();
+ keys.add("key2");
+ keys.add("key3");
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "ZUNIONSTORE",
+ RedisConstants.KEY, "key",
+ RedisConstants.DESTINATION, "destination",
+ RedisConstants.KEYS, keys);
+
+ verify(zSetOperations).unionAndStore("key", keys, "destination");
+ }
+}
+
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisSortedSetTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisStringTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisStringTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisStringTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisStringTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,319 @@
+/**
+ * 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.component.redis;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ValueOperations;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisStringTest extends RedisTestSupport {
+ private ValueOperations valueOperations;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ when(redisTemplate.opsForValue()).thenReturn(valueOperations);
+
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ valueOperations = mock(ValueOperations.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteSET() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SET",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(valueOperations).set("key", "value");
+ }
+
+ @Test
+ public void shouldExecuteSETNX() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SETNX",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(valueOperations).setIfAbsent("key", "value");
+ }
+
+
+ @Test
+ public void shouldExecuteSETEX() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SETEX",
+ RedisConstants.KEY, "key",
+ RedisConstants.TIMEOUT, "10",
+ RedisConstants.VALUE, "value");
+
+ verify(valueOperations).set("key", "value", 10, TimeUnit.SECONDS);
+ }
+
+
+ @Test
+ public void shouldExecuteSETRANGE() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SETRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.OFFSET, "10",
+ RedisConstants.VALUE, "value");
+
+ verify(valueOperations).set("key", "value", 10);
+ }
+
+
+ @Test
+ public void shouldExecuteGETRANGE() throws Exception {
+ when(valueOperations.get(anyString(), anyLong(), anyLong())).thenReturn("test");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "GETRANGE",
+ RedisConstants.KEY, "key",
+ RedisConstants.START, "2",
+ RedisConstants.END, "4");
+
+ verify(valueOperations).get("key", 2, 4);
+ assertEquals("test", result);
+ }
+
+
+ @Test
+ public void shouldExecuteSETBIT() throws Exception {
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "SETBIT",
+ RedisConstants.KEY, "key",
+ RedisConstants.OFFSET, "10",
+ RedisConstants.VALUE, "0");
+
+ verify(redisTemplate).execute(any(RedisCallback.class));
+ }
+
+
+ @Test
+ public void shouldExecuteGETBIT() throws Exception {
+ when(redisTemplate.execute(any(RedisCallback.class))).thenReturn(true);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "GETBIT",
+ RedisConstants.KEY, "key",
+ RedisConstants.OFFSET, "2");
+
+ verify(redisTemplate).execute(any(RedisCallback.class));
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void shouldExecuteGET() throws Exception {
+ when(valueOperations.get("key")).thenReturn("value");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "GET",
+ RedisConstants.KEY, "key");
+
+ verify(valueOperations).get("key");
+ assertEquals("value", result);
+ }
+
+ @Test
+ public void shouldExecuteAPPEND() throws Exception {
+ when(valueOperations.append(anyString(), anyString())).thenReturn(5);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "APPEND",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, "value");
+
+ verify(valueOperations).append("key", "value");
+ assertEquals(5, result);
+ }
+
+ @Test
+ public void shouldExecuteDECR() throws Exception {
+ when(valueOperations.increment(anyString(), anyLong())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "DECR",
+ RedisConstants.KEY, "key");
+
+ verify(valueOperations).increment("key", -1);
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteDECRBY() throws Exception {
+ when(valueOperations.increment(anyString(), anyLong())).thenReturn(1L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "DECRBY",
+ RedisConstants.VALUE, "2",
+ RedisConstants.KEY, "key");
+
+ verify(valueOperations).increment("key", -2);
+ assertEquals(1L, result);
+ }
+
+ @Test
+ public void shouldExecuteINCR() throws Exception {
+ when(valueOperations.increment(anyString(), anyLong())).thenReturn(2L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "INCR",
+ RedisConstants.KEY, "key");
+
+ verify(valueOperations).increment("key", 1);
+ assertEquals(2L, result);
+ }
+
+ @Test
+ public void shouldExecuteINCRBY() throws Exception {
+ when(valueOperations.increment(anyString(), anyLong())).thenReturn(1L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "INCRBY",
+ RedisConstants.VALUE, "2",
+ RedisConstants.KEY, "key");
+
+ verify(valueOperations).increment("key", 2);
+ assertEquals(1L, result);
+ }
+
+
+ @Test
+ public void shouldExecuteSTRLEN() throws Exception {
+ when(valueOperations.size(anyString())).thenReturn(5L);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "STRLEN",
+ RedisConstants.KEY, "key");
+
+ verify(valueOperations).size("key");
+ assertEquals(5L, result);
+ }
+
+
+ @Test
+ public void shouldExecuteMGET() throws Exception {
+ List<String> fields = new ArrayList<String>();
+ fields.add("field1");
+
+ List<String> values = new ArrayList<String>();
+ values.add("value1");
+
+ when(valueOperations.multiGet(fields)).thenReturn(values);
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "MGET",
+ RedisConstants.FIELDS, fields);
+
+ verify(valueOperations).multiGet(fields);
+ assertEquals(values, result);
+ }
+
+
+ @Test
+ public void shouldExecuteMSET() throws Exception {
+ HashMap<String, String> values = new HashMap<String, String>();
+ values.put("field1", "valu1");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "MSET",
+ RedisConstants.VALUES, values);
+
+ verify(valueOperations).multiSet(values);
+ }
+
+
+ @Test
+ public void shouldExecuteMSETNX() throws Exception {
+ HashMap<String, String> values = new HashMap<String, String>();
+ values.put("field1", "valu1");
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "MSETNX",
+ RedisConstants.VALUES, values);
+
+ verify(valueOperations).multiSetIfAbsent(values);
+ }
+
+ @Test
+ public void shouldExecuteGETSET() throws Exception {
+ when(valueOperations.getAndSet(anyString(), anyString())).thenReturn("old value");
+ String value = "new value";
+
+ Object result = sendHeaders(
+ RedisConstants.COMMAND, "GETSET",
+ RedisConstants.KEY, "key",
+ RedisConstants.VALUE, value);
+
+ verify(valueOperations).getAndSet("key", value);
+ assertEquals("old value", result);
+
+ }
+
+
+//
+// @Test
+// public void shouldExecuteMULTI() throws Exception {
+// //when(valueOperations.multi()).thenReturn(any(Transaction.class));
+//
+// Object result = sendHeaders(RedisConstants.COMMAND, "MULTI");
+//
+// verify(jedis).multi();
+// assertEquals("OK", result);
+// }
+//
+// @Test
+// public void shouldExecuteInTransaction() throws Exception {
+// Transaction transaction = mock(Transaction.class);
+// when(jedis.multi()).thenReturn(transaction);
+//
+// sendHeaders(RedisConstants.COMMAND, "MULTI");
+//
+//
+// Object result = sendHeaders(
+// RedisConstants.KEY, "key",
+// RedisConstants.VALUE, "value");
+//
+// verify(transaction).set("key", "value");
+// assertEquals("OK", result);
+//
+//
+// }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisStringTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTestSupport.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTestSupport.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTestSupport.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.component.redis;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.springframework.data.redis.core.RedisTemplate;
+
+public class RedisTestSupport extends CamelTestSupport {
+ protected RedisTemplate redisTemplate;
+
+ @Produce(uri = "direct:start")
+ protected ProducerTemplate template;
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .to("redis://localhost:6379?redisTemplate=#redisTemplate");
+ }
+ };
+ }
+
+ protected Object sendHeaders(final Object... headers) {
+ Exchange exchange = template.send(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ for (int i = 0; i < headers.length; i = i + 2) {
+ in.setHeader(headers[i].toString(), headers[i + 1]);
+ }
+ }
+ });
+
+ return exchange.getIn().getBody();
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTestSupport.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTransactionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTransactionTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTransactionTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTransactionTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,82 @@
+/**
+ * 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.component.redis;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class RedisTransactionTest extends RedisTestSupport {
+ private RedisTemplate redisTemplate;
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("redisTemplate", redisTemplate);
+ return registry;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ super.setUp();
+ }
+
+ @Test
+ public void shouldExecuteMULTI() throws Exception {
+ sendHeaders(RedisConstants.COMMAND, "MULTI");
+ verify(redisTemplate).multi();
+ }
+
+ @Test
+ public void shouldExecuteDISCARD() throws Exception {
+ sendHeaders(RedisConstants.COMMAND, "DISCARD");
+ verify(redisTemplate).discard();
+ }
+
+ @Test
+ public void shouldExecuteEXEC() throws Exception {
+ sendHeaders(RedisConstants.COMMAND, "EXEC");
+ verify(redisTemplate).exec();
+ }
+
+ @Test
+ public void shouldExecuteUNWATCH() throws Exception {
+ sendHeaders(RedisConstants.COMMAND, "UNWATCH");
+ verify(redisTemplate).unwatch();
+ }
+
+ @Test
+ public void shouldExecuteWATCH() throws Exception {
+ List<String> keys = new ArrayList<String>();
+ keys.add("key");
+
+ sendHeaders(
+ RedisConstants.COMMAND, "WATCH",
+ RedisConstants.KEYS, keys);
+ verify(redisTemplate).watch(keys);
+ }
+
+}
+
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/RedisTransactionTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java (added)
+++ camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java Tue Dec 4 11:38:57 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.component.redis.processor.idempotent;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.SetOperations;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RedisIdempotentRepositoryTest {
+ private static final String REPOSITORY = "testRepository";
+ private static final String KEY = "KEY";
+ private RedisTemplate redisTemplate;
+ private SetOperations setOperations;
+ private RedisIdempotentRepository idempotentRepository;
+
+ @Before
+ public void setUp() throws Exception {
+ redisTemplate = mock(RedisTemplate.class);
+ setOperations = mock(SetOperations.class);
+ when(redisTemplate.opsForSet()).thenReturn(setOperations);
+ idempotentRepository = RedisIdempotentRepository.redisIdempotentRepository(redisTemplate, REPOSITORY);
+ }
+
+ @Test
+ public void shouldAddKey() {
+ idempotentRepository.add(KEY);
+ verify(setOperations).add(REPOSITORY, KEY);
+ }
+
+ @Test
+ public void shoulCheckForMembers() {
+ idempotentRepository.contains(KEY);
+ verify(setOperations).isMember(REPOSITORY, KEY);
+ }
+
+ @Test
+ public void shouldRemoveKey() {
+ idempotentRepository.remove(KEY);
+ verify(setOperations).remove(REPOSITORY, KEY);
+ }
+
+ @Test
+ public void shouldReturnProcessorName() {
+ String processorName = idempotentRepository.getProcessorName();
+ assertThat(processorName, is(REPOSITORY));
+ }
+}
Propchange: camel/trunk/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/idempotent/RedisIdempotentRepositoryTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: camel/trunk/components/camel-redis/src/test/resources/RedisComponentSpringTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-redis/src/test/resources/RedisComponentSpringTest-context.xml?rev=1416896&view=auto
==============================================================================
--- camel/trunk/components/camel-redis/src/test/resources/RedisComponentSpringTest-context.xml (added)
+++ camel/trunk/components/camel-redis/src/test/resources/RedisComponentSpringTest-context.xml Tue Dec 4 11:38:57 2012
@@ -0,0 +1,44 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <bean id="idempotentRepository" class="org.apache.camel.component.redis.processor.idempotent.RedisIdempotentRepository">
+ <constructor-arg value="test-repo"/>
+ </bean>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route startupOrder="1">
+ <from uri="redis://localhost:6379?command=SUBSCRIBE&channels=testChannel"/>
+ <idempotentConsumer messageIdRepositoryRef="idempotentRepository">
+ <simple>${in.body}</simple>
+ <to uri="mock:result"/>
+ </idempotentConsumer>
+ </route>
+
+ <route startupOrder="2">
+ <from uri="direct:start"/>
+ <delay><!-- give time to listener above to start -->
+ <constant>2000</constant>
+ </delay>
+ <to uri="redis://localhost:6379"/>
+ </route>
+ </camelContext>
+</beans>
\ No newline at end of file
Propchange: camel/trunk/components/camel-redis/src/test/resources/RedisComponentSpringTest-context.xml
------------------------------------------------------------------------------
svn:executable = *
Modified: camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1416896&r1=1416895&r2=1416896&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Tue Dec 4 11:38:57 2012
@@ -132,6 +132,7 @@
<module>camel-protobuf</module>
<module>camel-quartz</module>
<module>camel-quickfix</module>
+ <module>camel-redis</module>
<module>camel-restlet</module>
<module>camel-rmi</module>
<module>camel-routebox</module>
Modified: camel/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1416896&r1=1416895&r2=1416896&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Tue Dec 4 11:38:57 2012
@@ -304,6 +304,7 @@
<solr-version>3.6.1</solr-version>
<spring-batch-version>2.1.9.RELEASE</spring-batch-version>
<spring-castor-bundle-version>1.2.0</spring-castor-bundle-version>
+ <spring-data-redis-version>1.0.0.RELEASE</spring-data-redis-version>
<spring-integration-version>2.1.4.RELEASE</spring-integration-version>
<spring-javaconfig-version>1.0.0-20090215</spring-javaconfig-version>
<spring-neo4j-version>2.1.0.RELEASE</spring-neo4j-version>
@@ -872,6 +873,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-redis</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<version>${project.version}</version>
</dependency>
Modified: camel/trunk/platforms/karaf/features/src/main/resources/features.xml
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/features/src/main/resources/features.xml?rev=1416896&r1=1416895&r2=1416896&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/features/src/main/resources/features.xml (original)
+++ camel/trunk/platforms/karaf/features/src/main/resources/features.xml Tue Dec 4 11:38:57 2012
@@ -648,6 +648,11 @@
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.quickfix/${quickfix-bundle-version}</bundle>
<bundle>mvn:org.apache.camel/camel-quickfix/${project.version}</bundle>
</feature>
+ <feature name='camel-redis' version='${project.version}' resolver='(obr)' start-level='50'>
+ <feature version='${project.version}'>camel-core</feature>
+ <bundle dependency='true'>mvn:org.springframework.data/spring-data-redis/${spring-data-redis-version}</bundle>
+ <bundle>mvn:org.apache.camel/camel-redis/${project.version}</bundle>
+ </feature>
<feature name='camel-restlet' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:http://maven.restlet.org!org.restlet.jse/org.restlet/${restlet-version}</bundle>
Modified: camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=1416896&r1=1416895&r2=1416896&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Tue Dec 4 11:38:57 2012
@@ -119,6 +119,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-redis</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<scope>test</scope>
</dependency>