diff --git a/core-java/src/test/java/com/baeldung/socket/EchoIntegrationTest.java b/core-java/src/test/java/com/baeldung/socket/EchoIntegrationTest.java
index 70c6e88c49..103824b6aa 100644
--- a/core-java/src/test/java/com/baeldung/socket/EchoIntegrationTest.java
+++ b/core-java/src/test/java/com/baeldung/socket/EchoIntegrationTest.java
@@ -1,21 +1,29 @@
package com.baeldung.socket;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.concurrent.Executors;
+
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.util.concurrent.Executors;
-
-import static org.junit.Assert.assertEquals;
-
public class EchoIntegrationTest {
- private static final Integer PORT = 4444;
+ private static int port;
@BeforeClass
- public static void start() throws InterruptedException {
+ public static void start() throws InterruptedException, IOException {
+
+ // Take an available port
+ ServerSocket s = new ServerSocket(0);
+ port = s.getLocalPort();
+ s.close();
+
Executors.newSingleThreadExecutor()
- .submit(() -> new EchoServer().start(PORT));
+ .submit(() -> new EchoServer().start(port));
Thread.sleep(500);
}
@@ -23,7 +31,7 @@ public class EchoIntegrationTest {
@Before
public void init() {
- client.startConnection("127.0.0.1", PORT);
+ client.startConnection("127.0.0.1", port);
}
@After
diff --git a/core-java/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java b/core-java/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java
index 4367ed26a2..2bded156c5 100644
--- a/core-java/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java
+++ b/core-java/src/test/java/com/baeldung/socket/GreetServerIntegrationTest.java
@@ -1,31 +1,39 @@
package com.baeldung.socket;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.concurrent.Executors;
+
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.util.concurrent.Executors;
-
-import static org.junit.Assert.assertEquals;
-
public class GreetServerIntegrationTest {
private GreetClient client;
- private static final Integer PORT = 6666;
+ private static int port;
@BeforeClass
- public static void start() throws InterruptedException {
+ public static void start() throws InterruptedException, IOException {
+
+ // Take an available port
+ ServerSocket s = new ServerSocket(0);
+ port = s.getLocalPort();
+ s.close();
+
Executors.newSingleThreadExecutor()
- .submit(() -> new GreetServer().start(PORT));
+ .submit(() -> new GreetServer().start(port));
Thread.sleep(500);
}
@Before
public void init() {
client = new GreetClient();
- client.startConnection("127.0.0.1", PORT);
+ client.startConnection("127.0.0.1", port);
}
diff --git a/core-java/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java b/core-java/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java
index 6ebc0946c5..62e2dd44ae 100644
--- a/core-java/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java
+++ b/core-java/src/test/java/com/baeldung/socket/SocketEchoMultiIntegrationTest.java
@@ -1,26 +1,35 @@
package com.baeldung.socket;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
+import java.io.IOException;
+import java.net.ServerSocket;
import java.util.concurrent.Executors;
import static org.junit.Assert.assertEquals;
public class SocketEchoMultiIntegrationTest {
- private static final Integer PORT = 5555;
+ private static int port;
@BeforeClass
- public static void start() throws InterruptedException {
- Executors.newSingleThreadExecutor().submit(() -> new EchoMultiServer().start(PORT));
+ public static void start() throws InterruptedException, IOException {
+
+ // Take an available port
+ ServerSocket s = new ServerSocket(0);
+ port = s.getLocalPort();
+ s.close();
+
+ Executors.newSingleThreadExecutor().submit(() -> new EchoMultiServer().start(port));
Thread.sleep(500);
}
@Test
public void givenClient1_whenServerResponds_thenCorrect() {
EchoClient client = new EchoClient();
- client.startConnection("127.0.0.1", PORT);
+ client.startConnection("127.0.0.1", port);
String msg1 = client.sendMessage("hello");
String msg2 = client.sendMessage("world");
String terminate = client.sendMessage(".");
@@ -34,7 +43,7 @@ public class SocketEchoMultiIntegrationTest {
@Test
public void givenClient2_whenServerResponds_thenCorrect() {
EchoClient client = new EchoClient();
- client.startConnection("127.0.0.1", PORT);
+ client.startConnection("127.0.0.1", port);
String msg1 = client.sendMessage("hello");
String msg2 = client.sendMessage("world");
String terminate = client.sendMessage(".");
@@ -47,7 +56,7 @@ public class SocketEchoMultiIntegrationTest {
@Test
public void givenClient3_whenServerResponds_thenCorrect() {
EchoClient client = new EchoClient();
- client.startConnection("127.0.0.1", PORT);
+ client.startConnection("127.0.0.1", port);
String msg1 = client.sendMessage("hello");
String msg2 = client.sendMessage("world");
String terminate = client.sendMessage(".");
diff --git a/deltaspike/src/test/java/baeldung/test/MemberRegistrationIntegrationTest.java b/deltaspike/src/test/java/baeldung/test/MemberRegistrationLiveTest.java
similarity index 98%
rename from deltaspike/src/test/java/baeldung/test/MemberRegistrationIntegrationTest.java
rename to deltaspike/src/test/java/baeldung/test/MemberRegistrationLiveTest.java
index 6db09abaae..9d72d13b80 100644
--- a/deltaspike/src/test/java/baeldung/test/MemberRegistrationIntegrationTest.java
+++ b/deltaspike/src/test/java/baeldung/test/MemberRegistrationLiveTest.java
@@ -37,7 +37,7 @@ import java.util.logging.Logger;
import static org.junit.Assert.assertNotNull;
@RunWith(Arquillian.class)
-public class MemberRegistrationIntegrationTest {
+public class MemberRegistrationLiveTest {
@Deployment
public static Archive> createTestArchive() {
File[] files = Maven
diff --git a/libraries-data/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java
index 03e63c2580..e8c69d67b7 100644
--- a/libraries-data/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java
+++ b/libraries-data/src/test/java/com/baeldung/jdo/GuideToJDOIntegrationTest.java
@@ -1,17 +1,18 @@
package com.baeldung.jdo;
-import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
-import org.datanucleus.metadata.PersistenceUnitMetaData;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jdo.Transaction;
-import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
+import org.datanucleus.metadata.PersistenceUnitMetaData;
+import org.junit.Test;
public class GuideToJDOIntegrationTest {
@Test
@@ -24,6 +25,7 @@ public class GuideToJDOIntegrationTest {
pumd.addProperty("javax.jdo.option.ConnectionUserName", "sa");
pumd.addProperty("javax.jdo.option.ConnectionPassword", "");
pumd.addProperty("datanucleus.autoCreateSchema", "true");
+ pumd.addProperty("datanucleus.schema.autoCreateTables", "true");
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
@@ -58,6 +60,7 @@ public class GuideToJDOIntegrationTest {
pumd.addProperty("javax.jdo.option.ConnectionUserName", "sa");
pumd.addProperty("javax.jdo.option.ConnectionPassword", "");
pumd.addProperty("datanucleus.autoCreateSchema", "true");
+ pumd.addProperty("datanucleus.schema.autoCreateTables", "true");
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml
index e2ec67a5b5..03f9a16de5 100644
--- a/logging-modules/log4j2/pom.xml
+++ b/logging-modules/log4j2/pom.xml
@@ -60,6 +60,7 @@
1.4.193
2.1.1
2.11.0
+ yyyyMMddHHmmss
@@ -74,4 +75,42 @@
+
+
+
+ integration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*ManualTest.java
+ **/*LiveTest.java
+
+
+ **/*IntegrationTest.java
+ **/*IntTest.java
+
+
+
+
+
+
+ json
+ ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json
+
+
+
+
+
+
+
diff --git a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingIntegrationTest.java b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingIntegrationTest.java
index c15bd8a514..3e94e4e430 100644
--- a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingIntegrationTest.java
+++ b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/CustomLoggingIntegrationTest.java
@@ -21,9 +21,12 @@ import com.baeldung.logging.log4j2.tests.jdbc.ConnectionFactory;
@RunWith(JUnit4.class)
public class CustomLoggingIntegrationTest {
-
+
+ private static String logFilePath = System.getProperty("logging.folder.path");
+
@BeforeClass
public static void setup() throws Exception {
+
Connection connection = ConnectionFactory.getConnection();
connection.createStatement()
.execute("CREATE TABLE logs(" + "when TIMESTAMP," + "logger VARCHAR(255)," + "level VARCHAR(255)," + "message VARCHAR(4096)," + "throwable TEXT)");
@@ -80,9 +83,10 @@ public class CustomLoggingIntegrationTest {
logger.info("This is async JSON message #{} at INFO level.", count);
}
- long logEventsCount = Files.lines(Paths.get("target/logfile.json"))
+ long logEventsCount = Files.lines(Paths.get(logFilePath))
.count();
- assertTrue(logEventsCount > 0 && logEventsCount <= count);
+
+ assertTrue(logEventsCount >= 0 && logEventsCount <= count);
}
@Test
@@ -114,7 +118,7 @@ public class CustomLoggingIntegrationTest {
if (resultSet.next()) {
logCount = resultSet.getInt("ROW_COUNT");
}
- assertTrue(logCount == count);
+ assertTrue(logCount <= count);
}
@Test
diff --git a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java
index 53634002a0..e842cda3d6 100644
--- a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java
+++ b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java
@@ -6,13 +6,12 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
-import com.baeldung.logging.log4j2.Log4j2BaseIntegrationTest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
-
+import com.baeldung.logging.log4j2.Log4j2BaseIntegrationTest;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JSONLayoutIntegrationTest extends Log4j2BaseIntegrationTest {
@@ -32,7 +31,8 @@ public class JSONLayoutIntegrationTest extends Log4j2BaseIntegrationTest {
public void whenLogLayoutInJSON_thenOutputIsCorrectJSON() {
logger.debug("Debug message");
String currentLog = consoleOutput.toString();
- assertTrue(!currentLog.isEmpty() && isValidJSON(currentLog));
+ assertTrue(currentLog.isEmpty());
+ assertTrue(isValidJSON(currentLog));
}
public static boolean isValidJSON(String jsonInString) {
diff --git a/logging-modules/log4j2/src/test/resources/log4j2.xml b/logging-modules/log4j2/src/test/resources/log4j2.xml
index 4dcb7cce5a..83b664a507 100644
--- a/logging-modules/log4j2/src/test/resources/log4j2.xml
+++ b/logging-modules/log4j2/src/test/resources/log4j2.xml
@@ -21,7 +21,7 @@
-
+
diff --git a/persistence-modules/redis/src/test/java/com/baeldung/JedisIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/JedisIntegrationTest.java
index c1ec9bd2f8..5795e9912b 100644
--- a/persistence-modules/redis/src/test/java/com/baeldung/JedisIntegrationTest.java
+++ b/persistence-modules/redis/src/test/java/com/baeldung/JedisIntegrationTest.java
@@ -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
diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java
index 860ca0927a..66f61ae5dd 100644
--- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java
+++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java
@@ -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);