Merge branch 'eugenp:master' into JAVA-23970
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ public class ApacheHttpClient5UnitTest {
|
||||
public static final String DUMMY_URL = "https://postman-echo.com/get";
|
||||
|
||||
@Test
|
||||
public void whenUseApacheHttpClient_thenCorrect() throws IOException {
|
||||
void whenUseApacheHttpClient_thenCorrect() throws IOException {
|
||||
HttpGet request = new HttpGet(DUMMY_URL);
|
||||
|
||||
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
||||
|
||||
+4
-3
@@ -1,6 +1,5 @@
|
||||
package com.baeldung.httpclient.readresponsebodystring;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -8,11 +7,13 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
public class HttpClientUnitTest {
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HttpClientUnitTest {
|
||||
public static final String DUMMY_URL = "https://postman-echo.com/get";
|
||||
|
||||
@Test
|
||||
public void whenUseHttpClient_thenCorrect() throws IOException, InterruptedException {
|
||||
void whenUseHttpClient_thenCorrect() throws IOException, InterruptedException {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(DUMMY_URL)).build();
|
||||
|
||||
|
||||
+6
-4
@@ -1,7 +1,7 @@
|
||||
package com.baeldung.httpclient.readresponsebodystring;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -10,12 +10,14 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class HttpUrlConnectionUnitTest {
|
||||
|
||||
public static final String DUMMY_URL = "https://postman-echo.com/get";
|
||||
|
||||
@Test
|
||||
public void whenUseHttpUrlConnection_thenCorrect() throws IOException {
|
||||
void whenUseHttpUrlConnection_thenCorrect() throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(DUMMY_URL).openConnection();
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
@@ -28,7 +30,7 @@ public class HttpUrlConnectionUnitTest {
|
||||
response.append(currentLine);
|
||||
|
||||
in.close();
|
||||
Assert.assertNotNull(response.toString());
|
||||
assertNotNull(response.toString());
|
||||
System.out.println("Response -> " + response.toString());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.httpclient.readresponsebodystring;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class SpringRestTemplateUnitTest {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.httpclient.readresponsebodystring;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class SpringWebClientUnitTest {
|
||||
public static final String DUMMY_URL = "https://postman-echo.com/get";
|
||||
|
||||
@Test
|
||||
public void whenUseWebClientRetrieve_thenCorrect() {
|
||||
void whenUseWebClientRetrieve_thenCorrect() {
|
||||
WebClient webClient = WebClient.create(DUMMY_URL);
|
||||
Mono<String> body = webClient.get().retrieve().bodyToMono(String.class);
|
||||
String s = body.block();
|
||||
|
||||
Reference in New Issue
Block a user