From b4862828b08115ebe7b70b21da428ffa1ca3859f Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Tue, 3 Aug 2010 23:47:52 -0300 Subject: [PATCH] Implemented AUTH --- src/main/java/redis/clients/jedis/Client.java | 4 +++ src/main/java/redis/clients/jedis/Jedis.java | 5 ++++ .../commands/AllKindOfValuesCommandsTest.java | 21 +------------ .../ConnectionHandlingCommandsTest.java | 28 +---------------- .../tests/commands/HashesCommandsTest.java | 21 +------------ .../tests/commands/JedisCommandTestBase.java | 30 +++++++++++++++++++ .../tests/commands/ListCommandsTest.java | 20 +------------ .../jedis/tests/commands/SetCommandsTest.java | 21 +------------ .../tests/commands/SortedSetCommandsTest.java | 21 +------------ .../tests/commands/SortingCommandsTest.java | 22 +------------- .../commands/StringValuesCommandsTest.java | 21 +------------ .../commands/TransactionCommandsTest.java | 22 ++------------ 12 files changed, 50 insertions(+), 186 deletions(-) create mode 100644 src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index b6403a1..25d6279 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -417,4 +417,8 @@ public class Client extends Connection { public void brpop(String[] args) throws JedisException { sendCommand("BRPOP", args); } + + public void auth(String password) throws JedisException { + sendCommand("AUTH", password); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 56902ac..2891231 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -542,4 +542,9 @@ public class Jedis { client.brpop(args.toArray(new String[args.size()])); return client.getMultiBulkReply(); } + + public String auth(String password) throws JedisException { + client.auth(password); + return client.getStatusCodeReply(); + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java index ede6083..44e90c7 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java @@ -3,30 +3,11 @@ package redis.clients.jedis.tests.commands; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; -public class AllKindOfValuesCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class AllKindOfValuesCommandsTest extends JedisCommandTestBase { @Test public void ping() throws JedisException { String status = jedis.ping(); diff --git a/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java index 5af3d82..6d6ac31 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ConnectionHandlingCommandsTest.java @@ -1,38 +1,12 @@ package redis.clients.jedis.tests.commands; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; -public class ConnectionHandlingCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class ConnectionHandlingCommandsTest extends JedisCommandTestBase { @Test public void quit() throws JedisException { jedis.quit(); } - - @Test - @Ignore(value = "Need to implement!") - public void auth() { - - } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java index 2e1db6c..f358a64 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/HashesCommandsTest.java @@ -6,30 +6,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; -public class HashesCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class HashesCommandsTest extends JedisCommandTestBase { @Test public void hset() throws JedisException { int status = jedis.hset("foo", "bar", "car"); diff --git a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java new file mode 100644 index 0000000..242fa68 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java @@ -0,0 +1,30 @@ +package redis.clients.jedis.tests.commands; + +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; + +import redis.clients.jedis.Jedis; + +public class JedisCommandTestBase extends Assert { + + protected Jedis jedis; + + public JedisCommandTestBase() { + super(); + } + + @Before + public void setUp() throws Exception { + jedis = new Jedis("localhost"); + jedis.connect(); + jedis.auth("foobared"); + jedis.flushDB(); + } + + @After + public void tearDown() throws Exception { + jedis.disconnect(); + } +} \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java index 543a7b8..171edb5 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java @@ -3,30 +3,12 @@ package redis.clients.jedis.tests.commands; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; -public class ListCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class ListCommandsTest extends JedisCommandTestBase { @Test public void rpush() throws JedisException { int size = jedis.rpush("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java index 30b22fc..abb0c32 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SetCommandsTest.java @@ -3,30 +3,11 @@ package redis.clients.jedis.tests.commands; import java.util.LinkedHashSet; import java.util.Set; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; -public class SetCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class SetCommandsTest extends JedisCommandTestBase { @Test public void sadd() throws JedisException { int status = jedis.sadd("foo", "a"); diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java index cc924ba..d895928 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SortedSetCommandsTest.java @@ -3,31 +3,12 @@ package redis.clients.jedis.tests.commands; import java.util.LinkedHashSet; import java.util.Set; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; import redis.clients.jedis.Tuple; -public class SortedSetCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class SortedSetCommandsTest extends JedisCommandTestBase { @Test public void zadd() throws JedisException { int status = jedis.zadd("foo", 1d, "a"); diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java index 765594a..da84e0b 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java @@ -3,32 +3,12 @@ package redis.clients.jedis.tests.commands; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; import redis.clients.jedis.SortingParams; -public class SortingCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - jedis.flushDB(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class SortingCommandsTest extends JedisCommandTestBase { @Test public void sort() throws JedisException { jedis.lpush("foo", "3"); diff --git a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java index c908a03..cb12466 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java @@ -3,30 +3,11 @@ package redis.clients.jedis.tests.commands; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisException; -public class StringValuesCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class StringValuesCommandsTest extends JedisCommandTestBase { @Test public void setAndGet() throws JedisException { String status = jedis.set("foo", "bar"); diff --git a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java index 8da1e82..8b96f09 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java @@ -5,10 +5,6 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; import redis.clients.jedis.Jedis; @@ -16,21 +12,7 @@ import redis.clients.jedis.JedisException; import redis.clients.jedis.Transaction; import redis.clients.jedis.TransactionBlock; -public class TransactionCommandsTest extends Assert { - private Jedis jedis; - - @Before - public void setUp() throws Exception { - jedis = new Jedis("localhost"); - jedis.connect(); - } - - @After - public void tearDown() throws Exception { - jedis.flushDB(); - jedis.disconnect(); - } - +public class TransactionCommandsTest extends JedisCommandTestBase { @Test public void multi() throws JedisException { Transaction trans = jedis.multi(); @@ -85,6 +67,7 @@ public class TransactionCommandsTest extends Assert { Jedis nj = new Jedis("localhost"); nj.connect(); + nj.auth("foobared"); nj.set("mykey", "bar"); nj.disconnect(); @@ -105,6 +88,7 @@ public class TransactionCommandsTest extends Assert { Jedis nj = new Jedis("localhost"); nj.connect(); + nj.auth("foobared"); nj.set("mykey", "bar"); nj.disconnect();