Skip to content

Commit e006a5a

Browse files
committed
Enable full request and response logging for REST Assured Quarkus tests
Originally mentioned at: quarkusio#9174 (comment)
1 parent 53a8789 commit e006a5a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test-framework/common/src/main/java/io/quarkus/test/common/RestAssuredURLManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.restassured.RestAssured;
99
import io.restassured.config.HttpClientConfig;
1010
import io.restassured.config.RestAssuredConfig;
11+
import io.restassured.specification.RequestSpecification;
1112

1213
/**
1314
* Utility class that sets the rest assured port to the default test port and meaningful timeouts.
@@ -26,6 +27,7 @@ public class RestAssuredURLManager {
2627
private static String oldBaseURI;
2728
private static String oldBasePath;
2829
private static Object oldRestAssuredConfig; // we can't declare the type here as that would prevent this class for being loaded if RestAssured is not present
30+
private static Object oldRequestSpecification;
2931

3032
private static final boolean REST_ASSURED_PRESENT;
3133

@@ -113,14 +115,17 @@ public static void setURL(boolean useSecureConnection, Integer port, String addi
113115
RestAssured.basePath = bp.toString();
114116
}
115117

118+
oldRestAssuredConfig = RestAssured.config();
119+
116120
Duration timeout = ConfigProvider.getConfig()
117121
.getOptionalValue("quarkus.http.test-timeout", Duration.class).orElse(Duration.ofSeconds(30));
118122
configureTimeouts(timeout);
123+
124+
oldRequestSpecification = RestAssured.requestSpecification;
125+
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
119126
}
120127

121128
private static void configureTimeouts(Duration d) {
122-
oldRestAssuredConfig = RestAssured.config();
123-
124129
RestAssured.config = RestAssured.config().httpClient(new HttpClientConfig()
125130
.setParam("http.conn-manager.timeout", d.toMillis()) // this needs to be long
126131
.setParam("http.connection.timeout", (int) d.toMillis()) // this needs to be int
@@ -136,5 +141,6 @@ public static void clearURL() {
136141
RestAssured.baseURI = oldBaseURI;
137142
RestAssured.basePath = oldBasePath;
138143
RestAssured.config = (RestAssuredConfig) oldRestAssuredConfig;
144+
RestAssured.requestSpecification = (RequestSpecification) oldRequestSpecification;
139145
}
140146
}

0 commit comments

Comments
 (0)