package ${domain};

import ${domain}.frame.ApiRequest;
import ${domain}.frame.ApiResponse;
import ${domain}.frame.MapperUtil;
<#list apiList as item>
import ${domain}.module.${module}.req.${item.request};
</#list>
<#list apiList as item>
import ${domain}.module.${module}.rsp.${item.response};
</#list>
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ApiTest - 测试用例
 *
 * @author author
 * @version 0.0.1
 * @since 2019-06-11
 */
public class ${className} {

    private ApiClient apiClient;

    @Before
    public void before() {
        //实例化API请求客户端
        ApiClient.init("http://localhost:8080/api", "app_key", "1234567890123456");
        apiClient = ApiClient.getInstance();
        ApiClient client = ApiClient.getInstance();
        client.setDebug(true);

        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        //设置发送网络请求前的统一操作
        client.setBefore(new ApiClient.Before() {
            public void call(ApiRequest request) {
                System.out.println("before-->request = " + MapperUtil.toJson(request));
                System.out.println("before-->path    = " + request.path());
            }
        });
        //设置网络请求完成后的统一操作
        client.setAfter(new ApiClient.After() {
            public void call(ApiRequest request, ApiResponse response) {
                System.out.println("after-->response = " + MapperUtil.toJson(response));
                Date end = new Date();
                System.out.println("after-->time     = " + simpleDateFormat.format(end));
            }
        });

    }
<#list apiList as item>

    @Test
    public void test${item.request}() {
        ${item.request} request = new ${item.request}();
        ${item.response} response = apiClient.execute(request);
        Assert.assertTrue(!response.hasError());
    }
</#list>
}
