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

hope.kola.contract.api.ThenResponse Maven / Gradle / Ivy

There is a newer version: 1.1.2-RELEASE
Show newest version
package hope.kola.contract.api;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import hope.kola.contract.validation.Validatable;

public class ThenResponse implements Validatable {

  protected boolean mock = true;

  /** if body present, then the body information is high priority, this should be json defined */
  protected String json;

  /**
   * for ApiHug api this post processor script for easy mock response for Stub test
   *
   * 

Mock it? */ protected String postProcessorScript; protected Body body; public String getJson() { return json; } public boolean shouldMock() { return mock; } /** * Set response mock flag to false, so the response will totally depend on the {@link * #body(String)} to supply */ public void withoutMock() { mock = true; } /** * Body presentation * * @param body String template */ public void body(String body) { this.json = body; } public String getPostProcessorScript() { return postProcessorScript; } /** * {@code Client} side stub logic to mock a more perfect {@code Response}
* {@code Groovy} script to manipulate the mocked response, Context Variables :
* *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
NameUsageTypeComment
$T当前测试用例hope.kola.contract.verifier.context.T操作上下文+帮助类
-$H方法写回头信息
-_$H方法删除头信息
-$P方法写回参数
-_$P方法删除参数
-$V方法写回变量
-_$V方法删除变量
$RQRequest对象Map 类型动态Bean发送前预处理
$RQSRequest Specification 对象io.restassured.specification.RequestSpecification组装测试用例而用
$RPResponse对象已经组装成Bean返回结果验证
$$RPResponse对象已经组装成Bean-解包的data部分返回结果验证
$RPJResponse Json对象com.jayway.jsonpath.DocumentContext可进行结果 Path 验证
* *
* Code sample:
* *
* *
   *     //Add a header to the global context
   *     $T.H('x-header', 'sample')
   *     $RP?.name.contract('-a-suffix')
   * 
* *
* * @param postProcessorScript */ public void postProcessorScript(String postProcessorScript) { this.postProcessorScript = postProcessorScript; } /** * Customized the Response body * * @param consumer manipulate the body; */ public void body(@DelegatesTo(Body.class) Closure consumer) { this.body = new Body(); consumer.setDelegate(body); consumer.call(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy