Configure Grails sample to run tests using a random server port

See gh-250
This commit is contained in:
Andy Wilkinson
2016-05-31 10:20:19 +01:00
parent d5a2dff210
commit 686914071a
2 changed files with 11 additions and 5 deletions

View File

@@ -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

View File

@@ -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()