From 3c42df08467ec0c35ed69bdd8bd9e640b403ca6d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 25 Nov 2010 20:02:43 +0200 Subject: [PATCH] + improve parameterized redis collection even more --- .../util/AbstractRedisCollectionTests.java | 17 +++++++ .../redis/util/CollectionTestParams.java | 44 +++++++++++++++++ .../keyvalue/redis/util/RedisListTests.java | 23 --------- .../keyvalue/redis/util/RedisSetTests.java | 47 +++++++++++++++++++ 4 files changed, 108 insertions(+), 23 deletions(-) create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/CollectionTestParams.java create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisSetTests.java diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java index bee4a1bf7..291b0ab74 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java @@ -21,6 +21,7 @@ import static org.junit.Assert.*; import static org.junit.matchers.JUnitMatchers.*; import java.util.Arrays; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -32,8 +33,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import org.springframework.beans.factory.DisposableBean; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; +import org.springframework.data.keyvalue.redis.core.RedisCallback; import org.springframework.data.keyvalue.redis.core.RedisTemplate; @@ -81,6 +85,11 @@ public abstract class AbstractRedisCollectionTests { } } + @Parameters + public static Collection testParams() { + return CollectionTestParams.testParams(); + } + /** * Return a new instance of T * @return @@ -93,6 +102,14 @@ public abstract class AbstractRedisCollectionTests { public void tearDown() throws Exception { // remove the collection entirely since clear() doesn't always work collection.getOperations().delete(collection.getKey()); + template.execute(new RedisCallback() { + + @Override + public Object doInRedis(RedisConnection connection) throws Exception { + connection.flushDb(); + return null; + } + }); } @Test diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/CollectionTestParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/CollectionTestParams.java new file mode 100644 index 000000000..1b08c5ea7 --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/CollectionTestParams.java @@ -0,0 +1,44 @@ +/* + * Copyright 2010 the original author or authors. + * + * 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.springframework.data.keyvalue.redis.util; + +import java.util.Arrays; +import java.util.Collection; + +import org.springframework.data.keyvalue.redis.Person; +import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.keyvalue.redis.core.RedisTemplate; + +/** + * @author Costin Leau + */ +public abstract class CollectionTestParams { + + public static Collection testParams() { + // create Jedis Factory + ObjectFactory stringFactory = new StringObjectFactory(); + ObjectFactory personFactory = new PersonObjectFactory(); + + JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); + jedisConnFactory.setPooling(false); + jedisConnFactory.afterPropertiesSet(); + + RedisTemplate stringTemplate = new RedisTemplate(jedisConnFactory); + RedisTemplate personTemplate = new RedisTemplate(jedisConnFactory); + + return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } }); + } +} diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisListTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisListTests.java index a684b26c6..9860e9b37 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisListTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisListTests.java @@ -15,12 +15,6 @@ */ package org.springframework.data.keyvalue.redis.util; -import java.util.Arrays; -import java.util.Collection; - -import org.junit.runners.Parameterized.Parameters; -import org.springframework.data.keyvalue.redis.Person; -import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.keyvalue.redis.core.RedisTemplate; /** @@ -40,23 +34,6 @@ public class RedisListTests extends AbstractRedisListTests { super(factory, template); } - @Parameters - public static Collection testParams() { - // create Jedis Factory - ObjectFactory stringFactory = new StringObjectFactory(); - ObjectFactory personFactory = new PersonObjectFactory(); - - JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); - jedisConnFactory.setPooling(false); - jedisConnFactory.afterPropertiesSet(); - - RedisTemplate stringTemplate = new RedisTemplate(jedisConnFactory); - RedisTemplate personTemplate = new RedisTemplate(jedisConnFactory); - - return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } }); - - } - @Override RedisStore copyStore(RedisStore store) { return new DefaultRedisList(store.getKey().toString(), store.getOperations()); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisSetTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisSetTests.java new file mode 100644 index 000000000..9e61a09fb --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisSetTests.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010 the original author or authors. + * + * 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.springframework.data.keyvalue.redis.util; + +import org.springframework.data.keyvalue.redis.core.RedisTemplate; + +/** + * Parameterized instance of Redis tests. + * + * @author Costin Leau + */ +public class RedisSetTests extends AbstractRedisSetTests { + + /** + * Constructs a new RedisSetTests instance. + * + * @param factory + * @param template + */ + public RedisSetTests(ObjectFactory factory, RedisTemplate template) { + super(factory, template); + } + + @Override + RedisStore copyStore(RedisStore store) { + return new DefaultRedisSet(store.getKey().toString(), store.getOperations()); + } + + @Override + AbstractRedisCollection createCollection() { + String redisName = getClass().getName(); + return new DefaultRedisSet(redisName, template); + } +}