From 686914071a38c2d25afb230fe88ecdaf111b16bc Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 31 May 2016 10:20:19 +0100 Subject: [PATCH] Configure Grails sample to run tests using a random server port See gh-250 --- .../grails-app/conf/application.yml | 2 ++ .../groovy/com/example/ApiDocumentationSpec.groovy | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/samples/rest-notes-grails/grails-app/conf/application.yml b/samples/rest-notes-grails/grails-app/conf/application.yml index 6d7d00e8..3fe5b297 100644 --- a/samples/rest-notes-grails/grails-app/conf/application.yml +++ b/samples/rest-notes-grails/grails-app/conf/application.yml @@ -74,6 +74,8 @@ environments: dataSource: dbCreate: update url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE + server: + port: 0 production: dataSource: dbCreate: update diff --git a/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy b/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy index ae594901..3f0da9ca 100644 --- a/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy +++ b/samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy @@ -35,8 +35,9 @@ import com.jayway.restassured.specification.RequestSpecification import grails.test.mixin.integration.Integration import grails.transaction.Rollback import org.junit.Rule -import org.springframework.restdocs.JUnitRestDocumentation +import org.springframework.beans.factory.annotation.Value import org.springframework.http.MediaType +import org.springframework.restdocs.JUnitRestDocumentation import spock.lang.Specification @Integration @@ -46,6 +47,9 @@ class ApiDocumentationSpec extends Specification { @Rule JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation('src/docs/generated-snippets') + @Value('${local.server.port}') + Integer serverPort + protected RequestSpecification documentationSpec void setup() { @@ -75,7 +79,7 @@ class ApiDocumentationSpec extends Specification { fieldWithPath('plugins').type(JsonFieldType.ARRAY).description('the plugins active for this project'), ))) .when() - .port(8080) + .port(this.serverPort) .get('/') .then() .assertThat() @@ -99,7 +103,7 @@ class ApiDocumentationSpec extends Specification { fieldWithPath('[].tags').type(JsonFieldType.ARRAY).description('the list of tags associated with the note'), ))) .when() - .port(8080) + .port(this.serverPort) .get('/notes') .then() .assertThat() @@ -130,7 +134,7 @@ class ApiDocumentationSpec extends Specification { ))) .body('{ "body": "My test example", "title": "Eureka!", "tags": [{"name": "testing123"}] }') .when() - .port(8080) + .port(this.serverPort) .post('/notes') .then() .assertThat() @@ -154,7 +158,7 @@ class ApiDocumentationSpec extends Specification { fieldWithPath('tags').type(JsonFieldType.ARRAY).description('the list of tags associated with the note'), ))) .when() - .port(8080) + .port(this.serverPort) .get('/notes/1') .then() .assertThat()