0

So I have a simple endpoint in my Spring Boot App, which just redirects to another website:

@Controller public class FeedbackController {

@GetMapping(path = "/test")
public Mono<ResponseEntity<Void>> method() {
    String redirectUrl = "https://www.google.com";
    return Mono
            .just(ResponseEntity.status(HttpStatus.TEMPORARY_REDIRECT).location(URI.create(redirectUrl)).build());
}

Making a GET request to this endpoint (e.g. in browser or with postman) gives me the page content of google as a response. However for testing purposes I want to make sure that the response is a TEMPORARY_REDIRECT with www.google.com as the Location Header. How can I make a request to this endpoint so that the response is the 307 TEMPORARY_REDIRECT instead of the 200 with page content from the target website?

Losyres
  • 82
  • 1
  • 7

1 Answers1

0

First

to test if its working, you could use simple tools like curl :

We add the -L flag to tell curl that we want to know if we are getting redirected

curl -L http://www.....

Go further

Then, you could simply use tools like MockMvc to automate this test See this SO post

Jacouille
  • 951
  • 8
  • 14