JAMES-2502 fix Eclipse Photon build for mailets, utils and imap
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3dddd7c5 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3dddd7c5 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3dddd7c5 Branch: refs/heads/master Commit: 3dddd7c55025c6f91604cccce215873cdef223f1 Parents: 8d22e35 Author: Raphael Ouazana <raphael.ouaz...@linagora.com> Authored: Fri Jul 27 18:02:03 2018 +0200 Committer: Matthieu Baechler <matth...@apache.org> Committed: Wed Aug 1 14:20:23 2018 +0200 ---------------------------------------------------------------------- backends-common/elasticsearch/pom.xml | 4 +- core/pom.xml | 3 +- .../org/apache/james/util/MimeMessageUtil.java | 55 -- mailbox/elasticsearch/pom.xml | 5 + mailbox/plugin/quota-mailing-cassandra/pom.xml | 5 + mailbox/plugin/quota-mailing-memory/pom.xml | 5 + mailbox/plugin/quota-mailing/pom.xml | 3 +- mailbox/tika/pom.xml | 3 +- mailet/base/pom.xml | 8 +- .../apache/mailet/base/MailAddressFixture.java | 56 -- .../org/apache/mailet/base/test/FakeMail.java | 464 -------------- .../mailet/base/test/FakeMailContext.java | 608 ------------------- .../apache/mailet/base/test/FakeMailTest.java | 41 -- .../mailet/base/test/FakeMailetConfig.java | 106 ---- .../mailet/base/test/FakeMatcherConfig.java | 95 --- .../org/apache/mailet/base/test/MailUtil.java | 92 --- mailet/icalendar/pom.xml | 3 +- mailet/pom.xml | 1 + mailet/standard/pom.xml | 9 +- mailet/test/pom.xml | 138 +++++ .../apache/mailet/base/MailAddressFixture.java | 56 ++ .../org/apache/mailet/base/test/FakeMail.java | 464 ++++++++++++++ .../mailet/base/test/FakeMailContext.java | 608 +++++++++++++++++++ .../mailet/base/test/FakeMailetConfig.java | 106 ++++ .../mailet/base/test/FakeMatcherConfig.java | 95 +++ .../org/apache/mailet/base/test/MailUtil.java | 92 +++ .../apache/mailet/base/test/FakeMailTest.java | 41 ++ mpt/impl/imap-mailbox/core/pom.xml | 5 - pom.xml | 5 + .../decode/ImapRequestStreamLineReader.java | 105 ++++ .../decode/main/ImapRequestStreamHandler.java | 129 ++++ .../main/OutputStreamImapResponseWriter.java | 70 +++ .../james/imap/encode/FakeImapSession.java | 145 +++++ .../decode/ImapRequestStreamLineReader.java | 105 ---- .../decode/main/ImapRequestStreamHandler.java | 129 ---- .../main/OutputStreamImapResponseWriter.java | 70 --- .../james/imap/encode/FakeImapSession.java | 145 ----- server/container/core/pom.xml | 3 +- .../metrics/metrics-es-reporter/pom.xml | 3 +- .../org/apache/james/util/docker/Images.java | 29 - .../util/docker/SwarmGenericContainer.java | 164 ----- server/container/util/pom.xml | 14 +- .../org/apache/james/util/MimeMessageUtil.java | 55 ++ .../data/data-ldap-integration-testing/pom.xml | 3 +- server/mailet/integration-testing/pom.xml | 3 +- server/pom.xml | 1 - server/protocols/jmap/pom.xml | 3 +- .../webadmin/webadmin-mailqueue/pom.xml | 3 +- .../webadmin/webadmin-mailrepository/pom.xml | 3 +- server/queue/queue-rabbitmq/pom.xml | 3 +- server/testing/pom.xml | 3 +- .../org/apache/james/util/docker/Images.java | 29 + .../util/docker/SwarmGenericContainer.java | 164 +++++ third-party/spamassassin/pom.xml | 5 + 54 files changed, 2358 insertions(+), 2204 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/backends-common/elasticsearch/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/elasticsearch/pom.xml b/backends-common/elasticsearch/pom.xml index 6d8d071..bf4ba84 100644 --- a/backends-common/elasticsearch/pom.xml +++ b/backends-common/elasticsearch/pom.xml @@ -34,9 +34,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> - <version>${project.version}</version> - <type>test-jar</type> + <artifactId>james-server-testing</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index 600c567..0f533dc 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -38,8 +38,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>javax-mail-extension</artifactId> - <type>test-jar</type> + <artifactId>james-server-util</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/javax-mail-extension/src/test/java/org/apache/james/util/MimeMessageUtil.java ---------------------------------------------------------------------- diff --git a/javax-mail-extension/src/test/java/org/apache/james/util/MimeMessageUtil.java b/javax-mail-extension/src/test/java/org/apache/james/util/MimeMessageUtil.java deleted file mode 100644 index 93715f8..0000000 --- a/javax-mail-extension/src/test/java/org/apache/james/util/MimeMessageUtil.java +++ /dev/null @@ -1,55 +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.util; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Properties; - -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.MimeMessage; - -public class MimeMessageUtil { - - public static String asString(MimeMessage mimeMessage) throws Exception { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - mimeMessage.writeTo(byteArrayOutputStream); - return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); - } - - public static MimeMessage defaultMimeMessage() { - return new MimeMessage(Session.getDefaultInstance(new Properties())); - } - - public static MimeMessage mimeMessageFromStream(InputStream inputStream) throws MessagingException { - return new MimeMessage(Session.getDefaultInstance(new Properties()), inputStream); - } - - public static MimeMessage mimeMessageFromBytes(byte[] bytes) throws MessagingException { - return mimeMessageFromStream(new ByteArrayInputStream(bytes)); - } - - public static MimeMessage mimeMessageFromString(String string) throws MessagingException { - return mimeMessageFromBytes(string.getBytes(StandardCharsets.UTF_8)); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailbox/elasticsearch/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/elasticsearch/pom.xml b/mailbox/elasticsearch/pom.xml index f2a2efd..b9563c9 100644 --- a/mailbox/elasticsearch/pom.xml +++ b/mailbox/elasticsearch/pom.xml @@ -91,6 +91,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>james-server-testing</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailbox/plugin/quota-mailing-cassandra/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing-cassandra/pom.xml b/mailbox/plugin/quota-mailing-cassandra/pom.xml index 849b385..8677f1f 100644 --- a/mailbox/plugin/quota-mailing-cassandra/pom.xml +++ b/mailbox/plugin/quota-mailing-cassandra/pom.xml @@ -91,6 +91,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-mailet-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-core</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailbox/plugin/quota-mailing-memory/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing-memory/pom.xml b/mailbox/plugin/quota-mailing-memory/pom.xml index f28cd55..7ba4274 100644 --- a/mailbox/plugin/quota-mailing-memory/pom.xml +++ b/mailbox/plugin/quota-mailing-memory/pom.xml @@ -81,6 +81,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.james</groupId> + <artifactId>apache-mailet-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${james.groupId}</groupId> <artifactId>james-server-core</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailbox/plugin/quota-mailing/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/pom.xml b/mailbox/plugin/quota-mailing/pom.xml index ec85841..6ad1c19 100644 --- a/mailbox/plugin/quota-mailing/pom.xml +++ b/mailbox/plugin/quota-mailing/pom.xml @@ -53,8 +53,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>apache-mailet-base</artifactId> - <type>test-jar</type> + <artifactId>apache-mailet-test</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailbox/tika/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/tika/pom.xml b/mailbox/tika/pom.xml index fc595d8..4564b56 100644 --- a/mailbox/tika/pom.xml +++ b/mailbox/tika/pom.xml @@ -38,8 +38,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-util-java8</artifactId> - <type>test-jar</type> + <artifactId>james-server-testing</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/base/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/base/pom.xml b/mailet/base/pom.xml index a094b2e..6b1fd46 100644 --- a/mailet/base/pom.xml +++ b/mailet/base/pom.xml @@ -44,6 +44,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>apache-mailet-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>apache-mime4j-core</artifactId> </dependency> <dependency> @@ -52,8 +57,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>javax-mail-extension</artifactId> - <type>test-jar</type> + <artifactId>james-server-util</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/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 deleted file mode 100644 index 4efe093..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/MailAddressFixture.java +++ /dev/null @@ -1,56 +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.mailet.base; - -import javax.mail.internet.AddressException; - -import org.apache.james.core.Domain; -import org.apache.james.core.MailAddress; - -public class MailAddressFixture { - public static final String JAMES_LOCAL = "localhost"; - public static final String JAMES_APACHE_ORG = "james.apache.org"; - public static final String JAMES2_APACHE_ORG = "james2.apache.org"; - - public static final Domain JAMES_LOCAL_DOMAIN = Domain.of(JAMES_LOCAL); - public static final Domain JAMES_APACHE_ORG_DOMAIN = Domain.of(JAMES_APACHE_ORG); - public static final Domain JAMES2_APACHE_ORG_DOMAIN = Domain.of(JAMES2_APACHE_ORG); - - public static final MailAddress SENDER = createMailAddress("sender@" + JAMES_LOCAL); - public static final MailAddress RECIPIENT1 = createMailAddress("recipient1@" + JAMES_LOCAL); - public static final MailAddress RECIPIENT2 = createMailAddress("recipient2@" + JAMES_LOCAL); - public static final MailAddress RECIPIENT3 = createMailAddress("recipient3@" + JAMES_LOCAL); - - public static final MailAddress ANY_AT_LOCAL = createMailAddress("any@" + JAMES_LOCAL); - public static final MailAddress OTHER_AT_LOCAL = createMailAddress("other@" + JAMES_LOCAL); - public static final MailAddress ANY_AT_JAMES = createMailAddress("any@" + JAMES_APACHE_ORG); - public static final MailAddress POSTMASTER_AT_JAMES = createMailAddress("postmaster@" + 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 new RuntimeException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/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 deleted file mode 100644 index 6791a1f..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java +++ /dev/null @@ -1,464 +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.mailet.base.test; - -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; - -import javax.mail.MessagingException; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; - -import org.apache.james.core.MailAddress; -import org.apache.james.core.builder.MimeMessageBuilder; -import org.apache.james.util.MimeMessageUtil; -import org.apache.mailet.Mail; -import org.apache.mailet.PerRecipientHeaders; -import org.apache.mailet.PerRecipientHeaders.Header; - -import com.github.fge.lambdas.Throwing; -import com.github.steveash.guavate.Guavate; -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -public class FakeMail implements Mail, Serializable { - - private static final String DEFAULT_REMOTE_HOST = "111.222.333.444"; - public static final String DEFAULT_REMOTE_ADDRESS = "127.0.0.1"; - - public static FakeMail fromMessage(MimeMessageBuilder message) throws MessagingException { - return FakeMail.builder() - .mimeMessage(message) - .build(); - } - - public static FakeMail fromMime(String text, String javaEncodingCharset, String javamailDefaultEncodingCharset) throws MessagingException, UnsupportedEncodingException { - Properties javamailProperties = new Properties(); - javamailProperties.setProperty("mail.mime.charset", javamailDefaultEncodingCharset); - return FakeMail.builder() - .mimeMessage(MimeMessageUtil.mimeMessageFromBytes((text.getBytes(javaEncodingCharset)))) - .build(); - } - - public static FakeMail fromMail(Mail mail) throws MessagingException { - return new FakeMail(mail.getMessage(), - Lists.newArrayList(mail.getRecipients()), - mail.getName(), - mail.getSender(), - mail.getState(), - mail.getErrorMessage(), - mail.getLastUpdated(), - attributes(mail), - mail.getMessageSize(), - mail.getRemoteAddr(), - mail.getRemoteHost(), - mail.getPerRecipientSpecificHeaders()); - } - - public static FakeMail from(MimeMessage message) throws MessagingException { - return builder() - .mimeMessage(message) - .build(); - } - - public static FakeMail from(MimeMessageBuilder message) throws MessagingException { - return from(message.build()); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private Optional<String> fileName; - private Optional<MimeMessage> mimeMessage; - private List<MailAddress> recipients; - private Optional<String> name; - private Optional<MailAddress> sender; - private Optional<String> state; - private Optional<String> errorMessage; - private Optional<Date> lastUpdated; - private Map<String, Serializable> attributes; - private Optional<Long> size; - private Optional<String> remoteAddr; - private Optional<String> remoteHost; - private PerRecipientHeaders perRecipientHeaders; - - private Builder() { - fileName = Optional.empty(); - mimeMessage = Optional.empty(); - recipients = Lists.newArrayList(); - name = Optional.empty(); - sender = Optional.empty(); - state = Optional.empty(); - errorMessage = Optional.empty(); - lastUpdated = Optional.empty(); - attributes = Maps.newHashMap(); - size = Optional.empty(); - remoteAddr = Optional.empty(); - remoteHost = Optional.empty(); - perRecipientHeaders = new PerRecipientHeaders(); - } - - public Builder size(long size) { - this.size = Optional.of(size); - return this; - } - - public Builder fileName(String fileName) { - this.fileName = Optional.of(fileName); - return this; - } - - public Builder mimeMessage(MimeMessage mimeMessage) { - this.mimeMessage = Optional.of(mimeMessage); - return this; - } - - public Builder mimeMessage(MimeMessageBuilder mimeMessage) throws MessagingException { - this.mimeMessage = Optional.of(mimeMessage.build()); - return this; - } - - public Builder recipients() { - return this; - } - - public Builder recipients(List<MailAddress> recipients) { - this.recipients.addAll(recipients); - return this; - } - - public Builder recipients(MailAddress... recipients) { - return recipients(ImmutableList.copyOf(recipients)); - } - - public Builder recipients(String... recipients) { - return recipients(Arrays.stream(recipients) - .map(Throwing.function(MailAddress::new)) - .collect(Guavate.toImmutableList())); - } - - public Builder recipient(MailAddress recipient) { - return recipients(recipient); - } - - public Builder recipient(String recipient) throws AddressException { - return recipients(recipient); - } - - public Builder name(String name) { - this.name = Optional.of(name); - return this; - } - - public Builder sender(MailAddress sender) { - this.sender = Optional.of(sender); - return this; - } - - public Builder sender(String sender) throws AddressException { - return sender(new MailAddress(sender)); - } - - public Builder state(String state) { - this.state = Optional.of(state); - return this; - } - - public Builder errorMessage(String errorMessage) { - this.errorMessage = Optional.of(errorMessage); - return this; - } - - public Builder lastUpdated(Date lastUpdated) { - this.lastUpdated = Optional.of(lastUpdated); - return this; - } - - public Builder attribute(String name, Serializable object) { - this.attributes.put(name, object); - return this; - } - - public Builder attributes(Map<String, Serializable> attributes) { - this.attributes.putAll(attributes); - return this; - } - - public Builder remoteAddr(String remoteAddr) { - this.remoteAddr = Optional.of(remoteAddr); - return this; - } - - public Builder remoteHost(String remoteHost) { - this.remoteHost = Optional.of(remoteHost); - return this; - } - - public Builder addHeaderForRecipient(Header header, MailAddress recipient) { - this.perRecipientHeaders.addHeaderForRecipient(header, recipient); - return this; - } - - public FakeMail build() throws MessagingException { - return new FakeMail(getMimeMessage(), recipients, name.orElse(null), sender.orElse(null), state.orElse(null), errorMessage.orElse(null), lastUpdated.orElse(null), - attributes, size.orElse(0L), remoteAddr.orElse(DEFAULT_REMOTE_ADDRESS), remoteHost.orElse(DEFAULT_REMOTE_HOST), perRecipientHeaders); - } - - private MimeMessage getMimeMessage() throws MessagingException { - Preconditions.checkState(!(fileName.isPresent() && mimeMessage.isPresent()), "You can not specify a MimeMessage object when you alredy set Content from a file"); - if (fileName.isPresent()) { - return MimeMessageUtil.mimeMessageFromStream(ClassLoader.getSystemResourceAsStream(fileName.get())); - } - return mimeMessage.orElse(null); - } - } - - public static FakeMail defaultFakeMail() throws MessagingException { - return FakeMail.builder().build(); - } - - private static Map<String, Serializable> attributes(Mail mail) { - ImmutableMap.Builder<String, Serializable> builder = ImmutableMap.builder(); - for (String attributeName: ImmutableList.copyOf(mail.getAttributeNames())) { - builder.put(attributeName, mail.getAttribute(attributeName)); - } - return builder.build(); - } - - private transient MimeMessage msg; - private Collection<MailAddress> recipients; - private String name; - private MailAddress sender; - private String state; - private String errorMessage; - private Date lastUpdated; - private Map<String, Serializable> attributes; - private long size; - private String remoteAddr; - private String remoteHost; - private PerRecipientHeaders perRecipientHeaders; - - public FakeMail(MimeMessage msg, List<MailAddress> recipients, String name, MailAddress sender, String state, String errorMessage, Date lastUpdated, - Map<String, Serializable> attributes, long size, String remoteAddr, String remoteHost, PerRecipientHeaders perRecipientHeaders) { - this.msg = msg; - this.recipients = recipients; - this.name = name; - this.sender = sender; - this.state = state; - this.errorMessage = errorMessage; - this.lastUpdated = lastUpdated; - this.attributes = attributes; - this.size = size; - this.remoteAddr = remoteAddr; - this.perRecipientHeaders = perRecipientHeaders; - this.remoteHost = remoteHost; - } - - @Override - public String getName() { - return name; - } - - @Override - public void setName(String newName) { - this.name = newName; - } - - @Override - public MimeMessage getMessage() throws MessagingException { - return msg; - } - - @Override - public Collection<MailAddress> getRecipients() { - return recipients; - } - - @Override - public void setRecipients(Collection<MailAddress> recipients) { - this.recipients = recipients; - } - - @Override - public MailAddress getSender() { - return sender; - } - - @Override - public String getState() { - return state; - } - - @Override - public String getRemoteHost() { - return remoteHost; - } - - @Override - public String getRemoteAddr() { - return remoteAddr; - } - - @Override - public String getErrorMessage() { - return errorMessage; - } - - @Override - public void setErrorMessage(String msg) { - this.errorMessage = msg; - } - - @Override - public void setMessage(MimeMessage message) { - this.msg = message; - try { - if (message != null && message.getSender() != null) { - this.sender = new MailAddress((InternetAddress) message.getSender()); - } - } catch (MessagingException e) { - throw new RuntimeException("Exception caught", e); - } - } - - @Override - public void setState(String state) { - this.state = state; - } - - @Override - public Serializable getAttribute(String name) { - return attributes.get(name); - } - - @Override - public Iterator<String> getAttributeNames() { - return attributes.keySet().iterator(); - } - - @Override - public boolean hasAttributes() { - return !attributes.isEmpty(); - } - - @Override - public Serializable removeAttribute(String name) { - return attributes.remove(name); - - } - - @Override - public void removeAllAttributes() { - attributes.clear(); - } - - @Override - public Serializable setAttribute(String name, Serializable object) { - return attributes.put(name, object); - } - - @Override - public long getMessageSize() throws MessagingException { - return size; - } - - @Override - public Date getLastUpdated() { - return lastUpdated; - } - - @Override - public void setLastUpdated(Date lastUpdated) { - this.lastUpdated = lastUpdated; - } - - public void setMessageSize(long size) { - this.size = size; - } - - @Override - public final boolean equals(Object o) { - if (o instanceof FakeMail) { - FakeMail that = (FakeMail) o; - - return Objects.equal(this.size, that.size) - && Objects.equal(this.recipients, that.recipients) - && Objects.equal(this.name, that.name) - && Objects.equal(this.sender, that.sender) - && Objects.equal(this.state, that.state) - && Objects.equal(this.errorMessage, that.errorMessage) - && Objects.equal(this.lastUpdated, that.lastUpdated) - && Objects.equal(this.attributes, that.attributes) - && Objects.equal(this.remoteHost, that.remoteHost) - && Objects.equal(this.perRecipientHeaders, that.perRecipientHeaders) - && Objects.equal(this.remoteAddr, that.remoteAddr); - } - return false; - } - - @Override - public final int hashCode() { - return Objects.hashCode(name, sender, recipients, state, errorMessage, lastUpdated, attributes, size, remoteAddr, remoteHost, perRecipientHeaders); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("msg", msg) - .add("recipients", recipients) - .add("name", name) - .add("sender", sender) - .add("state", state) - .add("errorMessage", errorMessage) - .add("lastUpdated", lastUpdated) - .add("attributes", attributes) - .add("size", size) - .add("remoteAddr", remoteAddr) - .toString(); - } - - @Override - public PerRecipientHeaders getPerRecipientSpecificHeaders() { - return perRecipientHeaders; - } - - @Override - public void addSpecificHeaderForRecipient(Header header, MailAddress recipient) { - perRecipientHeaders.addHeaderForRecipient(header, recipient); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java deleted file mode 100644 index eff41c9..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailContext.java +++ /dev/null @@ -1,608 +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.mailet.base.test; - -import java.io.Serializable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.TimeUnit; - -import javax.mail.MessagingException; -import javax.mail.internet.AddressException; -import javax.mail.internet.MimeMessage; - -import org.apache.james.core.Domain; -import org.apache.james.core.MailAddress; -import org.apache.james.core.builder.MimeMessageWrapper; -import org.apache.mailet.HostAddress; -import org.apache.mailet.LookupException; -import org.apache.mailet.Mail; -import org.apache.mailet.MailetContext; -import org.slf4j.Logger; - -import com.github.fge.lambdas.Throwing; -import com.github.fge.lambdas.functions.ThrowingFunction; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; - -@SuppressWarnings("deprecation") -public class FakeMailContext implements MailetContext { - - public static Builder builder() { - return new Builder(); - } - - public static SentMail.Builder sentMailBuilder() { - return new SentMail.Builder(); - } - - public static SentMail.Builder fromMail(Mail mail) throws MessagingException { - return sentMailBuilder() - .sender(mail.getSender()) - .recipients(mail.getRecipients()) - .message(mail.getMessage()) - .state(mail.getState()) - .attributes(buildAttributesMap(mail)) - .fromMailet(); - } - - private static ImmutableMap<String, Serializable> buildAttributesMap(Mail mail) { - Map<String, Serializable> result = new HashMap<>(); - List<String> attributesNames = Lists.newArrayList(mail.getAttributeNames()); - for (String attributeName: attributesNames) { - result.put(attributeName, mail.getAttribute(attributeName)); - } - return ImmutableMap.copyOf(result); - } - - public static FakeMailContext defaultContext() { - return builder().build(); - } - - public static class Builder { - - private Logger logger; - private Optional<MailAddress> postmaster; - - private Builder() { - postmaster = Optional.empty(); - } - - public Builder logger(Logger logger) { - this.logger = logger; - return this; - } - - public Builder postmaster(MailAddress postmaster) { - this.postmaster = Optional.of(postmaster); - return this; - } - - public FakeMailContext build() { - return new FakeMailContext(Optional.ofNullable(logger), postmaster.orElse(null)); - } - } - - public static class SentMail { - - private static MimeMessage tryCopyMimeMessage(MimeMessage msg) throws MessagingException { - ThrowingFunction<MimeMessage, MimeMessage> throwingFunction = MimeMessageWrapper::wrap; - - return Optional.ofNullable(msg) - .map(Throwing.function(throwingFunction).sneakyThrow()) - .orElse(null); - } - - public static class Builder { - private MailAddress sender; - private Optional<Collection<MailAddress>> recipients = Optional.empty(); - private MimeMessage msg; - private Map<String, Serializable> attributes = new HashMap<>(); - private Optional<String> state = Optional.empty(); - private Optional<Boolean> fromMailet = Optional.empty(); - private Optional<Delay> delay = Optional.empty(); - - public Builder sender(MailAddress sender) { - this.sender = sender; - return this; - } - - public Builder sender(String sender) throws AddressException { - return sender(new MailAddress(sender)); - } - - public Builder recipients(Collection<MailAddress> recipients) { - this.recipients = Optional.of(recipients); - return this; - } - - public Builder fromMailet() { - this.fromMailet = Optional.of(true); - return this; - } - - public Builder recipients(MailAddress... recipients) { - this.recipients = Optional.<Collection<MailAddress>>of(ImmutableList.copyOf(recipients)); - return this; - } - - public Builder recipient(MailAddress recipient) { - Preconditions.checkNotNull(recipient); - return recipients(ImmutableList.of(recipient)); - } - - public Builder recipient(String recipient) throws AddressException { - Preconditions.checkNotNull(recipient); - return recipients(new MailAddress(recipient)); - } - - public Builder message(MimeMessage mimeMessage) { - this.msg = mimeMessage; - return this; - } - - public Builder attributes(Map<String, Serializable> attributes) { - this.attributes.putAll(attributes); - return this; - } - - public Builder attribute(String key, Serializable value) { - this.attributes.put(key, value); - return this; - } - - public Builder state(String state) { - this.state = Optional.of(state); - return this; - } - - public Builder delay(Delay delay) { - this.delay = Optional.of(delay); - return this; - } - - public SentMail build() throws MessagingException { - if (fromMailet.orElse(false)) { - this.attribute(Mail.SENT_BY_MAILET, "true"); - } - return new SentMail(sender, recipients.orElse(ImmutableList.<MailAddress>of()), msg, - ImmutableMap.copyOf(attributes), state.orElse(Mail.DEFAULT), delay); - } - } - - private final MailAddress sender; - private final Collection<MailAddress> recipients; - private final MimeMessage msg; - private final Optional<String> subject; - private final Map<String, Serializable> attributes; - private final String state; - private final Optional<Delay> delay; - - private SentMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg, Map<String, Serializable> attributes, String state, Optional<Delay> delay) throws MessagingException { - this.sender = sender; - this.recipients = ImmutableList.copyOf(recipients); - this.msg = tryCopyMimeMessage(msg); - this.subject = getSubject(msg); - this.attributes = ImmutableMap.copyOf(attributes); - this.state = state; - this.delay = delay; - } - - private Optional<String> getSubject(MimeMessage msg) { - try { - return Optional.ofNullable(msg.getSubject()); - } catch (Exception e) { - return Optional.empty(); - } - } - - public MailAddress getSender() { - return sender; - } - - public Collection<MailAddress> getRecipients() { - return recipients; - } - - public MimeMessage getMsg() { - return msg; - } - - public String getState() { - return state; - } - - public Optional<String> getSubject() { - return subject; - } - - - public Optional<Delay> getDelay() { - return delay; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof SentMail)) { - return false; - } - - SentMail sentMail = (SentMail) o; - - return Objects.equals(this.sender, sentMail.sender) - && Objects.equals(this.recipients, sentMail.recipients) - && Objects.equals(this.attributes, sentMail.attributes) - && Objects.equals(this.state, sentMail.state); - } - - @Override - public int hashCode() { - return Objects.hash(sender, recipients, attributes, state); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("recipients", recipients) - .add("sender", sender) - .add("attributeNames", attributes) - .add("state", state) - .toString(); - } - } - - public static class Delay { - private final long duration; - private final TimeUnit timeUnit; - - public Delay(long duration, TimeUnit timeUnit) { - this.duration = duration; - this.timeUnit = timeUnit; - } - - public long getDuration() { - return duration; - } - - public TimeUnit getTimeUnit() { - return timeUnit; - } - - @Override - public final boolean equals(Object o) { - if (o instanceof Delay) { - Delay delay = (Delay) o; - - return Objects.equals(this.duration, delay.duration) - && Objects.equals(this.timeUnit, delay.timeUnit); - } - return false; - } - - @Override - public final int hashCode() { - return Objects.hash(duration, timeUnit); - } - } - - public static class BouncedMail { - private final SentMail sentMail; - private final String message; - private final Optional<MailAddress> bouncer; - - public BouncedMail(SentMail sentMail, String message, Optional<MailAddress> bouncer) { - this.sentMail = sentMail; - this.message = message; - this.bouncer = bouncer; - } - - public BouncedMail(SentMail.Builder sentMail, String message, Optional<MailAddress> bouncer) throws MessagingException { - this(sentMail.build(), message, bouncer); - } - - public SentMail getSentMail() { - return sentMail; - } - - public String getMessage() { - return message; - } - - public Optional<MailAddress> getBouncer() { - return bouncer; - } - - @Override - public boolean equals(Object o) { - if (o instanceof BouncedMail) { - BouncedMail that = (BouncedMail) o; - return Objects.equals(this.sentMail, that.sentMail) - && Objects.equals(this.message, that.message) - && Objects.equals(this.bouncer, that.bouncer); - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(sentMail, message, bouncer); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sentMail", sentMail) - .add("message", message) - .add("bouncer", bouncer) - .toString(); - } - } - - private final HashMap<String, Object> attributes; - private final Collection<SentMail> sentMails; - private final Collection<BouncedMail> bouncedMails; - private final Optional<Logger> logger; - private final MailAddress postmaster; - - private FakeMailContext(Optional<Logger> logger, MailAddress postmaster) { - attributes = new HashMap<>(); - sentMails = new ConcurrentLinkedQueue<>(); - bouncedMails = new ConcurrentLinkedQueue<>(); - this.logger = logger; - this.postmaster = postmaster; - } - - @Override - public void bounce(Mail mail, String message) throws MessagingException { - bouncedMails.add(new BouncedMail(fromMail(mail), message, Optional.empty())); - } - - @Override - public void bounce(Mail mail, String message, MailAddress bouncer) throws MessagingException { - bouncedMails.add(new BouncedMail(fromMail(mail), message, Optional.ofNullable(bouncer))); - } - - /** - * @deprecated use the generic dnsLookup method - */ - @Override - public Collection<String> getMailServers(Domain host) { - return null; // trivial implementation - } - - @Override - public MailAddress getPostmaster() { - return postmaster; - } - - @Override - public Object getAttribute(String name) { - return attributes.get(name); - } - - @Override - public Iterator<String> getAttributeNames() { - return attributes.keySet().iterator(); - } - - @Override - public int getMajorVersion() { - return 0; // trivial implementation - } - - @Override - public int getMinorVersion() { - return 0; // trivial implementation - } - - @Override - public String getServerInfo() { - return "Mock Server"; - } - - @Override - public boolean isLocalServer(Domain domain) { - return domain.equals(Domain.LOCALHOST); - } - - /** - * @deprecated use {@link #isLocalEmail(MailAddress)} instead - */ - @Override - public boolean isLocalUser(String userAccount) { - return false; // trivial implementation - } - - @Override - public boolean isLocalEmail(MailAddress mailAddress) { - return false; // trivial implementation - } - - /** - * @deprecated use {@link #log(LogLevel level, String message)} - */ - @Override - public void log(String message) { - System.out.println(message); - } - - /** - * @deprecated use {@link #log(LogLevel level, String message, Throwable t)} - */ - @Override - public void log(String message, Throwable t) { - System.out.println(message); - t.printStackTrace(System.out); - } - - @Override - public void removeAttribute(String name) { - // trivial implementation - } - - @Override - public void sendMail(MimeMessage mimemessage) throws MessagingException { - sentMails.add(sentMailBuilder() - .message(mimemessage) - .fromMailet() - .build()); - } - - @Override - public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg) throws MessagingException { - sentMails.add(sentMailBuilder() - .recipients(recipients) - .sender(sender) - .message(msg) - .fromMailet() - .build()); - } - - @Override - public void sendMail(MailAddress sender, Collection<MailAddress> recipients, MimeMessage msg, String state) throws MessagingException { - sentMails.add(sentMailBuilder() - .recipients(recipients) - .message(msg) - .state(state) - .sender(sender) - .fromMailet() - .build()); - } - - @Override - public void sendMail(Mail mail) throws MessagingException { - sendMail(mail, Mail.DEFAULT); - } - - @Override - public void sendMail(Mail mail, long delay, TimeUnit unit) throws MessagingException { - sendMail(mail, Mail.DEFAULT, delay, unit); - } - - @Override - public void sendMail(Mail mail, String state) throws MessagingException { - mail.setState(state); - sentMails.add(fromMail(mail).build()); - } - - @Override - public void sendMail(Mail mail, String state, long delay, TimeUnit unit) throws MessagingException { - mail.setState(state); - sentMails.add( - fromMail(mail) - .delay(new Delay(delay, unit)) - .build()); - } - - public void setAttribute(String name, Serializable object) { - attributes.put(name,object); - } - - public void storeMail(MailAddress sender, MailAddress recipient, MimeMessage msg) throws MessagingException { - // trivial implementation - } - - /** - * @deprecated use the generic dnsLookup method - */ - @Override - public Iterator<HostAddress> getSMTPHostAddresses(Domain domainName) { - return null; // trivial implementation - } - - @Override - public void setAttribute(String name, Object value) { - throw new UnsupportedOperationException("MOCKed method"); - } - - @Override - public void log(LogLevel level, String message) { - if (logger.isPresent()) { - switch (level) { - case INFO: - logger.get().info(message); - break; - case WARN: - logger.get().warn(message); - break; - case ERROR: - logger.get().error(message); - break; - default: - logger.get().debug(message); - } - } else { - System.out.println("[" + level + "]" + message); - } - } - - @Override - public void log(LogLevel level, String message, Throwable t) { - if (logger.isPresent()) { - switch (level) { - case INFO: - logger.get().info(message, t); - break; - case WARN: - logger.get().warn(message, t); - break; - case ERROR: - logger.get().error(message, t); - break; - default: - logger.get().debug(message, t); - } - } else { - System.out.println("[" + level + "]" + message); - t.printStackTrace(System.out); - } - } - - @Override - public List<String> dnsLookup(String name, RecordType type) throws LookupException { - return null; // trivial implementation - } - - public List<SentMail> getSentMails() { - return ImmutableList.copyOf(sentMails); - } - - public void resetSentMails() { - sentMails.clear(); - } - - public List<BouncedMail> getBouncedMails() { - return ImmutableList.copyOf(bouncedMails); - } - - @Override - public Logger getLogger() { - return logger.orElse(null); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailTest.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailTest.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailTest.java deleted file mode 100644 index fc0c03c..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailTest.java +++ /dev/null @@ -1,41 +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.mailet.base.test; - -import static org.mockito.Mockito.mock; - -import javax.mail.internet.MimeMessage; - -import org.junit.Test; - -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -public class FakeMailTest { - - @Test - public void beanShouldRespectBeanContract() { - EqualsVerifier.forClass(FakeMail.class) - .suppress(Warning.NONFINAL_FIELDS) - .withPrefabValues(MimeMessage.class, mock(MimeMessage.class), mock(MimeMessage.class)) - .verify(); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java deleted file mode 100644 index 73289d7..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMailetConfig.java +++ /dev/null @@ -1,106 +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.mailet.base.test; - -import java.util.Iterator; -import java.util.Optional; -import java.util.Properties; - -import org.apache.mailet.MailetConfig; -import org.apache.mailet.MailetContext; - -/** - * MailetConfig over Properties - */ -public class FakeMailetConfig implements MailetConfig { - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private static final String DEFAULT_MAILET_NAME = "A Mailet"; - private Optional<String> mailetName; - private Optional<MailetContext> mailetContext; - private Properties properties; - - private Builder() { - mailetName = Optional.empty(); - mailetContext = Optional.empty(); - properties = new Properties(); - } - - public Builder mailetName(String mailetName) { - this.mailetName = Optional.ofNullable(mailetName); - return this; - } - - public Builder mailetContext(MailetContext mailetContext) { - this.mailetContext = Optional.ofNullable(mailetContext); - return this; - } - - public Builder mailetContext(FakeMailContext.Builder mailetContext) { - return mailetContext(mailetContext.build()); - } - - public Builder setProperty(String key, String value) { - this.properties.setProperty(key, value); - return this; - } - - public FakeMailetConfig build() { - return new FakeMailetConfig(mailetName.orElse(DEFAULT_MAILET_NAME), - mailetContext.orElse(FakeMailContext.defaultContext()), - properties); - } - } - - private final String mailetName; - private final MailetContext mailetContext; - private final Properties properties; - - private FakeMailetConfig(String mailetName, MailetContext mailetContext, Properties properties) { - this.mailetName = mailetName; - this.mailetContext = mailetContext; - this.properties = properties; - } - - @Override - public String getInitParameter(String name) { - return properties.getProperty(name); - } - - @Override - public Iterator<String> getInitParameterNames() { - return properties.stringPropertyNames().iterator(); - } - - @Override - public MailetContext getMailetContext() { - return mailetContext; - } - - @Override - public String getMailetName() { - return mailetName; - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMatcherConfig.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMatcherConfig.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMatcherConfig.java deleted file mode 100644 index 1917c3d..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMatcherConfig.java +++ /dev/null @@ -1,95 +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.mailet.base.test; - -import java.util.Optional; - -import org.apache.mailet.MailetContext; -import org.apache.mailet.MatcherConfig; - -import com.google.common.base.Preconditions; - -/** - * MatcherConfig - */ -public class FakeMatcherConfig implements MatcherConfig { - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String matcherName; - private Optional<MailetContext> mailetContext; - private Optional<String> condition; - - private Builder() { - condition = Optional.empty(); - mailetContext = Optional.empty(); - } - - public Builder matcherName(String matcherName) { - this.matcherName = matcherName; - return this; - } - - public Builder mailetContext(MailetContext mailetContext) { - Preconditions.checkNotNull(mailetContext); - this.mailetContext = Optional.of(mailetContext); - return this; - } - - public Builder condition(String condition) { - this.condition = Optional.ofNullable(condition); - return this; - } - - public FakeMatcherConfig build() { - Preconditions.checkNotNull(matcherName, "'matcherName' is mandatory"); - return new FakeMatcherConfig(matcherName, mailetContext.orElse(FakeMailContext.defaultContext()), condition); - } - } - - private final String matcherName; - private final MailetContext mailetContext; - private final Optional<String> condition; - - private FakeMatcherConfig(String matcherName, MailetContext mailetContext, Optional<String> condition) { - this.matcherName = matcherName; - this.mailetContext = mailetContext; - this.condition = condition; - } - - @Override - public String getMatcherName() { - return matcherName; - } - - @Override - public MailetContext getMailetContext() { - return mailetContext; - } - - @Override - public String getCondition() { - return condition.orElse(null); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java ---------------------------------------------------------------------- diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java b/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java deleted file mode 100644 index ecbee4f..0000000 --- a/mailet/base/src/test/java/org/apache/mailet/base/test/MailUtil.java +++ /dev/null @@ -1,92 +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.mailet.base.test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; - -import org.apache.james.core.MailAddress; -import org.apache.james.core.builder.MimeMessageBuilder; -import org.apache.mailet.Mail; - -/** - * some utilities for James unit testing - */ -public class MailUtil { - - public static final String SENDER = "t...@james.apache.org"; - public static final String RECIPIENT = "te...@james.apache.org"; - private static int m_counter = 0; - - public static String newId() { - m_counter++; - return "MockMailUtil-ID-" + m_counter; - } - - public static FakeMail createMockMail2Recipients() throws MessagingException { - return FakeMail.builder() - .name(newId()) - .recipients(new MailAddress("t...@james.apache.org"), new MailAddress("te...@james.apache.org")) - .build(); - } - - public static FakeMail createMockMail2Recipients(MimeMessage message) throws MessagingException { - return FakeMail.builder() - .name(newId()) - .mimeMessage(message) - .recipients(new MailAddress("t...@james.apache.org"), new MailAddress("te...@james.apache.org")) - .build(); - } - - public static MimeMessage createMimeMessage() throws MessagingException { - return createMimeMessage(null, null); - } - - public static MimeMessage createMimeMessageWithSubject(String subject) throws MessagingException { - return createMimeMessage(null, null, subject); - } - - public static MimeMessage createMimeMessage(String headerName, String headerValue) throws MessagingException { - return createMimeMessage(headerName, headerValue, "testmail"); - } - - private static MimeMessage createMimeMessage(String headerName, String headerValue, String subject) throws MessagingException { - MimeMessageBuilder mimeMessageBuilder = MimeMessageBuilder.mimeMessageBuilder() - .addToRecipient(RECIPIENT) - .addFrom(SENDER) - .setSubject(subject); - if (headerName != null) { - mimeMessageBuilder.addHeader(headerName, headerValue); - } - return mimeMessageBuilder.build(); - } - - public static String toString(Mail mail, String charset) throws IOException, MessagingException { - ByteArrayOutputStream rawMessage = new ByteArrayOutputStream(); - mail.getMessage().writeTo( - rawMessage, - new String[] { "Bcc", "Content-Length", "Message-ID" }); - return rawMessage.toString(charset); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/icalendar/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/icalendar/pom.xml b/mailet/icalendar/pom.xml index b11e5cb..767e9fb 100644 --- a/mailet/icalendar/pom.xml +++ b/mailet/icalendar/pom.xml @@ -36,8 +36,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>apache-mailet-base</artifactId> - <type>test-jar</type> + <artifactId>apache-mailet-test</artifactId> <scope>test</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/pom.xml b/mailet/pom.xml index 37cc224..722fc87 100644 --- a/mailet/pom.xml +++ b/mailet/pom.xml @@ -52,6 +52,7 @@ <module>icalendar</module> <module>mailetdocs-maven-plugin</module> <module>standard</module> + <module>test</module> </modules> <issueManagement> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/standard/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/standard/pom.xml b/mailet/standard/pom.xml index cd49a33..d0dc22b 100644 --- a/mailet/standard/pom.xml +++ b/mailet/standard/pom.xml @@ -43,9 +43,7 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>apache-mailet-base</artifactId> - <type>test-jar</type> - <scope>test</scope> + <artifactId>apache-mailet-test</artifactId> </dependency> <dependency> <groupId>${james.groupId}</groupId> @@ -54,6 +52,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>james-server-util</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>james-server-util-java8</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/test/pom.xml ---------------------------------------------------------------------- diff --git a/mailet/test/pom.xml b/mailet/test/pom.xml new file mode 100644 index 0000000..80f5e64 --- /dev/null +++ b/mailet/test/pom.xml @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.james</groupId> + <artifactId>apache-mailet</artifactId> + <version>3.2.0-SNAPSHOT</version> + <relativePath>../</relativePath> + </parent> + + <artifactId>apache-mailet-test</artifactId> + <packaging>bundle</packaging> + + <name>Apache James :: Test helpers for Mailet</name> + <description>Apache James Mailet Test is a collection of utilities to help testing mailets.</description> + + <dependencies> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>apache-mailet-api</artifactId> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>apache-mime4j-core</artifactId> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>james-server-util</artifactId> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>javax-mail-extension</artifactId> + </dependency> + <dependency> + <groupId>com.github.steveash.guavate</groupId> + <artifactId>guavate</artifactId> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>com.sun.mail</groupId> + <artifactId>javax.mail</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.activation</groupId> + <artifactId>activation</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-guava</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package>org.apache.mailet.base.*</Export-Package> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>${james.groupId}</groupId> + <artifactId>maven-mailetdocs-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/3dddd7c5/mailet/test/src/main/java/org/apache/mailet/base/MailAddressFixture.java ---------------------------------------------------------------------- diff --git a/mailet/test/src/main/java/org/apache/mailet/base/MailAddressFixture.java b/mailet/test/src/main/java/org/apache/mailet/base/MailAddressFixture.java new file mode 100644 index 0000000..4efe093 --- /dev/null +++ b/mailet/test/src/main/java/org/apache/mailet/base/MailAddressFixture.java @@ -0,0 +1,56 @@ +/**************************************************************** + * 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.james.core.Domain; +import org.apache.james.core.MailAddress; + +public class MailAddressFixture { + public static final String JAMES_LOCAL = "localhost"; + public static final String JAMES_APACHE_ORG = "james.apache.org"; + public static final String JAMES2_APACHE_ORG = "james2.apache.org"; + + public static final Domain JAMES_LOCAL_DOMAIN = Domain.of(JAMES_LOCAL); + public static final Domain JAMES_APACHE_ORG_DOMAIN = Domain.of(JAMES_APACHE_ORG); + public static final Domain JAMES2_APACHE_ORG_DOMAIN = Domain.of(JAMES2_APACHE_ORG); + + public static final MailAddress SENDER = createMailAddress("sender@" + JAMES_LOCAL); + public static final MailAddress RECIPIENT1 = createMailAddress("recipient1@" + JAMES_LOCAL); + public static final MailAddress RECIPIENT2 = createMailAddress("recipient2@" + JAMES_LOCAL); + public static final MailAddress RECIPIENT3 = createMailAddress("recipient3@" + JAMES_LOCAL); + + public static final MailAddress ANY_AT_LOCAL = createMailAddress("any@" + JAMES_LOCAL); + public static final MailAddress OTHER_AT_LOCAL = createMailAddress("other@" + JAMES_LOCAL); + public static final MailAddress ANY_AT_JAMES = createMailAddress("any@" + JAMES_APACHE_ORG); + public static final MailAddress POSTMASTER_AT_JAMES = createMailAddress("postmaster@" + 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 new RuntimeException(e); + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org