[BAEL-14088] - Moved interceptop, rest config and live test back to spring-rest module
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package com.baeldung.resttemplate;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.baeldung.config.RestClientConfig;
|
||||
import com.baeldung.transfer.LoginForm;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = RestClientConfig.class)
|
||||
public class RestTemplateLiveTest {
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void givenRestTemplate_whenRequested_thenLogAndModifyResponse() {
|
||||
LoginForm loginForm = new LoginForm("userName", "password");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<LoginForm> requestEntity = new HttpEntity<LoginForm>(loginForm, headers);
|
||||
|
||||
ResponseEntity<String> responseEntity = restTemplate.postForEntity("http://httpbin.org/post", requestEntity, String.class);
|
||||
|
||||
assertThat(responseEntity.getStatusCode(), is(equalTo(HttpStatus.OK)));
|
||||
assertThat(responseEntity.getHeaders()
|
||||
.get("Foo")
|
||||
.get(0), is(equalTo("bar")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user