Skip to content

Commit 17b3669

Browse files
Theo-lbgCopilot
andcommitted
feat(test): refactor authentication to use values from application properties
Co-authored-by: Copilot <copilot@github.com>
1 parent 8e87ff6 commit 17b3669

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/test/java/feature/SpringIntegrationTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate;
88
import org.springframework.boot.test.context.SpringBootTest;
99
import org.springframework.boot.test.web.server.LocalServerPort;
10+
import org.springframework.beans.factory.annotation.Value;
1011
import org.springframework.http.HttpEntity;
1112
import org.springframework.http.HttpHeaders;
1213
import org.springframework.http.HttpMethod;
@@ -27,8 +28,11 @@
2728
)
2829
public class SpringIntegrationTest {
2930

30-
private static final String TEST_USERNAME = "testadmin";
31-
private static final String TEST_PASSWORD = "testadminpass";
31+
@Value("${app.security.admin.username}")
32+
private String testUsername;
33+
34+
@Value("${app.security.admin.password}")
35+
private String testPassword;
3236

3337
@Autowired
3438
protected TestRestTemplate restTemplate;
@@ -41,7 +45,7 @@ public class SpringIntegrationTest {
4145
protected void executeGet(String path) {
4246
String url = "http://localhost:" + port + path;
4347
latestResponse = restTemplate
44-
.withBasicAuth(TEST_USERNAME, TEST_PASSWORD)
48+
.withBasicAuth(testUsername, testPassword)
4549
.getForEntity(url, String.class);
4650
}
4751

@@ -51,14 +55,14 @@ protected void executePost(String path, Object payload) {
5155
headers.setContentType(MediaType.APPLICATION_JSON);
5256
HttpEntity<Object> request = new HttpEntity<>(payload, headers);
5357
latestResponse = restTemplate
54-
.withBasicAuth(TEST_USERNAME, TEST_PASSWORD)
58+
.withBasicAuth(testUsername, testPassword)
5559
.postForEntity(url, request, String.class);
5660
}
5761

5862
protected void executeDelete(String path) {
5963
String url = "http://localhost:" + port + path;
6064
latestResponse = restTemplate
61-
.withBasicAuth(TEST_USERNAME, TEST_PASSWORD)
65+
.withBasicAuth(testUsername, testPassword)
6266
.exchange(url, HttpMethod.DELETE, HttpEntity.EMPTY, String.class);
6367
}
6468
}

0 commit comments

Comments
 (0)