Skip to content

Commit

Permalink
refactor: cleanup tests
Browse files Browse the repository at this point in the history
� Conflicts:
�	carapace-server/src/test/java/org/carapaceproxy/DatabaseConfigurationTest.java
�	carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java
  • Loading branch information
NiccoMlt committed Nov 29, 2024
1 parent 1c17c7d commit 9a2026c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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");
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -35,6 +36,7 @@ public void test() throws Exception {
.withBody("it <b>works</b> !!")));

config = new Properties(HTTP_ADMIN_SERVER_CONFIG);
config.put("healthmanager.tolerant", "true");
startServer(config);

// Default certificate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -33,6 +34,7 @@ public void test() throws Exception {
.withBody("it <b>works</b> !!")));

config = new Properties(HTTP_ADMIN_SERVER_CONFIG);
config.put("healthmanager.tolerant", "true");
startServer(config);

// Default certificate
Expand Down Expand Up @@ -71,7 +73,6 @@ public void test() throws Exception {

changeDynamicConfiguration(config);


HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a2026c

Please sign in to comment.