Author: matthieu
Date: Fri Dec 11 12:32:47 2015
New Revision: 1719381
URL: http://svn.apache.org/viewvc?rev=1719381&view=rev
Log:
JAMES-1644 Introduce JMAP filter
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Filter.java
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterOperator.java
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Operator.java
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/OperatorSerializeDeserializeTest.java
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterOperatorTest.java
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Filter.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Filter.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Filter.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Filter.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import com.fasterxml.jackson.annotation.JsonSubTypes;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+@JsonTypeInfo(
+ use = JsonTypeInfo.Id.NAME,
+ include = JsonTypeInfo.As.PROPERTY,
+ property = "filter",
+ defaultImpl = FilterCondition.class
+)
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = FilterOperator.class, name = "operator")
+})
+public interface Filter {
+
+}
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterCondition.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,273 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.commons.lang.NotImplementedException;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+
+@JsonDeserialize(builder = FilterCondition.Builder.class)
+public class FilterCondition implements Filter {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+
+ private ImmutableList.Builder<String> inMailboxes;
+ private ImmutableList.Builder<String> notInMailboxes;
+ private Date before;
+ private Date after;
+ private Integer minSize;
+ private Integer maxSize;
+ private Boolean isFlagged;
+ private Boolean isUnread;
+ private Boolean isAnswered;
+ private Boolean isDraft;
+ private Boolean hasAttachment;
+ private String text;
+ private String from;
+ private String to;
+ private String cc;
+ private String bcc;
+ private String subject;
+ private String body;
+ private ImmutableList.Builder<String> header;
+
+ private Builder() {
+ inMailboxes = ImmutableList.builder();
+ notInMailboxes = ImmutableList.builder();
+ header = ImmutableList.builder();
+ }
+
+ public Builder inMailboxes(List<String> inMailboxes) {
+ this.inMailboxes.addAll(inMailboxes);
+ return this;
+ }
+
+ public Builder notInMailboxes(List<Filter> notInMailboxes) {
+ throw new NotImplementedException();
+ }
+
+ public Builder before(Date before) {
+ throw new NotImplementedException();
+ }
+
+ public Builder after(Date after) {
+ throw new NotImplementedException();
+ }
+
+ public Builder minSize(int minSize) {
+ throw new NotImplementedException();
+ }
+
+ public Builder maxSize(int maxSize) {
+ throw new NotImplementedException();
+ }
+
+ public Builder isFlagged(boolean isFlagger) {
+ throw new NotImplementedException();
+ }
+
+ public Builder isUnread(boolean isUnread) {
+ throw new NotImplementedException();
+ }
+
+ public Builder isAnswered(boolean isAnswered) {
+ throw new NotImplementedException();
+ }
+
+ public Builder isDraft(boolean isDraft) {
+ throw new NotImplementedException();
+ }
+
+ public Builder hasAttachment(boolean hasAttachment) {
+ throw new NotImplementedException();
+ }
+
+ public Builder text(String text) {
+ throw new NotImplementedException();
+ }
+
+ public Builder from(String from) {
+ throw new NotImplementedException();
+ }
+
+ public Builder to(String to) {
+ throw new NotImplementedException();
+ }
+
+ public Builder cc(String cc) {
+ throw new NotImplementedException();
+ }
+
+ public Builder bcc(String bcc) {
+ throw new NotImplementedException();
+ }
+
+ public Builder subject(String subject) {
+ throw new NotImplementedException();
+ }
+
+ public Builder body(String body) {
+ throw new NotImplementedException();
+ }
+
+ public Builder header(List<String> body) {
+ throw new NotImplementedException();
+ }
+
+ public FilterCondition build() {
+ return new FilterCondition(inMailboxes.build(),
notInMailboxes.build(), Optional.ofNullable(before),
Optional.ofNullable(after), Optional.ofNullable(minSize),
Optional.ofNullable(maxSize),
+ Optional.ofNullable(isFlagged),
Optional.ofNullable(isUnread), Optional.ofNullable(isAnswered),
Optional.ofNullable(isDraft), Optional.ofNullable(hasAttachment),
+ Optional.ofNullable(text), Optional.ofNullable(from),
Optional.ofNullable(to), Optional.ofNullable(cc), Optional.ofNullable(bcc),
Optional.ofNullable(subject), Optional.ofNullable(body), header.build());
+ }
+ }
+
+ private final List<String> inMailboxes;
+ private final List<String> notInMailboxes;
+ private final Optional<Date> before;
+ private final Optional<Date> after;
+ private final Optional<Integer> minSize;
+ private final Optional<Integer> maxSize;
+ private final Optional<Boolean> isFlagged;
+ private final Optional<Boolean> isUnread;
+ private final Optional<Boolean> isAnswered;
+ private final Optional<Boolean> isDraft;
+ private final Optional<Boolean> hasAttachment;
+ private final Optional<String> text;
+ private final Optional<String> from;
+ private final Optional<String> to;
+ private final Optional<String> cc;
+ private final Optional<String> bcc;
+ private final Optional<String> subject;
+ private final Optional<String> body;
+ private final List<String> header;
+
+ @VisibleForTesting FilterCondition(List<String> inMailboxes, List<String>
notInMailboxes, Optional<Date> before, Optional<Date> after, Optional<Integer>
minSize, Optional<Integer> maxSize,
+ Optional<Boolean> isFlagged, Optional<Boolean> isUnread,
Optional<Boolean> isAnswered, Optional<Boolean> isDraft, Optional<Boolean>
hasAttachment,
+ Optional<String> text, Optional<String> from, Optional<String> to,
Optional<String> cc, Optional<String> bcc, Optional<String> subject,
Optional<String> body, List<String> header) {
+
+ this.inMailboxes = inMailboxes;
+ this.notInMailboxes = notInMailboxes;
+ this.before = before;
+ this.after = after;
+ this.minSize = minSize;
+ this.maxSize = maxSize;
+ this.isFlagged = isFlagged;
+ this.isUnread = isUnread;
+ this.isAnswered = isAnswered;
+ this.isDraft = isDraft;
+ this.hasAttachment = hasAttachment;
+ this.text = text;
+ this.from = from;
+ this.to = to;
+ this.cc = cc;
+ this.bcc = bcc;
+ this.subject = subject;
+ this.body = body;
+ this.header = header;
+ }
+
+ public List<String> getInMailboxes() {
+ return inMailboxes;
+ }
+
+ public List<String> getNotInMailboxes() {
+ return notInMailboxes;
+ }
+
+ public Optional<Date> getBefore() {
+ return before;
+ }
+
+ public Optional<Date> getAfter() {
+ return after;
+ }
+
+ public Optional<Integer> getMinSize() {
+ return minSize;
+ }
+
+ public Optional<Integer> getMaxSize() {
+ return maxSize;
+ }
+
+ public Optional<Boolean> getIsFlagged() {
+ return isFlagged;
+ }
+
+ public Optional<Boolean> getIsUnread() {
+ return isUnread;
+ }
+
+ public Optional<Boolean> getIsAnswered() {
+ return isAnswered;
+ }
+
+ public Optional<Boolean> getIsDraft() {
+ return isDraft;
+ }
+
+ public Optional<Boolean> getHasAttachment() {
+ return hasAttachment;
+ }
+
+ public Optional<String> getText() {
+ return text;
+ }
+
+ public Optional<String> getFrom() {
+ return from;
+ }
+
+ public Optional<String> getTo() {
+ return to;
+ }
+
+ public Optional<String> getCc() {
+ return cc;
+ }
+
+ public Optional<String> getBcc() {
+ return bcc;
+ }
+
+ public Optional<String> getSubject() {
+ return subject;
+ }
+
+ public Optional<String> getBody() {
+ return body;
+ }
+
+ public List<String> getHeader() {
+ return header;
+ }
+}
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterOperator.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterOperator.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterOperator.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/FilterOperator.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import java.util.List;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+@JsonDeserialize(builder = FilterOperator.Builder.class)
+public class FilterOperator implements Filter {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ @JsonPOJOBuilder(withPrefix = "")
+ public static class Builder {
+
+ private Operator operator;
+ private ImmutableList.Builder<Filter> conditionsBuilder;
+
+ private Builder() {
+ conditionsBuilder = ImmutableList.builder();
+ }
+
+ public Builder operator(Operator operator) {
+ Preconditions.checkNotNull(operator);
+ this.operator = operator;
+ return this;
+ }
+
+ public Builder conditions(List<Filter> conditions) {
+ this.conditionsBuilder.addAll(conditions);
+ return this;
+ }
+
+ public FilterOperator build() {
+ Preconditions.checkState(operator != null, "'operator' is
mandatory");
+ ImmutableList<Filter> conditions = conditionsBuilder.build();
+ Preconditions.checkState(!conditions.isEmpty(), "'conditions' is
mandatory");
+ return new FilterOperator(operator, conditions);
+ }
+ }
+
+ private final Operator operator;
+ private final List<Filter> conditions;
+
+ @VisibleForTesting FilterOperator(Operator operator, List<Filter>
conditions) {
+ this.operator = operator;
+ this.conditions = conditions;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public List<Filter> getConditions() {
+ return conditions;
+ }
+}
Added:
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Operator.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Operator.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Operator.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Operator.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public enum Operator {
+
+ @JsonProperty("AND")
+ AND,
+ @JsonProperty("OR")
+ OR,
+ @JsonProperty("NOT")
+ NOT;
+}
Added:
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/OperatorSerializeDeserializeTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/OperatorSerializeDeserializeTest.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/OperatorSerializeDeserializeTest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/OperatorSerializeDeserializeTest.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.jmap.json;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.jmap.model.Operator;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.exc.InvalidFormatException;
+
+public class OperatorSerializeDeserializeTest {
+
+ @Test
+ public void deserializeKnownValue() throws Exception {
+ ObjectWithOperator operator = new
ObjectMapper().readValue("{\"operator\":\"AND\"}", ObjectWithOperator.class);
+ assertThat(operator.operator).isEqualTo(Operator.AND);
+ }
+
+ @Test(expected=InvalidFormatException.class)
+ public void deserializeUnknownValue() throws Exception {
+ new ObjectMapper().readValue("{\"operator\":\"UNKNOWN\"}",
ObjectWithOperator.class);
+ }
+
+ @Test
+ public void serializeKnownValue() throws Exception {
+ ObjectWithOperator objectWithOperator = new ObjectWithOperator();
+ objectWithOperator.operator = Operator.AND;
+ String operator = new
ObjectMapper().writeValueAsString(objectWithOperator);
+ assertThat(operator).isEqualTo("{\"operator\":\"AND\"}");
+ }
+
+ private static class ObjectWithOperator {
+
+ public Operator operator;
+ }
+}
Added:
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterConditionTest.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,149 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class FilterConditionTest {
+
+ @Test
+ public void buildShouldWorkWhenNoInMailboxes() {
+ FilterCondition filterCondition = FilterCondition.builder().build();
+ assertThat(filterCondition.getInMailboxes()).isEmpty();
+ }
+
+ @Test
+ public void buildShouldWorkWhenGivenInMailboxes() {
+ FilterCondition filterCondition = FilterCondition.builder()
+ .inMailboxes(ImmutableList.of("1", "2"))
+ .build();
+ assertThat(filterCondition.getInMailboxes()).containsOnly("1", "2");
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenNotInMailboxes() {
+ FilterCondition.builder().notInMailboxes(ImmutableList.of());
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenBefore() {
+ FilterCondition.builder().before(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenAfter() {
+ FilterCondition.builder().after(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenMinSize() {
+ FilterCondition.builder().minSize(0);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenMaxSize() {
+ FilterCondition.builder().maxSize(0);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenIsFlagged() {
+ FilterCondition.builder().isFlagged(false);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenIsUnread() {
+ FilterCondition.builder().isUnread(false);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenIsAnswered() {
+ FilterCondition.builder().isAnswered(false);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenIsDraft() {
+ FilterCondition.builder().isDraft(false);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenHasAttachment() {
+ FilterCondition.builder().hasAttachment(false);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenText() {
+ FilterCondition.builder().text(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenFrom() {
+ FilterCondition.builder().from(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenTo() {
+ FilterCondition.builder().to(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenCc() {
+ FilterCondition.builder().cc(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenBcc() {
+ FilterCondition.builder().bcc(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenSubject() {
+ FilterCondition.builder().subject(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenBody() {
+ FilterCondition.builder().body(null);
+ }
+
+ @Test(expected=NotImplementedException.class)
+ public void builderShouldThrowWhenHeader() {
+ FilterCondition.builder().header(ImmutableList.of());
+ }
+
+ @Test
+ public void buildShouldWork() {
+ FilterCondition expectedFilterCondition = new
FilterCondition(ImmutableList.of("1"), ImmutableList.of(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(),
+ Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
+ Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), ImmutableList.of());
+
+ FilterCondition filterCondition = FilterCondition.builder()
+ .inMailboxes(ImmutableList.of("1"))
+ .build();
+
+
assertThat(filterCondition).isEqualToComparingFieldByField(expectedFilterCondition);
+ }
+}
Added:
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterOperatorTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterOperatorTest.java?rev=1719381&view=auto
==============================================================================
---
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterOperatorTest.java
(added)
+++
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/FilterOperatorTest.java
Fri Dec 11 12:32:47 2015
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class FilterOperatorTest {
+
+ @Test(expected=IllegalStateException.class)
+ public void builderShouldThrowWhenOperatorIsNotGiven() {
+ FilterOperator.builder().build();
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void builderShouldThrowWhenOperatorIsNull() {
+ FilterOperator.builder().operator(null);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void builderShouldThrowWhenConditionsIsEmpty() {
+ FilterOperator.builder().operator(Operator.AND).build();
+ }
+
+ @Test
+ public void builderShouldWork() {
+ ImmutableList<Filter> conditions =
ImmutableList.of(FilterCondition.builder().build());
+ FilterOperator expectedFilterOperator = new
FilterOperator(Operator.AND, conditions);
+
+ FilterOperator filterOperator = FilterOperator.builder()
+ .operator(Operator.AND)
+ .conditions(conditions)
+ .build();
+
+
assertThat(filterOperator).isEqualToComparingFieldByField(expectedFilterOperator);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]