Search in sources :

Example 51 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckRoleMembershipQuotaRoleCountExceeded.

@Test
public void testCheckRoleMembershipQuotaRoleCountExceeded() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setRole(2).setRoleMember(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countRoleMembers("athenz", "readers")).thenReturn(2);
    try {
        quotaCheck.checkRoleMembershipQuota(con, "athenz", "readers", "caller");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.TOO_MANY_REQUESTS);
        assertTrue(ex.getMessage().contains("role member quota exceeded"));
    }
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 52 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckServiceQuota.

@Test
public void testCheckServiceQuota() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setService(2).setServiceHost(2).setPublicKey(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countServiceIdentities("athenz")).thenReturn(1);
    ArrayList<String> hosts = new ArrayList<>();
    hosts.add("host1");
    ArrayList<PublicKeyEntry> publicKeys = new ArrayList<>();
    publicKeys.add(new PublicKeyEntry().setId("id1").setKey("key"));
    ServiceIdentity service = new ServiceIdentity();
    service.setHosts(hosts);
    service.setPublicKeys(publicKeys);
    // this should be successful - no exceptions
    quotaCheck.checkServiceIdentityQuota(con, "athenz", service, "caller");
}
Also used : ArrayList(java.util.ArrayList) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 53 with ObjectStoreConnection

use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.

the class QuotaCheckerTest method testCheckEntityQuota.

@Test
public void testCheckEntityQuota() {
    QuotaChecker quotaCheck = new QuotaChecker();
    Quota mockQuota = new Quota().setName("athenz").setEntity(2);
    ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota);
    Mockito.when(con.countEntities("athenz")).thenReturn(1);
    Entity entity = new Entity();
    // this should be successful - no exceptions
    quotaCheck.checkEntityQuota(con, "athenz", entity, "caller");
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Aggregations

ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)53 Test (org.testng.annotations.Test)22 ArrayList (java.util.ArrayList)14 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)4 Timestamp (com.yahoo.rdl.Timestamp)1