48 lines
1.8 KiB
Java
Raw Normal View History

2019-04-29 15:06:17 +03:00
package com.baeldung.client;
2013-07-25 00:54:33 +03:00
2013-08-09 11:16:11 +03:00
import static org.hamcrest.Matchers.equalTo;
2014-04-23 18:22:14 +03:00
import static org.hamcrest.Matchers.is;
2013-08-09 11:16:11 +03:00
import static org.junit.Assert.assertThat;
2019-04-29 15:06:17 +03:00
import com.baeldung.client.spring.ClientConfig;
import com.baeldung.web.dto.Foo;
2013-07-25 00:54:33 +03:00
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
2013-07-25 01:03:26 +03:00
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
2013-07-25 00:54:33 +03:00
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
2013-08-09 11:16:11 +03:00
import org.springframework.web.client.ResourceAccessException;
2013-07-25 00:54:33 +03:00
import org.springframework.web.client.RestTemplate;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ClientConfig.class }, loader = AnnotationConfigContextLoader.class)
public class ClientLiveTest {
@Autowired
2013-08-09 16:08:53 +03:00
private RestTemplate secureRestTemplate;
2013-07-25 00:54:33 +03:00
// tests
@Test
2014-04-23 18:22:14 +03:00
public final void whenContextIsBootstrapped_thenNoExceptions() {
//
}
2013-07-25 01:03:26 +03:00
2014-04-23 18:22:14 +03:00
@Test
public final void whenSecuredRestApiIsConsumed_then200OK() {
final ResponseEntity<Foo> responseEntity = secureRestTemplate.exchange("http://localhost:8082/httpclient-simple/api/foos/1", HttpMethod.GET, null, Foo.class);
2014-04-23 18:22:14 +03:00
assertThat(responseEntity.getStatusCode().value(), is(200));
2013-07-25 00:54:33 +03:00
}
2013-08-09 11:16:11 +03:00
@Test(expected = ResourceAccessException.class)
public final void whenHttpsUrlIsConsumed_thenException() {
final String urlOverHttps = "https://localhost:8443/httpclient-simple/api/bars/1";
2013-08-09 11:16:11 +03:00
final ResponseEntity<String> response = new RestTemplate().exchange(urlOverHttps, HttpMethod.GET, null, String.class);
assertThat(response.getStatusCode().value(), equalTo(200));
}
2013-07-25 00:54:33 +03:00
}