Validate our own tests work with JUnit5 and the vintage engine
Closes gh-14737 Co-authored-by: Stephane Nicoll <snicoll@pivotal.io>
This commit is contained in:
committed by
Stephane Nicoll
parent
d9f339a1b6
commit
1db1c8b03c
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package sample.jersey;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
|
||||
@@ -25,7 +24,6 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -35,10 +33,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.server.port=0", "spring.jersey.application-path=/app" })
|
||||
public class JerseyApplicationPathAndManagementPortTests {
|
||||
class JerseyApplicationPathAndManagementPortTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@@ -50,7 +47,7 @@ public class JerseyApplicationPathAndManagementPortTests {
|
||||
private TestRestTemplate testRestTemplate;
|
||||
|
||||
@Test
|
||||
public void applicationPathShouldNotAffectActuators() {
|
||||
void applicationPathShouldNotAffectActuators() {
|
||||
ResponseEntity<String> entity = this.testRestTemplate.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/actuator/health",
|
||||
String.class);
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package sample.jersey;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -25,26 +24,24 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class SampleJerseyApplicationTests {
|
||||
class SampleJerseyApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
void contextLoads() {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverse() {
|
||||
void reverse() {
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.getForEntity("/reverse?input=olleh", String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -52,14 +49,14 @@ public class SampleJerseyApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validation() {
|
||||
void validation() {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/reverse",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void actuatorStatus() {
|
||||
void actuatorStatus() {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity("/actuator/health",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
Reference in New Issue
Block a user