RestAssured Interceptor
Installation
gradle
implementation group: 'dev.jora.postman4j', name: 'restassured-interceptor', version: '0.0.5-alpha'
Usage
Define a custom filter for RestAssured requests and responses. The filter will automatically generate a Postman collection based on the requests and responses made during the given
HTTP call execution.
import dev.jora.postman4j.restassured.PostmanRestassuredFilter;
import dev.jora.postman4j.utils.PostmanSettings;
// ...
PostmanSettings settings = PostmanSettings.builder()
.baseCollectionName("My Collection")
.baseCollectionDescription("My Collection Description")
.schemaVersion(SchemaVersion.V2_1_0)
.requestResponseMode(RequestResponseMode.REQUEST_AND_RESPONSE)
.enableRequestBody(true)
.enableResponseBody(true)
.logWhenChanged(true)
.itemNamingStrategy(ItemNamingStrategy.COUNTER)
.build();
PostmanRestassuredFilter postmanRestassuredFilter = new PostmanRestassuredFilter(settings);
RestAssured.filters(postmanRestassuredFilter);
After executing the HTTP call generated Postman collection will be saved in the data
object. You can use the PostmanCollection
class to serialize the collection to a JSON string or file.
PostmanCollection collection = filter.getData().get("My Collection");
System.out.println(ConverterUtils.toJsonString(collection));
How to setup generation and saving postman collection in your java tests read in next chapters.
Last updated on