Skip to content

Commit 437927e

Browse files
authored
Merge pull request #166 from marklogic/feature/contrib-update
Added support for logging the request and response in tests
2 parents f3f98be + 309f53d commit 437927e

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ Use the following steps to install GDS as a standalone project and run the tests
88
password
99
2. Run `./gradlew -i mlDeploy loadTestData test`
1010

11+
## Inspecting logging of HTTP requests and responses
12+
13+
If you wish to see the HTTP request/response that each test sends/receives, set the following value in your
14+
`gradle-local.properties` file:
15+
16+
logRequestAndResponse=true
17+
18+
Or include it on the command line when running tests:
19+
20+
./gradlew -i test -PlogRequestAndResponse=true
21+
22+
This is often helpful when running a single test so that you can see what the input and output is for a particular
23+
scenario. To run a single test, such as `PointQueries`, run the following (this adds the property to the command
24+
line, but you can also just add it to your `gradle-local.properties` file so you don't need to remember to add it
25+
each time):
26+
27+
./gradlew -i test --tests PointQueries -PlogRequestAndResponse=true
28+
29+
To run an individual test method, add a period and the method name to the test class name:
30+
31+
./gradlew -i test --tests PointQueries.testPointIntersects1 -PlogRequestAndResponse=true
32+
33+
To force tests to be run, include `cleanTest`, which will prevent Gradle from not running a test due to it not
34+
having changed:
35+
36+
./gradlew -i cleanTest test --tests PointQueries.testPointIntersects1 -PlogRequestAndResponse=true
37+
1138
# Manual testing
1239

1340
You can perform manual testing by following the instructions in the `examples/sample-project/README.md` file for

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ dependencies {
3636
}
3737

3838
test {
39-
systemProperty "sonar.projectVersion", project.version
39+
systemProperty "sonar.projectVersion", project.version
40+
systemProperty "logRequestAndResponse", logRequestAndResponse
4041
}
4142

4243
task loadTestData(dependsOn: [

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ mlContentDatabaseName=geo-data-services-test-content
2727
mlSchemasDatabaseName=geo-data-services-test-schemas
2828
mlContentForestsPerHost=1
2929

30+
# Set to true for each test to log the HTTP request it sends and the HTTP response it receives.
31+
logRequestAndResponse=false
32+
3033
# Sonar settings
3134
systemProp.sonar.login=set this in gradle-local.properties
3235
systemProp.sonar.host.url=set this in gradle-local.properties

src/test/java/AbstractTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import com.marklogic.gds.GeoQueryRequest;
22
import io.restassured.RestAssured;
33
import io.restassured.filter.log.LogDetail;
4+
import io.restassured.filter.log.RequestLoggingFilter;
5+
import io.restassured.filter.log.ResponseLoggingFilter;
46
import io.restassured.http.ContentType;
57
import io.restassured.path.json.JsonPath;
68
import io.restassured.path.json.config.JsonPathConfig;
@@ -20,6 +22,10 @@ public void setup() {
2022
RestAssured.port = 8096;
2123
RestAssured.authentication = basic("test-geo-data-services-writer", "test-geo-data-services-writer");
2224

25+
if ("true".equals(System.getProperty("logRequestAndResponse"))) {
26+
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
27+
}
28+
2329
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL);
2430
}
2531

0 commit comments

Comments
 (0)