Skip to content

Commit

Permalink
test all redirect codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Athou committed Jan 2, 2024
1 parent 46065d9 commit 4ea2bad
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,26 @@ void validFeed() throws Exception {
Assertions.assertEquals(this.feedUrl, result.getUrlAfterRedirect());
}

@Test
void followRedirects() throws Exception {
@ParameterizedTest
@ValueSource(
ints = { HttpStatus.MOVED_PERMANENTLY_301, HttpStatus.MOVED_TEMPORARILY_302, HttpStatus.TEMPORARY_REDIRECT_307,
HttpStatus.PERMANENT_REDIRECT_308 })
void followRedirects(int code) throws Exception {
// first redirect
this.mockServerClient.when(HttpRequest.request().withMethod("GET").withPath("/"))
.respond(HttpResponse.response()
.withStatusCode(code)
.withHeader(HttpHeaders.LOCATION, "http://localhost:" + this.mockServerClient.getPort() + "/redirected"));

// second redirect
this.mockServerClient.when(HttpRequest.request().withMethod("GET").withPath("/redirected"))
.respond(HttpResponse.response()
.withStatusCode(HttpStatus.MOVED_TEMPORARILY_302)
.withStatusCode(code)
.withHeader(HttpHeaders.LOCATION, "http://localhost:" + this.mockServerClient.getPort() + "/redirected-2"));

// final destination
this.mockServerClient.when(HttpRequest.request().withMethod("GET").withPath("/redirected-2"))
.respond(HttpResponse.response().withBody(feedContent).withContentType(MediaType.APPLICATION_ATOM_XML));
this.mockServerClient.when(HttpRequest.request().withMethod("GET"))
.respond(HttpResponse.response()
.withStatusCode(HttpStatus.MOVED_PERMANENTLY_301)
.withHeader(HttpHeaders.LOCATION, "http://localhost:" + this.mockServerClient.getPort() + "/redirected"));

HttpResult result = getter.getBinary(this.feedUrl, TIMEOUT);
Assertions.assertEquals("http://localhost:" + this.mockServerClient.getPort() + "/redirected-2", result.getUrlAfterRedirect());
Expand Down

0 comments on commit 4ea2bad

Please sign in to comment.