From 6b61edca8f8c404ed16b91e84284d7fb06bf76fe Mon Sep 17 00:00:00 2001 From: Sandeep Gupta Date: Thu, 13 Apr 2017 12:06:20 +0530 Subject: [PATCH] Updated deps and README --- README.md | 50 ++++++++----------- pom.xml | 17 ++----- .../TestDryRunGridFSTemplate.java | 16 ++++++ 3 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 src/test/java/DryRunGridFSTemplate/TestDryRunGridFSTemplate.java diff --git a/README.md b/README.md index 8bf989c..4106390 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,6 @@ For example unit testing code with `RedisTemplate` usually involves spinning a R Our `DryRunRedisTemplate` uses the `Dry-Redis` framework to connect to an in-memory Redis, that connects uses pure Java method calls than running in an in-process server. -## Available Mocks - -* MongoGridFSTempalte - to test Spring-data based Mongo GridFS code -* RedisTemplate - to test Spring-data based Redis code - -## Dependencies - -The library depends on the following external libraries to accomplish its goal: - -* Dry-Redis: in-memory Redis clone - ## Features * Mocked implementation to `RedisTemplate` using `MockJedis`. Following are supported: @@ -31,37 +20,42 @@ The library depends on the following external libraries to accomplish its goal: ## Examples -### RedisTemplate testing +### RedisTemplate To test code that uses `RedisTemplate` as a service, just inject the mocked template as: ```java -// create a MockJedis instance -MockJedis jedis = new MockJedis("mock-jedis"); +// create a DryRedis instance +DryRedis dryRedis = DryRedis.getDatabase("testdb"); // create an instance of RedisTemplate -RedisTemplate template = new DryRunRedisTemplate(jedis); +RedisTemplate template = new DryRunRedisTemplate(dryRedis); // must specify the key and value serializers template.setKeySerializer(new StringRedisSerializer()); -template.setValueSerializer(new RedisSerializer() { - - @Override - public byte[] serialize(byte[] t) throws SerializationException { - return t; - } +template.setValueSerializer(new StringRedisSerializer()); - @Override - public byte[] deserialize(byte[] bytes) throws SerializationException { - return bytes; - } -}); - -// inject in your service +// inject in your service for unit testing MyTestableService service = new DefaultMyTestableServiceImpl(); service.setRedisTemplate(redisTemplate); ``` +### GridFSTemplate + +```java +// create a new in-memory GridFSTemplate +GridFSTemplate template = new DryRunGridFSTemplate("myBucket"); + +// start using it +template.store(stream, "myfile.txt"); +``` + +## Dependencies + +The library depends on the following external libraries to accomplish its goal: + +* Dry-Redis: in-memory Redis clone + ## Downloads The library can be downloaded from Maven Central using: diff --git a/pom.xml b/pom.xml index c37688d..2ba0288 100644 --- a/pom.xml +++ b/pom.xml @@ -54,13 +54,6 @@ 3.0.0 - - - jitpack.io - https://jitpack.io - - - junit @@ -77,9 +70,9 @@ provided - com.github.sangupta - dry-redis - -SNAPSHOT + com.sangupta + dryredis + 0.8.0 @@ -118,8 +111,8 @@ maven-compiler-plugin 3.6.1 - 1.6 - 1.6 + 1.7 + 1.7 diff --git a/src/test/java/DryRunGridFSTemplate/TestDryRunGridFSTemplate.java b/src/test/java/DryRunGridFSTemplate/TestDryRunGridFSTemplate.java new file mode 100644 index 0000000..27cf48a --- /dev/null +++ b/src/test/java/DryRunGridFSTemplate/TestDryRunGridFSTemplate.java @@ -0,0 +1,16 @@ +package DryRunGridFSTemplate; + +import org.junit.Test; +import org.springframework.data.mongodb.gridfs.GridFsTemplate; + +import com.sangupta.dryrun.mongo.DryRunGridFSTemplate; + +public class TestDryRunGridFSTemplate { + + @Test + public void testGridFSTemplate() { + GridFsTemplate template = new DryRunGridFSTemplate("myBucket"); + + // test with the template + } +}