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"));
}
}
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");
}
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");
}
Aggregations