Convert remaining samples to use random port
Partial fix for gh-337. See also gh-607 which complements this, but might conflict on a merge.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
@@ -43,14 +44,17 @@ import static org.junit.Assert.assertTrue;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleWebUiApplication.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest
|
||||
@IntegrationTest("server.port:0")
|
||||
@DirtiesContext
|
||||
public class SampleWebUiApplicationTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080", String.class);
|
||||
"http://localhost:" + port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity
|
||||
.getBody().contains("<title>Messages"));
|
||||
@@ -63,16 +67,16 @@ public class SampleWebUiApplicationTests {
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||
map.set("text", "FOO text");
|
||||
map.set("summary", "FOO");
|
||||
URI location = new TestRestTemplate().postForLocation("http://localhost:8080",
|
||||
URI location = new TestRestTemplate().postForLocation("http://localhost:" + port,
|
||||
map);
|
||||
assertTrue("Wrong location:\n" + location,
|
||||
location.toString().contains("localhost:8080"));
|
||||
location.toString().contains("localhost:" + port));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:8080/css/bootstrap.min.css", String.class);
|
||||
"http://localhost:" + port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user