Skip to content

Commit 6869140

Browse files
committed
Configure Grails sample to run tests using a random server port
See gh-250
1 parent d5a2dff commit 6869140

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

samples/rest-notes-grails/grails-app/conf/application.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ environments:
7474
dataSource:
7575
dbCreate: update
7676
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
77+
server:
78+
port: 0
7779
production:
7880
dataSource:
7981
dbCreate: update

samples/rest-notes-grails/src/integration-test/groovy/com/example/ApiDocumentationSpec.groovy

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ import com.jayway.restassured.specification.RequestSpecification
3535
import grails.test.mixin.integration.Integration
3636
import grails.transaction.Rollback
3737
import org.junit.Rule
38-
import org.springframework.restdocs.JUnitRestDocumentation
38+
import org.springframework.beans.factory.annotation.Value
3939
import org.springframework.http.MediaType
40+
import org.springframework.restdocs.JUnitRestDocumentation
4041
import spock.lang.Specification
4142

4243
@Integration
@@ -46,6 +47,9 @@ class ApiDocumentationSpec extends Specification {
4647
@Rule
4748
JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation('src/docs/generated-snippets')
4849

50+
@Value('${local.server.port}')
51+
Integer serverPort
52+
4953
protected RequestSpecification documentationSpec
5054

5155
void setup() {
@@ -75,7 +79,7 @@ class ApiDocumentationSpec extends Specification {
7579
fieldWithPath('plugins').type(JsonFieldType.ARRAY).description('the plugins active for this project'),
7680
)))
7781
.when()
78-
.port(8080)
82+
.port(this.serverPort)
7983
.get('/')
8084
.then()
8185
.assertThat()
@@ -99,7 +103,7 @@ class ApiDocumentationSpec extends Specification {
99103
fieldWithPath('[].tags').type(JsonFieldType.ARRAY).description('the list of tags associated with the note'),
100104
)))
101105
.when()
102-
.port(8080)
106+
.port(this.serverPort)
103107
.get('/notes')
104108
.then()
105109
.assertThat()
@@ -130,7 +134,7 @@ class ApiDocumentationSpec extends Specification {
130134
)))
131135
.body('{ "body": "My test example", "title": "Eureka!", "tags": [{"name": "testing123"}] }')
132136
.when()
133-
.port(8080)
137+
.port(this.serverPort)
134138
.post('/notes')
135139
.then()
136140
.assertThat()
@@ -154,7 +158,7 @@ class ApiDocumentationSpec extends Specification {
154158
fieldWithPath('tags').type(JsonFieldType.ARRAY).description('the list of tags associated with the note'),
155159
)))
156160
.when()
157-
.port(8080)
161+
.port(this.serverPort)
158162
.get('/notes/1')
159163
.then()
160164
.assertThat()

0 commit comments

Comments
 (0)