// 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;
package com.github.vaibhavsinha.kong;



/**
 * Created by vaibhav on 12/06/17.
 *
 * Updated by fanhua on 2017-08-04.
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RetrofitApiServiceTest extends BaseTest {

    private String API_NAME_V1 = "Test_V1_Api";
//    private String API_ID_V1 = "f813a66b-bac6-4951-831b-f04d53ae0bf0"; // not exist
    private String API_ID_V1 = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3";

    private String API_NAME_V2 = "Test_V2_Api";
    private String API_NAME_V2_NEW = "Test.V2.Api";
    private String API_ID_V2 = "f813a66b-bac6-4952-831b-f04d53ae0bf0";

    private String API_UPSTREAM_URL = "http://httpbin.org";
    private String[] API_HOSTS = new String[] {"example.com"};
    private String[] API_URIS = new String[] {"/v1/example", "/v2/example"};


    // -----------------------------------------------------------------------

    @Test
    public void test01_CreateApi() throws IOException {
        Api request = new Api();
        request.setId(API_ID_V2);
        request.setName(API_NAME_V2);
        request.setUpstreamUrl(API_UPSTREAM_URL);
//        request.setHosts(Arrays.asList(API_HOSTS));
        request.setUris(Arrays.asList(API_URIS));

        Api response = kongClient.getApiService().createApi(request);
        printJson(response);
        Assert.assertEquals(request.getName(), response.getName());
    }

    @Test
    public void test02_GetApi() throws IOException {
        Api response = kongClient.getApiService().getApi(API_NAME_V2);
        printJson(response);
        Assert.assertEquals(API_NAME_V2, response.getName());
    }

// 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;

package com.github.vaibhavsinha.kong;



/**
 * Created by vaibhav on 12/06/17.
 *
 * Updated by fanhua on 2017-08-04.
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RetrofitApiServiceTest extends BaseTest {

    private String API_NAME_V1 = "Test_V1_Api";
//    private String API_ID_V1 = "f813a66b-bac6-4951-831b-f04d53ae0bf0"; // not exist
    private String API_ID_V1 = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3";

    private String API_NAME_V2 = "Test_V2_Api";
    private String API_NAME_V2_NEW = "Test.V2.Api";
    private String API_ID_V2 = "f813a66b-bac6-4952-831b-f04d53ae0bf0";

    private String API_UPSTREAM_URL = "http://httpbin.org";
    private String[] API_HOSTS = new String[] {"example.com"};
    private String[] API_URIS = new String[] {"/v1/example", "/v2/example"};


    // -----------------------------------------------------------------------

    @Test
    public void test01_CreateApi() throws IOException {
        Api request = new Api();
        request.setId(API_ID_V2);
        request.setName(API_NAME_V2);
        request.setUpstreamUrl(API_UPSTREAM_URL);
//        request.setHosts(Arrays.asList(API_HOSTS));
        request.setUris(Arrays.asList(API_URIS));

        Api response = kongClient.getApiService().createApi(request);
        printJson(response);
        Assert.assertEquals(request.getName(), response.getName());
    }

    @Test
    public void test02_GetApi() throws IOException {
        Api response = kongClient.getApiService().getApi(API_NAME_V2);
        printJson(response);
        Assert.assertEquals(API_NAME_V2, response.getName());
    }

    @Test(expected = KongClientException.class)