JAMES-1877 Add tests for running RemoteDelivery
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9b59d55e Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9b59d55e Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9b59d55e Branch: refs/heads/master Commit: 9b59d55e0d21754d14e6e3da331404c7d0eb6197 Parents: dbeea26 Author: Benoit Tellier <btell...@linagora.com> Authored: Thu Dec 8 14:45:21 2016 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Tue Jan 10 15:12:52 2017 +0700 ---------------------------------------------------------------------- .../RemoteDeliveryRunningTest.java | 85 ++++++++++++++++++++ 1 file changed, 85 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/9b59d55e/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryRunningTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryRunningTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryRunningTest.java new file mode 100644 index 0000000..5c6abf7 --- /dev/null +++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryRunningTest.java @@ -0,0 +1,85 @@ +/**************************************************************** + * 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.remoteDelivery; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.apache.james.dnsservice.api.DNSService; +import org.apache.james.domainlist.api.DomainList; +import org.apache.james.metrics.api.MetricFactory; +import org.apache.james.queue.api.MailQueue; +import org.apache.james.queue.api.MailQueueFactory; +import org.apache.james.transport.mailets.RemoteDelivery; +import org.apache.mailet.base.test.FakeMailetConfig; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +public class RemoteDeliveryRunningTest { + + public static final String QUEUE_NAME = "queueName"; + private RemoteDelivery remoteDelivery; + private MailQueue mailQueue; + private CountDownLatch countDownLatch; + + @Before + public void setUp() throws Exception { + countDownLatch = new CountDownLatch(1); + MailQueueFactory mailQueueFactory = mock(MailQueueFactory.class); + remoteDelivery = new RemoteDelivery(mock(DNSService.class), mock(DomainList.class), mailQueueFactory, + mock(MetricFactory.class), RemoteDelivery.THREAD_STATE.START_THREADS); + + mailQueue = mock(MailQueue.class); + when(mailQueueFactory.getQueue(QUEUE_NAME)).thenReturn(mailQueue); + } + + @Test + public void remoteDeliveryShouldStart() throws Exception { + when(mailQueue.deQueue()).thenAnswer(new Answer<MailQueue.MailQueueItem>() { + @Override + public MailQueue.MailQueueItem answer(InvocationOnMock invocation) throws Throwable { + countDownLatch.countDown(); + Thread.sleep(TimeUnit.SECONDS.toMillis(20)); + return null; + } + }); + remoteDelivery.init(FakeMailetConfig.builder() + .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") + .setProperty(RemoteDeliveryConfiguration.OUTGOING, QUEUE_NAME) + .setProperty(RemoteDeliveryConfiguration.HELO_NAME, "Hello_name") + .build()); + + countDownLatch.await(); + verify(mailQueue).deQueue(); + } + + @After + public void tearDown() throws InterruptedException { + remoteDelivery.destroy(); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org