Last active
July 1, 2016 11:43
-
-
Save mp911de/73d4b95b04a66eae084395beb25bd499 to your computer and use it in GitHub Desktop.
Self-contained Spring Data Redis Test using Spring Boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.testcase</groupId> | |
<artifactId>testcase</artifactId> | |
<version>0.1.0-SNAPSHOT</version> | |
<name>spring-data-redis-test-case</name> | |
<description>Self-contained Spring Data Redis Test using Spring Boot</description> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>1.3.5.RELEASE</version> | |
<relativePath/> | |
</parent> | |
<repositories> | |
<repository> | |
<id>spring-snapshots</id> | |
<name>Spring Snapshots</name> | |
<url>https://repo.spring.io/libs-snapshot</url> | |
<snapshots> | |
<enabled>true</enabled> | |
</snapshots> | |
</repository> | |
</repositories> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<java.version>1.8</java.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-data-redis</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.projectlombok</groupId> | |
<artifactId>lombok</artifactId> | |
<version>1.16.8</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-test</artifactId> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.test.SpringApplicationConfiguration; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.data.redis.core.RedisOperations; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
/** | |
* Test case for: | |
* @author | |
*/ | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = SpringDataRedisTests.Config.class) | |
public class SpringDataRedisTests { | |
@Autowired | |
RedisOperations<String, String> redisOperations; | |
@Test | |
public void contextLoads() { | |
redisOperations.opsForValue().set("key", "value"); | |
assertEquals("value", redisOperations.opsForValue().get("key")); | |
} | |
@SpringBootApplication | |
@Configuration | |
static class Config { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment