Skip to content

Commit

Permalink
JAMES-2267 Factorize ConditionFactory (awaitability) for mailet integ…
Browse files Browse the repository at this point in the history
…ration tests
  • Loading branch information
chibenwa committed Jan 5, 2018
1 parent bb56d23 commit fb6e2f0
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 172 deletions.
Expand Up @@ -19,6 +19,8 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;

import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe; import org.apache.james.probe.DataProbe;
Expand All @@ -32,9 +34,7 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class AddDeliveredToHeaderTest { public class AddDeliveredToHeaderTest {


Expand All @@ -48,18 +48,10 @@ public class AddDeliveredToHeaderTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;


@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
jamesServer = TemporaryJamesServer.builder().build(temporaryFolder); jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with()
.pollInterval(slowPacedPollInterval)
.and()
.with()
.pollDelay(slowPacedPollInterval)
.await();
} }


@After @After
Expand Down
Expand Up @@ -19,6 +19,8 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;

import org.apache.james.MemoryJamesServerMain; import org.apache.james.MemoryJamesServerMain;
import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailets.configuration.CommonProcessors; import org.apache.james.mailets.configuration.CommonProcessors;
Expand All @@ -41,14 +43,11 @@
import org.apache.james.utils.IMAPMessageReader; import org.apache.james.utils.IMAPMessageReader;
import org.apache.james.utils.SMTPMessageSender; import org.apache.james.utils.SMTPMessageSender;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class BounceIntegrationTest { public class BounceIntegrationTest {
private static final String LOCALHOST_IP = "127.0.0.1"; private static final String LOCALHOST_IP = "127.0.0.1";
Expand All @@ -65,21 +64,8 @@ public class BounceIntegrationTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;
private DataProbe dataProbe; private DataProbe dataProbe;



@Before
public void setup() throws Exception {
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with()
.pollInterval(slowPacedPollInterval)
.and()
.with()
.pollDelay(slowPacedPollInterval)
.await();
}

@After @After
public void tearDown() { public void tearDown() {
jamesServer.shutdown(); jamesServer.shutdown();
Expand Down
Expand Up @@ -19,6 +19,8 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;

import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe; import org.apache.james.probe.DataProbe;
Expand All @@ -31,9 +33,7 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class CommonMailetConfigurationTest { public class CommonMailetConfigurationTest {


Expand All @@ -47,13 +47,10 @@ public class CommonMailetConfigurationTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;


@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
jamesServer = TemporaryJamesServer.builder().build(temporaryFolder); jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await();
} }


@After @After
Expand Down
Expand Up @@ -24,6 +24,7 @@
import static com.jayway.restassured.config.RestAssuredConfig.newConfig; import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
import static org.apache.james.MemoryJamesServerMain.SMTP_AND_IMAP_MODULE; import static org.apache.james.MemoryJamesServerMain.SMTP_AND_IMAP_MODULE;
import static org.apache.james.MemoryJamesServerMain.SMTP_ONLY_MODULE; import static org.apache.james.MemoryJamesServerMain.SMTP_ONLY_MODULE;
import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;


Expand Down Expand Up @@ -58,9 +59,7 @@
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.testcontainers.containers.wait.HostPortWaitStrategy; import org.testcontainers.containers.wait.HostPortWaitStrategy;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;
import com.jayway.restassured.RestAssured; import com.jayway.restassured.RestAssured;
import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.http.ContentType; import com.jayway.restassured.http.ContentType;
Expand Down Expand Up @@ -90,19 +89,10 @@ public class GatewayRemoteDeliveryIntegrationTest {
public final RuleChain chain = RuleChain.outerRule(smtpFolder).around(fakeSmtp); public final RuleChain chain = RuleChain.outerRule(smtpFolder).around(fakeSmtp);


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;
private DataProbe dataProbe; private DataProbe dataProbe;


@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with()
.pollInterval(slowPacedPollInterval)
.and()
.with()
.pollDelay(slowPacedPollInterval)
.await();

calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> fakeSmtp.tryConnect(25)); calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> fakeSmtp.tryConnect(25));


RestAssured.requestSpecification = new RequestSpecBuilder() RestAssured.requestSpecification = new RequestSpecBuilder()
Expand Down
Expand Up @@ -19,6 +19,7 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;


import org.apache.james.MemoryJamesServerMain; import org.apache.james.MemoryJamesServerMain;
Expand All @@ -38,14 +39,11 @@
import org.apache.james.utils.MailRepositoryProbeImpl; import org.apache.james.utils.MailRepositoryProbeImpl;
import org.apache.james.utils.SMTPMessageSender; import org.apache.james.utils.SMTPMessageSender;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class NetworkMatcherIntegrationTest { public class NetworkMatcherIntegrationTest {
private static final String LOCALHOST_IP = "127.0.0.1"; private static final String LOCALHOST_IP = "127.0.0.1";
Expand All @@ -61,18 +59,6 @@ public class NetworkMatcherIntegrationTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;

@Before
public void setup() throws Exception {
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with()
.pollInterval(slowPacedPollInterval)
.and()
.with()
.pollDelay(slowPacedPollInterval)
.await();
}


private TemporaryJamesServer createJamesServerWithRootProcessor(ProcessorConfiguration.Builder rootProcessor) throws Exception { private TemporaryJamesServer createJamesServerWithRootProcessor(ProcessorConfiguration.Builder rootProcessor) throws Exception {
TemporaryJamesServer temporaryJamesServer = TemporaryJamesServer.builder() TemporaryJamesServer temporaryJamesServer = TemporaryJamesServer.builder()
Expand Down
Expand Up @@ -19,6 +19,8 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;

import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.modules.MailboxProbeImpl;
import org.apache.james.probe.DataProbe; import org.apache.james.probe.DataProbe;
Expand All @@ -31,9 +33,7 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class RecipientRewriteTableIntegrationTest { public class RecipientRewriteTableIntegrationTest {
private static final String LOCALHOST_IP = "127.0.0.1"; private static final String LOCALHOST_IP = "127.0.0.1";
Expand All @@ -56,15 +56,12 @@ public class RecipientRewriteTableIntegrationTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;
private DataProbe dataProbe; private DataProbe dataProbe;




@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
jamesServer = TemporaryJamesServer.builder().build(temporaryFolder); jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await();
dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe = jamesServer.getProbe(DataProbeImpl.class);


dataProbe.addDomain(JAMES_APACHE_ORG); dataProbe.addDomain(JAMES_APACHE_ORG);
Expand Down
Expand Up @@ -19,6 +19,8 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;

import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.store.probe.MailboxProbe; import org.apache.james.mailbox.store.probe.MailboxProbe;
import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.modules.MailboxProbeImpl;
Expand All @@ -33,9 +35,7 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class SieveDelivery { public class SieveDelivery {


Expand All @@ -49,13 +49,10 @@ public class SieveDelivery {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;


@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
jamesServer = TemporaryJamesServer.builder().build(temporaryFolder); jamesServer = TemporaryJamesServer.builder().build(temporaryFolder);
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await();
} }


@After @After
Expand Down
Expand Up @@ -19,6 +19,7 @@


package org.apache.james.mailets; package org.apache.james.mailets;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;


import org.apache.james.MemoryJamesServerMain; import org.apache.james.MemoryJamesServerMain;
Expand All @@ -42,9 +43,7 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class SmtpAuthIntegrationTest { public class SmtpAuthIntegrationTest {
private static final String LOCALHOST_IP = "127.0.0.1"; private static final String LOCALHOST_IP = "127.0.0.1";
Expand All @@ -61,7 +60,6 @@ public class SmtpAuthIntegrationTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;


@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
Expand Down Expand Up @@ -91,14 +89,6 @@ public void setup() throws Exception {
DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class); DataProbe dataProbe = jamesServer.getProbe(DataProbeImpl.class);
dataProbe.addDomain(JAMES_APACHE_ORG); dataProbe.addDomain(JAMES_APACHE_ORG);
dataProbe.addUser(FROM, PASSWORD); dataProbe.addUser(FROM, PASSWORD);

Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with()
.pollInterval(slowPacedPollInterval)
.and()
.with()
.pollDelay(slowPacedPollInterval)
.await();
} }


private ProcessorConfiguration deliverOnlyTransport() { private ProcessorConfiguration deliverOnlyTransport() {
Expand Down
@@ -0,0 +1,34 @@
/****************************************************************
* 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.configuration;

import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;

public class AwaitUtils {
public static Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
public static ConditionFactory calmlyAwait = Awaitility.with()
.pollInterval(slowPacedPollInterval)
.and()
.with()
.pollDelay(slowPacedPollInterval)
.await();
}
Expand Up @@ -19,6 +19,7 @@


package org.apache.james.mailets.crypto; package org.apache.james.mailets.crypto;


import static org.apache.james.mailets.configuration.AwaitUtils.calmlyAwait;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;


import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -47,9 +48,7 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import com.jayway.awaitility.Awaitility;
import com.jayway.awaitility.Duration; import com.jayway.awaitility.Duration;
import com.jayway.awaitility.core.ConditionFactory;


public class SMIMEDecryptIntegrationTest { public class SMIMEDecryptIntegrationTest {
private static final ZonedDateTime DATE_2015 = ZonedDateTime.parse("2015-10-15T14:10:00Z"); private static final ZonedDateTime DATE_2015 = ZonedDateTime.parse("2015-10-15T14:10:00Z");
Expand All @@ -65,7 +64,6 @@ public class SMIMEDecryptIntegrationTest {
public TemporaryFolder temporaryFolder = new TemporaryFolder(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


private TemporaryJamesServer jamesServer; private TemporaryJamesServer jamesServer;
private ConditionFactory calmlyAwait;


@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
Expand All @@ -92,8 +90,6 @@ public void setup() throws Exception {
.withOverrides(binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(() -> DATE_2015)) .withOverrides(binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(() -> DATE_2015))
.withMailetContainer(mailetContainer) .withMailetContainer(mailetContainer)
.build(temporaryFolder); .build(temporaryFolder);
Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await();


DataProbeImpl serverProbe = jamesServer.getProbe(DataProbeImpl.class); DataProbeImpl serverProbe = jamesServer.getProbe(DataProbeImpl.class);
serverProbe.addDomain(DEFAULT_DOMAIN); serverProbe.addDomain(DEFAULT_DOMAIN);
Expand Down

0 comments on commit fb6e2f0

Please sign in to comment.