Smarter test.

This commit is contained in:
dotasek 2024-08-22 17:09:03 -04:00
parent 59f5eeb3c4
commit 62758b57c5
2 changed files with 14 additions and 9 deletions

View File

@ -21,8 +21,6 @@ public class SimpleHTTPClientTest {
private MockWebServer server;
@BeforeEach
void setup() {
setupMockServer();
@ -78,24 +76,31 @@ public class SimpleHTTPClientTest {
HttpUrl[] url = new HttpUrl[urlArgs.length];
for (int i = 0; i < urlArgs.length; i++) {
url[i] = server.url(urlArgs[i]);
if (i > 0 && i < urlArgs.length - 1) {
if (i > 0 && i < urlArgs.length) {
server.enqueue(
new MockResponse()
.setResponseCode(code)
.setBody("Pumas")
.addHeader("Location", url[i].url().toString()));
} else if (i == urlArgs.length - 1) {
server.enqueue(
new MockResponse()
.setBody("Monkeys").setResponseCode(200)
);
}
}
server.enqueue(
new MockResponse()
.setBody("Monkeys").setResponseCode(200)
);
SimpleHTTPClient http = new SimpleHTTPClient();
HTTPResult res = http.get(url[0].url().toString(), "application/json");
assertThat(res.getCode()).isEqualTo(200);
assertThat(res.getContentAsString()).isEqualTo("Monkeys");
assertThat(server.getRequestCount()).isEqualTo(urlArgs.length);
for (int i = 0; i < urlArgs.length; i++) {
RecordedRequest packageRequest = server.takeRequest();
assertThat(packageRequest.getMethod()).isEqualTo("GET");
assertThat(packageRequest.getHeader("Accept")).isEqualTo("application/json");
}
}
}

View File

@ -21,7 +21,7 @@
<commons_compress_version>1.26.0</commons_compress_version>
<guava_version>32.0.1-jre</guava_version>
<hapi_fhir_version>6.4.1</hapi_fhir_version>
<validator_test_case_version>1.5.19</validator_test_case_version>
<validator_test_case_version>1.5.20-SNAPSHOT</validator_test_case_version>
<jackson_version>2.17.0</jackson_version>
<junit_jupiter_version>5.9.2</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>