-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSpringFoxSpec.groovy
33 lines (28 loc) · 1.02 KB
/
SpringFoxSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package grails.springfox.sample
import grails.testing.mixin.integration.Integration
import groovy.json.JsonOutput
import org.junit.Assert
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode
import org.springframework.boot.context.embedded.LocalServerPort
import spock.lang.Specification
import static io.restassured.RestAssured.get
@Integration
class SpringFoxSpec extends Specification implements FileAccess {
@LocalServerPort
private int port
void "Contract tests for the api documentation"() {
given:
def expected = fileContents("/expected-service-description.json")
def actual = get("http://localhost:$port/v2/api-docs").asString()
expect:
try {
JSONAssert.assertEquals(
expected.replaceAll("__PORT__", "$port"),
actual,
JSONCompareMode.NON_EXTENSIBLE)
} catch (AssertionError e) {
Assert.fail("${e.getMessage()}${System.getProperty("line.separator")}${JsonOutput.prettyPrint(actual)}")
}
}
}