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

lv.ctco.cukes.rest.internal.PreprocessRestRequestBody Maven / Gradle / Ivy

There is a newer version: 1.0.10
Show newest version
package lv.ctco.cukes.rest.internal;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import lv.ctco.cukes.core.internal.templating.TemplatingEngine;
import lv.ctco.cukes.http.extension.CukesHttpPlugin;
import lv.ctco.cukes.rest.facade.RestRequestFacade;

@Singleton
public class PreprocessRestRequestBody implements CukesHttpPlugin {

    @Inject
    TemplatingEngine templatingEngine;
    @Inject
    RestRequestFacade requestFacade;

    @Override
    public void beforeRequest(RequestSpecification requestSpecification) {
        String requestBody = this.requestFacade.getRequestBody();
        if (requestBody != null) {
            String processed = templatingEngine.processBody(requestBody);
            requestSpecification.body(processed);
        }
    }

    @Override
    public void afterRequest(Response response) {
        this.requestFacade.clearRequestBody();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy