BAEL-3242: Use random port for test execution in spring-vertx module

This commit is contained in:
Krzysiek
2019-12-17 20:24:33 +01:00
parent 9cd4a0a16e
commit 70ce72124b
3 changed files with 47 additions and 5 deletions
@@ -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());
}
}