From 4603aee532c6d4fc0c058aa60300d2044e994c64 Mon Sep 17 00:00:00 2001 From: Markus Malkusch Date: Mon, 6 Nov 2023 14:48:11 +0100 Subject: [PATCH] Add tests --- src/test/java/de/malkusch/km200/KM200Test.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/de/malkusch/km200/KM200Test.java b/src/test/java/de/malkusch/km200/KM200Test.java index 077739d..41f5cac 100644 --- a/src/test/java/de/malkusch/km200/KM200Test.java +++ b/src/test/java/de/malkusch/km200/KM200Test.java @@ -15,6 +15,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; +import static com.google.common.net.HttpHeaders.LOCATION; import static de.malkusch.km200.KM200.RETRY_DISABLED; import static de.malkusch.km200.KM200.USER_AGENT; import static java.nio.charset.StandardCharsets.UTF_8; @@ -74,6 +75,18 @@ public void queryShouldSucceedWith2xx(int status) throws Exception { assertEquals("2021-09-21T10:49:25", dateTime); } + @ParameterizedTest + @ValueSource(ints = { 301, 302, 303 }) + public void queryShouldFollowRedirect(int status) throws Exception { + stubFor(get("/moved").willReturn(aResponse().withStatus(status).withHeader(LOCATION, "/new"))); + stubFor(get("/new").willReturn(ok(loadBody("gateway.DateTime")))); + var km200 = new KM200(URI, TIMEOUT, GATEWAY_PASSWORD, PRIVATE_PASSWORD, SALT); + + var dateTime = km200.queryString("/moved"); + + assertEquals("2021-09-21T10:49:25", dateTime); + } + @ParameterizedTest @ValueSource(strings = { "http://localhost:" + PORT, "http://localhost:" + PORT + "/" }) public void queryShouldReplaceSlashesInURI(String uri) throws Exception {