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
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,10 +19,9 @@ import java.io.IOException;
|
||||
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -33,13 +32,11 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
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 = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class SampleOauth2ResourceServerApplicationTests {
|
||||
class SampleOauth2ResourceServerApplicationTests {
|
||||
|
||||
private static MockWebServer server = new MockWebServer();
|
||||
|
||||
@@ -52,7 +49,7 @@ public class SampleOauth2ResourceServerApplicationTests {
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws Exception {
|
||||
server.start();
|
||||
String url = server.url("/.well-known/jwks.json").toString();
|
||||
@@ -60,14 +57,14 @@ public class SampleOauth2ResourceServerApplicationTests {
|
||||
System.setProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri", url);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void shutdown() throws IOException {
|
||||
server.shutdown();
|
||||
System.clearProperty("spring.security.oauth2.resourceserver.jwt.jwk-set-uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withValidBearerTokenShouldAllowAccess() {
|
||||
void withValidBearerTokenShouldAllowAccess() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBearerAuth(VALID_TOKEN);
|
||||
HttpEntity<?> request = new HttpEntity<Void>(headers);
|
||||
@@ -77,7 +74,7 @@ public class SampleOauth2ResourceServerApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNoBearerTokenShouldNotAllowAccess() {
|
||||
void withNoBearerTokenShouldNotAllowAccess() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
HttpEntity<?> request = new HttpEntity<Void>(headers);
|
||||
ResponseEntity<String> entity = this.restTemplate.exchange("/", HttpMethod.GET,
|
||||
|
||||
Reference in New Issue
Block a user