2727)
2828public class SpringIntegrationTest {
2929
30+ private static final String TEST_USERNAME = "testuser" ;
31+ private static final String TEST_PASSWORD = "testpass" ;
32+
3033 @ Autowired
3134 protected TestRestTemplate restTemplate ;
3235
@@ -37,19 +40,25 @@ public class SpringIntegrationTest {
3740
3841 protected void executeGet (String path ) {
3942 String url = "http://localhost:" + port + path ;
40- latestResponse = restTemplate .getForEntity (url , String .class );
43+ latestResponse = restTemplate
44+ .withBasicAuth (TEST_USERNAME , TEST_PASSWORD )
45+ .getForEntity (url , String .class );
4146 }
4247
4348 protected void executePost (String path , Object payload ) {
4449 String url = "http://localhost:" + port + path ;
4550 HttpHeaders headers = new HttpHeaders ();
4651 headers .setContentType (MediaType .APPLICATION_JSON );
4752 HttpEntity <Object > request = new HttpEntity <>(payload , headers );
48- latestResponse = restTemplate .postForEntity (url , request , String .class );
53+ latestResponse = restTemplate
54+ .withBasicAuth (TEST_USERNAME , TEST_PASSWORD )
55+ .postForEntity (url , request , String .class );
4956 }
5057
5158 protected void executeDelete (String path ) {
5259 String url = "http://localhost:" + port + path ;
53- latestResponse = restTemplate .exchange (url , HttpMethod .DELETE , HttpEntity .EMPTY , String .class );
60+ latestResponse = restTemplate
61+ .withBasicAuth (TEST_USERNAME , TEST_PASSWORD )
62+ .exchange (url , HttpMethod .DELETE , HttpEntity .EMPTY , String .class );
5463 }
5564}
0 commit comments