修正随机端口
This commit is contained in:
parent
12f2a596bb
commit
4b35d74853
|
@ -3,8 +3,10 @@ package ocean.gateway.filters;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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;
|
||||
|
@ -15,14 +17,18 @@ import ocean.gateway.service.ServiceApplication;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {ServiceApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
|
||||
public class TokenFilterTests {
|
||||
|
||||
@LocalServerPort
|
||||
int randomServerPort;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate ;
|
||||
|
||||
@Test
|
||||
public void GetHello() {
|
||||
ResponseEntity<String> response = restTemplate.getForEntity("http://127.0.0.1:8080/hello", String.class);
|
||||
ResponseEntity<String> response = restTemplate.getForEntity("http://127.0.0.1:" + randomServerPort +"/hello", String.class);
|
||||
Assert.notNull(response, "The class must not be null");
|
||||
Assert.state(response.getStatusCode() == HttpStatus.UNAUTHORIZED, "response.getStatusCode() must be HttpStatus.UNAUTHORIZED");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user