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 ro...@apache.org on 2016/09/07 09:26:36 UTC
[1/2] james-project git commit: MAILET-128 Slighty rewrite
ToRepository to our conding standards
Repository: james-project
Updated Branches:
refs/heads/master 39d0cda0d -> 35c541597
MAILET-128 Slighty rewrite ToRepository to our conding standards
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/35c54159
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/35c54159
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/35c54159
Branch: refs/heads/master
Commit: 35c54159790899cd6693d70d1097922db90ed6c4
Parents: 56a0836
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Tue Sep 6 11:44:36 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Wed Sep 7 11:24:43 2016 +0200
----------------------------------------------------------------------
.../james/transport/mailets/ToRepository.java | 47 +++++++-------------
1 file changed, 15 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/35c54159/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRepository.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRepository.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRepository.java
index 46c8100..46152fd 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRepository.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/ToRepository.java
@@ -29,27 +29,15 @@ import org.apache.mailet.base.GenericMailet;
/**
* Stores incoming Mail in the specified Repository.<br>
- * If the "passThrough" in confs is true the mail will be returned untouched in
- * the pipe. If false will be destroyed.
- *
- * @version 1.0.0, 24/04/1999
+ * If the "passThrough" in conf is true the mail will be returned untouched in
+ * the pipe and may be processed by additional mailets. If false will be destroyed.
*/
public class ToRepository extends GenericMailet {
- /**
- * The repository where this mailet stores mail.
- */
private MailRepository repository;
- /**
- * Whether this mailet should allow mails to be processed by additional
- * mailets or mark it as finished.
- */
private boolean passThrough = false;
- /**
- * The path to the repository
- */
private String repositoryPath;
private MailRepositoryStore mailStore;
@@ -59,31 +47,30 @@ public class ToRepository extends GenericMailet {
this.mailStore = mailStore;
}
- /**
- * Initialize the mailet, loading configuration information.
- */
+ @Override
public void init() throws MessagingException {
repositoryPath = getInitParameter("repositoryPath");
+ passThrough = getPassThroughParameter();
+ repository = selectRepository();
+ }
+
+ private boolean getPassThroughParameter() {
try {
- passThrough = Boolean.valueOf(getInitParameter("passThrough"));
+ return getInitParameter("passThrough", false);
} catch (Exception e) {
- // Ignore exception, default to false
+ return false;
}
+ }
+ private MailRepository selectRepository() throws MessagingException {
try {
- repository = mailStore.select(repositoryPath);
+ return mailStore.select(repositoryPath);
} catch (Exception e) {
throw new MessagingException("Failed to retrieve MailRepository for url " + repositoryPath, e);
}
-
}
- /**
- * Store a mail in a particular repository.
- *
- * @param mail
- * the mail to process
- */
+ @Override
public void service(Mail mail) throws javax.mail.MessagingException {
String logBuffer = "Storing mail " + mail.getName() + " in " + repositoryPath;
log(logBuffer);
@@ -93,11 +80,7 @@ public class ToRepository extends GenericMailet {
}
}
- /**
- * Return a string describing this mailet.
- *
- * @return a string describing this mailet
- */
+ @Override
public String getMailetInfo() {
return "ToRepository Mailet";
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/2] james-project git commit: MAILET-128 Add full test coverage to
ToRepository mailet
Posted by ro...@apache.org.
MAILET-128 Add full test coverage to ToRepository mailet
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/56a0836a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/56a0836a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/56a0836a
Branch: refs/heads/master
Commit: 56a0836abc397288a7281f1ac7ec73bf17683c6f
Parents: 39d0cda
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Tue Sep 6 11:38:56 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Wed Sep 7 11:24:43 2016 +0200
----------------------------------------------------------------------
.../transport/mailets/ToRepositoryTest.java | 131 +++++++++++++++++++
1 file changed, 131 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/56a0836a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
new file mode 100644
index 0000000..32f1c67
--- /dev/null
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
@@ -0,0 +1,131 @@
+/****************************************************************
+ * 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.mailets;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import javax.mail.MessagingException;
+
+import org.apache.james.mailrepository.api.MailRepository;
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailetConfig;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.apache.mailet.base.test.MailUtil;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class ToRepositoryTest {
+ @Rule public ExpectedException expectedException = ExpectedException.none();
+
+ private ToRepository mailet;
+ private FakeMailetConfig mailetConfig;
+ private MailRepositoryStore mailRepositoryStore;
+ private FakeMail message;
+
+
+ @Before
+ public void setup() throws Exception {
+ mailRepositoryStore = mock(MailRepositoryStore.class);
+ mailet = new ToRepository();
+ mailet.setStore(mailRepositoryStore);
+ mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+ message = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
+ }
+
+ @Test
+ public void getMailetInfoShouldReturnExpectedContent() {
+ String expected = "ToRepository Mailet";
+
+ String actual = mailet.getMailetInfo();
+
+ assertThat(actual).isEqualTo(expected);
+ }
+
+ @Test
+ public void initShouldNotThrowWhenInvalidPassThrough() throws Exception {
+ MailetConfig mockedMailetConfig = mock(MailetConfig.class);
+ when(mockedMailetConfig.getInitParameter("passThrough")).thenThrow(new RuntimeException());
+
+ mailet.init(mockedMailetConfig);
+ }
+
+ @Test
+ public void initShouldThrowWhenMailStoreThrows() throws Exception {
+ when(mailRepositoryStore.select(any(String.class))).thenThrow(new RuntimeException());
+ expectedException.expect(MessagingException.class);
+
+ mailet.init(mailetConfig);
+ }
+
+ @Test
+ public void serviceShouldStoreMailIntoRepository() throws Exception {
+ MailRepository mailRepository = mock(MailRepository.class);
+ when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
+ mailet.init(mailetConfig);
+
+ mailet.service(message);
+
+ verify(mailRepository).store(message);
+ }
+
+ @Test
+ public void serviceShouldGhostMailIfPassThroughNotSet() throws Exception {
+ MailRepository mailRepository = mock(MailRepository.class);
+ when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
+ mailet.init(mailetConfig);
+
+ mailet.service(message);
+
+ assertThat(message.getState()).isEqualTo(Mail.GHOST);
+ }
+
+ @Test
+ public void serviceShouldGhostMailIfPassThroughSetToFalse() throws Exception {
+ mailetConfig.setProperty("passThrough", "false");
+ MailRepository mailRepository = mock(MailRepository.class);
+ when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
+ mailet.init(mailetConfig);
+
+ mailet.service(message);
+
+ assertThat(message.getState()).isEqualTo(Mail.GHOST);
+ }
+
+ @Test
+ public void serviceShouldNotGhostMailIfPassThroughSetToTrue() throws Exception {
+ mailetConfig.setProperty("passThrough", "true");
+ MailRepository mailRepository = mock(MailRepository.class);
+ when(mailRepositoryStore.select(any(String.class))).thenReturn(mailRepository);
+ mailet.init(mailetConfig);
+
+ mailet.service(message);
+
+ assertThat(message.getState()).isNull();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org