diff --git a/libraries-http-2/pom.xml b/libraries-http-2/pom.xml
index 96f9e2911d..d0bdb26bd4 100644
--- a/libraries-http-2/pom.xml
+++ b/libraries-http-2/pom.xml
@@ -84,7 +84,6 @@
3.14.2
2.8.5
3.14.2
-
1.0.3
9.4.19.v20190610
2.2.11
diff --git a/libraries-http-2/src/main/resources/logback.xml b/libraries-http-2/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/libraries-http-2/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java
index 4a3e67a7c5..876586032a 100644
--- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java
+++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/AbstractUnitTest.java
@@ -3,23 +3,16 @@ package com.baeldung.jetty.httpclient;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
public abstract class AbstractUnitTest {
- protected HttpClient httpClient;
- protected Server server;
+ protected static HttpClient httpClient;
+ protected static Server server;
protected static final String CONTENT = "Hello World!";
- protected final int port = 9080;
-
- @Before
- public void init() {
- startServer(new RequestHandler());
- startClient();
- }
- private void startClient() {
+ protected static void startClient() {
httpClient = new HttpClient();
try {
httpClient.start();
@@ -28,7 +21,7 @@ public abstract class AbstractUnitTest {
}
}
- private void startServer(Handler handler) {
+ protected static void startServer(Handler handler, int port) {
server = new Server(port);
server.setHandler(handler);
try {
@@ -37,18 +30,9 @@ public abstract class AbstractUnitTest {
e.printStackTrace();
}
}
-
- @After
- public void dispose() throws Exception {
- if (httpClient != null) {
- httpClient.stop();
- }
- if (server != null) {
- server.stop();
- }
- }
-
- protected String uri() {
+
+ protected String uri(int port) {
return "http://localhost:" + port;
}
+
}
\ No newline at end of file
diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java
index 6d79773609..db27ea1c89 100644
--- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java
+++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ProjectReactorUnitTest.java
@@ -4,18 +4,29 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.reactive.client.ReactiveRequest;
import org.eclipse.jetty.reactive.client.ReactiveResponse;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
public class ProjectReactorUnitTest extends AbstractUnitTest {
+ protected static int port = 9080;
+
+ @BeforeAll
+ public static void init() {
+ startServer(new RequestHandler(), port);
+ startClient();
+ }
+
@Test
public void givenReactiveClient_whenRequested_shouldReturn200() throws Exception {
- Request request = httpClient.newRequest(uri());
+ Request request = httpClient.newRequest(uri(port));
ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request)
.build();
Publisher publisher = reactiveRequest.response();
@@ -23,8 +34,19 @@ public class ProjectReactorUnitTest extends AbstractUnitTest {
ReactiveResponse response = Mono.from(publisher)
.block();
- Assert.assertNotNull(response);
- Assert.assertEquals(response.getStatus(), HttpStatus.OK_200);
+ assertNotNull(response);
+ assertEquals(response.getStatus(), HttpStatus.OK_200);
}
+
+ @AfterAll
+ public static void dispose() throws Exception {
+ if (httpClient != null) {
+ httpClient.stop();
+ }
+ if (server != null) {
+ server.stop();
+ }
+ }
+
}
diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java
index 3db4553c86..494d65e9e1 100644
--- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java
+++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/ReactiveStreamsUnitTest.java
@@ -4,16 +4,27 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.reactive.client.ReactiveRequest;
import org.eclipse.jetty.reactive.client.ReactiveResponse;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
public class ReactiveStreamsUnitTest extends AbstractUnitTest {
+
+ protected static int port = 9081;
+
+ @BeforeAll
+ public static void init() {
+ startServer(new RequestHandler(), port);
+ startClient();
+ }
@Test
public void givenReactiveClient_whenRequested_shouldReturn200() throws Exception {
- Request request = httpClient.newRequest(uri());
+ Request request = httpClient.newRequest(uri(port));
ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request)
.build();
Publisher publisher = reactiveRequest.response();
@@ -21,8 +32,18 @@ public class ReactiveStreamsUnitTest extends AbstractUnitTest {
BlockingSubscriber subscriber = new BlockingSubscriber();
publisher.subscribe(subscriber);
ReactiveResponse response = subscriber.block();
- Assert.assertNotNull(response);
- Assert.assertEquals(response.getStatus(), HttpStatus.OK_200);
+ assertNotNull(response);
+ assertEquals(response.getStatus(), HttpStatus.OK_200);
+ }
+
+ @AfterAll
+ public static void dispose() throws Exception {
+ if (httpClient != null) {
+ httpClient.stop();
+ }
+ if (server != null) {
+ server.stop();
+ }
}
}
diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java
index dabd768702..a819eec475 100644
--- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java
+++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/RxJava2UnitTest.java
@@ -10,8 +10,11 @@ import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.reactive.client.ReactiveRequest;
import org.eclipse.jetty.reactive.client.ReactiveRequest.Event.Type;
import org.eclipse.jetty.reactive.client.ReactiveResponse;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import org.springframework.http.MediaType;
@@ -19,11 +22,19 @@ import io.reactivex.Flowable;
import io.reactivex.Single;
public class RxJava2UnitTest extends AbstractUnitTest {
+
+ protected static int port = 9082;
+
+ @BeforeAll
+ public static void init() {
+ startServer(new RequestHandler(), port);
+ startClient();
+ }
@Test
public void givenReactiveClient_whenRequestedWithBody_ShouldReturnBody() throws Exception {
- Request request = httpClient.newRequest(uri());
+ Request request = httpClient.newRequest(uri(port));
ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request)
.content(ReactiveRequest.Content.fromString(CONTENT, MediaType.TEXT_PLAIN_VALUE, UTF_8))
.build();
@@ -32,12 +43,12 @@ public class RxJava2UnitTest extends AbstractUnitTest {
String responseContent = Single.fromPublisher(publisher)
.blockingGet();
- Assert.assertEquals(CONTENT, responseContent);
+ assertEquals(CONTENT, responseContent);
}
@Test
public void givenReactiveClient_whenRequested_ShouldPrintEvents() throws Exception {
- ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri())
+ ReactiveRequest request = ReactiveRequest.newBuilder(httpClient, uri(port))
.content(ReactiveRequest.Content.fromString(CONTENT, MediaType.TEXT_PLAIN_VALUE, UTF_8))
.build();
Publisher requestEvents = request.requestEvents();
@@ -58,10 +69,20 @@ public class RxJava2UnitTest extends AbstractUnitTest {
int actualStatus = response.blockingGet()
.getStatus();
- Assert.assertEquals(6, requestEventTypes.size());
- Assert.assertEquals(5, responseEventTypes.size());
+ assertEquals(6, requestEventTypes.size());
+ assertEquals(5, responseEventTypes.size());
- Assert.assertEquals(actualStatus, HttpStatus.OK_200);
+ assertEquals(actualStatus, HttpStatus.OK_200);
+ }
+
+ @AfterAll
+ public static void dispose() throws Exception {
+ if (httpClient != null) {
+ httpClient.stop();
+ }
+ if (server != null) {
+ server.stop();
+ }
}
}
\ No newline at end of file
diff --git a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java
index 4a1a9bb2b5..f14fc38e1d 100644
--- a/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java
+++ b/libraries-http-2/src/test/java/com/baeldung/jetty/httpclient/SpringWebFluxUnitTest.java
@@ -1,8 +1,11 @@
package com.baeldung.jetty.httpclient;
import org.eclipse.jetty.client.HttpClient;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.JettyClientHttpConnector;
@@ -12,25 +15,40 @@ import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
public class SpringWebFluxUnitTest extends AbstractUnitTest {
-
+
+ protected static int port = 9083;
+
+ @BeforeAll
+ public static void init() {
+ startServer(new RequestHandler(), port);
+ startClient();
+ }
+
@Test
public void givenReactiveClient_whenRequested_shouldReturnResponse() throws Exception {
-
- HttpClient httpClient = new HttpClient();
- httpClient.start();
ClientHttpConnector clientConnector = new JettyClientHttpConnector(httpClient);
WebClient client = WebClient.builder()
.clientConnector(clientConnector)
.build();
String responseContent = client.post()
- .uri(uri())
+ .uri(uri(port))
.contentType(MediaType.TEXT_PLAIN)
.body(BodyInserters.fromPublisher(Mono.just(CONTENT), String.class))
.retrieve()
.bodyToMono(String.class)
.block();
- Assert.assertNotNull(responseContent);
- Assert.assertEquals(CONTENT, responseContent);
+ assertNotNull(responseContent);
+ assertEquals(CONTENT, responseContent);
+ }
+
+ @AfterAll
+ public static void dispose() throws Exception {
+ if (httpClient != null) {
+ httpClient.stop();
+ }
+ if (server != null) {
+ server.stop();
+ }
}
}
\ No newline at end of file