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,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
@@ -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);
}
@@ -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(".");