Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/wasapi/Caller.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ protected static <Model> Response<Model> getResponse(String serviceName, Call<Mo
return call(call, strict, printBody, serviceName);
}

/**
* Gets the response from an API call and logs the results.
*
* @param call the Call object representing the API call
* @return the Response object representing the API response
* @throws FailedCallException if the call is strict and the response is not successful
*/
protected static <Model> Response<Model> getResponse(String serviceName, Call<Model> call){
return call(call, false, logResponseBody, serviceName);
}

/**
* Executes the given call and returns a Pair containing the response and potential error model.
* This method provides advanced error handling capabilities.
Expand Down
36 changes: 9 additions & 27 deletions src/main/java/wasapi/WasapiUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public <SuccessModel> void monitorResponseCode(
() -> {
boolean condition;
Call<?> callClone = call.clone();
Response<?> response = getResponse(serviceName, callClone, false, false);
Response<?> response = getResponse(serviceName, callClone, false, logResponseBody);
condition = response.code() == expectedCode;
if (condition) {
log.success("Status code verified as " + expectedCode + "!");
Expand Down Expand Up @@ -144,8 +144,6 @@ public <SuccessModel> Response<SuccessModel> getResponseForCode(
serviceName,
expectedCode,
call,
false,
false,
printLastCallBody
)
);
Expand All @@ -169,14 +167,7 @@ public <SuccessModel> Response<SuccessModel> getResponseForCode(
String serviceName = getPreviousMethodName();
boolean codeMatch = iterativeConditionalInvocation(
timeoutInSeconds,
() -> responseCodeMatch(
serviceName,
expectedCode,
call,
false,
false,
false
)
() -> responseCodeMatch(serviceName, expectedCode, call, false)
);
Assert.assertTrue("Response code did not match the expected code " + expectedCode + " within " + timeoutInSeconds + " seconds!", codeMatch);
return ContextStore.get("monitorResponseCodeResponse");
Expand Down Expand Up @@ -204,8 +195,6 @@ public <SuccessModel> Response<SuccessModel> monitorFieldValueFromResponse(
() -> fieldValueMatch(
serviceName,
call,
false,
false,
fieldName,
expectedValue,
printLastCallBody
Expand All @@ -224,30 +213,27 @@ public <SuccessModel> Response<SuccessModel> monitorFieldValueFromResponse(
* @param serviceName The name of the service for identification purposes.
* @param expectedCode The expected HTTP response code.
* @param call The network call to inspect.
* @param strict If true, performs strict checking of the response code.
* @param printBody If true, prints the response body.
* @param printLastCallBody If true, prints the response body of the last call.
* @return True if the response code matches the expected code; otherwise, false.
*/

public static <SuccessModel> boolean responseCodeMatch(String serviceName,
int expectedCode,
Call<SuccessModel> call,
Boolean strict,
Boolean printBody,
Boolean printLastCallBody) {
boolean printLastCallBody) {
Printer log = new Printer(WasapiUtilities.class);
boolean condition;
Call<?> callClone = call.clone();
Response<?> response = getResponse(serviceName, callClone, strict, printBody);
Response<?> response = getResponse(serviceName, callClone);
condition = response.code() == expectedCode;
if (condition) {
if (printLastCallBody) {
log.info("Response body: " + MappingUtilities.Json.getJsonStringFor(response.body()));
}
log.success("Status code verified as " + expectedCode + "!");
ContextStore.put("monitorResponseCodeResponse", response);
}
if (condition && printLastCallBody)
log.info("Response body: " + MappingUtilities.Json.getJsonStringFor(response.body()));
else if (printLastCallBody)
log.info("Response body: " + MappingUtilities.Json.getJsonStringFor(response.errorBody()));
return condition;
}

Expand All @@ -257,8 +243,6 @@ public static <SuccessModel> boolean responseCodeMatch(String serviceName,
* @param <SuccessModel> The type of the expected response model.
* @param serviceName The name of the service for identification purposes.
* @param call The network call to inspect.
* @param strict If true, performs strict checking of the response code.
* @param printBody If true, prints the response body.
* @param fieldName The name of the field to inspect.
* @param expectedValue The expected field value to match.
* @param printLastCallBody If true, prints the response body of the last call.
Expand All @@ -267,16 +251,14 @@ public static <SuccessModel> boolean responseCodeMatch(String serviceName,
public static <SuccessModel> boolean fieldValueMatch(
String serviceName,
Call<SuccessModel> call,
boolean strict,
boolean printBody,
String fieldName,
String expectedValue,
boolean printLastCallBody
) {
Printer log = new Printer(WasapiUtilities.class);
boolean condition;
Call<SuccessModel> callClone = call.clone();
Response<SuccessModel> response = getResponse(serviceName, callClone, strict, printBody);
Response<SuccessModel> response = getResponse(serviceName, callClone);
SuccessModel responseBody = response.body();
if (responseBody == null) return false;
condition = ReflectionUtilities.getField(fieldName, responseBody).toString().equals(expectedValue);
Expand Down