JAMES-2400 Introduce QuotaQuery
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/fec172dc Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/fec172dc Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/fec172dc Branch: refs/heads/master Commit: fec172dc5464368f4c7793df71ba5f376c8ffe65 Parents: 015d9ae Author: Antoine Duprat <adup...@linagora.com> Authored: Fri May 18 12:50:38 2018 +0200 Committer: Matthieu Baechler <matth...@apache.org> Committed: Tue May 22 14:53:25 2018 +0200 ---------------------------------------------------------------------- mailbox/plugin/quota-search/pom.xml | 74 +++++++ .../org/apache/james/quota/search/Limit.java | 70 +++++++ .../org/apache/james/quota/search/Offset.java | 68 +++++++ .../james/quota/search/QuotaBoundary.java | 59 ++++++ .../apache/james/quota/search/QuotaClause.java | 195 +++++++++++++++++++ .../apache/james/quota/search/QuotaQuery.java | 127 ++++++++++++ .../apache/james/quota/search/LimitTest.java | 63 ++++++ .../apache/james/quota/search/OffsetTest.java | 63 ++++++ .../quota/search/QuotaBoundaryFixture.java | 25 +++ .../james/quota/search/QuotaClauseTest.java | 121 ++++++++++++ .../james/quota/search/QuotaQueryTest.java | 76 ++++++++ mailbox/pom.xml | 1 + 12 files changed, 942 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/pom.xml b/mailbox/plugin/quota-search/pom.xml new file mode 100644 index 0000000..d3d2869 --- /dev/null +++ b/mailbox/plugin/quota-search/pom.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>apache-james-mailbox</artifactId> + <groupId>org.apache.james</groupId> + <version>3.1.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <artifactId>apache-james-mailbox-quota-search</artifactId> + <name>Apache James :: Mailbox :: Plugin :: Quota Search :: API</name> + <description>Apache James Mailbox API for quota search</description> + + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-api</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-api</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-core</artifactId> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-launcher</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Limit.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Limit.java b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Limit.java new file mode 100644 index 0000000..b62dd5e --- /dev/null +++ b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Limit.java @@ -0,0 +1,70 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import java.util.Objects; +import java.util.Optional; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +public class Limit { + public static Limit of(int value) { + Preconditions.checkArgument(value >= 0, "A limit need to be positive"); + return new Limit(Optional.of(value)); + } + + public static Limit unlimited() { + return new Limit(Optional.empty()); + } + + private final Optional<Integer> value; + + private Limit(Optional<Integer> value) { + this.value = value; + } + + public Optional<Integer> getValue() { + return value; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof Limit) { + Limit limit = (Limit) o; + + return Objects.equals(this.value, limit.value); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(value); + } + + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("value", value) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Offset.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Offset.java b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Offset.java new file mode 100644 index 0000000..bb91ab1 --- /dev/null +++ b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Offset.java @@ -0,0 +1,68 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import java.util.Objects; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +public class Offset { + public static Offset of(int value) { + return new Offset(value); + } + + public static Offset none() { + return new Offset(0); + } + + private final int value; + + private Offset(int value) { + Preconditions.checkArgument(value >= 0, "An offset can not be negative"); + this.value = value; + } + + public int getValue() { + return value; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof Offset) { + Offset offset = (Offset) o; + + return Objects.equals(this.value, offset.value); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(value); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("value", value) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaBoundary.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaBoundary.java b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaBoundary.java new file mode 100644 index 0000000..dcd16ba --- /dev/null +++ b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaBoundary.java @@ -0,0 +1,59 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import java.util.Objects; + +import com.google.common.base.MoreObjects; + +public class QuotaBoundary { + private final double ratio; + + public QuotaBoundary(double ratio) { + this.ratio = ratio; + } + + public double getRatio() { + return ratio; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof QuotaBoundary) { + QuotaBoundary that = (QuotaBoundary) o; + + return Objects.equals(this.ratio, that.ratio); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(ratio); + } + + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("ratio", ratio) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java new file mode 100644 index 0000000..359b231 --- /dev/null +++ b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaClause.java @@ -0,0 +1,195 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.quota.search; + +import java.util.List; +import java.util.Objects; + +import org.apache.james.core.Domain; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +public interface QuotaClause { + + class LessThan implements QuotaClause { + + private final QuotaBoundary quotaBoundary; + + private LessThan(QuotaBoundary quotaBoundary) { + Preconditions.checkNotNull(quotaBoundary, "'quotaBoundary' is mandatory"); + this.quotaBoundary = quotaBoundary; + } + + public QuotaBoundary getQuotaBoundary() { + return quotaBoundary; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof LessThan) { + LessThan lessThan = (LessThan) o; + + return Objects.equals(this.quotaBoundary, lessThan.quotaBoundary); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(quotaBoundary); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("quotaBoundary", quotaBoundary) + .toString(); + } + } + + class MoreThan implements QuotaClause { + + private final QuotaBoundary quotaBoundary; + + private MoreThan(QuotaBoundary quotaBoundary) { + Preconditions.checkNotNull(quotaBoundary, "'quotaBoundary' is mandatory"); + this.quotaBoundary = quotaBoundary; + } + + public QuotaBoundary getQuotaBoundary() { + return quotaBoundary; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof MoreThan) { + MoreThan moreThan = (MoreThan) o; + + return Objects.equals(this.quotaBoundary, moreThan.quotaBoundary); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(quotaBoundary); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("quotaRatio", quotaBoundary) + .toString(); + } + } + + class HasDomain implements QuotaClause { + + private final Domain domain; + + private HasDomain(Domain domain) { + Preconditions.checkNotNull(domain, "'domain' is mandatory"); + this.domain = domain; + } + + public Domain getDomain() { + return domain; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof HasDomain) { + HasDomain hasDomain = (HasDomain) o; + + return Objects.equals(this.domain, hasDomain.domain); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(domain); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("domain", domain) + .toString(); + } + } + + class And implements QuotaClause { + + private final ImmutableList<QuotaClause> clauses; + + private And(List<QuotaClause> clauses) { + Preconditions.checkNotNull(clauses, "'clauses' is mandatory"); + this.clauses = ImmutableList.copyOf(clauses); + } + + public List<QuotaClause> getClauses() { + return clauses; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof And) { + And and = (And) o; + + return Objects.equals(this.clauses, and.clauses); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(clauses); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("clauses", clauses) + .toString(); + } + } + + static LessThan lessThan(QuotaBoundary quotaBoundary) { + return new LessThan(quotaBoundary); + } + + static MoreThan moreThan(QuotaBoundary quotaBoundary) { + return new MoreThan(quotaBoundary); + } + + static HasDomain hasDomain(Domain domain) { + return new HasDomain(domain); + } + + static And and(List<QuotaClause> clauses) { + return new And(clauses); + } + + static And and(QuotaClause... clauses) { + return new And(ImmutableList.copyOf(clauses)); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaQuery.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaQuery.java b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaQuery.java new file mode 100644 index 0000000..b18ee47 --- /dev/null +++ b/mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/QuotaQuery.java @@ -0,0 +1,127 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import java.util.Objects; +import java.util.Optional; + +import org.apache.james.core.Domain; + +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableList; + +public class QuotaQuery { + + public static class Builder { + private ImmutableList.Builder<QuotaClause> clauses; + private Optional<Limit> limit; + private Optional<Offset> offset; + + private Builder() { + clauses = ImmutableList.builder(); + limit = Optional.empty(); + offset = Optional.empty(); + } + + public Builder moreThan(QuotaBoundary quotaBoundary) { + clauses.add(QuotaClause.moreThan(quotaBoundary)); + return this; + } + + public Builder lessThan(QuotaBoundary quotaBoundary) { + clauses.add(QuotaClause.lessThan(quotaBoundary)); + return this; + } + + public Builder hasDomain(Domain domain) { + clauses.add(QuotaClause.hasDomain(domain)); + return this; + } + + public Builder withLimit(Limit limit) { + this.limit = Optional.of(limit); + return this; + } + + public Builder withOffset(Offset offset) { + this.offset = Optional.of(offset); + return this; + } + + public QuotaQuery build() { + return new QuotaQuery( + QuotaClause.and(clauses.build()), + limit.orElse(Limit.unlimited()), + offset.orElse(Offset.none())); + } + } + + public static Builder builder() { + return new Builder(); + } + + private final QuotaClause.And clause; + private final Limit limit; + private final Offset offset; + + private QuotaQuery(QuotaClause.And clause, Limit limit, Offset offset) { + this.clause = clause; + this.limit = limit; + this.offset = offset; + } + + public QuotaClause.And getClause() { + return clause; + } + + public Limit getLimit() { + return limit; + } + + public Offset getOffset() { + return offset; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof QuotaQuery) { + QuotaQuery that = (QuotaQuery) o; + + return Objects.equals(this.clause, that.clause) + && Objects.equals(this.limit, that.limit) + && Objects.equals(this.offset, that.offset); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(clause, limit, offset); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("clause", clause) + .add("limit", limit) + .add("offset", offset) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java new file mode 100644 index 0000000..4e8387a --- /dev/null +++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java @@ -0,0 +1,63 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class LimitTest { + @Test + public void shouldMatchBeanContract() { + EqualsVerifier.forClass(Limit.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void getValueShouldReturnEmptyWhenUnlimited() { + assertThat(Limit.unlimited() + .getValue()) + .isEmpty(); + } + + @Test + public void getValueShouldReturnZeroWhenZero() { + assertThat(Limit.of(0) + .getValue()) + .contains(0); + } + + @Test + public void getValueShouldReturnSuppliedValue() { + assertThat(Limit.of(3) + .getValue()) + .contains(3); + } + + @Test + public void ofShouldThrowOnNegativeValue() { + assertThatThrownBy(() -> Limit.of(-1)) + .isInstanceOf(IllegalArgumentException.class); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java new file mode 100644 index 0000000..50ae174 --- /dev/null +++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/OffsetTest.java @@ -0,0 +1,63 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class OffsetTest { + @Test + public void shouldMatchBeanContract() { + EqualsVerifier.forClass(Offset.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void getValueShouldReturnZeroWhenNone() { + assertThat(Offset.none() + .getValue()) + .isEqualTo(0); + } + + @Test + public void getValueShouldReturnZeroWhenZero() { + assertThat(Offset.of(0) + .getValue()) + .isEqualTo(0); + } + + @Test + public void getValueShouldReturnSuppliedValue() { + assertThat(Offset.of(3) + .getValue()) + .isEqualTo(3); + } + + @Test + public void ofShouldThrowOnNegativeValue() { + assertThatThrownBy(() -> Offset.of(-1)) + .isInstanceOf(IllegalArgumentException.class); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaBoundaryFixture.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaBoundaryFixture.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaBoundaryFixture.java new file mode 100644 index 0000000..a9cd311 --- /dev/null +++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaBoundaryFixture.java @@ -0,0 +1,25 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +public interface QuotaBoundaryFixture { + QuotaBoundary _50 = new QuotaBoundary(0.5); + QuotaBoundary _75 = new QuotaBoundary(0.75); +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java new file mode 100644 index 0000000..66055c7 --- /dev/null +++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaClauseTest.java @@ -0,0 +1,121 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.quota.search; + +import static org.apache.james.quota.search.QuotaBoundaryFixture._50; +import static org.apache.james.quota.search.QuotaBoundaryFixture._75; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.List; + +import org.apache.james.core.Domain; +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class QuotaClauseTest implements QuotaClause { + + @Test + public void lessThanShouldMatchBeanContract() { + EqualsVerifier.forClass(QuotaClause.LessThan.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void moreThanShouldMatchBeanContract() { + EqualsVerifier.forClass(QuotaClause.MoreThan.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void hasDomainShouldMatchBeanContract() { + EqualsVerifier.forClass(QuotaClause.HasDomain.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void andShouldMatchBeanContract() { + EqualsVerifier.forClass(QuotaClause.And.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void lessThanClauseShouldThrowWhenQuotaThresholdIsNull() { + assertThatThrownBy(() -> QuotaClause.lessThan(null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + public void moreThanClauseShouldThrowWhenQuotaThresholdIsNull() { + assertThatThrownBy(() -> QuotaClause.moreThan(null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + public void hasDomainClauseShouldThrowWhenDomainIsNull() { + assertThatThrownBy(() -> QuotaClause.hasDomain(null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + public void andClauseShouldThrowWhenDomainIsNull() { + List<QuotaClause> clauses = null; + assertThatThrownBy(() -> QuotaClause.and(clauses)) + .isInstanceOf(NullPointerException.class); + } + + @Test + public void lessThanClauseShouldInstanciate() { + QuotaClause.LessThan lessThanQuery = QuotaClause.lessThan(_50); + + assertThat(lessThanQuery.getQuotaBoundary()).isEqualTo(_50); + } + + @Test + public void moreThanClauseShouldInstanciate() { + QuotaClause.MoreThan moreThanQuery = QuotaClause.moreThan(_50); + + assertThat(moreThanQuery.getQuotaBoundary()).isEqualTo(_50); + } + + @Test + public void hasDomainClauseShouldInstanciate() { + Domain domain = Domain.of("domain.org"); + + QuotaClause.HasDomain hasDomainQuery = QuotaClause.hasDomain(domain); + + assertThat(hasDomainQuery.getDomain()).isEqualTo(domain); + } + + @Test + public void andClauseShouldInstanciate() { + QuotaClause.MoreThan first = QuotaClause.moreThan(_50); + QuotaClause.MoreThan second = QuotaClause.moreThan(_75); + + QuotaClause.And andQuery = QuotaClause.and(first, second); + + assertThat(andQuery.getClauses()) + .containsExactly(first, second); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java new file mode 100644 index 0000000..c2371db --- /dev/null +++ b/mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/QuotaQueryTest.java @@ -0,0 +1,76 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.quota.search; + +import static org.apache.james.quota.search.QuotaBoundaryFixture._50; +import static org.apache.james.quota.search.QuotaBoundaryFixture._75; + +import org.apache.james.core.Domain; +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class QuotaQueryTest { + + @Test + public void shouldMatchBeanContract() { + EqualsVerifier.forClass(QuotaQuery.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void builderShouldProvideDefaults() { + QuotaQuery quotaQuery = QuotaQuery.builder() + .build(); + + SoftAssertions softly = new SoftAssertions(); + softly.assertThat(quotaQuery.getClause()).isEqualTo(QuotaClause.and()); + softly.assertThat(quotaQuery.getLimit()).isEqualTo(Limit.unlimited()); + softly.assertThat(quotaQuery.getOffset()).isEqualTo(Offset.none()); + softly.assertAll(); + } + + @Test + public void builderShouldUseProvidedValues() { + Limit limit = Limit.of(10); + + Offset offset = Offset.of(50); + QuotaQuery quotaQuery = QuotaQuery.builder() + .withLimit(limit) + .withOffset(offset) + .lessThan(_75) + .moreThan(_50) + .hasDomain(Domain.LOCALHOST) + .build(); + + SoftAssertions softly = new SoftAssertions(); + softly.assertThat(quotaQuery.getClause()) + .isEqualTo(QuotaClause.and( + QuotaClause.lessThan(_75), + QuotaClause.moreThan(_50), + QuotaClause.hasDomain(Domain.LOCALHOST))); + softly.assertThat(quotaQuery.getLimit()).isEqualTo(limit); + softly.assertThat(quotaQuery.getOffset()).isEqualTo(offset); + softly.assertAll(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/fec172dc/mailbox/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/pom.xml b/mailbox/pom.xml index 4390469..beac9a4 100644 --- a/mailbox/pom.xml +++ b/mailbox/pom.xml @@ -56,6 +56,7 @@ <module>plugin/quota-mailing</module> <module>plugin/quota-mailing-cassandra</module> <module>plugin/quota-mailing-memory</module> + <module>plugin/quota-search</module> <module>plugin/spamassassin</module> </modules> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org