77import org .springframework .boot .resttestclient .autoconfigure .AutoConfigureTestRestTemplate ;
88import org .springframework .boot .test .context .SpringBootTest ;
99import org .springframework .boot .test .web .server .LocalServerPort ;
10+ import org .springframework .beans .factory .annotation .Value ;
1011import org .springframework .http .HttpEntity ;
1112import org .springframework .http .HttpHeaders ;
1213import org .springframework .http .HttpMethod ;
2728)
2829public 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