Skip to content

Commit

Permalink
Adds tests for acl and jwt services
Browse files Browse the repository at this point in the history
  • Loading branch information
dvilela committed Oct 23, 2017
1 parent e7636df commit dee4cf9
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/test/java/com/github/vaibhavsinha/kong/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BaseTest {
public static final String KONG_ADMIN_URL = "http://test.com:8001";
public static final String KONG_API_URL = "https://test.com:8443";

protected KongClient kongClient;
protected static KongClient kongClient;

protected Gson gson;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
package com.github.vaibhavsinha.kong;

import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer;
import com.github.vaibhavsinha.kong.model.plugin.security.acl.Acl;
import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.UUID;

import static org.junit.Assert.assertEquals;

/**
* Created by dvilela on 10/22/17.
*/
public class RetrofitAclServiceTest {
public class RetrofitAclServiceTest extends BaseTest {

private Consumer consumer;

@Before
public void createConsumer() throws Exception {
consumer = new Consumer();
String id = UUID.randomUUID().toString();
consumer.setCustomId(id);

consumer = kongClient.getConsumerService().createConsumer(consumer);
}

@After
public void deleteConsumer() throws Exception {
kongClient.getConsumerService().deleteConsumer(consumer.getId());
}

@Test
public void testAssociateAndListAcls() throws Exception {
kongClient.getAclService().associateConsumer(consumer.getId(), "default");

AclList list = kongClient.getAclService().listAcls(consumer.getId(), 1L, null);

Acl acl = list.getData().get(0);
assertEquals(consumer.getId(), acl.getConsumerId());
assertEquals("default", acl.getGroup());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.vaibhavsinha.kong;

import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer;
import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential;
import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import java.util.UUID;

import static org.junit.Assert.assertEquals;

/**
* Created by dvilela on 10/22/17.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RetrofitJwtServiceTest extends BaseTest {

private static Consumer consumer;

@BeforeClass
public static void createConsumer() throws Exception {
Consumer c = new Consumer();
c.setCustomId(UUID.randomUUID().toString());
consumer = kongClient.getConsumerService().createConsumer(c);
}

@AfterClass
public static void deleteConsumer() throws Exception {
kongClient.getConsumerService().deleteConsumer(consumer.getId());
}

@Test
public void test01_addCredentialTest() throws Exception {
JwtCredential credential = kongClient.getJwtService().addCredentials(consumer.getId(), new JwtCredential());
assertEquals(consumer.getId(), credential.getConsumerId());
}

@Test
public void test02_listCredentialsTest() throws Exception {
JwtCredentialList list = kongClient.getJwtService().listCredentials(consumer.getId(), null, null);
JwtCredential credential = list.getData().get(0);
assertEquals(consumer.getId(), credential.getConsumerId());
}

@Test
public void test03_deleteCredentialTest() throws Exception {
JwtCredentialList list = kongClient.getJwtService().listCredentials(consumer.getId(), null, null);
JwtCredential credential = list.getData().get(0);
kongClient.getJwtService().deleteCredentials(consumer.getId(), credential.getId());
JwtCredentialList list2 = kongClient.getJwtService().listCredentials(consumer.getId(), null, null);
assertEquals(0L, (long) list2.getTotal());
}

}

0 comments on commit dee4cf9

Please sign in to comment.