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


import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.github.vaibhavsinha.kong.model.admin.plugin.OAuth2Config;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import com.github.vaibhavsinha.kong.exception.KongClientException;
import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin;
import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;
package com.github.vaibhavsinha.kong;




/**
 * Created by fanhua on 2017-08-05.
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RetrofitApiPluginServiceTest extends BaseTest {

    private String PLUGIN_ID = "3d3ee453-161c-449b-a468-42f06b7c0dc5";
    private String PLUGIN_NAME = "oauth2";
    private OAuth2Config OAUTH2_CONFIG = new OAuth2Config();
    private String OAUTH2_PROVISION_KEY = "1f2b8d4baadb4b6f93c82b1599cad575";

    private String API_NAME = "Test.V2.Api";

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

    @Test
    public void test01_CreatePluginForApi() throws IOException {
        Plugin request = new Plugin();
        request.setId(PLUGIN_ID);
        request.setName(PLUGIN_NAME);

        OAUTH2_CONFIG.setProvisionKey(OAUTH2_PROVISION_KEY);
        OAUTH2_CONFIG.setEnableAuthorizationCode(true);
        OAUTH2_CONFIG.setEnableImplicitGrant(true);
        OAUTH2_CONFIG.setEnablePasswordGrant(true);
        OAUTH2_CONFIG.setEnableClientCredentials(true);
        OAUTH2_CONFIG.setTokenExpiration(7200);
        request.setConfig(OAUTH2_CONFIG);

        Plugin response = kongClient.getApiPluginService().addPluginForApi(API_NAME, request);
        printJson(response);
        Assert.assertEquals(request.getName(), response.getName());
    }

    @Test
    public void test02_GetPluginForApi() throws IOException {
        Plugin response = kongClient.getApiPluginService().getPluginForApi(API_NAME, PLUGIN_ID);
        printJson(response);
        Assert.assertEquals(PLUGIN_NAME, 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/test/java/com/github/vaibhavsinha/kong/RetrofitApiPluginServiceTest.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.github.vaibhavsinha.kong.model.admin.plugin.OAuth2Config;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import com.github.vaibhavsinha.kong.exception.KongClientException;
import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin;
import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList;

package com.github.vaibhavsinha.kong;




/**
 * Created by fanhua on 2017-08-05.
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RetrofitApiPluginServiceTest extends BaseTest {

    private String PLUGIN_ID = "3d3ee453-161c-449b-a468-42f06b7c0dc5";
    private String PLUGIN_NAME = "oauth2";
    private OAuth2Config OAUTH2_CONFIG = new OAuth2Config();
    private String OAUTH2_PROVISION_KEY = "1f2b8d4baadb4b6f93c82b1599cad575";

    private String API_NAME = "Test.V2.Api";

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

    @Test
    public void test01_CreatePluginForApi() throws IOException {
        Plugin request = new Plugin();
        request.setId(PLUGIN_ID);
        request.setName(PLUGIN_NAME);

        OAUTH2_CONFIG.setProvisionKey(OAUTH2_PROVISION_KEY);
        OAUTH2_CONFIG.setEnableAuthorizationCode(true);
        OAUTH2_CONFIG.setEnableImplicitGrant(true);
        OAUTH2_CONFIG.setEnablePasswordGrant(true);
        OAUTH2_CONFIG.setEnableClientCredentials(true);
        OAUTH2_CONFIG.setTokenExpiration(7200);
        request.setConfig(OAUTH2_CONFIG);

        Plugin response = kongClient.getApiPluginService().addPluginForApi(API_NAME, request);
        printJson(response);
        Assert.assertEquals(request.getName(), response.getName());
    }

    @Test
    public void test02_GetPluginForApi() throws IOException {
        Plugin response = kongClient.getApiPluginService().getPluginForApi(API_NAME, PLUGIN_ID);
        printJson(response);
        Assert.assertEquals(PLUGIN_NAME, response.getName());
    }


    @Test(expected = KongClientException.class)