QuotaChecker { void checkSubdomainQuota(ObjectStoreConnection con, String domainName, String caller) { if (!quotaCheckEnabled) { return; } int idx = domainName.indexOf('.'); if (idx == -1) { return; } final String topLevelDomain = domainName.substring(0, idx); final Quota quota = getDomainQuota(con, topLevelDomain); final String domainPrefix = topLevelDomain + "."; int objectCount = con.listDomains(domainPrefix, 0).size() + 1; if (quota.getSubdomain() < objectCount) { throw ZMSUtils.quotaLimitError("subdomain quota exceeded - limit: " + quota.getSubdomain() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckSubDomainQuotaTopLevel() { QuotaChecker quotaCheck = new QuotaChecker(); quotaCheck.checkSubdomainQuota(null, "athenz", "caller"); }
@Test public void testCheckSubDomainQuota() { QuotaChecker quotaCheck = new QuotaChecker(); Quota mockQuota = new Quota().setName("athenz") .setSubdomain(2); ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class); Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota); ArrayList<String> domains = new ArrayList<>(); domains.add("athenz.one"); Mockito.when(con.listDomains("athenz.", 0)).thenReturn(domains); quotaCheck.checkSubdomainQuota(con, "athenz.quota", "caller"); }