All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.aoreshin.allure.rest.assured.ApiExtractingSteps Maven / Gradle / Ivy

There is a newer version: 83
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy