Skip to content

Commit

Permalink
wiremockgh-2705 add acceptance test for mappings with big json with c…
Browse files Browse the repository at this point in the history
…ommon keys
  • Loading branch information
Veli Döngelci committed May 3, 2024
1 parent d8d9c81 commit 0e6d6e2
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
import com.github.tomakehurst.wiremock.testsupport.WireMockResponse;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Objects;

public class MappingsAcceptanceTest extends AcceptanceTestBase {

Expand Down Expand Up @@ -238,6 +245,27 @@ public void responseContainsContentLengthAndChunkedEncodingHeadersIfItIsDefinedI
"expected Transfer-Encoding head to be absent");
}

@Test
@Timeout(10)
public void mappingShouldResponseBeforeTimeoutBigJsonWithCommonKeys() {
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_1);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_2);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_3);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_4);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_5);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_6);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_7);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_8);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_9);
testClient.addResponse(MappingJsonSamples.MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_10);

var body = readFileContent("/test-requests/big-json-with-common-keys.json");
WireMockResponse bigJsonWithCommonKeys =
testClient.postJson("/body/big-json-common-keys", body);

assertThat(bigJsonWithCommonKeys.statusCode(), is(202));
}

private void getResponseAndAssert200Status(String url) {
WireMockResponse response = testClient.get(url);
assertThat(response.statusCode(), is(200));
Expand All @@ -251,4 +279,14 @@ private void getResponseAndAssert404Status(String url) {
private void add200ResponseFor(String url) {
testClient.addResponse(String.format(MappingJsonSamples.STATUS_ONLY_GET_MAPPING_TEMPLATE, url));
}

private static String readFileContent(String pathString) {
try {
var resource = Objects.requireNonNull(MappingsAcceptanceTest.class.getResource(pathString));
var resourcePath = Paths.get(resource.toURI());
return Files.readString(resourcePath);
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
*/
package com.github.tomakehurst.wiremock.testsupport;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

import static com.github.tomakehurst.wiremock.common.Encoding.encodeBase64;

public class MappingJsonSamples {
Expand Down Expand Up @@ -274,4 +280,24 @@ public class MappingJsonSamples {

public static final String MAPPING_REQUEST_JSON_BODY_DECIMALS_TRAILING_ZEROS =
MAPPING_REQUEST_JSON_BODY_DECIMALS_NO_TRAILING_ZEROS.replace("1.2", "1.20000000");

public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_1 = readFileContent("/equals-to-json/big-json-with-common-keys-1.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_2 = readFileContent("/equals-to-json/big-json-with-common-keys-2.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_3 = readFileContent("/equals-to-json/big-json-with-common-keys-3.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_4 = readFileContent("/equals-to-json/big-json-with-common-keys-4.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_5 = readFileContent("/equals-to-json/big-json-with-common-keys-5.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_6 = readFileContent("/equals-to-json/big-json-with-common-keys-6.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_7 = readFileContent("/equals-to-json/big-json-with-common-keys-7.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_8 = readFileContent("/equals-to-json/big-json-with-common-keys-8.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_9 = readFileContent("/equals-to-json/big-json-with-common-keys-9.json");
public static final String MAPPING_REQUEST_BIG_JSON_BODY_WITH_COMMON_KEYS_10 = readFileContent("/equals-to-json/big-json-with-common-keys-10.json");

private static String readFileContent(String pathString) {
try {
var resourceStream = Objects.requireNonNull(MappingJsonSamples.class.getResourceAsStream(pathString));
return IOUtils.toString(Objects.requireNonNull(resourceStream), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 0e6d6e2

Please sign in to comment.