mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-04 13:10:15 +00:00
8378595: Refactor miscellaneous tests under test/jdk/java/net/httpclient from TestNG to JUnit
Reviewed-by: syan, vyazici
This commit is contained in:
parent
373ad02d3a
commit
2c3e4f08fa
@ -214,6 +214,6 @@ public class BufferingSubscriberCancelTest {
|
||||
return;
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertEquals(expected, actual); // will fail with the usual testng message
|
||||
assertEquals(expected, actual); // will fail with the usual junit message
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -37,15 +37,11 @@
|
||||
* jdk.test.lib.net.SimpleSSLContext
|
||||
* jdk.test.lib.Platform
|
||||
* jdk.test.lib.util.FileUtils
|
||||
* @run testng/othervm BodyHandlerOfFileDownloadTest
|
||||
* @run junit/othervm BodyHandlerOfFileDownloadTest
|
||||
*/
|
||||
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.IOException;
|
||||
@ -73,28 +69,35 @@ import static java.net.http.HttpOption.H3_DISCOVERY;
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
||||
import static java.nio.file.StandardOpenOption.WRITE;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
|
||||
static final String MSG = "msg";
|
||||
static final String contentDispositionValue = "attachment; filename=example.html";
|
||||
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
|
||||
HttpTestServer httpsTestServer; // HTTPS/1.1
|
||||
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
|
||||
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
|
||||
HttpTestServer http3TestServer; // HTTP/3 ( h3 )
|
||||
String httpURI;
|
||||
String httpsURI;
|
||||
String http2URI;
|
||||
String https2URI;
|
||||
String http3URI;
|
||||
private static HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
|
||||
private static HttpTestServer httpsTestServer; // HTTPS/1.1
|
||||
private static HttpTestServer http2TestServer; // HTTP/2 ( h2c )
|
||||
private static HttpTestServer https2TestServer; // HTTP/2 ( h2 )
|
||||
private static HttpTestServer http3TestServer; // HTTP/3 ( h3 )
|
||||
private static String httpURI;
|
||||
private static String httpsURI;
|
||||
private static String http2URI;
|
||||
private static String https2URI;
|
||||
private static String http3URI;
|
||||
|
||||
FileSystem zipFs;
|
||||
Path defaultFsPath;
|
||||
Path zipFsPath;
|
||||
private static FileSystem zipFs;
|
||||
private static Path defaultFsPath;
|
||||
private static Path zipFsPath;
|
||||
|
||||
// Default file system
|
||||
|
||||
@ -106,12 +109,10 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
|
||||
return dir;
|
||||
}
|
||||
|
||||
@DataProvider(name = "defaultFsData")
|
||||
public Object[][] defaultFsData() {
|
||||
public static Object[][] defaultFsData() {
|
||||
return new Object[][]{
|
||||
{ http3URI, defaultFsPath, MSG, true },
|
||||
{ http3URI, defaultFsPath, MSG, false },
|
||||
|
||||
{ httpURI, defaultFsPath, MSG, true },
|
||||
{ httpsURI, defaultFsPath, MSG, true },
|
||||
{ http2URI, defaultFsPath, MSG, true },
|
||||
@ -123,7 +124,8 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "defaultFsData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("defaultFsData")
|
||||
public void testDefaultFs(String uriString,
|
||||
Path path,
|
||||
String expectedMsg,
|
||||
@ -171,10 +173,10 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
|
||||
out.printf("Resp code: %s\n", resp.statusCode());
|
||||
out.println("Resp body Path: " + resp.body());
|
||||
out.printf("Resp body written to file: %s\n", msg);
|
||||
assertEquals(resp.statusCode(), 200);
|
||||
assertEquals(msg, expectedMsg);
|
||||
assertEquals(200, resp.statusCode());
|
||||
assertEquals(expectedMsg, msg);
|
||||
assertTrue(resp.headers().firstValue("Content-Disposition").isPresent());
|
||||
assertEquals(resp.headers().firstValue("Content-Disposition").get(), contentDispositionValue);
|
||||
assertEquals(contentDispositionValue, resp.headers().firstValue("Content-Disposition").get());
|
||||
if (!sameClient) {
|
||||
client.close();
|
||||
}
|
||||
@ -199,15 +201,17 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
|
||||
return dir;
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testZipFs() {
|
||||
out.printf("\n\n--- testZipFs(): starting\n");
|
||||
BodyHandlers.ofFileDownload(zipFsPath, CREATE, TRUNCATE_EXISTING, WRITE);
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
out.printf("\n\n--- testZipFs(): starting\n");
|
||||
BodyHandlers.ofFileDownload(zipFsPath, CREATE, TRUNCATE_EXISTING, WRITE);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
defaultFsPath = defaultFsDir();
|
||||
zipFs = newZipFs();
|
||||
zipFsPath = zipFsDir(zipFs);
|
||||
@ -239,8 +243,8 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
|
||||
http3TestServer.start();
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void teardown() throws Exception {
|
||||
@AfterAll
|
||||
public static void teardown() throws Exception {
|
||||
if (Files.exists(zipFsPath))
|
||||
FileUtils.deleteFileTreeWithRetry(zipFsPath);
|
||||
if (Files.exists(defaultFsPath))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -36,15 +36,11 @@
|
||||
* jdk.httpclient.test.lib.http2.Queue
|
||||
* jdk.test.lib.net.SimpleSSLContext
|
||||
* jdk.test.lib.Platform jdk.test.lib.util.FileUtils
|
||||
* @run testng/othervm BodyHandlerOfFileTest
|
||||
* @run junit/othervm BodyHandlerOfFileTest
|
||||
*/
|
||||
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.IOException;
|
||||
@ -56,7 +52,10 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpRequest.BodyPublishers;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import jdk.httpclient.test.lib.common.HttpServerAdapters;
|
||||
import static java.lang.System.out;
|
||||
@ -66,26 +65,31 @@ import static java.net.http.HttpClient.Version.HTTP_2;
|
||||
import static java.net.http.HttpClient.Version.HTTP_3;
|
||||
import static java.net.http.HttpOption.Http3DiscoveryMode.HTTP_3_URI_ONLY;
|
||||
import static java.net.http.HttpOption.H3_DISCOVERY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
static final String MSG = "msg";
|
||||
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
|
||||
HttpTestServer httpsTestServer; // HTTPS/1.1
|
||||
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
|
||||
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
|
||||
HttpTestServer http3TestServer; // HTTP/3 ( h3 )
|
||||
String httpURI;
|
||||
String httpsURI;
|
||||
String http2URI;
|
||||
String https2URI;
|
||||
String http3URI;
|
||||
private static HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
|
||||
private static HttpTestServer httpsTestServer; // HTTPS/1.1
|
||||
private static HttpTestServer http2TestServer; // HTTP/2 ( h2c )
|
||||
private static HttpTestServer https2TestServer; // HTTP/2 ( h2 )
|
||||
private static HttpTestServer http3TestServer; // HTTP/3 ( h3 )
|
||||
private static String httpURI;
|
||||
private static String httpsURI;
|
||||
private static String http2URI;
|
||||
private static String https2URI;
|
||||
private static String http3URI;
|
||||
|
||||
FileSystem zipFs;
|
||||
Path defaultFsPath;
|
||||
Path zipFsPath;
|
||||
private static FileSystem zipFs;
|
||||
private static Path defaultFsPath;
|
||||
private static Path zipFsPath;
|
||||
|
||||
// Default file system set-up
|
||||
|
||||
@ -97,8 +101,7 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
return file;
|
||||
}
|
||||
|
||||
@DataProvider(name = "defaultFsData")
|
||||
public Object[][] defaultFsData() {
|
||||
public static Object[][] defaultFsData() {
|
||||
return new Object[][]{
|
||||
{ http3URI, defaultFsPath, MSG, true },
|
||||
{ http3URI, defaultFsPath, MSG, false },
|
||||
@ -114,7 +117,8 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "defaultFsData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("defaultFsData")
|
||||
public void testDefaultFs(String uriString,
|
||||
Path path,
|
||||
String expectedMsg,
|
||||
@ -139,8 +143,7 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
return file;
|
||||
}
|
||||
|
||||
@DataProvider(name = "zipFsData")
|
||||
public Object[][] zipFsData() {
|
||||
public static Object[][] zipFsData() {
|
||||
return new Object[][]{
|
||||
{ http3URI, zipFsPath, MSG, true },
|
||||
{ http3URI, zipFsPath, MSG, false },
|
||||
@ -156,7 +159,8 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "zipFsData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("zipFsData")
|
||||
public void testZipFs(String uriString,
|
||||
Path path,
|
||||
String expectedMsg,
|
||||
@ -203,8 +207,8 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
String msg = Files.readString(path, StandardCharsets.UTF_8);
|
||||
out.printf("Resp code: %s\n", resp.statusCode());
|
||||
out.printf("Msg written to %s: %s\n", resp.body(), msg);
|
||||
assertEquals(resp.statusCode(), 200);
|
||||
assertEquals(msg, expectedMsg);
|
||||
assertEquals(200, resp.statusCode());
|
||||
assertEquals(expectedMsg, msg);
|
||||
if (!sameClient) {
|
||||
client.close();
|
||||
}
|
||||
@ -214,8 +218,8 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
defaultFsPath = defaultFsFile();
|
||||
zipFs = newZipFs();
|
||||
zipFsPath = zipFsFile(zipFs);
|
||||
@ -247,8 +251,8 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
|
||||
http3TestServer.start();
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void teardown() throws Exception {
|
||||
@AfterAll
|
||||
public static void teardown() throws Exception {
|
||||
if (Files.exists(zipFsPath))
|
||||
FileUtils.deleteFileTreeWithRetry(zipFsPath);
|
||||
if (Files.exists(defaultFsPath))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -35,15 +35,11 @@
|
||||
* jdk.httpclient.test.lib.http2.OutgoingPushPromise
|
||||
* jdk.httpclient.test.lib.http2.Queue jdk.test.lib.net.SimpleSSLContext
|
||||
* jdk.test.lib.Platform jdk.test.lib.util.FileUtils
|
||||
* @run testng/othervm BodySubscriberOfFileTest
|
||||
* @run junit/othervm BodySubscriberOfFileTest
|
||||
*/
|
||||
|
||||
import jdk.test.lib.net.SimpleSSLContext;
|
||||
import jdk.test.lib.util.FileUtils;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.IOException;
|
||||
@ -58,7 +54,10 @@ import java.net.http.HttpResponse.BodySubscribers;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.stream.IntStream;
|
||||
@ -70,26 +69,32 @@ import static java.net.http.HttpClient.Version.HTTP_2;
|
||||
import static java.net.http.HttpClient.Version.HTTP_3;
|
||||
import static java.net.http.HttpOption.Http3DiscoveryMode.HTTP_3_URI_ONLY;
|
||||
import static java.net.http.HttpOption.H3_DISCOVERY;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
static final String MSG = "msg";
|
||||
|
||||
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
|
||||
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
|
||||
HttpTestServer httpsTestServer; // HTTPS/1.1
|
||||
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
|
||||
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
|
||||
HttpTestServer http3TestServer; // HTTP/3 ( h3 )
|
||||
String httpURI;
|
||||
String httpsURI;
|
||||
String http2URI;
|
||||
String https2URI;
|
||||
String http3URI;
|
||||
private static HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
|
||||
private static HttpTestServer httpsTestServer; // HTTPS/1.1
|
||||
private static HttpTestServer http2TestServer; // HTTP/2 ( h2c )
|
||||
private static HttpTestServer https2TestServer; // HTTP/2 ( h2 )
|
||||
private static HttpTestServer http3TestServer; // HTTP/3 ( h3 )
|
||||
private static String httpURI;
|
||||
private static String httpsURI;
|
||||
private static String http2URI;
|
||||
private static String https2URI;
|
||||
private static String http3URI;
|
||||
|
||||
FileSystem zipFs;
|
||||
Path defaultFsPath;
|
||||
Path zipFsPath;
|
||||
private static FileSystem zipFs;
|
||||
private static Path defaultFsPath;
|
||||
private static Path zipFsPath;
|
||||
|
||||
// Default file system set-up
|
||||
|
||||
@ -101,8 +106,7 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
return file;
|
||||
}
|
||||
|
||||
@DataProvider(name = "defaultFsData")
|
||||
public Object[][] defaultFsData() {
|
||||
public static Object[][] defaultFsData() {
|
||||
return new Object[][]{
|
||||
{ http3URI, defaultFsPath, MSG, true },
|
||||
{ http3URI, defaultFsPath, MSG, false },
|
||||
@ -118,7 +122,8 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "defaultFsData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("defaultFsData")
|
||||
public void testDefaultFs(String uriString,
|
||||
Path path,
|
||||
String expectedMsg,
|
||||
@ -143,8 +148,7 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
return file;
|
||||
}
|
||||
|
||||
@DataProvider(name = "zipFsData")
|
||||
public Object[][] zipFsData() {
|
||||
public static Object[][] zipFsData() {
|
||||
return new Object[][]{
|
||||
{ http3URI, zipFsPath, MSG, true },
|
||||
{ http3URI, zipFsPath, MSG, false },
|
||||
@ -160,7 +164,8 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "zipFsData")
|
||||
@ParameterizedTest
|
||||
@MethodSource("zipFsData")
|
||||
public void testZipFs(String uriString,
|
||||
Path path,
|
||||
String expectedMsg,
|
||||
@ -209,8 +214,8 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
String msg = Files.readString(path, StandardCharsets.UTF_8);
|
||||
out.printf("Resp code: %s\n", resp.statusCode());
|
||||
out.printf("Msg written to %s: %s\n", resp.body(), msg);
|
||||
assertEquals(resp.statusCode(), 200);
|
||||
assertEquals(msg, expectedMsg);
|
||||
assertEquals(200, resp.statusCode());
|
||||
assertEquals(expectedMsg, msg);
|
||||
if (!sameClient) {
|
||||
client.close();
|
||||
}
|
||||
@ -240,12 +245,12 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
});
|
||||
subscriber.onNext(buffers);
|
||||
subscriber.onComplete();
|
||||
buffers.forEach(b -> assertEquals(b.remaining(), 0) );
|
||||
buffers.forEach(b -> assertEquals(0, b.remaining()) );
|
||||
assertEquals(expectedSize, Files.size(defaultFsPath));
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
public void setup() throws Exception {
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
defaultFsPath = defaultFsFile();
|
||||
zipFs = newZipFs();
|
||||
zipFsPath = zipFsFile(zipFs);
|
||||
@ -277,8 +282,8 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
|
||||
http3TestServer.start();
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
public void teardown() throws Exception {
|
||||
@AfterAll
|
||||
public static void teardown() throws Exception {
|
||||
if (Files.exists(zipFsPath))
|
||||
FileUtils.deleteFileTreeWithRetry(zipFsPath);
|
||||
if (Files.exists(defaultFsPath))
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @summary Demonstrates how to achieve testing without network connections
|
||||
* @build DelegatingHttpClient FixedHttpResponse FixedResponseHttpClient
|
||||
* @run testng/othervm OfflineTesting
|
||||
* @run junit/othervm OfflineTesting
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
@ -40,13 +40,15 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiPredicate;
|
||||
import org.testng.annotations.Test;
|
||||
import static java.lang.String.format;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class OfflineTesting {
|
||||
|
||||
@ -72,9 +74,9 @@ public class OfflineTesting {
|
||||
client.sendAsync(request, BodyHandlers.ofString())
|
||||
.thenAccept(response -> {
|
||||
System.out.println("response: " + response);
|
||||
assertEquals(response.statusCode(), 200);
|
||||
assertEquals(200, response.statusCode());
|
||||
assertTrue(response.headers().firstValue("Server").isPresent());
|
||||
assertEquals(response.body(), "A response message");
|
||||
assertEquals("A response message", response.body());
|
||||
})
|
||||
.join();
|
||||
}
|
||||
@ -91,9 +93,9 @@ public class OfflineTesting {
|
||||
client.sendAsync(request, BodyHandlers.ofByteArray())
|
||||
.thenAccept(response -> {
|
||||
System.out.println("response: " + response);
|
||||
assertEquals(response.statusCode(), 200);
|
||||
assertEquals(200, response.statusCode());
|
||||
assertTrue(response.headers().firstValue("Content-Type").isPresent());
|
||||
assertEquals(response.body(), "A response message".getBytes(UTF_8));
|
||||
Assertions.assertArrayEquals("A response message".getBytes(UTF_8), response.body());
|
||||
})
|
||||
.join();
|
||||
}
|
||||
@ -125,9 +127,9 @@ public class OfflineTesting {
|
||||
try (var client = fixedClient) {
|
||||
client.sendAsync(request, BodyHandlers.ofString())
|
||||
.thenAccept(response -> {
|
||||
assertEquals(response.statusCode(), 404);
|
||||
assertEquals(404, response.statusCode());
|
||||
response.headers().firstValue("Content-Type")
|
||||
.ifPresentOrElse(type -> assertEquals(type, "text/html"),
|
||||
.ifPresentOrElse(type -> assertEquals("text/html", type),
|
||||
() -> fail("Content-Type not present"));
|
||||
assertTrue(response.body().contains("404 Not Found"));
|
||||
})
|
||||
@ -151,8 +153,8 @@ public class OfflineTesting {
|
||||
client.sendAsync(request, BodyHandlers.ofString())
|
||||
.thenAccept(response -> {
|
||||
System.out.println("response: " + response);
|
||||
assertEquals(response.statusCode(), 200);
|
||||
assertEquals(response.body(), "Hello World");
|
||||
assertEquals(200, response.statusCode());
|
||||
assertEquals("Hello World", response.body());
|
||||
})
|
||||
.join();
|
||||
}
|
||||
@ -172,8 +174,8 @@ public class OfflineTesting {
|
||||
|
||||
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
|
||||
System.out.println("response: " + response);
|
||||
assertEquals(response.statusCode(), 200);
|
||||
assertEquals(response.body(), "Hello chegar!!");
|
||||
assertEquals(200, response.statusCode());
|
||||
assertEquals("Hello chegar!!", response.body());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @summary Basic checks for File Processors
|
||||
* @run testng/othervm FileProcessorPermissionTest
|
||||
* @run junit/othervm FileProcessorPermissionTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
@ -32,9 +32,9 @@ import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
import org.testng.annotations.Test;
|
||||
import static java.nio.file.StandardOpenOption.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FileProcessorPermissionTest {
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -25,7 +25,7 @@
|
||||
* @test
|
||||
* @summary Verifies security checks are performed before existence checks
|
||||
* in pre-defined body processors APIs
|
||||
* @run testng/othervm SecurityBeforeFile
|
||||
* @run junit/othervm SecurityBeforeFile
|
||||
*/
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@ -35,11 +35,13 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.net.http.HttpRequest.BodyPublishers;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import static java.lang.System.out;
|
||||
import static java.nio.file.StandardOpenOption.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class SecurityBeforeFile {
|
||||
|
||||
@ -57,8 +59,7 @@ public class SecurityBeforeFile {
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider(name = "handlerOpenOptions")
|
||||
public Object[][] handlerOpenOptions() {
|
||||
public static Object[][] handlerOpenOptions() {
|
||||
return new Object[][] {
|
||||
{ new OpenOption[] { } },
|
||||
{ new OpenOption[] { CREATE } },
|
||||
@ -66,7 +67,8 @@ public class SecurityBeforeFile {
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "handlerOpenOptions")
|
||||
@ParameterizedTest
|
||||
@MethodSource("handlerOpenOptions")
|
||||
public void BodyHandlersOfFileDownload(OpenOption[] openOptions) {
|
||||
Path p = Paths.get("doesNotExistDir");
|
||||
if (Files.exists(p))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user