QuotaChecker { void checkGroupQuota(ObjectStoreConnection con, String domainName, Group group, String caller) { if (!quotaCheckEnabled) { return; } if (group == null) { return; } final Quota quota = getDomainQuota(con, domainName); int objectCount = getListSize(group.getGroupMembers()); if (quota.getGroupMember() < objectCount) { throw ZMSUtils.quotaLimitError("group member quota exceeded - limit: " + quota.getGroupMember() + " actual: " + objectCount, caller); } objectCount = con.countGroups(domainName) + 1; if (quota.getGroup() < objectCount) { throw ZMSUtils.quotaLimitError("group quota exceeded - limit: " + quota.getGroup() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckGroupQuota() { QuotaChecker quotaCheck = new QuotaChecker(); Quota mockQuota = new Quota().setName("athenz") .setGroup(2).setGroupMember(2); ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class); Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota); Mockito.when(con.countGroups("athenz")).thenReturn(1); ArrayList<GroupMember> groupMembers = new ArrayList<>(); groupMembers.add(new GroupMember().setMemberName("user.joe")); Group group = new Group().setGroupMembers(groupMembers); quotaCheck.checkGroupQuota(con, "athenz", group, "caller"); }
@Test public void testCheckGroupQuotaNull() { QuotaChecker quotaCheck = new QuotaChecker(); quotaCheck.checkGroupQuota(null, "athenz", null, "caller"); }