MAILET-153 Integration test for AddDeliveredTo headers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d1a9f8d9 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d1a9f8d9 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d1a9f8d9 Branch: refs/heads/master Commit: d1a9f8d993d9317f1c0d4c558c5cf19dabec7a44 Parents: c56422b Author: benwa <btell...@linagora.com> Authored: Sat Apr 8 10:45:15 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Tue Apr 11 07:53:48 2017 +0700 ---------------------------------------------------------------------- .../james/mailets/AddDeliveredToHeaderTest.java | 106 +++++++++++++++++++ 1 file changed, 106 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/d1a9f8d9/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.java new file mode 100644 index 0000000..f72adf1 --- /dev/null +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/AddDeliveredToHeaderTest.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.mailets; + +import org.apache.james.mailbox.model.MailboxConstants; +import org.apache.james.mailets.configuration.CommonProcessors; +import org.apache.james.mailets.configuration.MailetContainer; +import org.apache.james.mailets.utils.SMTPMessageSender; +import org.apache.james.modules.MailboxProbeImpl; +import org.apache.james.probe.DataProbe; +import org.apache.james.transport.mailets.delivery.MailDispatcher; +import org.apache.james.utils.DataProbeImpl; +import org.apache.james.utils.IMAPMessageReader; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.jayway.awaitility.Awaitility; +import com.jayway.awaitility.Duration; +import com.jayway.awaitility.core.ConditionFactory; + +public class AddDeliveredToHeaderTest { + + private static final String DEFAULT_DOMAIN = "james.org"; + private static final String LOCALHOST_IP = "127.0.0.1"; + private static final int IMAP_PORT = 1143; + private static final int SMTP_PORT = 1025; + private static final String PASSWORD = "secret"; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + private TemporaryJamesServer jamesServer; + private ConditionFactory calmlyAwait; + + @Before + public void setup() throws Exception { + MailetContainer mailetContainer = MailetContainer.builder() + .postmaster("postmaster@" + DEFAULT_DOMAIN) + .threads(5) + .addProcessor(CommonProcessors.root()) + .addProcessor(CommonProcessors.error()) + .addProcessor(CommonProcessors.transport()) + .addProcessor(CommonProcessors.spam()) + .addProcessor(CommonProcessors.localAddressError()) + .addProcessor(CommonProcessors.relayDenied()) + .addProcessor(CommonProcessors.bounces()) + .addProcessor(CommonProcessors.sieveManagerCheck()) + .build(); + + jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer); + Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; + calmlyAwait = Awaitility.with() + .pollInterval(slowPacedPollInterval) + .and() + .with() + .pollDelay(slowPacedPollInterval) + .await(); + } + + @After + public void tearDown() { + jamesServer.shutdown(); + } + + @Test + public void receivedMessagesShouldContainDeliveredToHeaders() throws Exception { + String from = "user@" + DEFAULT_DOMAIN; + String recipient = "user2@" + DEFAULT_DOMAIN; + + DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class); + dataProbe.addDomain(DEFAULT_DOMAIN); + dataProbe.addUser(from, PASSWORD); + dataProbe.addUser(recipient, PASSWORD); + + jamesServer.getProbe(MailboxProbeImpl.class) + .createMailbox(MailboxConstants.USER_NAMESPACE, recipient, "INBOX"); + + try (SMTPMessageSender messageSender = SMTPMessageSender.noAuthentication(LOCALHOST_IP, SMTP_PORT, DEFAULT_DOMAIN); + IMAPMessageReader imapMessageReader = new IMAPMessageReader(LOCALHOST_IP, IMAP_PORT)) { + messageSender.sendMessage(from, recipient); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(messageSender::messageHasBeenSent); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> imapMessageReader.readFirstMessageHeadersInInbox(recipient, PASSWORD) + .contains(MailDispatcher.DELIVERED_TO + ": " + recipient)); + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org