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

View File

@@ -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);