com.github.aoreshin.allure.rest.assured.ApiExtractingSteps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of allure-rest-assured Show documentation
Show all versions of allure-rest-assured Show documentation
Fluent API for Rest Assured and Allure reports
package com.github.aoreshin.allure.rest.assured;
import com.github.aoreshin.junit5.allure.steps.StepWrapperSteps;
import io.qameta.allure.Step;
import io.restassured.response.Response;
import java.util.Map;
import static com.github.aoreshin.allure.rest.assured.ApiRequestSteps.apiRequest;
import static java.util.stream.Collectors.toMap;
public final class ApiExtractingSteps extends StepWrapperSteps {
private final Response response;
ApiExtractingSteps(Response response) {
this.response = response;
}
@Step("Сохранение {jsonPath} как {key}")
public ApiExtractingSteps saveBodyJsonPath(String jsonPath, String key, Map map) {
T value = response.getBody().jsonPath().get(jsonPath);
map.put(key, value);
return this;
}
@Step("Сохранение полей с соответствующими ключами {pathsAndKeys}")
public ApiExtractingSteps saveBodyJsonPath(Map pathsAndKeys, Map map) {
Map values = pathsAndKeys
.entrySet()
.stream()
.collect(toMap(Map.Entry::getValue, entry -> {
String expression = entry.getKey();
return response.getBody().jsonPath().get(expression);
}));
map.putAll(values);
return this;
}
@Step("Сохранение заголовка {header} как {key}")
public ApiExtractingSteps saveHeader(String header, String key, Map map) {
String value = response.getHeader(header);
map.put(key, value);
return this;
}
@Step("Сохранение заголовков как соответствующие им ключи {pathsAndKeys}")
public ApiExtractingSteps saveHeader(Map headersAndKeys, Map map) {
Map values = headersAndKeys
.entrySet()
.stream()
.collect(toMap(Map.Entry::getValue,
entry -> response.getHeader(entry.getKey())));
map.putAll(values);
return this;
}
public ApiRequestSteps next() {
return apiRequest();
}
}