JAMES-2344 JPA, Memory and Cassandra PerUserMaxQuotaManager should support domains
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8404daf4 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8404daf4 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8404daf4 Branch: refs/heads/master Commit: 8404daf496ece0a3bf305e7343b0a4557cef1ec3 Parents: 40921ed Author: benwa <[email protected]> Authored: Tue Mar 13 14:25:54 2018 +0700 Committer: benwa <[email protected]> Committed: Thu Mar 15 14:40:15 2018 +0700 ---------------------------------------------------------------------- .../quota/CassandraPerUserMaxQuotaManager.java | 36 ++++-- .../jpa/quota/JPAPerUserMaxQuotaManager.java | 29 +++-- .../quota/InMemoryPerUserMaxQuotaManager.java | 52 +++++---- .../store/quota/GenericMaxQuotaManagerTest.java | 117 +++++++++---------- 4 files changed, 131 insertions(+), 103 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/8404daf4/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java ---------------------------------------------------------------------- diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java index 5b151e3..7c4b716 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/quota/CassandraPerUserMaxQuotaManager.java @@ -21,17 +21,19 @@ package org.apache.james.mailbox.cassandra.quota; import java.util.Map; import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Stream; import javax.inject.Inject; import org.apache.commons.lang3.tuple.Pair; -import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.Quota; import org.apache.james.mailbox.model.QuotaRoot; import org.apache.james.mailbox.quota.MaxQuotaManager; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; +import org.apache.james.util.OptionalUtils; import com.github.fge.lambdas.Throwing; import com.github.steveash.guavate.Guavate; @@ -72,7 +74,7 @@ public class CassandraPerUserMaxQuotaManager implements MaxQuotaManager { } @Override - public void removeDomainMaxMessage(String domain) throws MailboxException { + public void removeDomainMaxMessage(String domain) { perDomainQuota.removeMaxMessage(domain); } @@ -133,22 +135,38 @@ public class CassandraPerUserMaxQuotaManager implements MaxQuotaManager { @Override public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) { - return perUserQuota.getMaxStorage(quotaRoot) - .map(Optional::of) - .orElseGet(Throwing.supplier(this::getDefaultMaxStorage).sneakyThrow()); + Supplier<Optional<QuotaSize>> domainQuotaSupplier = Throwing.supplier(() -> quotaRoot.getDomain() + .flatMap(this::getDomainMaxStorage)).sneakyThrow(); + Supplier<Optional<QuotaSize>> defaultDomainSupplier = Throwing.supplier(this::getDefaultMaxStorage).sneakyThrow(); + + return Stream + .of(() -> perUserQuota.getMaxStorage(quotaRoot), + domainQuotaSupplier, + defaultDomainSupplier) + .flatMap(supplier -> OptionalUtils.toStream(supplier.get())) + .findFirst(); } @Override public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) { - return perUserQuota.getMaxMessage(quotaRoot) - .map(Optional::of) - .orElseGet(Throwing.supplier(this::getDefaultMaxMessage).sneakyThrow()); + Supplier<Optional<QuotaCount>> domainQuotaSupplier = Throwing.supplier(() -> quotaRoot.getDomain() + .flatMap(this::getDomainMaxMessage)).sneakyThrow(); + Supplier<Optional<QuotaCount>> defaultDomainSupplier = Throwing.supplier(this::getDefaultMaxMessage).sneakyThrow(); + + return Stream + .of(() -> perUserQuota.getMaxMessage(quotaRoot), + domainQuotaSupplier, + defaultDomainSupplier) + .flatMap(supplier -> OptionalUtils.toStream(supplier.get())) + .findFirst(); } @Override public Map<Quota.Scope, QuotaCount> listMaxMessagesDetails(QuotaRoot quotaRoot) { + Function<String, Optional<QuotaCount>> domainQuotaSupplier = Throwing.function(this::getDomainMaxMessage).sneakyThrow(); return Stream.of( Pair.of(Quota.Scope.User, perUserQuota.getMaxMessage(quotaRoot)), + Pair.of(Quota.Scope.Domain, quotaRoot.getDomain().flatMap(domainQuotaSupplier)), Pair.of(Quota.Scope.Global, defaultQuota.getDefaultMaxMessage())) .filter(pair -> pair.getValue().isPresent()) .collect(Guavate.toImmutableMap(Pair::getKey, value -> value.getValue().get())); @@ -156,8 +174,10 @@ public class CassandraPerUserMaxQuotaManager implements MaxQuotaManager { @Override public Map<Quota.Scope, QuotaSize> listMaxStorageDetails(QuotaRoot quotaRoot) { + Function<String, Optional<QuotaSize>> domainQuotaSupplier = Throwing.function(this::getDomainMaxStorage).sneakyThrow(); return Stream.of( Pair.of(Quota.Scope.User, perUserQuota.getMaxStorage(quotaRoot)), + Pair.of(Quota.Scope.Domain, quotaRoot.getDomain().flatMap(domainQuotaSupplier)), Pair.of(Quota.Scope.Global, defaultQuota.getDefaultMaxStorage())) .filter(pair -> pair.getValue().isPresent()) .collect(Guavate.toImmutableMap(Pair::getKey, value -> value.getValue().get())); http://git-wip-us.apache.org/repos/asf/james-project/blob/8404daf4/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java index 402ea4b..bb75be5 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaManager.java @@ -21,18 +21,21 @@ package org.apache.james.mailbox.jpa.quota; import java.util.Map; import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Stream; import javax.inject.Inject; import org.apache.commons.lang3.tuple.Pair; -import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.Quota; import org.apache.james.mailbox.model.QuotaRoot; import org.apache.james.mailbox.quota.MaxQuotaManager; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; +import org.apache.james.util.OptionalUtils; +import com.github.fge.lambdas.Throwing; import com.github.steveash.guavate.Guavate; public class JPAPerUserMaxQuotaManager implements MaxQuotaManager { @@ -65,7 +68,7 @@ public class JPAPerUserMaxQuotaManager implements MaxQuotaManager { } @Override - public void removeDomainMaxMessage(String domain) throws MailboxException { + public void removeDomainMaxMessage(String domain) { dao.setDomainMaxMessage(domain, Optional.empty()); } @@ -116,22 +119,30 @@ public class JPAPerUserMaxQuotaManager implements MaxQuotaManager { @Override public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) { - return dao.getMaxStorage(quotaRoot) - .map(Optional::of) - .orElseGet(this::getDefaultMaxStorage); + return Stream + .of((Supplier<Optional<QuotaSize>>) () -> dao.getMaxStorage(quotaRoot), + () -> quotaRoot.getDomain().flatMap(this::getDomainMaxStorage), + this::getDefaultMaxStorage) + .flatMap(supplier -> OptionalUtils.toStream(supplier.get())) + .findFirst(); } @Override public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) { - return dao.getMaxMessage(quotaRoot) - .map(Optional::of) - .orElseGet(this::getDefaultMaxMessage); + return Stream + .of((Supplier<Optional<QuotaCount>>) () -> dao.getMaxMessage(quotaRoot), + () -> quotaRoot.getDomain().flatMap(this::getDomainMaxMessage), + this::getDefaultMaxMessage) + .flatMap(supplier -> OptionalUtils.toStream(supplier.get())) + .findFirst(); } @Override public Map<Quota.Scope, QuotaCount> listMaxMessagesDetails(QuotaRoot quotaRoot) { + Function<String, Optional<QuotaCount>> domainQuotaFunction = Throwing.function(this::getDomainMaxMessage).sneakyThrow(); return Stream.of( Pair.of(Quota.Scope.User, dao.getMaxMessage(quotaRoot)), + Pair.of(Quota.Scope.Domain, quotaRoot.getDomain().flatMap(domainQuotaFunction)), Pair.of(Quota.Scope.Global, dao.getDefaultMaxMessage())) .filter(pair -> pair.getValue().isPresent()) .collect(Guavate.toImmutableMap(Pair::getKey, value -> value.getValue().get())); @@ -139,8 +150,10 @@ public class JPAPerUserMaxQuotaManager implements MaxQuotaManager { @Override public Map<Quota.Scope, QuotaSize> listMaxStorageDetails(QuotaRoot quotaRoot) { + Function<String, Optional<QuotaSize>> domainQuotaFunction = Throwing.function(this::getDomainMaxStorage).sneakyThrow(); return Stream.of( Pair.of(Quota.Scope.User, dao.getMaxStorage(quotaRoot)), + Pair.of(Quota.Scope.Domain, quotaRoot.getDomain().flatMap(domainQuotaFunction)), Pair.of(Quota.Scope.Global, dao.getDefaultMaxStorage())) .filter(pair -> pair.getValue().isPresent()) .collect(Guavate.toImmutableMap(Pair::getKey, value -> value.getValue().get())); http://git-wip-us.apache.org/repos/asf/james-project/blob/8404daf4/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java ---------------------------------------------------------------------- diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java index 1026cd5..eb0a971 100644 --- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java +++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/quota/InMemoryPerUserMaxQuotaManager.java @@ -21,16 +21,18 @@ package org.apache.james.mailbox.inmemory.quota; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; import java.util.stream.Stream; import org.apache.commons.lang3.tuple.Pair; -import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.Quota; import org.apache.james.mailbox.model.QuotaRoot; import org.apache.james.mailbox.quota.MaxQuotaManager; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; +import org.apache.james.util.OptionalUtils; +import com.github.fge.lambdas.Throwing; import com.github.steveash.guavate.Guavate; public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager { @@ -45,7 +47,7 @@ public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager { private final Map<String, QuotaCount> userMaxMessage = new ConcurrentHashMap<>(); @Override - public void setDefaultMaxStorage(QuotaSize maxStorage) throws MailboxException { + public void setDefaultMaxStorage(QuotaSize maxStorage) { this.maxStorage = Optional.of(maxStorage); } @@ -60,7 +62,7 @@ public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager { } @Override - public void removeDomainMaxMessage(String domain) throws MailboxException { + public void removeDomainMaxMessage(String domain) { domainMaxMessage.remove(domain); } @@ -70,27 +72,27 @@ public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager { } @Override - public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) throws MailboxException { - QuotaSize max = userMaxStorage.get(quotaRoot.getValue()); - if (max == null) { - return maxStorage; - } - return Optional.of(max); + public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) { + return OptionalUtils.or( + Optional.ofNullable(userMaxStorage.get(quotaRoot.getValue())), + quotaRoot.getDomain().flatMap(this::getDomainMaxStorage), + maxStorage); } @Override - public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) throws MailboxException { - QuotaCount max = userMaxMessage.get(quotaRoot.getValue()); - if (max == null) { - return maxMessage; - } - return Optional.of(max); + public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) { + return OptionalUtils.or( + Optional.ofNullable(userMaxMessage.get(quotaRoot.getValue())), + quotaRoot.getDomain().flatMap(this::getDomainMaxMessage), + maxMessage); } @Override public Map<Quota.Scope, QuotaCount> listMaxMessagesDetails(QuotaRoot quotaRoot) { + Function<String, Optional<QuotaCount>> domainQuotaFunction = Throwing.function(this::getDomainMaxMessage).sneakyThrow(); return Stream.of( Pair.of(Quota.Scope.User, Optional.ofNullable(userMaxMessage.get(quotaRoot.getValue()))), + Pair.of(Quota.Scope.Domain, quotaRoot.getDomain().flatMap(domainQuotaFunction)), Pair.of(Quota.Scope.Global, maxMessage)) .filter(pair -> pair.getValue().isPresent()) .collect(Guavate.toImmutableMap(Pair::getKey, value -> value.getValue().get())); @@ -98,15 +100,17 @@ public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager { @Override public Map<Quota.Scope, QuotaSize> listMaxStorageDetails(QuotaRoot quotaRoot) { + Function<String, Optional<QuotaSize>> domainQuotaFunction = Throwing.function(this::getDomainMaxStorage).sneakyThrow(); return Stream.of( - Pair.of(Quota.Scope.User, Optional.ofNullable(userMaxStorage.get(quotaRoot.getValue()))), - Pair.of(Quota.Scope.Global, maxStorage)) + Pair.of(Quota.Scope.User, Optional.ofNullable(userMaxStorage.get(quotaRoot.getValue()))), + Pair.of(Quota.Scope.Domain, quotaRoot.getDomain().flatMap(domainQuotaFunction)), + Pair.of(Quota.Scope.Global, maxStorage)) .filter(pair -> pair.getValue().isPresent()) .collect(Guavate.toImmutableMap(Pair::getKey, value -> value.getValue().get())); } @Override - public void setDefaultMaxMessage(QuotaCount maxMessage) throws MailboxException { + public void setDefaultMaxMessage(QuotaCount maxMessage) { this.maxMessage = Optional.of(maxMessage); } @@ -131,32 +135,32 @@ public class InMemoryPerUserMaxQuotaManager implements MaxQuotaManager { } @Override - public Optional<QuotaSize> getDefaultMaxStorage() throws MailboxException { + public Optional<QuotaSize> getDefaultMaxStorage() { return maxStorage; } @Override - public Optional<QuotaCount> getDefaultMaxMessage() throws MailboxException { + public Optional<QuotaCount> getDefaultMaxMessage() { return maxMessage; } @Override - public void removeMaxMessage(QuotaRoot quotaRoot) throws MailboxException { + public void removeMaxMessage(QuotaRoot quotaRoot) { userMaxMessage.remove(quotaRoot.getValue()); } @Override - public void removeMaxStorage(QuotaRoot quotaRoot) throws MailboxException { + public void removeMaxStorage(QuotaRoot quotaRoot) { userMaxStorage.remove(quotaRoot.getValue()); } @Override - public void removeDefaultMaxStorage() throws MailboxException { + public void removeDefaultMaxStorage() { maxStorage = Optional.empty(); } @Override - public void removeDefaultMaxMessage() throws MailboxException { + public void removeDefaultMaxMessage() { maxMessage = Optional.empty(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/8404daf4/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/GenericMaxQuotaManagerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/GenericMaxQuotaManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/GenericMaxQuotaManagerTest.java index 8452fb3..bbb8c06 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/GenericMaxQuotaManagerTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/GenericMaxQuotaManagerTest.java @@ -29,86 +29,81 @@ import org.apache.james.mailbox.quota.MaxQuotaManager; import org.apache.james.mailbox.quota.QuotaCount; import org.apache.james.mailbox.quota.QuotaSize; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; public abstract class GenericMaxQuotaManagerTest { - private QuotaRoot quotaRoot; + public static final String DOMAIN = "domain"; + public static final QuotaRoot QUOTA_ROOT = QuotaRoot.quotaRoot("benwa@domain", Optional.of(DOMAIN)); private MaxQuotaManager maxQuotaManager; - private String domain; protected abstract MaxQuotaManager provideMaxQuotaManager(); @Before public void setUp() { maxQuotaManager = provideMaxQuotaManager(); - quotaRoot = QuotaRoot.quotaRoot("benwa", Optional.empty()); - domain = "domain"; } @Test public void getMaxMessageShouldReturnEmptyWhenNoDefaultValue() throws Exception { - assertThat(maxQuotaManager.getMaxMessage(quotaRoot)).isEmpty(); + assertThat(maxQuotaManager.getMaxMessage(QUOTA_ROOT)).isEmpty(); } @Test public void getMaxStorageShouldReturnEmptyWhenNoDefaultValue() throws Exception { - assertThat(maxQuotaManager.getMaxStorage(quotaRoot)).isEmpty(); + assertThat(maxQuotaManager.getMaxStorage(QUOTA_ROOT)).isEmpty(); } - @Ignore("how can we link domain and quotaRoot ?") @Test public void getMaxMessageShouldReturnDomainWhenNoValue() throws Exception { maxQuotaManager.setDefaultMaxMessage(QuotaCount.count(36)); - maxQuotaManager.setDomainMaxMessage(domain, QuotaCount.count(23)); - assertThat(maxQuotaManager.getMaxMessage(quotaRoot)).contains(QuotaCount.count(23)); + maxQuotaManager.setDomainMaxMessage(DOMAIN, QuotaCount.count(23)); + assertThat(maxQuotaManager.getMaxMessage(QUOTA_ROOT)).contains(QuotaCount.count(23)); } @Test public void getMaxMessageShouldReturnDefaultWhenNoValue() throws Exception { maxQuotaManager.setDefaultMaxMessage(QuotaCount.count(36)); - assertThat(maxQuotaManager.getMaxMessage(quotaRoot)).contains(QuotaCount.count(36)); + assertThat(maxQuotaManager.getMaxMessage(QUOTA_ROOT)).contains(QuotaCount.count(36)); } @Test public void getMaxStorageShouldReturnDefaultWhenNoValue() throws Exception { maxQuotaManager.setDefaultMaxStorage(QuotaSize.size(36)); - assertThat(maxQuotaManager.getMaxStorage(quotaRoot)).contains(QuotaSize.size(36)); + assertThat(maxQuotaManager.getMaxStorage(QUOTA_ROOT)).contains(QuotaSize.size(36)); } - @Ignore("how can we link domain and quotaRoot ?") @Test public void getMaxStorageShouldReturnDomainWhenNoValue() throws Exception { maxQuotaManager.setDefaultMaxStorage(QuotaSize.size(234)); - maxQuotaManager.setDomainMaxStorage(domain, QuotaSize.size(111)); - assertThat(maxQuotaManager.getMaxStorage(quotaRoot)).contains(QuotaSize.size(111)); + maxQuotaManager.setDomainMaxStorage(DOMAIN, QuotaSize.size(111)); + assertThat(maxQuotaManager.getMaxStorage(QUOTA_ROOT)).contains(QuotaSize.size(111)); } @Test public void getMaxMessageShouldReturnProvidedValue() throws Exception { - maxQuotaManager.setMaxMessage(quotaRoot, QuotaCount.count(36)); - assertThat(maxQuotaManager.getMaxMessage(quotaRoot)).contains(QuotaCount.count(36)); + maxQuotaManager.setMaxMessage(QUOTA_ROOT, QuotaCount.count(36)); + assertThat(maxQuotaManager.getMaxMessage(QUOTA_ROOT)).contains(QuotaCount.count(36)); } @Test public void getMaxStorageShouldReturnProvidedValue() throws Exception { - maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(36)); - assertThat(maxQuotaManager.getMaxStorage(quotaRoot)).contains(QuotaSize.size(36)); + maxQuotaManager.setMaxStorage(QUOTA_ROOT, QuotaSize.size(36)); + assertThat(maxQuotaManager.getMaxStorage(QUOTA_ROOT)).contains(QuotaSize.size(36)); } @Test public void deleteMaxStorageShouldRemoveCurrentValue() throws Exception { - maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(36)); - maxQuotaManager.removeMaxStorage(quotaRoot); - assertThat(maxQuotaManager.getMaxStorage(quotaRoot)).isEmpty(); + maxQuotaManager.setMaxStorage(QUOTA_ROOT, QuotaSize.size(36)); + maxQuotaManager.removeMaxStorage(QUOTA_ROOT); + assertThat(maxQuotaManager.getMaxStorage(QUOTA_ROOT)).isEmpty(); } @Test public void deleteMaxMessageShouldRemoveCurrentValue() throws Exception { - maxQuotaManager.setMaxMessage(quotaRoot, QuotaCount.count(36)); - maxQuotaManager.removeMaxMessage(quotaRoot); - assertThat(maxQuotaManager.getMaxMessage(quotaRoot)).isEmpty(); + maxQuotaManager.setMaxMessage(QUOTA_ROOT, QuotaCount.count(36)); + maxQuotaManager.removeMaxMessage(QUOTA_ROOT); + assertThat(maxQuotaManager.getMaxMessage(QUOTA_ROOT)).isEmpty(); } @Test @@ -127,35 +122,34 @@ public abstract class GenericMaxQuotaManagerTest { @Test public void listMaxMessagesDetailsShouldReturnEmptyWhenNoQuotaDefined() { - assertThat(maxQuotaManager.listMaxMessagesDetails(quotaRoot)).isEmpty(); + assertThat(maxQuotaManager.listMaxMessagesDetails(QUOTA_ROOT)).isEmpty(); } @Test public void listMaxStorageDetailsShouldReturnEmptyWhenNoQuotaDefined() { - assertThat(maxQuotaManager.listMaxStorageDetails(quotaRoot)).isEmpty(); + assertThat(maxQuotaManager.listMaxStorageDetails(QUOTA_ROOT)).isEmpty(); } @Test public void listMaxMessagesDetailsShouldReturnGlobalValueWhenDefined() throws Exception { maxQuotaManager.setDefaultMaxMessage(QuotaCount.count(123)); - assertThat(maxQuotaManager.listMaxMessagesDetails(quotaRoot)) + assertThat(maxQuotaManager.listMaxMessagesDetails(QUOTA_ROOT)) .hasSize(1) .containsEntry(Quota.Scope.Global, QuotaCount.count(123)); } - @Ignore("how can we link domain and quotaRoot ?") @Test public void listMaxMessagesDetailsShouldReturnDomainValueWhenDefined() throws Exception { - maxQuotaManager.setDomainMaxMessage(domain, QuotaCount.count(123)); - assertThat(maxQuotaManager.listMaxMessagesDetails(quotaRoot)) + maxQuotaManager.setDomainMaxMessage(DOMAIN, QuotaCount.count(123)); + assertThat(maxQuotaManager.listMaxMessagesDetails(QUOTA_ROOT)) .hasSize(1) .containsEntry(Quota.Scope.Domain, QuotaCount.count(123)); } @Test public void listMaxMessagesDetailsShouldReturnUserValueWhenDefined() throws Exception { - maxQuotaManager.setMaxMessage(quotaRoot, QuotaCount.count(123)); - assertThat(maxQuotaManager.listMaxMessagesDetails(quotaRoot)) + maxQuotaManager.setMaxMessage(QUOTA_ROOT, QuotaCount.count(123)); + assertThat(maxQuotaManager.listMaxMessagesDetails(QUOTA_ROOT)) .hasSize(1) .containsEntry(Quota.Scope.User, QuotaCount.count(123)); } @@ -163,20 +157,19 @@ public abstract class GenericMaxQuotaManagerTest { @Test public void listMaxMessagesDetailsShouldReturnBothValuesWhenGlobalAndUserDefined() throws Exception { maxQuotaManager.setDefaultMaxMessage(QuotaCount.count(1234)); - maxQuotaManager.setMaxMessage(quotaRoot, QuotaCount.count(123)); - assertThat(maxQuotaManager.listMaxMessagesDetails(quotaRoot)) + maxQuotaManager.setMaxMessage(QUOTA_ROOT, QuotaCount.count(123)); + assertThat(maxQuotaManager.listMaxMessagesDetails(QUOTA_ROOT)) .hasSize(2) .containsEntry(Quota.Scope.Global, QuotaCount.count(1234)) .containsEntry(Quota.Scope.User, QuotaCount.count(123)); } - @Ignore("how can we link domain and quotaRoot ?") @Test public void listMaxMessagesDetailsShouldReturnAllValuesWhenDefined() throws Exception { maxQuotaManager.setDefaultMaxMessage(QuotaCount.count(1234)); - maxQuotaManager.setDomainMaxMessage(domain, QuotaCount.count(333)); - maxQuotaManager.setMaxMessage(quotaRoot, QuotaCount.count(123)); - assertThat(maxQuotaManager.listMaxMessagesDetails(quotaRoot)) + maxQuotaManager.setDomainMaxMessage(DOMAIN, QuotaCount.count(333)); + maxQuotaManager.setMaxMessage(QUOTA_ROOT, QuotaCount.count(123)); + assertThat(maxQuotaManager.listMaxMessagesDetails(QUOTA_ROOT)) .hasSize(3) .containsEntry(Quota.Scope.Global, QuotaCount.count(1234)) .containsEntry(Quota.Scope.Domain, QuotaCount.count(333)) @@ -186,24 +179,23 @@ public abstract class GenericMaxQuotaManagerTest { @Test public void listMaxStorageDetailsShouldReturnGlobalValueWhenDefined() throws Exception { maxQuotaManager.setDefaultMaxStorage(QuotaSize.size(1111)); - assertThat(maxQuotaManager.listMaxStorageDetails(quotaRoot)) + assertThat(maxQuotaManager.listMaxStorageDetails(QUOTA_ROOT)) .hasSize(1) .containsEntry(Quota.Scope.Global, QuotaSize.size(1111)); } - @Ignore("how can we link domain and quotaRoot ?") @Test public void listMaxStorageDetailsShouldReturnDomainValueWhenDefined() throws Exception { - maxQuotaManager.setDomainMaxStorage(domain, QuotaSize.size(1111)); - assertThat(maxQuotaManager.listMaxStorageDetails(quotaRoot)) + maxQuotaManager.setDomainMaxStorage(DOMAIN, QuotaSize.size(1111)); + assertThat(maxQuotaManager.listMaxStorageDetails(QUOTA_ROOT)) .hasSize(1) .containsEntry(Quota.Scope.Domain, QuotaSize.size(1111)); } @Test public void listMaxStorageDetailsShouldReturnUserValueWhenDefined() throws Exception { - maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(2222)); - assertThat(maxQuotaManager.listMaxStorageDetails(quotaRoot)) + maxQuotaManager.setMaxStorage(QUOTA_ROOT, QuotaSize.size(2222)); + assertThat(maxQuotaManager.listMaxStorageDetails(QUOTA_ROOT)) .hasSize(1) .containsEntry(Quota.Scope.User, QuotaSize.size(2222)); } @@ -211,20 +203,19 @@ public abstract class GenericMaxQuotaManagerTest { @Test public void listMaxStorageDetailsShouldReturnBothValuesWhenDefined() throws Exception { maxQuotaManager.setDefaultMaxStorage(QuotaSize.size(3333)); - maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(4444)); - assertThat(maxQuotaManager.listMaxStorageDetails(quotaRoot)) + maxQuotaManager.setMaxStorage(QUOTA_ROOT, QuotaSize.size(4444)); + assertThat(maxQuotaManager.listMaxStorageDetails(QUOTA_ROOT)) .hasSize(2) .containsEntry(Quota.Scope.Global, QuotaSize.size(3333)) .containsEntry(Quota.Scope.User, QuotaSize.size(4444)); } - @Ignore("how can we link domain and quotaRoot ?") @Test public void listMaxStorageDetailsShouldReturnAllValuesWhenDefined() throws Exception { maxQuotaManager.setDefaultMaxStorage(QuotaSize.size(3333)); - maxQuotaManager.setDomainMaxStorage(domain, QuotaSize.size(2222)); - maxQuotaManager.setMaxStorage(quotaRoot, QuotaSize.size(4444)); - assertThat(maxQuotaManager.listMaxStorageDetails(quotaRoot)) + maxQuotaManager.setDomainMaxStorage(DOMAIN, QuotaSize.size(2222)); + maxQuotaManager.setMaxStorage(QUOTA_ROOT, QuotaSize.size(4444)); + assertThat(maxQuotaManager.listMaxStorageDetails(QUOTA_ROOT)) .hasSize(3) .containsEntry(Quota.Scope.Global, QuotaSize.size(3333)) .containsEntry(Quota.Scope.Domain, QuotaSize.size(2222)) @@ -233,38 +224,38 @@ public abstract class GenericMaxQuotaManagerTest { @Test public void getDomainMaxMessageShouldReturnEmptyWhenNoDefaultValue() { - assertThat(maxQuotaManager.getDomainMaxMessage(domain)).isEmpty(); + assertThat(maxQuotaManager.getDomainMaxMessage(DOMAIN)).isEmpty(); } @Test public void getDomainMaxStorageShouldReturnEmptyWhenNoDefaultValue() { - assertThat(maxQuotaManager.getDomainMaxStorage(domain)).isEmpty(); + assertThat(maxQuotaManager.getDomainMaxStorage(DOMAIN)).isEmpty(); } @Test public void getDomainMaxMessageShouldReturnProvidedValue() throws Exception { - maxQuotaManager.setDomainMaxMessage(domain, QuotaCount.count(36)); - assertThat(maxQuotaManager.getDomainMaxMessage(domain)).contains(QuotaCount.count(36)); + maxQuotaManager.setDomainMaxMessage(DOMAIN, QuotaCount.count(36)); + assertThat(maxQuotaManager.getDomainMaxMessage(DOMAIN)).contains(QuotaCount.count(36)); } @Test public void getDomainMaxStorageShouldReturnProvidedValue() throws Exception { - maxQuotaManager.setDomainMaxStorage(domain, QuotaSize.size(36)); - assertThat(maxQuotaManager.getDomainMaxStorage(domain)).contains(QuotaSize.size(36)); + maxQuotaManager.setDomainMaxStorage(DOMAIN, QuotaSize.size(36)); + assertThat(maxQuotaManager.getDomainMaxStorage(DOMAIN)).contains(QuotaSize.size(36)); } @Test public void deleteDomainMaxStorageShouldRemoveCurrentValue() throws Exception { - maxQuotaManager.setDomainMaxStorage(domain, QuotaSize.size(36)); - maxQuotaManager.removeDomainMaxStorage(domain); - assertThat(maxQuotaManager.getDomainMaxStorage(domain)).isEmpty(); + maxQuotaManager.setDomainMaxStorage(DOMAIN, QuotaSize.size(36)); + maxQuotaManager.removeDomainMaxStorage(DOMAIN); + assertThat(maxQuotaManager.getDomainMaxStorage(DOMAIN)).isEmpty(); } @Test public void deleteDomainMaxMessageShouldRemoveCurrentValue() throws Exception { - maxQuotaManager.setDomainMaxMessage(domain, QuotaCount.count(36)); - maxQuotaManager.removeDomainMaxMessage(domain); - assertThat(maxQuotaManager.getDomainMaxMessage(domain)).isEmpty(); + maxQuotaManager.setDomainMaxMessage(DOMAIN, QuotaCount.count(36)); + maxQuotaManager.removeDomainMaxMessage(DOMAIN); + assertThat(maxQuotaManager.getDomainMaxMessage(DOMAIN)).isEmpty(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
