QuotaChecker { void checkPolicyQuota(ObjectStoreConnection con, String domainName, Policy policy, String caller) { if (!quotaCheckEnabled) { return; } if (policy == null) { return; } final Quota quota = getDomainQuota(con, domainName); int objectCount = getListSize(policy.getAssertions()); if (quota.getAssertion() < objectCount) { throw ZMSUtils.quotaLimitError("policy assertion quota exceeded - limit: " + quota.getAssertion() + " actual: " + objectCount, caller); } objectCount = con.countPolicies(domainName) + 1; if (quota.getPolicy() < objectCount) { throw ZMSUtils.quotaLimitError("policy quota exceeded - limit: " + quota.getPolicy() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckPolicyQuotaNull() { QuotaChecker quotaCheck = new QuotaChecker(); quotaCheck.checkPolicyQuota(null, "athenz", null, "caller"); }
@Test public void testCheckPolicyQuota() { QuotaChecker quotaCheck = new QuotaChecker(); Quota mockQuota = new Quota().setName("athenz") .setPolicy(2).setAssertion(2); ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class); Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota); Mockito.when(con.countPolicies("athenz")).thenReturn(1); ArrayList<Assertion> assertions = new ArrayList<>(); assertions.add(new Assertion().setAction("*").setResource("*").setRole("admin")); Policy policy = new Policy(); policy.setAssertions(assertions); quotaCheck.checkPolicyQuota(con, "athenz", policy, "caller"); }