BAEL-2552 - use JUnit @Rule

This commit is contained in:
mthomas 2020-03-05 11:47:04 -06:00
parent f7a449978c
commit f37bb67f4c

View File

@ -6,7 +6,9 @@ import javax.net.ssl.SSLException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@ -35,6 +37,9 @@ public class TimeoutLiveTest {
private WebTestClient webTestClient; private WebTestClient webTestClient;
@Rule
public ExpectedException exception = ExpectedException.none();
@Before @Before
public void setup() throws SSLException { public void setup() throws SSLException {
webTestClient = WebTestClient.bindToServer(getConnector()) webTestClient = WebTestClient.bindToServer(getConnector())
@ -44,28 +49,22 @@ public class TimeoutLiveTest {
@Test @Test
public void shouldTimeout() { public void shouldTimeout() {
try { exception.expect(ReadTimeoutException.class);
webTestClient.get() webTestClient.get()
.uri("/timeout/{timeout}", 3) .uri("/timeout/{timeout}", 3)
.exchange(); .exchange();
Assert.fail(); Assert.fail();
} catch (ReadTimeoutException ignore) {
}
} }
@Test @Test
public void shouldNotTimeout() { public void shouldNotTimeout() {
try { WebTestClient.ResponseSpec response = webTestClient.get()
WebTestClient.ResponseSpec response = webTestClient.get() .uri("/timeout/{timeout}", 1)
.uri("/timeout/{timeout}", 1) .exchange();
.exchange(); response.expectStatus()
response.expectStatus() .isOk()
.isOk() .expectBody(String.class)
.expectBody(String.class) .isEqualTo("OK");
.isEqualTo("OK");
} catch (ReadTimeoutException e) {
Assert.fail();
}
} }
private ReactorClientHttpConnector getConnector() throws SSLException { private ReactorClientHttpConnector getConnector() throws SSLException {