QuotaChecker { void checkRoleQuota(ObjectStoreConnection con, String domainName, Role role, String caller) { if (!quotaCheckEnabled) { return; } if (role == null) { return; } final Quota quota = getDomainQuota(con, domainName); int objectCount = getListSize(role.getRoleMembers()); if (quota.getRoleMember() < objectCount) { throw ZMSUtils.quotaLimitError("role member quota exceeded - limit: " + quota.getRoleMember() + " actual: " + objectCount, caller); } objectCount = con.countRoles(domainName) + 1; if (quota.getRole() < objectCount) { throw ZMSUtils.quotaLimitError("role quota exceeded - limit: " + quota.getRole() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckRoleQuotaNull() { QuotaChecker quotaCheck = new QuotaChecker(); quotaCheck.checkRoleQuota(null, "athenz", null, "caller"); }
@Test public void testCheckRoleQuota() { 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.countRoles("athenz")).thenReturn(1); ArrayList<RoleMember> roleMembers = new ArrayList<>(); roleMembers.add(new RoleMember().setMemberName("user.joe")); Role role = new Role().setRoleMembers(roleMembers); quotaCheck.checkRoleQuota(con, "athenz", role, "caller"); }