Bael 4461 3 (#4557)

* [BAEL-4462] - Fixed integration tests

* [BAEL-7055] - Fix JUNIT in core java module
This commit is contained in:
Amit Pandey
2018-06-27 12:45:09 +05:30
committed by Grzegorz Piwowarek
parent 9c8d31aae6
commit e3978a5f95
11 changed files with 163 additions and 61 deletions
@@ -1,28 +1,45 @@
package com.baeldung;
import org.junit.*;
import redis.clients.jedis.*;
import redis.embedded.RedisServer;
import java.io.IOException;
import java.net.ServerSocket;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.embedded.RedisServer;
public class JedisIntegrationTest {
private Jedis jedis;
private static Jedis jedis;
private static RedisServer redisServer;
public JedisIntegrationTest() {
jedis = new Jedis();
}
private static int port;
@BeforeClass
public static void setUp() throws IOException {
redisServer = new RedisServer(6379);
// Take an available port
ServerSocket s = new ServerSocket(0);
port = s.getLocalPort();
s.close();
redisServer = new RedisServer(port);
redisServer.start();
// Configure JEDIS
jedis = new Jedis("localhost", port);
}
@AfterClass
@@ -178,7 +195,7 @@ public class JedisIntegrationTest {
public void givenAPoolConfiguration_thenCreateAJedisPool() {
final JedisPoolConfig poolConfig = buildPoolConfig();
try (JedisPool jedisPool = new JedisPool(poolConfig, "localhost"); Jedis jedis = jedisPool.getResource()) {
try (JedisPool jedisPool = new JedisPool(poolConfig, "localhost", port); Jedis jedis = jedisPool.getResource()) {
// do simple operation to verify that the Jedis resource is working
// properly
@@ -1,15 +1,20 @@
package com.baeldung;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.nio.charset.Charset;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import redis.embedded.RedisServer;
import java.io.File;
import java.io.IOException;
import com.google.common.io.Files;
import redis.embedded.RedisServer;
/**
* Created by johnson on 3/9/17.
@@ -17,10 +22,17 @@ import java.io.IOException;
public class RedissonConfigurationIntegrationTest {
private static RedisServer redisServer;
private static RedissonClient client;
private static int port;
@BeforeClass
public static void setUp() throws IOException {
redisServer = new RedisServer(6379);
// Take an available port
ServerSocket s = new ServerSocket(0);
port = s.getLocalPort();
s.close();
redisServer = new RedisServer(port);
redisServer.start();
}
@@ -36,7 +48,7 @@ public class RedissonConfigurationIntegrationTest {
public void givenJavaConfig_thenRedissonConnectToRedis() {
Config config = new Config();
config.useSingleServer()
.setAddress("127.0.0.1:6379");
.setAddress(String.format("127.0.0.1:%s", port));
client = Redisson.create(config);
@@ -45,10 +57,11 @@ public class RedissonConfigurationIntegrationTest {
@Test
public void givenJSONFileConfig_thenRedissonConnectToRedis() throws IOException {
Config config = Config.fromJSON(
new File(getClass().getClassLoader().getResource(
"singleNodeConfig.json").getFile()));
File configFile = new File(getClass().getClassLoader().getResource("singleNodeConfig.json").getFile());
String configContent = Files.toString(configFile, Charset.defaultCharset()).replace("6379", String.valueOf(port));
Config config = Config.fromJSON(configContent);
client = Redisson.create(config);
assert(client != null && client.getKeys().count() >= 0);
@@ -56,10 +69,11 @@ public class RedissonConfigurationIntegrationTest {
@Test
public void givenYAMLFileConfig_thenRedissonConnectToRedis() throws IOException {
Config config = Config.fromYAML(
new File(getClass().getClassLoader().getResource(
"singleNodeConfig.yaml").getFile()));
File configFile = new File(getClass().getClassLoader().getResource("singleNodeConfig.yaml").getFile());
String configContent = Files.toString(configFile, Charset.defaultCharset()).replace("6379", String.valueOf(port));
Config config = Config.fromYAML(configContent);
client = Redisson.create(config);
assert(client != null && client.getKeys().count() >= 0);