diff --git a/carapace-server/pom.xml b/carapace-server/pom.xml
index f513278fd..fd6dbc943 100644
--- a/carapace-server/pom.xml
+++ b/carapace-server/pom.xml
@@ -245,14 +245,14 @@
- junit
- junit
+ org.junit.jupiter
+ junit-jupiter
test
- pl.pragmatists
- JUnitParams
- ${libs.junitparams}
+ org.junit.platform
+
+ junit-platform-launcher
test
diff --git a/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java b/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java
index 5691ab1e9..8cac744d5 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java
@@ -23,7 +23,14 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
+import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
@@ -41,16 +48,10 @@
import org.carapaceproxy.user.UserRealm;
import org.carapaceproxy.utils.TestEndpointMapper;
import org.carapaceproxy.utils.TestUserRealm;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.BeforeClass;
import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/**
*
@@ -59,9 +60,9 @@
public class ApplyConfigurationTest {
@ClassRule
- public static WireMockRule wireMockRule = new WireMockRule(0);
+ public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(0)).build();
- @BeforeClass
+ @BeforeAll
public static void setupWireMock() {
stubFor(get(urlEqualTo("/index.html?redir"))
.willReturn(aResponse()
@@ -73,8 +74,8 @@ public static void setupWireMock() {
}
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ File tmpDir;
/**
* Static mapper, so that it can be references by configuration
@@ -82,7 +83,16 @@ public static void setupWireMock() {
public static final class StaticEndpointMapper extends TestEndpointMapper {
public StaticEndpointMapper() {
- super("localhost", wireMockRule.port());
+ super("localhost", wireMockRule.getPort());
+ }
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
}
}
@@ -90,7 +100,7 @@ public StaticEndpointMapper() {
@Test
public void testChangeListenersConfig() throws Exception {
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
{
Properties configuration = new Properties();
@@ -217,7 +227,7 @@ public void testChangeListenersConfig() throws Exception {
@Test
public void testReloadMapper() throws Exception {
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
{
Properties configuration = new Properties();
@@ -289,7 +299,7 @@ public void testReloadMapper() throws Exception {
public void testUserRealm() throws Exception {
// Default UserRealm
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"))) {
Properties configuration = new Properties();
server.configureAtBoot(new PropertiesConfigurationStore(configuration));
server.start();
@@ -307,7 +317,7 @@ public void testUserRealm() throws Exception {
}
// TestUserRealm
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"))) {
Properties configuration = new Properties();
configuration.put("userrealm.class", "org.carapaceproxy.utils.TestUserRealm");
configuration.put("user.test1", "pass1");
@@ -336,7 +346,7 @@ public void testUserRealm() throws Exception {
@Test
public void testChangeFiltersConfiguration() throws Exception {
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
{
Properties configuration = new Properties();
@@ -375,7 +385,7 @@ public void testChangeFiltersConfiguration() throws Exception {
@Test
public void testChangeBackendHealthManagerConfiguration() throws Exception {
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
{
Properties configuration = new Properties();
@@ -418,4 +428,13 @@ private void testIt(int port, boolean ok) throws URISyntaxException, IOException
}
}
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
+
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java b/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java
index 5e8f32553..88ece17aa 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java
@@ -19,6 +19,7 @@
*/
package org.carapaceproxy;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -37,11 +38,12 @@
import org.carapaceproxy.client.EndpointKey;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.TestEndpointMapper;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.io.TempDir;
/**
* The clients sends a big upload, and the server is very slow at draining the contents
@@ -52,12 +54,21 @@ public class BigUploadTest {
private static final Logger LOG = Logger.getLogger(BigUploadTest.class.getName());
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ public File tmpDir;
public interface ClientHandler {
public void handle(Socket client) throws Exception;
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
public static class ConnectionResetByPeerHandler implements ClientHandler {
@@ -81,6 +92,15 @@ public void handle(Socket client) {
LOG.log(Level.SEVERE, "error", ii);
}
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
public static class StaticResponseHandler implements ClientHandler {
@@ -101,6 +121,15 @@ public void handle(Socket client) {
LOG.log(Level.SEVERE, "error", ii);
}
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
public static final class SimpleBlockingTcpServer implements AutoCloseable {
@@ -160,6 +189,15 @@ public void close() throws IOException {
socket.close();
}
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
@Test
@@ -175,7 +213,7 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception {
int size = 20_000_000;
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
URL url = new URL("http://localhost:" + port + "/index.html");
@@ -204,16 +242,14 @@ public void testConnectionResetByPeerDuringWriteToEndpoint() throws Exception {
public void testBlockingServerWorks() throws Exception {
try (SimpleBlockingTcpServer mockServer =
- new SimpleBlockingTcpServer(() -> {
- return new StaticResponseHandler("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nit works!\r\n".getBytes(StandardCharsets.US_ASCII));
- })) {
+ new SimpleBlockingTcpServer(() -> new StaticResponseHandler("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nit works!\r\n".getBytes(StandardCharsets.US_ASCII)))) {
mockServer.start();
TestEndpointMapper mapper = new TestEndpointMapper("localhost", mockServer.getPort());
EndpointKey key = new EndpointKey("localhost", mockServer.getPort());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
URL url = new URL("http://localhost:" + port + "/index.html");
@@ -229,4 +265,13 @@ public void testBlockingServerWorks() throws Exception {
}
}
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
+
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java b/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java
index 8c2adb076..3611b0bb4 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java
@@ -23,7 +23,13 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
+import java.io.File;
+import java.io.IOException;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
@@ -34,12 +40,9 @@
import org.carapaceproxy.client.EndpointKey;
import org.carapaceproxy.core.HttpProxyServer;
import org.carapaceproxy.utils.TestEndpointMapper;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
/**
*
@@ -47,11 +50,11 @@
*/
public class ConcurrentClientsTest {
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(0);
+ @RegisterExtension
+ public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(0)).build();
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ File tmpDir;
@Test
public void test() throws Exception {
@@ -62,12 +65,12 @@ public void test() throws Exception {
.withHeader("Content-Type", "text/html")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- EndpointKey key = new EndpointKey("localhost", wireMockRule.port());
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ EndpointKey key = new EndpointKey("localhost", wireMockRule.getPort());
int size = 100;
int concurrentClients = 4;
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
@@ -99,4 +102,13 @@ public void run() {
}
}
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
+
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java b/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java
index 7b3d35033..109f9a75b 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java
@@ -20,6 +20,7 @@
*/
import java.io.File;
+import java.io.IOException;
import org.carapaceproxy.core.HttpProxyServer;
import java.util.Properties;
import org.carapaceproxy.configstore.HerdDBConfigurationStore;
@@ -28,12 +29,12 @@
import org.carapaceproxy.server.filters.XForwardedForRequestFilter;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/**
*
@@ -41,19 +42,19 @@
*/
public class DatabaseConfigurationTest {
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ public File tmpDir;
@Test
public void testBootWithDatabaseStore() throws Exception {
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
Properties configuration = new Properties();
configuration.put("config.type", "database");
configuration.put("db.jdbc.url", "jdbc:herddb:localhost");
- configuration.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ configuration.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
server.configureAtBoot(new PropertiesConfigurationStore(configuration));
server.start();
@@ -65,15 +66,15 @@ public void testBootWithDatabaseStore() throws Exception {
@SuppressWarnings("deprecation")
@Test
- @Ignore
+ @Disabled
public void testChangeFiltersConfiguration() throws Exception {
- File databaseFolder = tmpDir.newFolder();
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ File databaseFolder = newFolder(tmpDir, "junit");
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
Properties configurationAtBoot = new Properties();
configurationAtBoot.put("db.jdbc.url", "jdbc:herddb:localhost");
- configurationAtBoot.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ configurationAtBoot.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
server.configureAtBoot(new PropertiesConfigurationStore(configurationAtBoot));
server.start();
@@ -99,10 +100,10 @@ public void testChangeFiltersConfiguration() throws Exception {
}
// reboot, new configuration MUST be kept
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
Properties configurationAtBoot = new Properties();
configurationAtBoot.put("db.jdbc.url", "jdbc:herddb:localhost");
- configurationAtBoot.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ configurationAtBoot.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
server.configureAtBoot(new PropertiesConfigurationStore(configurationAtBoot));
assertEquals(2, server.getFilters().size());
@@ -118,10 +119,10 @@ public void testChangeFiltersConfiguration() throws Exception {
}
// reboot, new configuration MUST be kept
- try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) {
+ try (HttpProxyServer server = new HttpProxyServer(null, newFolder(tmpDir, "junit"));) {
Properties configurationAtBoot = new Properties();
configurationAtBoot.put("db.jdbc.url", "jdbc:herddb:localhost");
- configurationAtBoot.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ configurationAtBoot.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
server.configureAtBoot(new PropertiesConfigurationStore(configurationAtBoot));
assertEquals(1, server.getFilters().size());
@@ -129,4 +130,13 @@ public void testChangeFiltersConfiguration() throws Exception {
}
}
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
+
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java b/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java
index 5dea0e248..6125c7dd8 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java
@@ -1,11 +1,12 @@
package org.carapaceproxy;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
import org.carapaceproxy.api.UseAdminServer;
import org.carapaceproxy.utils.TestUtils;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
@@ -14,13 +15,13 @@
import java.util.Properties;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class MaintenanceModeTest extends UseAdminServer {
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(0);
+ @RegisterExtension
+ public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(0)).build();
private Properties config;
@@ -38,7 +39,7 @@ public void test() throws Exception {
startServer(config);
// Default certificate
- String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir.getRoot());
+ String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir);
config.put("certificate.1.hostname", "*");
config.put("certificate.1.file", defaultCertificate);
config.put("certificate.1.password", "changeit");
@@ -53,12 +54,12 @@ public void test() throws Exception {
config.put("backend.1.id", "localhost");
config.put("backend.1.enabled", "true");
config.put("backend.1.host", "localhost");
- config.put("backend.1.port", wireMockRule.port() + "");
+ config.put("backend.1.port", wireMockRule.getPort() + "");
config.put("backend.2.id", "localhost2");
config.put("backend.2.enabled", "true");
config.put("backend.2.host", "localhost2");
- config.put("backend.2.port", wireMockRule.port() + "");
+ config.put("backend.2.port", wireMockRule.getPort() + "");
// Default director
config.put("director.1.id", "*");
@@ -114,7 +115,7 @@ public void maintenanceModeApiTest() throws Exception {
startServer(config);
// Default certificate
- String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir.getRoot());
+ String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir);
config.put("certificate.1.hostname", "*");
config.put("certificate.1.file", defaultCertificate);
config.put("certificate.1.password", "changeit");
@@ -129,12 +130,12 @@ public void maintenanceModeApiTest() throws Exception {
config.put("backend.1.id", "localhost");
config.put("backend.1.enabled", "true");
config.put("backend.1.host", "localhost");
- config.put("backend.1.port", wireMockRule.port() + "");
+ config.put("backend.1.port", wireMockRule.getPort() + "");
config.put("backend.2.id", "localhost2");
config.put("backend.2.enabled", "true");
config.put("backend.2.host", "localhost2");
- config.put("backend.2.port", wireMockRule.port() + "");
+ config.put("backend.2.port", wireMockRule.getPort() + "");
// Default director
config.put("director.1.id", "*");
diff --git a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java
index 405bd2c62..5811d28c6 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java
@@ -35,12 +35,13 @@
import static org.carapaceproxy.utils.RawHttpClient.consumeHttpResponseInput;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static reactor.netty.http.HttpProtocol.HTTP11;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.http.HttpHeader;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import com.github.tomakehurst.wiremock.matching.UrlPattern;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.Unpooled;
@@ -67,15 +68,18 @@
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpUtil;
import io.netty.handler.codec.http.LastHttpContent;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
+import java.lang.reflect.Method;
import java.net.Socket;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -101,12 +105,12 @@
import org.carapaceproxy.utils.RawHttpServer;
import org.carapaceproxy.utils.TestEndpointMapper;
import org.carapaceproxy.utils.TestUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
import org.junit.runner.RunWith;
/**
@@ -118,23 +122,27 @@ public class RawClientTest {
private static final Logger LOG = Logger.getLogger(RawClientTest.class.getName());
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(0);
+ @RegisterExtension
+ public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(0)).build();
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ File tmpDir;
- @Rule
- public TestName testName = new TestName();
+ @RegisterExtension
+ public String testName;
- @Before
- public void dumpTestName() {
- LOG.log(Level.INFO, "Starting {0}", testName.getMethodName());
+ @BeforeEach
+ public void dumpTestName(TestInfo testInfo) {
+ Optional testMethod = testInfo.getTestMethod();
+ if (testMethod.isPresent()) {
+ this.testName = testMethod.get().getName();
+ }
+ LOG.log(Level.INFO, "Starting {0}", testName);
}
- @After
+ @AfterEach
public void dumpTestNameEnd() {
- LOG.log(Level.INFO, "End {0}", testName.getMethodName());
+ LOG.log(Level.INFO, "End {0}", testName);
}
@Test
@@ -147,8 +155,8 @@ public void clientsKeepAliveSimpleTest() throws Exception {
.withHeader("Content-Length", "it works !!".length() + "")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
try (RawHttpClient client = new RawHttpClient("localhost", port)) {
@@ -193,10 +201,10 @@ public void downloadSmallPayloadsTest() throws Exception {
.withHeader("Content-Length", "1")
.withBody("a")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- EndpointKey key = new EndpointKey("localhost", wireMockRule.port());
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ EndpointKey key = new EndpointKey("localhost", wireMockRule.getPort());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
@@ -234,8 +242,8 @@ public void testManyInflightRequests() throws Exception {
.withHeader("Content-Type", "text/html")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
assertTrue(port > 0);
@@ -268,7 +276,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
int httpServerPort = httpServer.start();
TestEndpointMapper mapper = new TestEndpointMapper("localhost", httpServerPort);
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
assertTrue(port > 0);
@@ -296,7 +304,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
int httpServerPort = httpServer.start();
TestEndpointMapper mapper = new TestEndpointMapper("localhost", httpServerPort);
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
assertTrue(port > 0);
@@ -325,7 +333,7 @@ public void testServerRequestContinue() throws Exception {
CarapaceLogger.setLoggingDebugEnabled(true);
- try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
+ try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"))) {
ConnectionPoolConfiguration defaultConnectionPool = proxy.getCurrentConfiguration().getDefaultConnectionPool();
defaultConnectionPool.setMaxConnectionsPerEndpoint(1);
proxy.getCurrentConfiguration().setClientsIdleTimeoutSeconds(300);
@@ -515,6 +523,15 @@ public void close() throws Exception {
bossGroup.shutdownGracefully();
}
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
@Test
@@ -533,15 +550,15 @@ public void testMultiClientTimeout() throws Exception {
.withHeader("Content-Length", "it works !!".length() + "")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- EndpointKey key = new EndpointKey("localhost", wireMockRule.port());
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ EndpointKey key = new EndpointKey("localhost", wireMockRule.getPort());
ExecutorService ex = Executors.newFixedThreadPool(2);
List futures = new ArrayList<>();
CarapaceLogger.setLoggingDebugEnabled(true);
- try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
+ try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"))) {
ConnectionPoolConfiguration defaultConnectionPool = proxy.getCurrentConfiguration().getDefaultConnectionPool();
defaultConnectionPool.setMaxConnectionsPerEndpoint(1);
proxy.getCurrentConfiguration().setClientsIdleTimeoutSeconds(10);
@@ -626,7 +643,7 @@ public void testMaxConnectionsAndBorrowTimeout() throws Exception {
try (DummyServer server = new DummyServer("localhost", 8086, responseEnabled)) {
TestEndpointMapper mapper = new TestEndpointMapper("localhost", 8086, false);
- try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
+ try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"))) {
ConnectionPoolConfiguration defaultConnectionPool = proxy.getCurrentConfiguration().getDefaultConnectionPool();
defaultConnectionPool.setMaxConnectionsPerEndpoint(1);
defaultConnectionPool.setBorrowTimeout(1);
@@ -726,8 +743,8 @@ public void testInvalidUriChars() throws Exception {
.withHeader("Content-Length", "it works !!".length() + "")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
try (RawHttpClient client = new RawHttpClient("localhost", port)) {
@@ -739,15 +756,16 @@ public void testInvalidUriChars() throws Exception {
}
@Test
+ // JunitParamsRunnerToParameterized conversion not supported
@Parameters({"http", "https"})
public void testClosedProxy(String scheme) throws Exception {
- String certificate = TestUtils.deployResource("localhost.p12", tmpDir.getRoot());
+ String certificate = TestUtils.deployResource("localhost.p12", tmpDir);
// Proxy requests have to use "localhost:port" as endpoint instead of the one in the url (ex yahoo.com)
// in order to avoid open proxy vulnerability
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port(), true);
- EndpointKey key = new EndpointKey("localhost", wireMockRule.port());
- try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) {
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort(), true);
+ EndpointKey key = new EndpointKey("localhost", wireMockRule.getPort());
+ try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir);) {
server.addCertificate(new SSLCertificateConfiguration("localhost", null, "localhost.p12", "testproxy", STATIC));
server.addListener(new NetworkListenerConfiguration("localhost", 0, scheme.equals("https"), null, "localhost", DEFAULT_SSL_PROTOCOLS, 128, true, 300, 60, 8, 100, DEFAULT_FORWARDED_STRATEGY, Set.of(), Set.of(HTTP11.name())));
@@ -818,8 +836,8 @@ public void testCookies() throws Exception {
.withHeader(HttpHeaderNames.SET_COOKIE.toString(), "responseCookie=responseValue; responseCookie2=responseValue2")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
try (RawHttpClient client = new RawHttpClient("localhost", port)) {
@@ -848,4 +866,13 @@ public void testCookies() throws Exception {
assertThat(headerCookie.values().size(), is(1));
assertThat(headerCookie.values().get(0), is("requestCookie=requestValue; requestCookie2=requestValue2"));
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java b/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java
index 179fb2dc6..a3a220c64 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java
@@ -19,7 +19,9 @@
*/
package org.carapaceproxy;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -34,10 +36,9 @@
import org.carapaceproxy.utils.CarapaceLogger;
import org.carapaceproxy.utils.RawHttpClient;
import org.carapaceproxy.utils.TestEndpointMapper;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
/**
*
@@ -77,11 +78,11 @@ private static RawHttpClient.HttpResponse doPost(RawHttpClient client, String ho
}
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ public File tmpDir;
@Test
- @Ignore
+ @Disabled
public void testRequestsRealBackend() throws Exception {
CarapaceLogger.setLoggingDebugEnabled(true);
@@ -98,7 +99,7 @@ public void testRequestsRealBackend() throws Exception {
int port = 443;
boolean isLocal = carapaceHost.equals("localhost");
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"))) {
RuntimeServerConfiguration config = new RuntimeServerConfiguration();
config.setMaxConnectionsPerEndpoint(1);
server.getProxyRequestsManager().reloadConfiguration(config, mapper.getBackends().values());
@@ -162,4 +163,13 @@ public void testRequestsRealBackend() throws Exception {
assertFalse(countError.get() > 0);
}
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
+
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/SimpleHTTPProxyTest.java b/carapace-server/src/test/java/org/carapaceproxy/SimpleHTTPProxyTest.java
index 26772bafa..16d4c3dc7 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/SimpleHTTPProxyTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/SimpleHTTPProxyTest.java
@@ -27,12 +27,15 @@
import static org.carapaceproxy.server.config.NetworkListenerConfiguration.DEFAULT_FORWARDED_STRATEGY;
import static org.carapaceproxy.server.config.NetworkListenerConfiguration.DEFAULT_SSL_PROTOCOLS;
import static org.carapaceproxy.server.config.SSLCertificateConfiguration.CertificateMode.STATIC;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import static reactor.netty.http.HttpProtocol.HTTP11;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
@@ -45,9 +48,9 @@
import org.carapaceproxy.utils.HttpTestUtils;
import org.carapaceproxy.utils.TestEndpointMapper;
import org.carapaceproxy.utils.TestUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
/**
*
@@ -55,11 +58,11 @@
*/
public class SimpleHTTPProxyTest {
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(0);
+ @RegisterExtension
+ public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(0)).build();
- @Rule
- public TemporaryFolder tmpDir = new TemporaryFolder();
+ @TempDir
+ File tmpDir;
@Test
public void test() throws Exception {
@@ -70,10 +73,10 @@ public void test() throws Exception {
.withHeader("Content-Type", "text/html")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- EndpointKey key = new EndpointKey("localhost", wireMockRule.port());
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ EndpointKey key = new EndpointKey("localhost", wireMockRule.getPort());
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
@@ -99,8 +102,8 @@ public void testSsl() throws Exception {
HttpTestUtils.overrideJvmWideHttpsVerifier();
- String certificate = TestUtils.deployResource("ia.p12", tmpDir.getRoot());
- String caCertificate = TestUtils.deployResource("ca.p12", tmpDir.getRoot());
+ String certificate = TestUtils.deployResource("ia.p12", tmpDir);
+ String caCertificate = TestUtils.deployResource("ca.p12", tmpDir);
stubFor(get(urlEqualTo("/index.html?redir"))
.willReturn(aResponse()
@@ -108,10 +111,10 @@ public void testSsl() throws Exception {
.withHeader("Content-Type", "text/html")
.withBody("it works !!")));
- TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port());
- EndpointKey key = new EndpointKey("localhost", wireMockRule.port());
+ TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.getPort());
+ EndpointKey key = new EndpointKey("localhost", wireMockRule.getPort());
- try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir.getRoot());) {
+ try (HttpProxyServer server = new HttpProxyServer(mapper, tmpDir);) {
server.addCertificate(new SSLCertificateConfiguration("localhost", null, certificate, "changeit", STATIC));
server.addListener(new NetworkListenerConfiguration("localhost", 0, true, null, "localhost", DEFAULT_SSL_PROTOCOLS, 128, true, 300, 60, 8, 1000, DEFAULT_FORWARDED_STRATEGY, Set.of(), Set.of(HTTP11.name())));
server.start();
@@ -142,7 +145,7 @@ public void testEndpointDown() throws Exception {
TestEndpointMapper mapper = new TestEndpointMapper("localhost", badPort);
EndpointKey key = new EndpointKey("localhost", badPort);
- try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) {
+ try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, newFolder(tmpDir, "junit"));) {
server.start();
int port = server.getLocalPort();
@@ -151,4 +154,13 @@ public void testEndpointDown() throws Exception {
assertEquals(503, result.responseCode);
}
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/api/AuthenticationAPIServerTest.java b/carapace-server/src/test/java/org/carapaceproxy/api/AuthenticationAPIServerTest.java
index fe458db5b..b6d8ae80c 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/api/AuthenticationAPIServerTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/api/AuthenticationAPIServerTest.java
@@ -25,11 +25,12 @@
import org.carapaceproxy.utils.RawHttpClient;
import org.carapaceproxy.utils.RawHttpClient.BasicAuthCredentials;
import org.carapaceproxy.utils.RawHttpClient.HttpResponse;
+import org.junit.jupiter.api.Test;
+
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
diff --git a/carapace-server/src/test/java/org/carapaceproxy/api/ClusterReconfigTest.java b/carapace-server/src/test/java/org/carapaceproxy/api/ClusterReconfigTest.java
index 2b0b154f3..eec5e59bf 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/api/ClusterReconfigTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/api/ClusterReconfigTest.java
@@ -19,18 +19,21 @@
*/
package org.carapaceproxy.api;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
import java.util.Properties;
import org.apache.curator.test.TestingServer;
import org.carapaceproxy.utils.RawHttpClient;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class ClusterReconfigTest extends UseAdminServer {
@Test
public void testReconfigInClusterMode() throws Exception {
- try (TestingServer testingServer = new TestingServer(2229, tmpDir.newFolder());) {
+ try (TestingServer testingServer = new TestingServer(2229, newFolder(tmpDir, "junit"));) {
testingServer.start();
Properties configuration = new Properties(HTTP_ADMIN_SERVER_CONFIG);
@@ -82,4 +85,13 @@ public void testReconfigInClusterMode() throws Exception {
assertEquals(30, server.getBackendHealthManager().getPeriod());
}
}
+
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/api/ConfigResourceTest.java b/carapace-server/src/test/java/org/carapaceproxy/api/ConfigResourceTest.java
index 97337a787..aec4184ca 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/api/ConfigResourceTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/api/ConfigResourceTest.java
@@ -21,12 +21,13 @@
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.io.File;
+import java.io.IOException;
import java.util.Properties;
import org.carapaceproxy.utils.RawHttpClient;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests around {@link ConfigResource} while using configuration on database
@@ -45,7 +46,7 @@ public void testDynamicConfigurationDumpingAndApplying() throws Exception {
Properties configuration = new Properties(HTTP_ADMIN_SERVER_CONFIG);
configuration.put("config.type", "database");
configuration.put("db.jdbc.url", "jdbc:herddb:localhost");
- configuration.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ configuration.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
configuration.put("dynamiccertificatesmanager.period", 25); // will be ignore due to db-mode
startServer(configuration);
@@ -111,7 +112,7 @@ public void testReconfig() throws Exception {
configuration.put("config.type", "database");
configuration.put("db.jdbc.url", "jdbc:herddb:localhost");
- configuration.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ configuration.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
startServer(configuration);
try (RawHttpClient client = new RawHttpClient("localhost", 8761)) {
@@ -156,4 +157,13 @@ public void testReconfig() throws Exception {
assertEquals(30, server.getBackendHealthManager().getPeriod());
}
+ private static File newFolder(File root, String... subDirs) throws IOException {
+ String subFolder = String.join("/", subDirs);
+ File result = new File(root, subFolder);
+ if (!result.mkdirs()) {
+ throw new IOException("Couldn't create folders " + root);
+ }
+ return result;
+ }
+
}
diff --git a/carapace-server/src/test/java/org/carapaceproxy/api/ConnectionPoolsResourceTest.java b/carapace-server/src/test/java/org/carapaceproxy/api/ConnectionPoolsResourceTest.java
index 99d178871..36076810b 100644
--- a/carapace-server/src/test/java/org/carapaceproxy/api/ConnectionPoolsResourceTest.java
+++ b/carapace-server/src/test/java/org/carapaceproxy/api/ConnectionPoolsResourceTest.java
@@ -9,7 +9,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
+import java.io.File;
+import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -17,8 +20,8 @@
import org.carapaceproxy.utils.HttpTestUtils;
import org.carapaceproxy.utils.RawHttpClient;
import org.carapaceproxy.utils.TestUtils;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
public class ConnectionPoolsResourceTest extends UseAdminServer {
private static final ObjectMapper MAPPER = new ObjectMapper();
@@ -38,8 +41,8 @@ public class ConnectionPoolsResourceTest extends UseAdminServer {
private static final int KEEPALIVE_INTERVAL = 50;
private static final int KEEPALIVE_COUNT = 5;
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(0);
+ @RegisterExtension
+ public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.options().port(0)).build();
private void configureAndStartServer() throws Exception {
@@ -55,13 +58,13 @@ private void configureAndStartServer() throws Exception {
final Properties config = new Properties(HTTP_ADMIN_SERVER_CONFIG);
config.put("config.type", "database");
config.put("db.jdbc.url", "jdbc:herddb:localhost");
- config.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath());
+ config.put("db.server.base.dir", newFolder(tmpDir, "junit").getAbsolutePath());
config.put("aws.accesskey", "accesskey");
config.put("aws.secretkey", "secretkey");
startServer(config);
// Default certificate
- String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir.getRoot());
+ String defaultCertificate = TestUtils.deployResource("ia.p12", tmpDir);
config.put("certificate.1.hostname", "*");
config.put("certificate.1.file", defaultCertificate);
config.put("certificate.1.password", "changeit");
@@ -76,12 +79,12 @@ private void configureAndStartServer() throws Exception {
config.put("backend.1.id", "localhost");
config.put("backend.1.enabled", "true");
config.put("backend.1.host", "localhost");
- config.put("backend.1.port", String.valueOf(wireMockRule.port()));
+ config.put("backend.1.port", String.valueOf(wireMockRule.getPort()));
config.put("backend.2.id", "localhost2");
config.put("backend.2.enabled", "true");
config.put("backend.2.host", "localhost2");
- config.put("backend.2.port", String.valueOf(wireMockRule.port()));
+ config.put("backend.2.port", String.valueOf(wireMockRule.getPort()));
// Default director
config.put("director.1.id", "*");
@@ -220,6 +223,14 @@ private static ConnectionPoolsResource.ConnectionPoolBean buildConnectionPoolBea
return pool;
}
- private static class MapTypeReference extends TypeReference
- junit
- junit
- ${libs.junit}
-
-
-
- org.hamcrest
- hamcrest-core
-
-
+ org.junit
+ junit-bom
+ 5.11.3
+ pom
+ import