// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java
// public class KongClientException extends RuntimeException {
// 
//     private int code;
// 
//     private String error;
// 
//     public KongClientException(String message) {
//         super(message);
//     }
// 
//     public KongClientException(String message, int code, String error) {
//         super(message);
//         this.code = code;
//         this.error = error;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     public String getError() {
//         return error;
//     }
// }
// 
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java
// @Data
// public class ApiList extends AbstractEntityList {
//     Long total;
//     String next;
//     List<Api> data;
// }


import com.github.vaibhavsinha.kong.exception.KongClientException;
import com.github.vaibhavsinha.kong.model.admin.api.Api;
import com.github.vaibhavsinha.kong.model.admin.api.ApiList;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


    //    @Test
    public void test05_CreateOrUpdateApi() throws IOException {
        //Test by HTTP PUT method....
        // API name is required, otherwise you will get exception.
        // if API id is not set, then Kong will add API by name.
        // if API id is set, the Kong will update API by id and name.
        // if API id is set, but the API is actually not exist, then Kong will response 200(OK), but the API won't be created!!!
        Api request = new Api();
        request.setName(API_NAME_V1);
        //        request.setId(API_ID_V1);
        request.setUpstreamUrl(API_UPSTREAM_URL);
        request.setUris(Arrays.asList(API_URIS));
        request.setCreatedAt(System.currentTimeMillis());
        Api response = kongClient.getApiService().createOrUpdateApi(request);
        Assert.assertNotNull(response);
        printJson(response);
        Assert.assertEquals(request.getName(), response.getName());
    }

    @Test
    public void test09_testDeleteApi() throws IOException {
        kongClient.getApiService().deleteApi(API_ID_V2);
    }


    @Test
    public void test10_ListApis() throws IOException {
        List<Api> apis = new ArrayList<>();
// Path: src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java
// public class KongClientException extends RuntimeException {
// 
//     private int code;
// 
//     private String error;
// 
//     public KongClientException(String message) {
//         super(message);
//     }
// 
//     public KongClientException(String message, int code, String error) {
//         super(message);
//         this.code = code;
//         this.error = error;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     public String getError() {
//         return error;
//     }
// }
// 
// Path: src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java
// @Data
// public class ApiList extends AbstractEntityList {
//     Long total;
//     String next;
//     List<Api> data;
// }


// Path: src/test/java/com/github/vaibhavsinha/kong/RetrofitApiServiceTest.java
import com.github.vaibhavsinha.kong.exception.KongClientException;
import com.github.vaibhavsinha.kong.model.admin.api.Api;
import com.github.vaibhavsinha.kong.model.admin.api.ApiList;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;



    //    @Test
    public void test05_CreateOrUpdateApi() throws IOException {
        //Test by HTTP PUT method....
        // API name is required, otherwise you will get exception.
        // if API id is not set, then Kong will add API by name.
        // if API id is set, the Kong will update API by id and name.
        // if API id is set, but the API is actually not exist, then Kong will response 200(OK), but the API won't be created!!!
        Api request = new Api();
        request.setName(API_NAME_V1);
        //        request.setId(API_ID_V1);
        request.setUpstreamUrl(API_UPSTREAM_URL);
        request.setUris(Arrays.asList(API_URIS));
        request.setCreatedAt(System.currentTimeMillis());
        Api response = kongClient.getApiService().createOrUpdateApi(request);
        Assert.assertNotNull(response);
        printJson(response);
        Assert.assertEquals(request.getName(), response.getName());
    }

    @Test
    public void test09_testDeleteApi() throws IOException {
        kongClient.getApiService().deleteApi(API_ID_V2);
    }


    @Test
    public void test10_ListApis() throws IOException {
        List<Api> apis = new ArrayList<>();
        ApiList apiList = kongClient.getApiService().listApis(null, null, null, null, 1L, null);