|
2 | 2 |
|
3 | 3 | import org.junit.jupiter.api.Test; |
4 | 4 | import org.springframework.beans.factory.annotation.Autowired; |
5 | | -import org.springframework.boot.test.context.SpringBootTest; |
6 | 5 | import org.springframework.boot.test.web.server.LocalServerPort; |
7 | 6 | import org.springframework.http.HttpHeaders; |
8 | 7 | import org.springframework.http.HttpStatus; |
|
11 | 10 | import org.springframework.test.context.ContextConfiguration; |
12 | 11 | import org.springframework.test.context.TestPropertySource; |
13 | 12 | import org.springframework.web.client.RestTemplate; |
14 | | - |
| 13 | +import org.springframework.http.HttpEntity; |
| 14 | +import org.springframework.http.HttpMethod.*; |
15 | 15 | import static org.assertj.core.api.Assertions.assertThat; |
16 | 16 |
|
17 | 17 | @ContextConfiguration() |
@@ -55,12 +55,17 @@ void shouldAllowAccessToUnsecuredEndpoint() { |
55 | 55 | @Test |
56 | 56 | void shouldGrantAccessToSecuredEndpointWithValidCredentials() { |
57 | 57 | // Arrange |
58 | | - String securedUrl = "http://localhost:5000" + port + "/api/payments/test"; |
| 58 | + String securedUrl = "http://localhost:" + port + "/api/payments/test"; |
59 | 59 | HttpHeaders headers = new HttpHeaders(); |
60 | | - headers.setBasicAuth("user", "password"); |
| 60 | + //headers.setBasicAuth("username", "password1234"); // Adjust |
| 61 | + // credentials as needed |
| 62 | + |
| 63 | + HttpEntity<Void> requestEntity = new HttpEntity<>(headers); |
61 | 64 |
|
62 | 65 | // Act |
63 | | - ResponseEntity<String> response = restTemplate.getForEntity(securedUrl, String.class); |
| 66 | + ResponseEntity<String> response = restTemplate.exchange( |
| 67 | + securedUrl, org.springframework.http.HttpMethod.GET, requestEntity, String.class |
| 68 | + ); |
64 | 69 |
|
65 | 70 | // Assert |
66 | 71 | assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); |
|
0 commit comments