From 789f506b5bb02730367c3e62569604d24c332232 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 5 May 2014 14:50:48 +0200 Subject: [PATCH] Fix freemarker integration tests Freemarker integration tests now use a random port so boot builds properly when port 8080 is taken. --- .../SampleWebFreeMarkerApplicationTests.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java index ffd0882a1e..d27f2366e0 100644 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java @@ -20,6 +20,7 @@ import java.util.Arrays; 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.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; @@ -45,14 +46,17 @@ import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = SampleWebFreeMarkerApplication.class) @WebAppConfiguration -@IntegrationTest +@IntegrationTest("server.port=0") @DirtiesContext public class SampleWebFreeMarkerApplicationTests { + @Value("${local.server.port}") + private int port; + @Test public void testFreeMarkerTemplate() throws Exception { ResponseEntity entity = new TestRestTemplate().getForEntity( - "http://localhost:8080", String.class); + "http://localhost:" + port, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("Hello, Andy")); @@ -65,7 +69,7 @@ public class SampleWebFreeMarkerApplicationTests { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity responseEntity = new TestRestTemplate().exchange( - "http://localhost:8080/does-not-exist", HttpMethod.GET, requestEntity, + "http://localhost:" +port+ "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());