Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ScienJus committed Mar 4, 2016
1 parent d67e615 commit 68407fe
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 2 deletions.
19 changes: 19 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 22,46 @@
<version>4.2.2.RELEASE</version>
<scope>provided</scope>
</dependency>

<!--JDBC-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.2.RELEASE</version>
<scope>provided</scope>
</dependency>

<!--Redis-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
<scope>provided</scope>
</dependency>

<!--Servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<!--test-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.2.RELEASE</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,7 @@ public void setJedisPool(JedisPool jedisPool) {
}

@Override
public void delSingleRelationshipByKey(String key) {
protected void delSingleRelationshipByKey(String key) {
String token = getToken(key);
if (token != null) {
delete(formatKey(key), formatToken(token));
Expand Down Expand Up @@ -63,7 63,7 @@ protected void createMultipleRelationship(String key, String token) {
}

@Override
public String getKeyByToken(String token) {
protected String getKeyByToken(String token) {
return get(formatToken(token));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,101 @@
package com.scienjus.authorization.test;

import com.scienjus.authorization.manager.impl.RedisTokenManager;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.io.IOException;

import static org.junit.Assert.*;

/**
* @author XieEnlong
* @date 2016/3/1.
*/
public class RedisTokenManagerTest {


private static JedisPool jedisPool;

private RedisTokenManager tokenManager;

private static final String KEY = "key";

private static final String TOKEN = "token";

private static final String ANOTHER_TOKEN = "another_token";

@BeforeClass
public static void startup() throws IOException {
jedisPool = new JedisPool("localhost", 6379);
}

@Before
public void init() {
try (Jedis jedis = jedisPool.getResource()) {
jedis.flushAll();
}
tokenManager = new RedisTokenManager();
tokenManager.setJedisPool(jedisPool);
}

@Test
public void testCreate() {
tokenManager.createRelationship(KEY, TOKEN);

assertEquals(KEY, tokenManager.getKey(TOKEN));
}

@Test
public void testDelByKey() {
tokenManager.createRelationship(KEY, TOKEN);

tokenManager.delRelationshipByKey(KEY);

assertNull(tokenManager.getKey(TOKEN));
}

@Test
public void testDelByToken() {
tokenManager.createRelationship(KEY, TOKEN);

tokenManager.delRelationshipByToken(TOKEN);

assertNull(tokenManager.getKey(TOKEN));
}

@Test
public void testSingleRelationship() {
tokenManager.createRelationship(KEY, TOKEN);

tokenManager.createRelationship(KEY, ANOTHER_TOKEN);

assertNull(tokenManager.getKey(TOKEN));

assertEquals(KEY, tokenManager.getKey(ANOTHER_TOKEN));
}

@Test
public void testMultipleRelationship() {
tokenManager.setSingleTokenWithUser(false);

tokenManager.createRelationship(KEY, TOKEN);

tokenManager.createRelationship(KEY, ANOTHER_TOKEN);

assertEquals(KEY, tokenManager.getKey(TOKEN));

assertEquals(KEY, tokenManager.getKey(ANOTHER_TOKEN));
}

@AfterClass
public static void shutdown() {
jedisPool.close();
}


}

0 comments on commit 68407fe

Please sign in to comment.