Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JAMES-2294 Integration test for mail reprocessing
- Loading branch information
Showing
5 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...ntegration-testing/src/test/java/org/apache/james/transport/mailets/ToRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/**************************************************************** | ||
* 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 com.jayway.restassured.RestAssured.with; | ||
import static org.apache.james.mailets.configuration.Constants.DEFAULT_DOMAIN; | ||
import static org.apache.james.mailets.configuration.Constants.IMAP_PORT; | ||
import static org.apache.james.mailets.configuration.Constants.LOCALHOST_IP; | ||
import static org.apache.james.mailets.configuration.Constants.PASSWORD; | ||
import static org.apache.james.mailets.configuration.Constants.SMTP_PORT; | ||
import static org.apache.james.mailets.configuration.Constants.awaitOneMinute; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.james.mailets.TemporaryJamesServer; | ||
import org.apache.james.mailets.configuration.MailetConfiguration; | ||
import org.apache.james.mailets.configuration.MailetContainer; | ||
import org.apache.james.mailets.configuration.ProcessorConfiguration; | ||
import org.apache.james.probe.DataProbe; | ||
import org.apache.james.transport.matchers.All; | ||
import org.apache.james.utils.DataProbeImpl; | ||
import org.apache.james.utils.IMAPMessageReader; | ||
import org.apache.james.utils.MailRepositoryProbeImpl; | ||
import org.apache.james.utils.SMTPMessageSender; | ||
import org.apache.james.utils.WebAdminGuiceProbe; | ||
import org.apache.james.webadmin.WebAdminUtils; | ||
import org.apache.james.webadmin.routes.MailRepositoriesRoutes; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import com.jayway.restassured.specification.RequestSpecification; | ||
|
||
public class ToRepositoryTest { | ||
private static final String RECIPIENT = "touser@" + DEFAULT_DOMAIN; | ||
public static final String CUSTOM_REPOSITORY = "file://var/mail/custom/"; | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
@Rule | ||
public IMAPMessageReader imapMessageReader = new IMAPMessageReader(); | ||
@Rule | ||
public SMTPMessageSender messageSender = new SMTPMessageSender(DEFAULT_DOMAIN); | ||
|
||
private TemporaryJamesServer jamesServer; | ||
private MailRepositoryProbeImpl probe; | ||
private RequestSpecification webAdminAPI; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
MailetContainer.Builder mailetContainer = TemporaryJamesServer.SIMPLE_MAILET_CONTAINER_CONFIGURATION | ||
.putProcessor(ProcessorConfiguration.root() | ||
.addMailet(MailetConfiguration.builder() | ||
.matcher(All.class) | ||
.mailet(ToRepository.class) | ||
.addProperty("repositoryPath", CUSTOM_REPOSITORY))); | ||
|
||
jamesServer = TemporaryJamesServer.builder() | ||
.withMailetContainer(mailetContainer) | ||
.build(temporaryFolder); | ||
|
||
DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class); | ||
dataProbe.addDomain(DEFAULT_DOMAIN); | ||
dataProbe.addUser(RECIPIENT, PASSWORD); | ||
|
||
probe = jamesServer.getProbe(MailRepositoryProbeImpl.class); | ||
webAdminAPI = WebAdminUtils.buildRequestSpecification( | ||
jamesServer.getProbe(WebAdminGuiceProbe.class) | ||
.getWebAdminPort()) | ||
.build(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
jamesServer.shutdown(); | ||
} | ||
|
||
@Test | ||
public void incomingShouldBeStoredInProcessorByDefault() throws Exception { | ||
messageSender.connect(LOCALHOST_IP, SMTP_PORT) | ||
.sendMessage(RECIPIENT, RECIPIENT) | ||
.awaitSent(awaitOneMinute) | ||
.sendMessage(RECIPIENT, RECIPIENT) | ||
.awaitSent(awaitOneMinute); | ||
|
||
awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 2); | ||
} | ||
|
||
@Test | ||
public void userShouldBeAbleToAccessReprocessedMails() throws Exception { | ||
messageSender.connect(LOCALHOST_IP, SMTP_PORT) | ||
.sendMessage(RECIPIENT, RECIPIENT) | ||
.awaitSent(awaitOneMinute) | ||
.sendMessage(RECIPIENT, RECIPIENT) | ||
.awaitSent(awaitOneMinute); | ||
|
||
awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 2); | ||
|
||
with() | ||
.spec(webAdminAPI) | ||
.queryParam("processor", ProcessorConfiguration.STATE_TRANSPORT) | ||
.queryParam("action", "reprocess") | ||
.patch(MailRepositoriesRoutes.MAIL_REPOSITORIES | ||
+ "/" + URLEncoder.encode(CUSTOM_REPOSITORY, StandardCharsets.UTF_8.displayName()) | ||
+ "/mails") | ||
.jsonPath() | ||
.get("taskId"); | ||
|
||
imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT) | ||
.login(RECIPIENT, PASSWORD) | ||
.select(IMAPMessageReader.INBOX) | ||
.awaitMessage(awaitOneMinute) | ||
.hasMessageCount(2); | ||
awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 0); | ||
} | ||
|
||
@Test | ||
public void userShouldBeAbleToAccessReprocessedMail() throws Exception { | ||
messageSender.connect(LOCALHOST_IP, SMTP_PORT) | ||
.sendMessage(RECIPIENT, RECIPIENT) | ||
.awaitSent(awaitOneMinute) | ||
.sendMessage(RECIPIENT, RECIPIENT) | ||
.awaitSent(awaitOneMinute); | ||
|
||
awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 2); | ||
String key = probe.listMailKeys(CUSTOM_REPOSITORY).get(0); | ||
|
||
with() | ||
.spec(webAdminAPI) | ||
.queryParam("processor", ProcessorConfiguration.STATE_TRANSPORT) | ||
.queryParam("action", "reprocess") | ||
.patch(MailRepositoriesRoutes.MAIL_REPOSITORIES | ||
+ "/" + URLEncoder.encode(CUSTOM_REPOSITORY, StandardCharsets.UTF_8.displayName()) | ||
+ "/mails/" + key) | ||
.jsonPath() | ||
.get("taskId"); | ||
|
||
imapMessageReader.connect(LOCALHOST_IP, IMAP_PORT) | ||
.login(RECIPIENT, PASSWORD) | ||
.select(IMAPMessageReader.INBOX) | ||
.awaitMessage(awaitOneMinute) | ||
.hasMessageCount(1); | ||
awaitOneMinute.until(() -> probe.getRepositoryMailCount(CUSTOM_REPOSITORY) == 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters