From 9a2026c09b1c64c0c683903a3e6211d40675af64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maltoni?= Date: Wed, 27 Nov 2024 17:39:14 +0100 Subject: [PATCH] refactor: cleanup tests  Conflicts:  carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java  carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java --- .../carapaceproxy/ApplyConfigurationTest.java | 13 +++++++----- .../java/org/carapaceproxy/BigUploadTest.java | 4 ++-- .../carapaceproxy/ConcurrentClientsTest.java | 6 +++--- .../DatabaseConfigurationTest.java | 8 ++++---- .../carapaceproxy/MaintenanceModeTest.java | 20 ++++++++++--------- .../backends/ConnectionPoolTest.java | 2 +- .../carapaceproxy/core/MaxHeaderSizeTest.java | 19 +++++++++--------- .../server/certificates/CertificatesTest.java | 1 + 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java b/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java index 18cb1d467..a9cd7a899 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/ApplyConfigurationTest.java @@ -81,16 +81,19 @@ public static void setupWireMock() { */ public static final class StaticEndpointMapper extends TestEndpointMapper { + public StaticEndpointMapper(final HttpProxyServer ignoredServer) { + this(); // required for reflective construction + } + public StaticEndpointMapper() { super("localhost", wireMockRule.port()); } - } @Test public void testChangeListenersConfig() throws Exception { - try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) { + try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) { { Properties configuration = new Properties(); @@ -217,7 +220,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, tmpDir.newFolder())) { { Properties configuration = new Properties(); @@ -336,7 +339,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, tmpDir.newFolder())) { { Properties configuration = new Properties(); @@ -375,7 +378,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, tmpDir.newFolder())) { { Properties configuration = new Properties(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java b/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java index fd85ee6d8..e41e2ad85 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/BigUploadTest.java @@ -19,6 +19,8 @@ */ package org.carapaceproxy; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -35,8 +37,6 @@ import org.apache.commons.io.IOUtils; 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; diff --git a/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java b/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java index 1856300c2..207161a3b 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/ConcurrentClientsTest.java @@ -23,6 +23,9 @@ 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import com.github.tomakehurst.wiremock.junit.WireMockRule; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -34,9 +37,6 @@ import org.apache.commons.io.IOUtils; 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; diff --git a/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java b/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java index 130fa5c28..492904bf7 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java @@ -48,7 +48,7 @@ public class DatabaseConfigurationTest { @Test public void testBootWithDatabaseStore() throws Exception { - try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) { + try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) { Properties configuration = new Properties(); @@ -70,7 +70,7 @@ public void testBootWithDatabaseStore() throws Exception { public void testChangeFiltersConfiguration() throws Exception { File databaseFolder = tmpDir.newFolder(); - try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder());) { + try (HttpProxyServer server = new HttpProxyServer(null, tmpDir.newFolder())) { Properties configurationAtBoot = new Properties(); configurationAtBoot.put("db.jdbc.url", "jdbc:herddb:localhost"); @@ -100,7 +100,7 @@ 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, tmpDir.newFolder())) { Properties configurationAtBoot = new Properties(); configurationAtBoot.put("db.jdbc.url", "jdbc:herddb:localhost"); configurationAtBoot.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath()); @@ -119,7 +119,7 @@ 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, tmpDir.newFolder())) { Properties configurationAtBoot = new Properties(); configurationAtBoot.put("db.jdbc.url", "jdbc:herddb:localhost"); configurationAtBoot.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath()); diff --git a/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java b/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java index 5dea0e248..daa47a2e2 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/MaintenanceModeTest.java @@ -1,21 +1,22 @@ package org.carapaceproxy; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; 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 java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.Base64; 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 org.carapaceproxy.api.UseAdminServer; +import org.carapaceproxy.utils.TestUtils; +import org.junit.Rule; +import org.junit.Test; public class MaintenanceModeTest extends UseAdminServer { @@ -35,6 +36,7 @@ public void test() throws Exception { .withBody("it works !!"))); config = new Properties(HTTP_ADMIN_SERVER_CONFIG); + config.put("healthmanager.tolerant", "true"); startServer(config); // Default certificate diff --git a/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java b/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java index 8e9fac3da..708af19ee 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/backends/ConnectionPoolTest.java @@ -69,7 +69,6 @@ public class ConnectionPoolTest extends UseAdminServer { public WireMockRule wireMockRule = new WireMockRule(0); private void configureAndStartServer() throws Exception { - HttpTestUtils.overrideJvmWideHttpsVerifier(); stubFor(get(urlEqualTo("/index.html")) @@ -85,6 +84,7 @@ private void configureAndStartServer() throws Exception { config.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath()); config.put("aws.accesskey", "accesskey"); config.put("aws.secretkey", "secretkey"); + config.put("healthmanager.tolerant", "true"); startServer(config); // Default certificate diff --git a/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java b/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java index 77a5a5a69..a91e74c1e 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/core/MaxHeaderSizeTest.java @@ -1,19 +1,20 @@ package org.carapaceproxy.core; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +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 static org.junit.Assert.assertEquals; 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 java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.Properties; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static org.junit.Assert.assertEquals; +import org.carapaceproxy.api.UseAdminServer; +import org.carapaceproxy.utils.TestUtils; +import org.junit.Rule; +import org.junit.Test; public class MaxHeaderSizeTest extends UseAdminServer { @@ -33,6 +34,7 @@ public void test() throws Exception { .withBody("it works !!"))); config = new Properties(HTTP_ADMIN_SERVER_CONFIG); + config.put("healthmanager.tolerant", "true"); startServer(config); // Default certificate @@ -71,7 +73,6 @@ public void test() throws Exception { changeDynamicConfiguration(config); - HttpClient httpClient = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_1_1) .build(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/server/certificates/CertificatesTest.java b/carapace-server/src/test/java/org/carapaceproxy/server/certificates/CertificatesTest.java index da3f01f59..2b2ae8b27 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/server/certificates/CertificatesTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/server/certificates/CertificatesTest.java @@ -123,6 +123,7 @@ private void configureAndStartServer() throws Exception { config.put("db.server.base.dir", tmpDir.newFolder().getAbsolutePath()); config.put("aws.accesskey", "accesskey"); config.put("aws.secretkey", "secretkey"); + config.put("healthmanager.tolerant", "true"); startServer(config); // Default certificate