james-project git commit: MAILBOX-270: Checking the old behavior with enable metadata extension
Repository: james-project Updated Branches: refs/heads/master a3aa6a005 -> b3fb0ef51 MAILBOX-270: Checking the old behavior with enable metadata extension Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b3fb0ef5 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b3fb0ef5 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b3fb0ef5 Branch: refs/heads/master Commit: b3fb0ef51bd4de402a05faa1c49abd68d2ad6651 Parents: a3aa6a0 Author: Quynh Nguyen Authored: Tue Aug 30 11:27:37 2016 +0700 Committer: Quynh Nguyen Committed: Thu Sep 15 11:06:46 2016 +0700 -- .../mailbox/store/StoreMailboxManager.java | 7 +- .../store/event/MailboxAnnotationListener.java | 73 ++ .../StoreMailboxManagerAnnotationTest.java | 19 ++- .../event/MailboxAnnotationListenerTest.java| 132 +++ .../apache/james/imap/scripts/Annotation.test | 26 5 files changed, 252 insertions(+), 5 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/b3fb0ef5/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java -- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java index 1f46c77..6bdb110 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java @@ -64,6 +64,7 @@ import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener; import org.apache.james.mailbox.store.event.DelegatingMailboxListener; +import org.apache.james.mailbox.store.event.MailboxAnnotationListener; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.AnnotationMapper; import org.apache.james.mailbox.store.mail.MailboxMapper; @@ -203,6 +204,10 @@ public class StoreMailboxManager implements MailboxManager { if (moveBatcher == null) { moveBatcher = new MessageBatcher(MessageBatcher.NO_BATCH_SIZE); } +if (hasCapability(MailboxCapabilities.Annotation)) { +MailboxSession session = null; +this.addGlobalListener(new MailboxAnnotationListener(mailboxSessionMapperFactory), session); +} } @Override @@ -491,7 +496,7 @@ public class StoreMailboxManager implements MailboxManager { } @Override -public void deleteMailbox(final MailboxPath mailboxPath, MailboxSession session) throws MailboxException { +public void deleteMailbox(final MailboxPath mailboxPath, final MailboxSession session) throws MailboxException { session.getLog().info("deleteMailbox " + mailboxPath); final MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session); http://git-wip-us.apache.org/repos/asf/james-project/blob/b3fb0ef5/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java -- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java new file mode 100644 index 000..43656a5 --- /dev/null +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java @@ -0,0 +1,73 @@ +/ + * 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 * +
[jira] [Created] (JAMES-1822) Create a docker-compose for James+Cassandra+ES
Antoine Duprat created JAMES-1822: - Summary: Create a docker-compose for James+Cassandra+ES Key: JAMES-1822 URL: https://issues.apache.org/jira/browse/JAMES-1822 Project: James Server Issue Type: Improvement Reporter: Antoine Duprat -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[jira] [Updated] (JAMES-1091) Call for new logo
[ https://issues.apache.org/jira/browse/JAMES-1091?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Laura Royet updated JAMES-1091: --- Attachment: logo_james.svg Hi everybody, I am currently working on a promoting website for James and also on a proposal for a new logo. I attached here my proposal. This logo uses the symbolism of the carrier pigeon messages. It is stylized in Phoenix, noble bird that rises from its ashes : the resumption of the James project. The animal is in 2 parts : the body shape of the letter J James and wing takes the pen belonging to Apache. Colors red + orange are done to the dynamism. The logo is here in different variants as required for different uses. Thanks in advance for your comments. Regards, Laura Royet > Call for new logo > - > > Key: JAMES-1091 > URL: https://issues.apache.org/jira/browse/JAMES-1091 > Project: James Server > Issue Type: Sub-task >Affects Versions: 3.0.0 >Reporter: Eric Charles >Assignee: Ioan Eugen Stan > Fix For: 3.0.0 > > Attachments: logo_james.svg > > > We already have some great contribution for a new james logo on > http://propositum.biz/james.html > We should express a bit more the requirements (apache mention, different > types of logo,...). > If we really have many contributions and different preferences from the > community, we also may propose a vote for the final choice. > Up-to your imagination and favorite drawing tool !!! -- This message was sent by Atlassian JIRA (v6.3.4#6332) - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[04/17] james-project git commit: MAILET-124 Simplify XOR composite matcher
MAILET-124 Simplify XOR composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/28445fb9 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/28445fb9 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/28445fb9 Branch: refs/heads/master Commit: 28445fb928ea684c2539a2bc06e176d707e3dc79 Parents: beb9cd6 Author: Benoit Tellier Authored: Thu Sep 1 15:21:07 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 11:51:15 2016 +0200 -- .../mailetcontainer/impl/matchers/Xor.java | 59 ++-- 1 file changed, 18 insertions(+), 41 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/28445fb9/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Xor.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Xor.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Xor.java index 849e7ab..c7da294 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Xor.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Xor.java @@ -20,7 +20,6 @@ package org.apache.james.mailetcontainer.impl.matchers; import java.util.Collection; -import java.util.Iterator; import java.util.ArrayList; import org.apache.mailet.MailAddress; @@ -28,6 +27,11 @@ import org.apache.mailet.Mail; import javax.mail.MessagingException; import org.apache.mailet.Matcher; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + public class Xor extends GenericCompositeMatcher { /** @@ -40,54 +44,27 @@ public class Xor extends GenericCompositeMatcher { */ public Collection match(Mail mail) throws MessagingException { Collection finalResult = null; -Matcher matcher; boolean first = true; -for (Iterator matcherIter = iterator(); matcherIter.hasNext();) { -matcher = matcherIter.next(); -Collection result = matcher.match(mail); -if (result == null) { -result = new ArrayList(0); -} -// log("Matching with " + -// matcher.getMatcherConfig().getMatcherName() + -// " result="+result.toString() ); +for (Matcher matcher: getMatchers()) { +Collection matchedAddresses = Optional.fromNullable(matcher.match(mail)).or(new ArrayList()); if (first) { -finalResult = result; +finalResult = matchedAddresses; first = false; } else { -// Check if we need to Xor ... -// if the finalResult and the subsequent result are the same -// collection, then it contains the same recipients -// so we can short-circuit building the XOR and return an empty -// set -if (finalResult == result) { -// the XOR of the same collection is empty -finalResult.clear(); -// log("same collection - so clear"); -} else { -// the two results are different collections, so we XOR them -// Ensure that the finalResult does not contain recipients -// in the result collection -MailAddress recipient; -for (Object aResult : result) { -recipient = (MailAddress) (aResult); -if (!finalResult.contains(recipient)) { -finalResult.add(recipient); -} else { -finalResult.remove(recipient); -} -} -recipient = null; -// log("xor recipients into new finalResult="+finalResult); -} -// basically the finalResult gets replaced with a smaller result -// otherwise finalResult would have been equal to result (in all -// cases) +finalResult = performXor(finalResult, matchedAddresses); } -result = null; } return finalResult; } +private Collection performXor(Collection collection1, Collection collection2) { +ImmutableSet set1 = ImmutableSet.copyOf(collection1); +ImmutableSet set2 = ImmutableSet.copyOf(collect
[05/17] james-project git commit: MAILET-124 Simplify AND composite matcher
MAILET-124 Simplify AND composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/12df8f9c Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/12df8f9c Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/12df8f9c Branch: refs/heads/master Commit: 12df8f9cc3f12d604dc7e82b1058f8649075536b Parents: 28445fb Author: Benoit Tellier Authored: Thu Sep 1 15:21:50 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 11:51:19 2016 +0200 -- .../mailetcontainer/impl/matchers/And.java | 87 +++- 1 file changed, 32 insertions(+), 55 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/12df8f9c/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java index 931f01c..9738495 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java @@ -20,14 +20,18 @@ package org.apache.james.mailetcontainer.impl.matchers; / import java.util.Collection; -import java.util.Iterator; -import java.util.ArrayList; +import java.util.List; +import java.util.Set; import org.apache.mailet.MailAddress; import org.apache.mailet.Mail; import javax.mail.MessagingException; import org.apache.mailet.Matcher; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + /** * This matcher performs And conjunction between the two recipients */ @@ -41,64 +45,37 @@ public class And extends GenericCompositeMatcher { * @return Collection of Recipient from the And composition results of the * child Matchers. */ -public Collection match(Mail mail) throws MessagingException { -Collection finalResult = null; -Matcher matcher; -boolean first = true; -for (Iterator matcherIter = iterator(); matcherIter.hasNext();) { -matcher = (matcherIter.next()); -Collection result = matcher.match(mail); - -if (result == null) { -// short-circuit -// log("Matching with " + -// matcher.getMatcherConfig().getMatcherName() + -// " result.size()=0"); -return new ArrayList(0); -} -if (result.size() == 0) { -return result; -} +public Collection match(final Mail mail) throws MessagingException { +List> individualMatchedResults = performMatchOnMatchers(mail); +return computeIntersection(individualMatchedResults); +} -// log("Matching with " + -// matcher.getMatcherConfig().getMatcherName() + -// " result.size()="+result.size()); +private Collection computeIntersection(List> individualMatchedResults) { +if (individualMatchedResults.size() == 0) { +return null; +} +if (individualMatchedResults.size() == 1) { +return individualMatchedResults.get(0); +} +Set temporaryResult = ImmutableSet.copyOf(individualMatchedResults.get(0)); +List> followingResults = individualMatchedResults.subList(1, individualMatchedResults.size()); +for(Set matchedAddresses: followingResults) { +temporaryResult = Sets.intersection(temporaryResult, matchedAddresses); +} +return temporaryResult; +} -if (first) { -finalResult = result; -first = false; +private List> performMatchOnMatchers(Mail mail) throws MessagingException { +ImmutableList.Builder> builder = ImmutableList.builder(); +for (Matcher matcher : getMatchers()) { +Collection matchedMailAddress = matcher.match(mail); +if (matchedMailAddress != null && !matchedMailAddress.isEmpty()) { +builder.add(ImmutableSet.copyOf(matchedMailAddress)); } else { -// Check if we need to And ... -// if the finalResult and the subsequent result are the same -// collection, then it contains the same recipients -// so we can short-circuit building the AND of the two -if (finalResult != result) { -
[02/17] james-project git commit: MAILET-124 Simplify Or composite matcher
MAILET-124 Simplify Or composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cc718f06 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cc718f06 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cc718f06 Branch: refs/heads/master Commit: cc718f06ca094ecdb5778d261a9eff79e583209b Parents: 185f5b0 Author: Benoit Tellier Authored: Thu Sep 1 15:19:58 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 11:50:49 2016 +0200 -- .../james/mailetcontainer/impl/matchers/Or.java | 70 +++- 1 file changed, 9 insertions(+), 61 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/cc718f06/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java index f6d2379..cc7ab84 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java @@ -28,78 +28,26 @@ import java.util.Iterator; import java.util.ArrayList; import javax.mail.MessagingException; +import com.google.common.collect.ImmutableSet; + public class Or extends GenericCompositeMatcher { /** * This is the Or CompositeMatcher - consider it to be a union of the - * results. If any match results in a full set of recipients the matching is - * short-circuited. + * results. * * @return Collection of Recipient from the Or composition results of the * child matchers. */ public Collection match(Mail mail) throws MessagingException { -Collection finalResult = null; -Matcher matcher; -boolean first = true; - -// the size of the complete set of recipients -int size = mail.getRecipients().size(); - -// Loop through until the finalResult is full or all the child matchers -// have been executed -for (Iterator matcherIter = iterator(); matcherIter.hasNext();) { -matcher = matcherIter.next(); -// log("Matching with " -// + matcher -// .getMatcherConfig() -// .getMatcherName() -// ); -Collection result = matcher.match(mail); -if (first) { -if (result == null) { -result = new ArrayList(0); -} -finalResult = result; -first = false; -} else { -// Check if we need to Or ... -// if the finalResult and the subsequent result are the same -// collection, then it contains the same recipients -// so we can short-circuit building the OR of the two -if (finalResult != result) { -if (result != null) { -if (finalResult == null) { -finalResult = result; -} else { -// the two results are different collections, so we -// must OR them -// Ensure that the finalResult only contains one -// copy of the recipients in the result collection -MailAddress recipient; -for (Object aResult : result) { -recipient = (MailAddress) aResult; -if (!finalResult.contains(recipient)) { -System.out.println(recipient); -finalResult.add(recipient); -} -} -recipient = null; -} -} -} -} -if (finalResult.size() == size) { -// we have a complete set of recipients, no need to OR in -// anymore -// i.e. short-circuit the Or -break; +ImmutableSet.Builder result = ImmutableSet.builder(); +for (Matcher matcher : getMatchers()) { +Collection matchResult = matcher.match(mail); +if (matchResult != null) { +result.addAll(matchResult); } -result = null; -matcher = null; } -// log("OrMatch: end.");
[07/17] james-project git commit: MAILET-124 Provide tests for Not composite matcher
MAILET-124 Provide tests for Not composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a86a67dc Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a86a67dc Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a86a67dc Branch: refs/heads/master Commit: a86a67dce1edd993718bc733c6de4243f578c0f3 Parents: e114c6d Author: Benoit Tellier Authored: Thu Sep 1 15:06:52 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 12:04:57 2016 +0200 -- .../mailetcontainer/impl/matchers/NotTest.java | 106 +++ 1 file changed, 106 insertions(+) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/a86a67dc/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/NotTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/NotTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/NotTest.java new file mode 100644 index 000..ca555da --- /dev/null +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/NotTest.java @@ -0,0 +1,106 @@ +/ + * 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.mailetcontainer.impl.matchers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +import org.apache.mailet.Matcher; +import org.apache.mailet.base.test.FakeMail; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +public class NotTest { + +private Not testee; +private Matcher matcher1; +private Matcher matcher2; +private Mail mail; +private MailAddress recipient1; +private MailAddress recipient2; +private MailAddress recipient3; +private MailAddress recipient4; + +@Before +public void setUp() throws Exception { +matcher1 = mock(Matcher.class); +matcher2 = mock(Matcher.class); + +testee = new Not(); + +recipient1 = new MailAddress("a...@apahe.org"); +recipient2 = new MailAddress("ot...@apahe.org"); +recipient3 = new MailAddress("b...@apache.org"); +recipient4 = new MailAddress("y...@apache.org"); +mail = FakeMail.builder().recipients(recipient1, recipient2, recipient3, recipient4).build(); +} + +@Test +public void shouldReturnAllAddressesWhenNoMatcherSpecified() throws Exception { +assertThat(testee.match(mail)).containsOnly(recipient1, recipient2, recipient3, recipient4); +} + +@Test +public void shouldNegateWhenOneMatcher() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(recipient1, recipient3)); + +testee.add(matcher1); + +assertThat(testee.match(mail)).containsOnly(recipient2, recipient4); +} + +@Test +public void shouldNegateUnionWhenTwoMatchers() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(recipient1, recipient3)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of(recipient1, recipient2)); + +testee.add(matcher1); +testee.add(matcher2); + +assertThat(testee.match(mail)).containsOnly(recipient4); +} + +@Test +public void shouldAcceptEmptyResults() throws Exception { +when(matcher1.match(mail)).thenReturn(Imm
[10/17] james-project git commit: MAILET-124 Adding a MailAddress fixture, to ease tests with matchers
MAILET-124 Adding a MailAddress fixture, to ease tests with matchers Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5636d897 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5636d897 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5636d897 Branch: refs/heads/master Commit: 5636d8974229e21654ba2924b8ab8f63a3dcb40d Parents: 3a5c2af Author: Benoit Tellier Authored: Thu Sep 15 11:55:11 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:05:20 2016 +0200 -- .../apache/mailet/base/MailAddressFixture.java | 46 +++ .../org/apache/mailet/base/test/FakeMail.java | 9 +++ .../james/transport/matchers/AllTest.java | 15 ++--- .../transport/matchers/FetchedFromTest.java | 18 +++--- .../transport/matchers/HasAttachmentTest.java | 11 ++-- .../transport/matchers/HostIsLocalTest.java | 52 - .../james/transport/matchers/HostIsTest.java| 52 - .../matchers/IsSingleRecipientTest.java | 14 ++--- .../transport/matchers/RelayLimitTest.java | 17 +++--- .../transport/matchers/SenderIsNullTest.java| 9 ++- .../transport/matchers/SizeGreaterThanTest.java | 59 +--- 11 files changed, 171 insertions(+), 131 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java -- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java b/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java new file mode 100644 index 000..f98a160 --- /dev/null +++ b/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java @@ -0,0 +1,46 @@ +/ + * 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.mailet.base; + +import javax.mail.internet.AddressException; + +import org.apache.mailet.MailAddress; + +import com.google.common.base.Throwables; + +public class MailAddressFixture { + + +public static final String JAMES_APACHE_ORG = "james.apache.org"; +public static final String JAMES2_APACHE_ORG = "james2.apache.org"; + +public static final MailAddress ANY_AT_JAMES = createMailAddress("any@" + JAMES_APACHE_ORG); +public static final MailAddress OTHER_AT_JAMES = createMailAddress("other@" + JAMES_APACHE_ORG); +public static final MailAddress ANY_AT_JAMES2 = createMailAddress("any@" + JAMES2_APACHE_ORG); +public static final MailAddress OTHER_AT_JAMES2 = createMailAddress("other@" + JAMES2_APACHE_ORG); + +private static MailAddress createMailAddress(String mailAddress) { +try { +return new MailAddress(mailAddress); +} catch (AddressException e) { +throw Throwables.propagate(e); +} +} +} http://git-wip-us.apache.org/repos/asf/james-project/blob/5636d897/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java -- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java index 77a1288..7e42940 100644 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java +++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java @@ -63,11 +63,17 @@ public class FakeMail implements Mail { public static class Builder { private Optional fileName = Optional.absent(); +private Optional size = Optional.absent(); private Op
[03/17] james-project git commit: MAILET-124 Changing composite matcher interface
MAILET-124 Changing composite matcher interface Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/185f5b09 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/185f5b09 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/185f5b09 Branch: refs/heads/master Commit: 185f5b098094e54c96a437038b5f22434686e3db Parents: b3fb0ef Author: Benoit Tellier Authored: Thu Sep 1 15:19:17 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 11:50:49 2016 +0200 -- .../impl/jmx/JMXStateMailetProcessorListener.java | 2 +- .../mailetcontainer/impl/matchers/CompositeMatcher.java | 7 --- .../impl/matchers/GenericCompositeMatcher.java | 12 +++- 3 files changed, 12 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/185f5b09/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java index acb977a..1a826cf 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/jmx/JMXStateMailetProcessorListener.java @@ -150,7 +150,7 @@ public class JMXStateMailetProcessorListener implements MailetProcessorListener, if (matcher instanceof CompositeMatcher) { // we increment the nesting as we have one more child level and // register the child matchers -registerMatchers(matcherMBeanName, ((CompositeMatcher) matcher).iterator(), nestingLevel + 1); +registerMatchers(matcherMBeanName, ((CompositeMatcher) matcher).getMatchers().iterator(), nestingLevel + 1); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/185f5b09/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/CompositeMatcher.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/CompositeMatcher.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/CompositeMatcher.java index 7bdf47f..6a759d4 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/CompositeMatcher.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/CompositeMatcher.java @@ -19,7 +19,8 @@ package org.apache.james.mailetcontainer.impl.matchers; -import java.util.Iterator; +import java.util.List; + import org.apache.mailet.Matcher; /** @@ -54,9 +55,9 @@ import org.apache.mailet.Matcher; public interface CompositeMatcher extends Matcher { /** - * @return Iterator if child Matchers + * @return Immutable list for the child matchers */ -Iterator iterator(); +List getMatchers(); /** * Add a child matcher to this composite matcher. This is called by http://git-wip-us.apache.org/repos/asf/james-project/blob/185f5b09/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/GenericCompositeMatcher.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/GenericCompositeMatcher.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/GenericCompositeMatcher.java index 936fcc1..7158ef2 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/GenericCompositeMatcher.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/GenericCompositeMatcher.java @@ -19,13 +19,15 @@ package org.apache.james.mailetcontainer.impl.matchers; -import java.util.Collection; -import java.util.Iterator; import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import org.apache.mailet.Matcher; import org.apache.mailet.base.GenericMatcher; +import com.google.common.collect.ImmutableList; + /** * Abstract base class for CompositeMatchers. This class handles the child * collection of Matchers a
[09/17] james-project git commit: MAILET-124 Provide tests for Xor composite matcher
MAILET-124 Provide tests for Xor composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b626c0c9 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b626c0c9 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b626c0c9 Branch: refs/heads/master Commit: b626c0c90ef57e0293ab9463304cac4832dfef4a Parents: a86a67d Author: Benoit Tellier Authored: Thu Sep 1 15:15:29 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 12:05:16 2016 +0200 -- .../mailetcontainer/impl/matchers/XorTest.java | 87 ++-- 1 file changed, 60 insertions(+), 27 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/b626c0c9/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java index fe29bfc..c06aeaf 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/XorTest.java @@ -18,51 +18,84 @@ / package org.apache.james.mailetcontainer.impl.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.apache.mailet.Matcher; +import org.apache.mailet.base.test.FakeMail; import org.junit.Before; import org.junit.Test; -import javax.mail.MessagingException; -import java.util.Collection; -import java.util.Iterator; +import com.google.common.collect.ImmutableList; + +public class XorTest { -public class XorTest extends BaseMatchersTest { +private Xor testee; +private Matcher matcher1; +private Matcher matcher2; +private Mail mail; -@Override @Before public void setUp() throws Exception { -super.setUp(); -setupCompositeMatcher("Xor", Xor.class); +matcher1 = mock(Matcher.class); +matcher2 = mock(Matcher.class); + +testee = new Xor(); + +mail = FakeMail.builder().recipients(ANY_AT_JAMES, OTHER_AT_JAMES, ANY_AT_JAMES2, OTHER_AT_JAMES2).build(); +} + +@Test +public void shouldReturnNoResultWhenNoMatcherSpecified() throws Exception { +assertThat(testee.match(mail)).isNull(); +} + +@Test +public void shouldReturnMatchResultWhenOnlyOneMatcher() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); + +testee.add(matcher1); + +assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES, ANY_AT_JAMES2); } -// test if all recipients was returned @Test -public void testIntersectSame() throws MessagingException { -setupChild("RecipientIsRegex=t...@james.apache.org"); -setupChild("RecipientIsRegex=t...@james.apache.org"); +public void shouldPerformXorWhenTwoMatchers() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); -Collection matchedRecipients = matcher.match(mockedMail); +testee.add(matcher1); +testee.add(matcher2); -assertNotNull(matchedRecipients); -assertEquals(0, matchedRecipients.size()); +assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES2, OTHER_AT_JAMES); } @Test -public void testNoIntersect() throws MessagingException { -setupChild("RecipientIsRegex=t...@james.apache.org"); -setupChild("RecipientIsRegex=te...@james.apache.org"); +public void shouldAcceptEmptyResults() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of()); -Collection matchedRecipients = matcher.match(mockedMail); +test
[13/17] james-project git commit: MAILET-124 OrTest should not be sensitive to address order
MAILET-124 OrTest should not be sensitive to address order Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c8648a19 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c8648a19 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c8648a19 Branch: refs/heads/master Commit: c8648a199ded879e793b41c45cf5b4197ca473c2 Parents: a78c854 Author: Benoit Tellier Authored: Thu Sep 8 14:58:13 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:06:33 2016 +0200 -- .../james/mailetcontainer/impl/matchers/Or.java | 2 +- .../mailetcontainer/impl/matchers/OrTest.java | 28 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/c8648a19/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java index 5d4f3c1..b375d4c 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java @@ -50,7 +50,7 @@ public class Or extends GenericCompositeMatcher { break; } } -return ImmutableSet.copyOf(result); +return result; } } http://git-wip-us.apache.org/repos/asf/james-project/blob/c8648a19/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java index d71ee19..94fb41c 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java @@ -19,10 +19,10 @@ package org.apache.james.mailetcontainer.impl.matchers; -import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_1; -import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_2; -import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_3_OTHER_DOMAIN; -import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_4_OTHER_DOMAIN; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES2; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -50,7 +50,7 @@ public class OrTest { testee = new Or(); -mail = FakeMail.builder().recipients(MAIL_ADDRESS_1, MAIL_ADDRESS_2, MAIL_ADDRESS_3_OTHER_DOMAIN, MAIL_ADDRESS_4_OTHER_DOMAIN).build(); +mail = FakeMail.builder().recipients(ANY_AT_JAMES, OTHER_AT_JAMES, ANY_AT_JAMES2, OTHER_AT_JAMES2).build(); } @Test @@ -60,43 +60,43 @@ public class OrTest { @Test public void shouldReturnMatchResultWhenOnlyOneMatcher() throws Exception { -when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN)); +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); testee.add(matcher1); -assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN); +assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES, ANY_AT_JAMES2); } @Test public void shouldReturnUnionWhenTwoMatchers() throws Exception { -when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN)); -when(matcher2.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_2)); +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); testee.add(matcher1); testee.add(matcher2); -assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN, MAIL_AD
[15/17] james-project git commit: MAILET-124 Mail recipients should be copied by Not matcher
MAILET-124 Mail recipients should be copied by Not matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/028dc503 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/028dc503 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/028dc503 Branch: refs/heads/master Commit: 028dc503cecd0831867b5287b38d97102b8f9e59 Parents: d1b0b8d Author: Benoit Tellier Authored: Thu Sep 8 15:02:30 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:07:40 2016 +0200 -- .../apache/james/mailetcontainer/impl/matchers/Not.java | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/028dc503/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java index d061583..b8751f2 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java @@ -21,15 +21,15 @@ package org.apache.james.mailetcontainer.impl.matchers; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; +import javax.mail.MessagingException; + +import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; import org.apache.mailet.Matcher; -import org.apache.mailet.Mail; - -import javax.mail.MessagingException; import com.google.common.base.Optional; +import com.google.common.collect.Lists; public class Not extends GenericCompositeMatcher { @@ -43,7 +43,7 @@ public class Not extends GenericCompositeMatcher { * Matcher(s). */ public Collection match(Mail mail) throws MessagingException { -Collection finalResult = Optional.fromNullable(mail.getRecipients()).or(new ArrayList()); +Collection finalResult = Optional.fromNullable(Lists.newArrayList(mail.getRecipients())).or(new ArrayList()); for (Matcher matcher : getMatchers()) { Collection matcherResult = matcher.match(mail); if (matcherResult != null) { - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[01/17] james-project git commit: MAILET-124 Simplify Not composite matcher
Repository: james-project Updated Branches: refs/heads/master b3fb0ef51 -> ee6589d5d MAILET-124 Simplify Not composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/beb9cd63 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/beb9cd63 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/beb9cd63 Branch: refs/heads/master Commit: beb9cd637738235c794acd16f39e83952e005522 Parents: cc718f0 Author: Benoit Tellier Authored: Thu Sep 1 15:20:31 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 11:50:49 2016 +0200 -- .../mailetcontainer/impl/matchers/Not.java | 20 +++- 1 file changed, 7 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/beb9cd63/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java index 7f44777..d061583 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Not.java @@ -29,6 +29,8 @@ import org.apache.mailet.Mail; import javax.mail.MessagingException; +import com.google.common.base.Optional; + public class Not extends GenericCompositeMatcher { /** @@ -41,19 +43,11 @@ public class Not extends GenericCompositeMatcher { * Matcher(s). */ public Collection match(Mail mail) throws MessagingException { -Collection finalResult = mail.getRecipients(); -Matcher matcher; -for (Iterator matcherIter = iterator(); matcherIter.hasNext();) { -matcher = (matcherIter.next()); -// log("Matching with " + -// matcher.getMatcherConfig().getMatcherName()); -Collection result = matcher.match(mail); -if (result == finalResult) { -// Not is an empty list -finalResult = null; -} else if (result != null) { -finalResult = new ArrayList(finalResult); -finalResult.removeAll(result); +Collection finalResult = Optional.fromNullable(mail.getRecipients()).or(new ArrayList()); +for (Matcher matcher : getMatchers()) { +Collection matcherResult = matcher.match(mail); +if (matcherResult != null) { +finalResult.removeAll(matcherResult); } } return finalResult; - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[12/17] james-project git commit: MAILET-124 Remove useless old abstract class for testing composite mailets
MAILET-124 Remove useless old abstract class for testing composite mailets Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3a5c2aff Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3a5c2aff Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3a5c2aff Branch: refs/heads/master Commit: 3a5c2aff7890d3ae47cb36194364f861c84ffce4 Parents: b626c0c Author: Benoit Tellier Authored: Thu Sep 1 15:16:06 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 12:05:20 2016 +0200 -- .../impl/matchers/BaseMatchersTest.java | 68 1 file changed, 68 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/3a5c2aff/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java deleted file mode 100644 index 1f99c58..000 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/BaseMatchersTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/ - * 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.mailetcontainer.impl.matchers; - -import java.util.Arrays; - -import javax.mail.MessagingException; - -import org.apache.james.transport.matchers.All; -import org.apache.james.transport.matchers.RecipientIs; -import org.apache.mailet.MailAddress; -import org.apache.mailet.Matcher; -import org.apache.mailet.base.test.FakeMail; -import org.apache.mailet.base.test.FakeMailContext; -import org.apache.mailet.base.test.FakeMatcherConfig; -import org.junit.Before; - -public class BaseMatchersTest { - -protected FakeMailContext context; -protected FakeMail mockedMail; -protected CompositeMatcher matcher; - -@Before -public void setUp() throws Exception { -mockedMail = new FakeMail(); -mockedMail.setRecipients(Arrays.asList(new MailAddress("t...@james.apache.org"), new MailAddress( -"te...@james.apache.org"))); -} - -void setupCompositeMatcher(String matcherName, Class matcherClass) -throws Exception { -context = FakeMailContext.defaultContext(); -matcher = matcherClass.newInstance(); -FakeMatcherConfig mci = new FakeMatcherConfig(matcherName, context); -matcher.init(mci); -} - -void setupChild(String matcherName) throws MessagingException { -Matcher child; -if (matcherName.equals("All")) { -child = new All(); -} -else { -child = new RecipientIs(); -} -FakeMatcherConfig sub = new FakeMatcherConfig(matcherName, context); -child.init(sub); -matcher.add(child); -} -} - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[11/17] james-project git commit: MAILET-124 Add shortcut optimization on Or matcher
MAILET-124 Add shortcut optimization on Or matcher It is important as it might avoid some expensive matcher execution Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a78c8547 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a78c8547 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a78c8547 Branch: refs/heads/master Commit: a78c8547e7b77675a6ba007f4d8979428e1d7d7b Parents: 5636d89 Author: Benoit Tellier Authored: Thu Sep 8 14:50:00 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:05:20 2016 +0200 -- .../james/mailetcontainer/impl/matchers/Or.java | 19 +++ 1 file changed, 11 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/a78c8547/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java index cc7ab84..5d4f3c1 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/Or.java @@ -19,15 +19,15 @@ package org.apache.james.mailetcontainer.impl.matchers; -import org.apache.mailet.MailAddress; -import org.apache.mailet.Mail; -import org.apache.mailet.Matcher; - import java.util.Collection; -import java.util.Iterator; -import java.util.ArrayList; +import java.util.HashSet; + import javax.mail.MessagingException; +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; +import org.apache.mailet.Matcher; + import com.google.common.collect.ImmutableSet; public class Or extends GenericCompositeMatcher { @@ -40,14 +40,17 @@ public class Or extends GenericCompositeMatcher { * child matchers. */ public Collection match(Mail mail) throws MessagingException { -ImmutableSet.Builder result = ImmutableSet.builder(); +HashSet result = new HashSet(); for (Matcher matcher : getMatchers()) { Collection matchResult = matcher.match(mail); if (matchResult != null) { result.addAll(matchResult); } +if (result.size() == mail.getRecipients().size()) { +break; +} } -return result.build(); +return ImmutableSet.copyOf(result); } } - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[08/17] james-project git commit: MAILET-124 Upgrade OrTest
MAILET-124 Upgrade OrTest Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e114c6d1 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e114c6d1 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e114c6d1 Branch: refs/heads/master Commit: e114c6d14931b651d4e68f8186e7a61749616c7c Parents: 2a996ba Author: Benoit Tellier Authored: Thu Sep 1 14:24:59 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 12:04:57 2016 +0200 -- .../mailetcontainer/impl/matchers/OrTest.java | 85 +++- 1 file changed, 64 insertions(+), 21 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/e114c6d1/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java index 373e790..d71ee19 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/OrTest.java @@ -19,41 +19,84 @@ package org.apache.james.mailetcontainer.impl.matchers; +import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_1; +import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_2; +import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_3_OTHER_DOMAIN; +import static org.apache.mailet.base.MailAddressFixture.MAIL_ADDRESS_4_OTHER_DOMAIN; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.apache.mailet.Matcher; +import org.apache.mailet.base.test.FakeMail; import org.junit.Before; import org.junit.Test; -import java.util.Collection; -import java.util.Iterator; +import com.google.common.collect.ImmutableList; + +public class OrTest { -public class OrTest extends BaseMatchersTest { +private Or testee; +private Matcher matcher1; +private Matcher matcher2; +private Mail mail; -@Override @Before public void setUp() throws Exception { -super.setUp(); -setupCompositeMatcher("Or", Or.class); +matcher1 = mock(Matcher.class); +matcher2 = mock(Matcher.class); + +testee = new Or(); + +mail = FakeMail.builder().recipients(MAIL_ADDRESS_1, MAIL_ADDRESS_2, MAIL_ADDRESS_3_OTHER_DOMAIN, MAIL_ADDRESS_4_OTHER_DOMAIN).build(); +} + +@Test +public void shouldReturnNoResultWhenNoMatcherSpecified() throws Exception { +assertThat(testee.match(mail)).isEmpty(); +} + +@Test +public void shouldReturnMatchResultWhenOnlyOneMatcher() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN)); + +testee.add(matcher1); + +assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN); } -// test if all recipients was returned @Test -public void testAllRecipientsReturned() throws Exception { -setupChild("RecipientIsRegex=t...@james.apache.org"); -setupChild("RecipientIsRegex=te...@james.apache.org"); +public void shouldReturnUnionWhenTwoMatchers() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_2)); + +testee.add(matcher1); +testee.add(matcher2); + +assertThat(testee.match(mail)).containsExactly(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN, MAIL_ADDRESS_2); +} -Collection matchedRecipients = matcher.match(mockedMail); +@Test +public void shouldAcceptEmptyResults() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(MAIL_ADDRESS_1, MAIL_ADDRESS_3_OTHER_DOMAIN)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of()); -assertNotNull(matchedRecipients); -assertEquals(matchedRecipients.size(), mockedMail.getRecipients().size()); +testee.add(matcher1); +testee.add(matcher2); -// Now ensure they match the actual recipients -Iterator iterator = matchedRecipients.iterator(); -MailAddress address = iterat
[17/17] james-project git commit: MAILET-124 Ordering is not required by AllTest
MAILET-124 Ordering is not required by AllTest Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ee6589d5 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ee6589d5 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ee6589d5 Branch: refs/heads/master Commit: ee6589d5dc6b40c3976e9079f0cd8d5da07d31e2 Parents: 8c4d013 Author: Benoit Tellier Authored: Wed Sep 14 11:04:43 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:07:45 2016 +0200 -- .../src/test/java/org/apache/james/transport/matchers/AllTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/ee6589d5/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java -- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java index f46f1b2..f8fde23 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/AllTest.java @@ -52,7 +52,7 @@ public class AllTest { .recipients(ANY_AT_JAMES, OTHER_AT_JAMES) .build(); -assertThat(matcher.match(mail)).containsExactly(OTHER_AT_JAMES, OTHER_AT_JAMES); +assertThat(matcher.match(mail)).containsOnly(ANY_AT_JAMES, OTHER_AT_JAMES); } } - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[16/17] james-project git commit: MAILET-124 Simplify AND composite matcher
MAILET-124 Simplify AND composite matcher Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8c4d0139 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8c4d0139 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8c4d0139 Branch: refs/heads/master Commit: 8c4d01393998934f47cf14bb177911301328a4a6 Parents: 028dc50 Author: Benoit Tellier Authored: Mon Sep 12 15:07:59 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:07:44 2016 +0200 -- .../apache/james/mailetcontainer/impl/matchers/And.java | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/8c4d0139/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java index f556a73..3d5e7e7 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java @@ -20,12 +20,12 @@ package org.apache.james.mailetcontainer.impl.matchers; / import java.util.Collection; -import java.util.List; import java.util.Set; -import org.apache.mailet.MailAddress; -import org.apache.mailet.Mail; import javax.mail.MessagingException; + +import org.apache.mailet.Mail; +import org.apache.mailet.MailAddress; import org.apache.mailet.Matcher; import com.google.common.collect.ImmutableList; @@ -46,11 +46,11 @@ public class And extends GenericCompositeMatcher { * child Matchers. */ public Collection match(final Mail mail) throws MessagingException { -List> individualMatchedResults = performMatchOnMatchers(mail); +ImmutableList> individualMatchedResults = performMatchOnMatchers(mail); return computeIntersection(individualMatchedResults); } -private Set computeIntersection(List> individualMatchedResults) { +private Set computeIntersection(ImmutableList> individualMatchedResults) { if (individualMatchedResults.size() == 0) { return ImmutableSet.of(); } @@ -61,7 +61,7 @@ public class And extends GenericCompositeMatcher { computeIntersection(individualMatchedResults.subList(1, individualMatchedResults.size(; } -private List> performMatchOnMatchers(Mail mail) throws MessagingException { +private ImmutableList> performMatchOnMatchers(Mail mail) throws MessagingException { ImmutableList.Builder> builder = ImmutableList.builder(); for (Matcher matcher : getMatchers()) { Collection matchedMailAddress = matcher.match(mail); - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[14/17] james-project git commit: MAILET-124 And should use recursion
MAILET-124 And should use recursion Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d1b0b8d8 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d1b0b8d8 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d1b0b8d8 Branch: refs/heads/master Commit: d1b0b8d84cca847da7046291d522b9cb06a7a0f3 Parents: c8648a1 Author: Benoit Tellier Authored: Thu Sep 8 14:58:46 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:06:37 2016 +0200 -- .../apache/james/mailetcontainer/impl/matchers/And.java | 12 .../james/mailetcontainer/impl/matchers/AndTest.java| 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/d1b0b8d8/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java -- diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java index 9738495..f556a73 100644 --- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java +++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/matchers/And.java @@ -50,19 +50,15 @@ public class And extends GenericCompositeMatcher { return computeIntersection(individualMatchedResults); } -private Collection computeIntersection(List> individualMatchedResults) { +private Set computeIntersection(List> individualMatchedResults) { if (individualMatchedResults.size() == 0) { -return null; +return ImmutableSet.of(); } if (individualMatchedResults.size() == 1) { return individualMatchedResults.get(0); } -Set temporaryResult = ImmutableSet.copyOf(individualMatchedResults.get(0)); -List> followingResults = individualMatchedResults.subList(1, individualMatchedResults.size()); -for(Set matchedAddresses: followingResults) { -temporaryResult = Sets.intersection(temporaryResult, matchedAddresses); -} -return temporaryResult; +return Sets.intersection(individualMatchedResults.get(0), +computeIntersection(individualMatchedResults.subList(1, individualMatchedResults.size(; } private List> performMatchOnMatchers(Mail mail) throws MessagingException { http://git-wip-us.apache.org/repos/asf/james-project/blob/d1b0b8d8/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java index 1ec5d76..490b248 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java @@ -53,7 +53,7 @@ public class AndTest { @Test public void shouldNotMatchWhenNoChild() throws Exception { -assertThat(testee.match(mail)).isNull(); +assertThat(testee.match(mail)).isEmpty(); } @Test @@ -84,7 +84,7 @@ public class AndTest { testee.add(matcher1); testee.add(matcher2); -assertThat(testee.match(mail)).isNull(); +assertThat(testee.match(mail)).isEmpty(); } @Test @@ -95,6 +95,6 @@ public class AndTest { testee.add(matcher1); testee.add(matcher2); -assertThat(testee.match(mail)).isNull(); +assertThat(testee.match(mail)).isEmpty(); } } - To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org
[06/17] james-project git commit: MAILET-122 Improve And tests
MAILET-122 Improve And tests Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2a996bad Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2a996bad Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2a996bad Branch: refs/heads/master Commit: 2a996badaf1884ab74f8ff8aef91f68558649a82 Parents: 12df8f9 Author: Benoit Tellier Authored: Thu Sep 1 14:10:49 2016 +0700 Committer: Benoit Tellier Committed: Thu Sep 15 12:04:53 2016 +0200 -- .../mailetcontainer/impl/matchers/AndTest.java | 84 ++-- 1 file changed, 60 insertions(+), 24 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/2a996bad/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java -- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java index e5ca169..1ec5d76 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/matchers/AndTest.java @@ -18,47 +18,83 @@ / package org.apache.james.mailetcontainer.impl.matchers; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.OTHER_AT_JAMES; +import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.mailet.Mail; import org.apache.mailet.MailAddress; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import org.apache.mailet.Matcher; +import org.apache.mailet.base.test.FakeMail; import org.junit.Before; import org.junit.Test; -import javax.mail.MessagingException; -import java.util.Collection; +import com.google.common.collect.ImmutableList; + +public class AndTest { -public class AndTest extends BaseMatchersTest { +private And testee; +private Matcher matcher1; +private Matcher matcher2; +private Mail mail; -@Override @Before public void setUp() throws Exception { -super.setUp(); -setupCompositeMatcher("And", And.class); +matcher1 = mock(Matcher.class); +matcher2 = mock(Matcher.class); + +testee = new And(); + +mail = FakeMail.builder().recipients(ANY_AT_JAMES, OTHER_AT_JAMES, ANY_AT_JAMES2).build(); +} + +@Test +public void shouldNotMatchWhenNoChild() throws Exception { +assertThat(testee.match(mail)).isNull(); +} + +@Test +public void shouldMatchWhenSingleUnderlyingMatcherMatch() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES)); + +testee.add(matcher1); + +assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES); +} + +@Test +public void shouldMatchWhenTwoUnderlyingMatcherMatch() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, ANY_AT_JAMES2)); + +testee.add(matcher1); +testee.add(matcher2); + +assertThat(testee.match(mail)).containsOnly(ANY_AT_JAMES); } -// test if all recipients was returned @Test -public void testAndIntersectSameTwice() throws MessagingException { -setupChild("RecipientIs=t...@james.apache.org"); -setupChild("RecipientIs=t...@james.apache.org"); -setupChild("All"); +public void shouldMatchWhenAtLeastOneUnderlyingMatcherDoNotMatch() throws Exception { +when(matcher1.match(mail)).thenReturn(ImmutableList.of(ANY_AT_JAMES, OTHER_AT_JAMES)); +when(matcher2.match(mail)).thenReturn(ImmutableList.of()); -Collection matchedRecipients = matcher.match(mockedMail); +testee.add(matcher1); +testee.add(matcher2); -assertNotNull(matchedRecipients); -assertEquals(1, matchedRecipients.size()); -MailAddress address = (MailAddress) matchedRecipients.iterator().next(); -assertEquals(address.toString(), "t...@james.apache.org"); +assertThat(testee.match(mail)).isNull(); } @Test -public void testAndNoIntersect() throws MessagingException { -setupChild("RecipientIs=t...@james.apache.org"); -
james-project git commit: MAILET-121 MailAddressColectionReader should consider coma, space and tabulation as delimiters
Repository: james-project Updated Branches: refs/heads/master ee6589d5d -> 3a8592d67 MAILET-121 MailAddressColectionReader should consider coma, space and tabulation as delimiters Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3a8592d6 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3a8592d6 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3a8592d6 Branch: refs/heads/master Commit: 3a8592d67a9478ac679191e1cb6cfc05fac471ca Parents: ee6589d Author: Benoit Tellier Authored: Thu Sep 8 16:42:06 2016 +0200 Committer: Benoit Tellier Committed: Thu Sep 15 12:12:52 2016 +0200 -- .../utils/MailAddressCollectionReader.java | 27 +--- .../util/MailAddressCollectionReaderTest.java | 21 ++- 2 files changed, 33 insertions(+), 15 deletions(-) -- http://git-wip-us.apache.org/repos/asf/james-project/blob/3a8592d6/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java -- diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java index 17ee09e..3855ed1 100644 --- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java +++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/utils/MailAddressCollectionReader.java @@ -27,6 +27,7 @@ import org.apache.mailet.MailAddress; import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.base.Strings; import com.google.common.base.Throwables; @@ -38,16 +39,24 @@ public class MailAddressCollectionReader { public static Set read(String condition) { Preconditions.checkArgument(!Strings.isNullOrEmpty(condition)); -return FluentIterable.from(Splitter.onPattern(",( |\t)").split(condition)).transform(new Function() { -@Override -public MailAddress apply(String s) { -try { -return new MailAddress(s); -} catch (AddressException e) { -throw Throwables.propagate(e); +return FluentIterable.from(Splitter.onPattern("(,| |\t)") +.split(condition)) +.filter(new Predicate() { +@Override +public boolean apply(String s) { +return !Strings.isNullOrEmpty(s); } -} -}).toSet(); +}) +.transform(new Function() { +@Override +public MailAddress apply(String s) { +try { +return new MailAddress(s); +} catch (AddressException e) { +throw Throwables.propagate(e); +} +} +}).toSet(); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/3a8592d6/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java -- diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java index 46cc41e..c7c0494 100644 --- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java +++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/util/MailAddressCollectionReaderTest.java @@ -65,30 +65,39 @@ public class MailAddressCollectionReaderTest { } @Test -public void readShouldParseTwoEmail() throws Exception { +public void readShouldParseTwoEmailSeparatedByComaOnly() throws Exception { MailAddress mailAddress1 = new MailAddress("va...@apache.org"); MailAddress mailAddress2 = new MailAddress("b...@apache.org"); -assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + ", " + mailAddress2.toString())) +assertThat(MailAddressCollectionReader.read(mailAddress1.toString() + "," + mailAddress2.toString())) .containsExactly(mailAddress1, mailAddress2); } @Test -public void readShouldParseTwoEmailTabSeparated() throws Exception { +public void readShouldParseTwoEmailSeparatedBySpaceOnly() throws Exception { MailAddress mailAddress1 = new MailAddress("va...@apache.or