BAEL-3242: Use random port for test execution in spring-vertx module
This commit is contained in:
+10
-4
@@ -1,27 +1,33 @@
|
||||
package com.baeldung.vertxspring;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
public class VertxSpringApplicationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private Integer port;
|
||||
|
||||
private TestRestTemplate restTemplate = new TestRestTemplate();
|
||||
|
||||
@Test
|
||||
public void givenUrl_whenReceivedArticles_thenSuccess() throws InterruptedException {
|
||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:8080/api/baeldung/articles", String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate
|
||||
.getForEntity("http://localhost:" + port + "/api/baeldung/articles", String.class);
|
||||
|
||||
assertEquals(200, responseEntity.getStatusCodeValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user