This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/io/cloudbeat/common/restassured/CbRestAssuredFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.cloudbeat.common.restassured; | ||
|
||
import io.cloudbeat.common.CbTestContext; | ||
import io.restassured.filter.FilterContext; | ||
import io.restassured.filter.OrderedFilter; | ||
import io.restassured.internal.NameAndValue; | ||
import io.restassured.internal.support.Prettifier; | ||
import io.restassured.response.Response; | ||
import io.restassured.specification.FilterableRequestSpecification; | ||
import io.restassured.specification.FilterableResponseSpecification; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class CbRestAssuredFilter implements OrderedFilter { | ||
final CbTestContext ctx; | ||
public CbRestAssuredFilter(CbTestContext ctx) { | ||
this.ctx = ctx; | ||
} | ||
|
||
@Override | ||
public Response filter(final FilterableRequestSpecification requestSpec, | ||
final FilterableResponseSpecification responseSpec, | ||
final FilterContext filterContext) { | ||
//public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { | ||
final Prettifier prettifier = new Prettifier(); | ||
final String url = requestSpec.getURI(); | ||
final String method = requestSpec.getMethod(); | ||
final Map<String, String> requestHeaders = toMap(requestSpec.getHeaders()); | ||
String requestBody = null; | ||
if (Objects.nonNull(requestSpec.getBody())) { | ||
requestBody = prettifier.getPrettifiedBodyIfPossible(requestSpec); | ||
} | ||
final Response response = filterContext.next(requestSpec, responseSpec); | ||
final String statusText = response.getStatusLine(); | ||
final int statusCode = response.getStatusCode(); | ||
final String responseBody = prettifier.getPrettifiedBodyIfPossible(response, response.getBody()); | ||
final Map<String, String> responseHeaders = toMap(response.getHeaders()); | ||
final String stepName = String.format("%s %s", method, url); | ||
final String stepId = ctx.getReporter().startStep(stepName); | ||
ctx.getReporter().endStep(stepId); | ||
return response; | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
private static Map<String, String> toMap(final Iterable<? extends NameAndValue> items) { | ||
final Map<String, String> result = new HashMap<>(); | ||
items.forEach(h -> result.put(h.getName(), h.getValue())); | ||
return result; | ||
} | ||
|
||
} |
8 changes: 4 additions & 4 deletions
8
src/main/java/io/cloudbeat/common/restassured/RestAssuredFailureListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/main/java/io/cloudbeat/common/restassured/RestAssuredRequestLogger.java
This file was deleted.
Oops, something went wrong.