Skip to content

Commit

Permalink
Updated deps and README
Browse files Browse the repository at this point in the history
  • Loading branch information
sangupta committed Apr 13, 2017
1 parent 6b0dc75 commit 6b61edc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 40 deletions.
50 changes: 22 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<String, byte[]> template = new DryRunRedisTemplate<String, byte[]>(jedis);
RedisTemplate<String, byte[]> template = new DryRunRedisTemplate<String, byte[]>(dryRedis);

// must specify the key and value serializers
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new RedisSerializer<byte[]>() {

@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:
Expand Down
17 changes: 5 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@
<maven>3.0.0</maven>
</prerequisites>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -77,9 +70,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.sangupta</groupId>
<artifactId>dry-redis</artifactId>
<version>-SNAPSHOT</version>
<groupId>com.sangupta</groupId>
<artifactId>dryredis</artifactId>
<version>0.8.0</version>
</dependency>

<!-- for gridfs template -->
Expand Down Expand Up @@ -118,8 +111,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

Expand Down
16 changes: 16 additions & 0 deletions src/test/java/DryRunGridFSTemplate/TestDryRunGridFSTemplate.java
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 6b61edc

Please sign in to comment.