You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2016/11/18 14:21:30 UTC
[1/3] james-project git commit: MAILET-139 add a test to
SenderIsLocalTest
Repository: james-project
Updated Branches:
refs/heads/master 07a43adbe -> 3878e38b8
MAILET-139 add a test to SenderIsLocalTest
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/444aeb17
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/444aeb17
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/444aeb17
Branch: refs/heads/master
Commit: 444aeb171242a3f29e955ec0c4170c5574c749b7
Parents: 977ae9e
Author: Laura Royet <lr...@linagora.com>
Authored: Wed Nov 9 11:33:26 2016 +0100
Committer: Laura Royet <lr...@linagora.com>
Committed: Thu Nov 17 17:18:28 2016 +0100
----------------------------------------------------------------------
.../transport/matchers/SenderIsLocalTest.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/444aeb17/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
index 31f8251..a3ebb91 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderIsLocalTest.java
@@ -20,6 +20,7 @@
package org.apache.james.transport.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;
@@ -46,6 +47,7 @@ public class SenderIsLocalTest {
public void setUp() throws MessagingException {
MailetContext mailContext = mock(MailetContext.class);
when(mailContext.isLocalEmail(ANY_AT_JAMES)).thenReturn(true);
+ when(mailContext.isLocalEmail(OTHER_AT_JAMES)).thenReturn(false);
when(mailContext.isLocalEmail(ANY_AT_JAMES2)).thenReturn(false);
matcher = new SenderIsLocal();
@@ -65,9 +67,22 @@ public class SenderIsLocalTest {
//Then
assertThat(actual).containsExactly(ANY_AT_JAMES2);
}
+
+ @Test
+ public void shouldNotMatchWhenSenderIsUnknown() throws MessagingException {
+ //Given
+ Mail mail = FakeMail.builder()
+ .sender(OTHER_AT_JAMES)
+ .recipient(ANY_AT_JAMES2)
+ .build();
+ //When
+ Collection<MailAddress> actual = matcher.match(mail);
+ //Then
+ assertThat(actual).isNull();
+ }
@Test
- public void shouldNotMatchWhenSenderIsNotLocal() throws MessagingException {
+ public void shouldNotMatchWhenHostIsNotLocal() throws MessagingException {
//Given
Mail mail = FakeMail.builder()
.sender(ANY_AT_JAMES2)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/3] james-project git commit: Merge remote-tracking branch
'lroyet/MAILET-139'
Posted by ad...@apache.org.
Merge remote-tracking branch 'lroyet/MAILET-139'
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3878e38b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3878e38b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3878e38b
Branch: refs/heads/master
Commit: 3878e38b8257e0213d785e601fc9f4b403879615
Parents: 07a43ad 444aeb1
Author: Antoine Duprat <ad...@apache.org>
Authored: Fri Nov 18 15:20:56 2016 +0100
Committer: Antoine Duprat <ad...@apache.org>
Committed: Fri Nov 18 15:20:56 2016 +0100
----------------------------------------------------------------------
.../transport/matchers/SenderHostIsLocal.java | 16 ++--
.../matchers/SenderHostIsLocalTest.java | 85 ++++++++++++++++++++
.../transport/matchers/SenderIsLocalTest.java | 17 +++-
3 files changed, 111 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/3] james-project git commit: MAILET-139 SenderHostIsLocal should
be covered with tests
Posted by ad...@apache.org.
MAILET-139 SenderHostIsLocal should be covered with 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/977ae9e0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/977ae9e0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/977ae9e0
Branch: refs/heads/master
Commit: 977ae9e0e60d159c83f480fe944f4e67ccb5a58b
Parents: ff57437
Author: Laura Royet <lr...@linagora.com>
Authored: Tue Nov 8 14:31:46 2016 +0100
Committer: Laura Royet <lr...@linagora.com>
Committed: Thu Nov 17 17:18:28 2016 +0100
----------------------------------------------------------------------
.../transport/matchers/SenderHostIsLocal.java | 16 ++--
.../matchers/SenderHostIsLocalTest.java | 85 ++++++++++++++++++++
2 files changed, 95 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/977ae9e0/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderHostIsLocal.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderHostIsLocal.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderHostIsLocal.java
index 2092908..6200383 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderHostIsLocal.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/SenderHostIsLocal.java
@@ -20,11 +20,11 @@
package org.apache.james.transport.matchers;
-import org.apache.mailet.base.GenericMatcher;
+import java.util.Collection;
+
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
-
-import java.util.Collection;
+import org.apache.mailet.base.GenericMatcher;
/**
* Checks the sender's displayed domain name against a the hosts serviced by
@@ -38,12 +38,16 @@ import java.util.Collection;
*/
public class SenderHostIsLocal extends GenericMatcher {
public Collection<MailAddress> match(Mail mail) {
- if (mail.getSender() != null
- && this.getMailetContext().isLocalServer(
- mail.getSender().getDomain().toLowerCase())) {
+ if (mail.getSender() != null && isLocalServer(mail)) {
return mail.getRecipients();
}
return null;
+
+ }
+ private boolean isLocalServer(Mail mail) {
+ return this.getMailetContext().isLocalServer(
+ mail.getSender().getDomain().toLowerCase());
}
+
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/977ae9e0/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderHostIsLocalTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderHostIsLocalTest.java b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderHostIsLocalTest.java
new file mode 100644
index 0000000..e52fc4c
--- /dev/null
+++ b/mailet/standard/src/test/java/org/apache/james/transport/matchers/SenderHostIsLocalTest.java
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.transport.matchers;
+
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES;
+import static org.apache.mailet.base.MailAddressFixture.ANY_AT_JAMES2;
+import static org.apache.mailet.base.MailAddressFixture.JAMES2_APACHE_ORG;
+import static org.apache.mailet.base.MailAddressFixture.JAMES_APACHE_ORG;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetContext;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMatcherConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SenderHostIsLocalTest {
+
+ private Matcher matcher;
+
+ @Before
+ public void setUp() throws MessagingException {
+ MailetContext mailContext = mock(MailetContext.class);
+ when(mailContext.isLocalServer(JAMES_APACHE_ORG)).thenReturn(true);
+ when(mailContext.isLocalServer(JAMES2_APACHE_ORG)).thenReturn(false);
+
+ matcher = new SenderHostIsLocal();
+ FakeMatcherConfig mci= new FakeMatcherConfig("SenderHostIsLocal", mailContext);
+ matcher.init(mci);
+ }
+
+ @Test
+ public void shouldMatchWhenSenderHostIsLocal() throws MessagingException {
+ //Given
+ Mail mail = FakeMail.builder()
+ .sender(ANY_AT_JAMES)
+ .recipient(ANY_AT_JAMES2)
+ .build();
+ //When
+ Collection<MailAddress> actual = matcher.match(mail);
+ //Then
+ assertThat(actual).containsExactly(ANY_AT_JAMES2);
+ }
+
+ @Test
+ public void shouldNotMatchWhenSenderHostIsNotLocal() throws MessagingException {
+ //Given
+ Mail mail = FakeMail.builder()
+ .sender(ANY_AT_JAMES2)
+ .recipient(ANY_AT_JAMES)
+ .build();
+ //When
+ Collection<MailAddress> actual = matcher.match(mail);
+ //Then
+ assertThat(actual).isNull();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org