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 {