http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java deleted file mode 100644 index 934dd58..0000000 --- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryConfigurationTest.java +++ /dev/null @@ -1,940 +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.transport.mailets.remoteDelivery; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Properties; - -import org.apache.james.domainlist.api.DomainList; -import org.apache.mailet.base.test.FakeMailetConfig; -import org.assertj.core.data.MapEntry; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class RemoteDeliveryConfigurationTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void isDebugShouldBeFalseByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isFalse(); - } - - @Test - public void isDebugShouldBeTrueIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.DEBUG, "true") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isTrue(); - } - - @Test - public void isDebugShouldBeFalseIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.DEBUG, "false") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isFalse(); - } - - @Test - public void isDebugShouldBeFalseIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.DEBUG, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isDebug()).isFalse(); - } - - @Test - public void getSmtpTimeoutShouldReturnDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_SMTP_TIMEOUT); - } - - @Test - public void getSmtpTimeoutShouldReturnProvidedValue() { - int value = 150000; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.TIMEOUT, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout()) - .isEqualTo(value); - } - - @Test - public void getSmtpTimeoutShouldReturnDefaultIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.TIMEOUT, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_SMTP_TIMEOUT); - } - - @Test - public void getSmtpTimeoutShouldReturnProvidedValueWhenZero() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.TIMEOUT, "0") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout()) - .isEqualTo(0); - } - - @Test - public void getSmtpTimeoutShouldReturnProvidedValueWhenNegativeNumber() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.TIMEOUT, "-1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getSmtpTimeout()) - .isEqualTo(-1); - } - - @Test - public void getOutGoingQueueNameShouldReturnDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getOutGoingQueueName()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_OUTGOING_QUEUE_NAME); - } - - @Test - public void getOutGoingQueueNameShouldReturnProvidedValue() { - String value = "value"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.OUTGOING, value) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getOutGoingQueueName()) - .isEqualTo(value); - } - - @Test - public void getConnectionTimeoutShouldReturnDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_CONNECTION_TIMEOUT); - } - - @Test - public void getConnectionTimeoutShouldReturnProvidedValue() { - int value = 150000; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout()) - .isEqualTo(value); - } - - @Test - public void getConnectionTimeoutShouldReturnDefaultIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_CONNECTION_TIMEOUT); - } - - @Test - public void getConnectionTimeoutShouldReturnProvidedValueWhenZero() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, "0") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout()) - .isEqualTo(0); - } - - @Test - public void getConnectionTimeoutShouldReturnProvidedValueWhenNegativeNumber() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, "-1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getConnectionTimeout()) - .isEqualTo(-1); - } - - @Test - public void isSendPartialShouldBeFalseByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isFalse(); - } - - @Test - public void isSendPartialShouldBeTrueIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "true") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isTrue(); - } - - @Test - public void isSendPartialShouldBeFalseIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "false") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isFalse(); - } - - @Test - public void isSendPartialShouldBeFalseIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSendPartial()).isFalse(); - } - - @Test - public void getBounceProcessorShouldReturnNullByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBounceProcessor()) - .isNull(); - } - - @Test - public void getBounceProcessorShouldReturnProvidedValue() { - String value = "value"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.BOUNCE_PROCESSOR, value) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBounceProcessor()) - .isEqualTo(value); - } - - @Test - public void isStartTLSShouldBeFalseByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isFalse(); - } - - @Test - public void isStartTLSShouldBeTrueIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.START_TLS, "true") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isTrue(); - } - - @Test - public void isStartTLSShouldBeFalseIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.START_TLS, "false") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isFalse(); - } - - @Test - public void isStartTLSShouldBeFalseIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.START_TLS, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isStartTLS()).isFalse(); - } - - @Test - public void isSSLEnableShouldBeFalseByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isFalse(); - } - - @Test - public void isSSLEnableShouldBeTrueIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "true") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isTrue(); - } - - @Test - public void isSSLEnableShouldBeFalseIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "false") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isFalse(); - } - - @Test - public void isSSLEnableShouldBeFalseIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isSSLEnable()).isFalse(); - } - - @Test - public void isBindUsedShouldBeFalseByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.BIND, "127.0.0.1:25") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isBindUsed()).isTrue(); - } - - @Test - public void getBindAddressShouldBeNullByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBindAddress()).isNull(); - } - - @Test - public void getBindAddressShouldReturnProvidedValue() { - String value = "127.0.0.1:25"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.BIND, value) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getBindAddress()).isEqualTo(value); - } - - @Test - public void getDnsProblemRetryShouldReturnDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_DNS_RETRY_PROBLEM); - } - - @Test - public void getDnsProblemRetryShouldReturnProvidedValue() { - int value = 4; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry()) - .isEqualTo(value); - } - - @Test - public void constructorShouldThrowOnInvalidDnsRetries() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "invalid") - .build(); - - expectedException.expect(NumberFormatException.class); - - new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)); - } - - @Test - public void getDnsProblemRetryShouldReturnProvidedValueWhenZero() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "0") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry()) - .isEqualTo(0); - } - - @Test - public void getDnsProblemRetryShouldReturnProvidedValueWhenEmpty() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry()) - .isEqualTo(0); - } - - @Test - public void getDnsProblemRetryShouldReturnProvidedValueWhenNegativeNumber() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_DNS_PROBLEM_RETRIES, "-1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDnsProblemRetry()) - .isEqualTo(-1); - } - - @Test - public void constructorShouldThrowOnNonSpecifiedThreadCount() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .build(); - - expectedException.expect(NumberFormatException.class); - - new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getWorkersThreadCount(); - } - - @Test - public void getWorkersThreadCountShouldReturnProvidedValue() { - int value = 36; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getWorkersThreadCount()) - .isEqualTo(value); - } - - @Test - public void constructorShouldThrowOnInvalidThreadCount() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "invalid") - .build(); - - expectedException.expect(NumberFormatException.class); - - new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getWorkersThreadCount(); - } - - @Test - public void isUsePriorityShouldBeFalseByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isFalse(); - } - - @Test - public void isUsePriorityShouldBeTrueIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "true") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isTrue(); - } - - @Test - public void isUsePriorityShouldBeFalseIfSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "false") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isFalse(); - } - - @Test - public void isUsePriorityShouldBeFalseIfParsingException() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "invalid") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).isUsePriority()).isFalse(); - } - - @Test - public void getHeloNameProviderShouldCallDomainListByDefault() throws Exception { - DomainList domainList = mock(DomainList.class); - String value = "value"; - when(domainList.getDefaultDomain()).thenReturn(value); - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, domainList).getHeloNameProvider().getHeloName()) - .isEqualTo(value); - } - - @Test - public void getHeloNameProviderShouldTakeCareOfProvidedValue() { - String value = "value"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.HELO_NAME, value) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getHeloNameProvider().getHeloName()) - .isEqualTo(value); - } - - @Test - public void getJavaxAdditionalPropertiesShouldBeEmptyByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties()) - .isEmpty(); - } - - @Test - public void getJavaxAdditionalPropertiesShouldTakeOneEntryIntoAccount() { - String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1"; - String value1 = "value1"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(key1, value1) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties()) - .containsOnly(MapEntry.entry(key1, value1)); - } - - @Test - public void getJavaxAdditionalPropertiesShouldTakeTwoEntriesIntoAccount() { - String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1"; - String value1 = "value1"; - String key2 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property2"; - String value2 = "value2"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(key1, value1) - .setProperty(key2, value2) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties()) - .containsOnly(MapEntry.entry(key1, value1), MapEntry.entry(key2, value2)); - } - - @Test - public void constructorShouldThrowOnNullValueJavaxProperty() { - expectedException.expect(NullPointerException.class); - - String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(key1, null) - .build(); - - new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)); - } - - @Test - public void getJavaxAdditionalPropertiesShouldTakeOneEmptyEntryIntoAccount() { - String key1 = RemoteDeliveryConfiguration.JAVAX_PREFIX + "property1"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(key1, "") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getJavaxAdditionalProperties()) - .containsOnly(MapEntry.entry(key1, "")); - } - - @Test - public void getGatewayServerShouldBeNullByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer()).isEmpty(); - } - - @Test - public void getGatewayServerShouldReturnProvidedValue() { - String value = "127.0.0.1"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY, value) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer()) - .containsOnly(value); - } - - @Test - public void getGatewayServerShouldReturnProvidedValues() { - String value1 = "127.0.0.1"; - String value2 = "domain"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY, value1 + ',' + value2) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer()) - .containsOnly(value1, value2); - } - - @Test - public void getGatewayServerShouldReturnGatewayWithGatewayPort() { - String server = "127.0.0.1"; - String port = "2525"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY, server) - .setProperty(RemoteDeliveryConfiguration.GATEWAY_PORT, port) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer()) - .containsOnly(server + ':' + port); - } - - @Test - public void getGatewayServerShouldOnlyOverridePortsNotInitiallySet() { - String server1 = "127.0.0.1:23432"; - String server2 = "domain"; - String port = "2525"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY, server1 + ',' + server2) - .setProperty(RemoteDeliveryConfiguration.GATEWAY_PORT, port) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getGatewayServer()) - .containsOnly(server1, server2 + ':' + port); - } - - @Test - public void getAuthUserShouldBeNullByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isNull(); - } - - @Test - public void getAuthUserShouldBeNullWhenGatewayIsNotSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, "name") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isNull(); - } - - @Test - public void getAuthUserShouldReturnSpecifiedValueWhenGatewaySpecified() { - String value = "name"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value); - } - - @Test - public void getAuthUserShouldReturnSpecifiedEmptyValueWhenGatewaySpecified() { - String value = ""; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value); - } - - @Test - public void getAuthUserShouldReturnSpecifiedCompatibilityValueWhenGatewaySpecified() { - String value = "name"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME_COMPATIBILITY, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value); - } - - @Test - public void getAuthUserShouldReturnSpecifiedEmptyCompatibilityValueWhenGatewaySpecified() { - String value = ""; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME_COMPATIBILITY, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value); - } - - @Test - public void getAuthUserShouldReturnSpecifiedValueWhenValueAndCompatibilitySpecified() { - String value = "name"; - String compatibilityValue = "compatibilityValue"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME_COMPATIBILITY, compatibilityValue) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthUser()).isEqualTo(value); - } - - @Test - public void getAuthPassShouldBeNullByDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isNull(); - } - - @Test - public void getAuthPassShouldBeNullWhenGatewayIsNotSpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, "name") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isNull(); - } - - @Test - public void getAuthPassShouldReturnSpecifiedValueWhenGatewaySpecified() { - String value = "name"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isEqualTo(value); - } - - @Test - public void getAuthPassShouldReturnSpecifiedEmptyValueWhenGatewaySpecified() { - String value = ""; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, value) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "127.0.0.1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getAuthPass()).isEqualTo(value); - } - - @Test - public void getMaxRetriesShouldReturnProvidedValue() { - int value = 36; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_RETRIES, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()).isEqualTo(value); - } - - @Test - public void getMaxRetriesShouldReturnOneWhenZero() { - int value = 0; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_RETRIES, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()).isEqualTo(1); - } - - @Test - public void getMaxRetriesShouldReturnOneWhenNegativeNumber() { - int value = -1; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.MAX_RETRIES, String.valueOf(value)) - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()).isEqualTo(1); - } - - @Test - public void getMaxRetriesShouldReturnDefaultWhenNoySpecified() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getMaxRetries()) - .isEqualTo(RemoteDeliveryConfiguration.DEFAULT_MAX_RETRY); - } - - @Test - public void getDelayTimesShouldReturnDefault() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDelayTimes()) - .containsOnly(Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME, Delay.DEFAULT_DELAY_TIME); - } - - @Test - public void getDelayTimesShouldWorkWithDefaultConfiguration() { - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.DELAY_TIME, "5000, 100000, 500000") - .build(); - - assertThat(new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).getDelayTimes()) - .containsOnly(5000L, 100000L, 500000L); - } - - @Test - public void createFinalJavaxPropertiesShouldProvidePropertiesWithMinimalConfiguration() { - String helo = "domain.com"; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.HELO_NAME, helo) - .build(); - - Properties properties = new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).createFinalJavaxProperties(); - - - assertThat(properties) - .containsOnly(MapEntry.entry("mail.smtp.ssl.enable", "false"), - MapEntry.entry("mail.smtp.sendpartial", "false"), - MapEntry.entry("mail.smtp.allow8bitmime", "true"), - MapEntry.entry("mail.smtp.ehlo", "true"), - MapEntry.entry("mail.smtp.connectiontimeout", "60000"), - MapEntry.entry("mail.smtp.localhost", helo), - MapEntry.entry("mail.smtp.timeout", "180000"), - MapEntry.entry("mail.debug", "false"), - MapEntry.entry("mail.smtp.starttls.enable", "false")); - } - - @Test - public void createFinalJavaxPropertiesShouldProvidePropertiesWithFullConfigurationWithoutGateway() { - String helo = "domain.com"; - int connectionTimeout = 1856; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "true") - .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "true") - .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, String.valueOf(connectionTimeout)) - .setProperty(RemoteDeliveryConfiguration.START_TLS, "true") - .setProperty(RemoteDeliveryConfiguration.HELO_NAME, helo) - .build(); - - Properties properties = new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).createFinalJavaxProperties(); - - - assertThat(properties) - .containsOnly(MapEntry.entry("mail.smtp.ssl.enable", "true"), - MapEntry.entry("mail.smtp.sendpartial", "true"), - MapEntry.entry("mail.smtp.allow8bitmime", "true"), - MapEntry.entry("mail.smtp.ehlo", "true"), - MapEntry.entry("mail.smtp.connectiontimeout", String.valueOf(connectionTimeout)), - MapEntry.entry("mail.smtp.localhost", helo), - MapEntry.entry("mail.smtp.timeout", "180000"), - MapEntry.entry("mail.debug", "false"), - MapEntry.entry("mail.smtp.starttls.enable", "true")); - } - - @Test - public void createFinalJavaxPropertiesShouldProvidePropertiesWithFullConfigurationWithGateway() { - String helo = "domain.com"; - int connectionTimeout = 1856; - FakeMailetConfig mailetConfig = FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.SSL_ENABLE, "true") - .setProperty(RemoteDeliveryConfiguration.SENDPARTIAL, "true") - .setProperty(RemoteDeliveryConfiguration.CONNECTIONTIMEOUT, String.valueOf(connectionTimeout)) - .setProperty(RemoteDeliveryConfiguration.START_TLS, "true") - .setProperty(RemoteDeliveryConfiguration.HELO_NAME, helo) - .setProperty(RemoteDeliveryConfiguration.GATEWAY, "gateway.domain.com") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_USERNAME, "user") - .setProperty(RemoteDeliveryConfiguration.GATEWAY_PASSWORD, "password") - .build(); - - Properties properties = new RemoteDeliveryConfiguration(mailetConfig, mock(DomainList.class)).createFinalJavaxProperties(); - - - assertThat(properties) - .containsOnly(MapEntry.entry("mail.smtp.ssl.enable", "true"), - MapEntry.entry("mail.smtp.sendpartial", "true"), - MapEntry.entry("mail.smtp.allow8bitmime", "true"), - MapEntry.entry("mail.smtp.ehlo", "true"), - MapEntry.entry("mail.smtp.connectiontimeout", String.valueOf(connectionTimeout)), - MapEntry.entry("mail.smtp.localhost", helo), - MapEntry.entry("mail.smtp.timeout", "180000"), - MapEntry.entry("mail.debug", "false"), - MapEntry.entry("mail.smtp.starttls.enable", "true"), - MapEntry.entry("mail.smtp.auth", "true")); - } -}
http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/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 deleted file mode 100644 index 54b0ee0..0000000 --- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryRunningTest.java +++ /dev/null @@ -1,80 +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.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; - -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(invocation -> { - 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(); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryTest.java deleted file mode 100644 index 2216a65..0000000 --- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RemoteDeliveryTest.java +++ /dev/null @@ -1,207 +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.transport.mailets.remoteDelivery; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.mail.MessagingException; - -import org.apache.commons.lang.NotImplementedException; -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.MailPrioritySupport; -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.Mail; -import org.apache.mailet.base.MailAddressFixture; -import org.apache.mailet.base.test.FakeMail; -import org.apache.mailet.base.test.FakeMailetConfig; -import org.junit.Before; -import org.junit.Test; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -public class RemoteDeliveryTest { - - public static final String MAIL_NAME = "mail_name"; - - private static class FakeMailQueue implements MailQueue { - private final List<Mail> enqueuedMail; - - private FakeMailQueue() { - this.enqueuedMail = Lists.newArrayList(); - } - - @Override - public void enQueue(Mail mail, long delay, TimeUnit unit) throws MailQueueException { - enQueue(mail); - } - - @Override - public void enQueue(Mail mail) throws MailQueueException { - try { - enqueuedMail.add(FakeMail.fromMail(mail)); - } catch (MessagingException e) { - throw Throwables.propagate(e); - } - } - - @Override - public MailQueueItem deQueue() throws MailQueueException, InterruptedException { - throw new NotImplementedException(); - } - - public List<Mail> getEnqueuedMail() { - return ImmutableList.copyOf(enqueuedMail); - } - } - - private RemoteDelivery remoteDelivery; - private FakeMailQueue mailQueue; - - @Before - public void setUp() { - MailQueueFactory queueFactory = mock(MailQueueFactory.class); - mailQueue = new FakeMailQueue(); - when(queueFactory.getQueue(RemoteDeliveryConfiguration.OUTGOING)).thenReturn(mailQueue); - remoteDelivery = new RemoteDelivery(mock(DNSService.class), mock(DomainList.class), queueFactory, mock(MetricFactory.class), RemoteDelivery.THREAD_STATE.DO_NOT_START_THREADS); - } - - @Test - public void remoteDeliveryShouldAddEmailToSpool() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build()); - - Mail mail = FakeMail.builder().name(MAIL_NAME).recipients(MailAddressFixture.ANY_AT_JAMES).build(); - remoteDelivery.service(mail); - - assertThat(mailQueue.getEnqueuedMail()).containsOnly(FakeMail.builder() - .name(MAIL_NAME + RemoteDelivery.NAME_JUNCTION + MailAddressFixture.JAMES_APACHE_ORG) - .recipient(MailAddressFixture.ANY_AT_JAMES) - .build()); - } - - @Test - public void remoteDeliveryShouldSplitMailsByServerWhenNoGateway() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build()); - - Mail mail = FakeMail.builder() - .name(MAIL_NAME) - .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.ANY_AT_JAMES2, MailAddressFixture.OTHER_AT_JAMES) - .build(); - remoteDelivery.service(mail); - - assertThat(mailQueue.getEnqueuedMail()).containsOnly( - FakeMail.builder() - .name(MAIL_NAME + RemoteDelivery.NAME_JUNCTION + MailAddressFixture.JAMES_APACHE_ORG) - .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES) - .build(), - FakeMail.builder() - .name(MAIL_NAME + RemoteDelivery.NAME_JUNCTION + MailAddressFixture.JAMES2_APACHE_ORG) - .recipients(MailAddressFixture.ANY_AT_JAMES2) - .build()); - } - - @Test - public void remoteDeliveryShouldNotSplitMailsByServerWhenGateway() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY, MailAddressFixture.JAMES_LOCAL) - .build()); - - Mail mail = FakeMail.builder() - .name(MAIL_NAME) - .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.ANY_AT_JAMES2, MailAddressFixture.OTHER_AT_JAMES) - .build(); - remoteDelivery.service(mail); - - assertThat(mailQueue.getEnqueuedMail()).containsOnly( - FakeMail.builder() - .name(MAIL_NAME) - .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.ANY_AT_JAMES2, MailAddressFixture.OTHER_AT_JAMES) - .build()); - } - - @Test - public void remoteDeliveryShouldGhostMails() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build()); - - Mail mail = FakeMail.builder().name(MAIL_NAME).recipients(MailAddressFixture.ANY_AT_JAMES).build(); - remoteDelivery.service(mail); - - assertThat(mail.getState()).isEqualTo(Mail.GHOST); - } - - @Test - public void remoteDeliveryShouldAddPriorityIfSpecified() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.USE_PRIORITY, "true") - .build()); - - Mail mail = FakeMail.builder().name(MAIL_NAME).recipients(MailAddressFixture.ANY_AT_JAMES).build(); - remoteDelivery.service(mail); - - assertThat(mailQueue.getEnqueuedMail()).containsOnly(FakeMail.builder() - .name(MAIL_NAME + RemoteDelivery.NAME_JUNCTION + MailAddressFixture.JAMES_APACHE_ORG) - .attribute(MailPrioritySupport.MAIL_PRIORITY, MailPrioritySupport.HIGH_PRIORITY) - .recipient(MailAddressFixture.ANY_AT_JAMES) - .build()); - } - - @Test - public void remoteDeliveryShouldNotForwardMailsWithNoRecipients() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .build()); - - Mail mail = FakeMail.builder().name(MAIL_NAME).build(); - remoteDelivery.service(mail); - - assertThat(mailQueue.getEnqueuedMail()).isEmpty(); - } - - @Test - public void remoteDeliveryShouldNotForwardMailsWithNoRecipientsWithGateway() throws Exception { - remoteDelivery.init(FakeMailetConfig.builder() - .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") - .setProperty(RemoteDeliveryConfiguration.GATEWAY, MailAddressFixture.JAMES_LOCAL) - .build()); - - Mail mail = FakeMail.builder().name(MAIL_NAME).build(); - remoteDelivery.service(mail); - - assertThat(mailQueue.getEnqueuedMail()).isEmpty(); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.java deleted file mode 100644 index 4ea1640..0000000 --- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/RepeatTest.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.james.transport.mailets.remoteDelivery; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class RepeatTest { - - public static final String ELEMENT = "a"; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void repeatShouldThrowOnNegativeTimes() { - expectedException.expect(IllegalArgumentException.class); - - Repeat.repeat(new Object(), -1); - } - - @Test - public void repeatShouldReturnEmptyListOnZeroTimes() { - assertThat(Repeat.repeat(new Object(), 0)).isEmpty(); - } - - @Test - public void repeatShouldWorkWithOneElement() { - assertThat(Repeat.repeat(ELEMENT, 1)).containsExactly(ELEMENT); - } - - @Test - public void repeatShouldWorkWithTwoElements() { - assertThat(Repeat.repeat(ELEMENT, 2)).containsExactly(ELEMENT, ELEMENT); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortingHierarchicalCollections.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortingHierarchicalCollections.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortingHierarchicalCollections.java index ca82680..c4a48cf 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortingHierarchicalCollections.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SortingHierarchicalCollections.java @@ -30,20 +30,20 @@ import org.apache.james.jmap.utils.DependencyGraph.CycleDetectedException; import com.google.common.collect.Lists; -public class SortingHierarchicalCollections<T, Id> { +public class SortingHierarchicalCollections<T, IdT> { - private final Function<T, Id> index; - private final Function<T, Optional<Id>> parentId; + private final Function<T, IdT> index; + private final Function<T, Optional<IdT>> parentId; - public SortingHierarchicalCollections(Function<T, Id> index, - Function<T, Optional<Id>> parentId) { + public SortingHierarchicalCollections(Function<T, IdT> index, + Function<T, Optional<IdT>> parentId) { this.index = index; this.parentId = parentId; } public List<T> sortFromRootToLeaf(Collection<T> elements) throws CycleDetectedException { - Map<Id, T> mapOfElementsById = indexElementsById(elements); + Map<IdT, T> mapOfElementsById = indexElementsById(elements); DependencyGraph<T> graph = new DependencyGraph<>(m -> parentId.apply(m).map(mapOfElementsById::get)); @@ -53,7 +53,7 @@ public class SortingHierarchicalCollections<T, Id> { return graph.getBuildChain().collect(Collectors.toList()); } - private Map<Id, T> indexElementsById(Collection<T> elements) { + private Map<IdT, T> indexElementsById(Collection<T> elements) { return elements.stream() .collect(Collectors.toMap(index, Function.identity())); } http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java index 3c8e66d..c088087 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java @@ -36,7 +36,7 @@ public class UpdateMessagePatchTest { public ExpectedException expectedException = ExpectedException.none(); @Test - public void UnsetUpdatePatchShouldBeValid() { + public void unsetUpdatePatchShouldBeValid() { UpdateMessagePatch emptyPatch = UpdateMessagePatch.builder().build(); assertThat(emptyPatch.isValid()).isTrue(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/SortOrderTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/SortOrderTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/SortOrderTest.java index 2c42890..e8e660c 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/SortOrderTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/SortOrderTest.java @@ -45,12 +45,12 @@ public class SortOrderTest { @Test public void sortOrderShouldBeComparable() { TreeSet<SortOrder> sortedSet = new TreeSet<>(); - SortOrder _66 = SortOrder.of(66); - SortOrder _4 = SortOrder.of(4); - SortOrder _5 = SortOrder.of(5); - sortedSet.add(_66); - sortedSet.add(_4); - sortedSet.add(_5); - assertThat(sortedSet).containsExactly(_4, _5, _66); + SortOrder sixtySix = SortOrder.of(66); + SortOrder four = SortOrder.of(4); + SortOrder five = SortOrder.of(5); + sortedSet.add(sixtySix); + sortedSet.add(four); + sortedSet.add(five); + assertThat(sortedSet).containsExactly(four, five, sixtySix); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java ---------------------------------------------------------------------- diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java index 39323e6..bccdd57 100644 --- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java +++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java @@ -156,12 +156,12 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC private final ChannelGroupHandler groupHandler = new ChannelGroupHandler(group); private final HashedWheelTimer timer = new HashedWheelTimer(); - private final TimeUnit TIMEOUT_UNIT = TimeUnit.SECONDS; + private final TimeUnit timeoutUnit = TimeUnit.SECONDS; public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = pipeline(); pipeline.addLast(GROUP_HANDLER, groupHandler); - pipeline.addLast("idleHandler", new IdleStateHandler(timer, 0, 0, timeout, TIMEOUT_UNIT)); + pipeline.addLast("idleHandler", new IdleStateHandler(timer, 0, 0, timeout, timeoutUnit)); pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler()); pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(IMAPServer.this.connectionLimit)); http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java ---------------------------------------------------------------------- diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java index 66fce45..962d114 100644 --- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java +++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java @@ -21,6 +21,7 @@ package org.apache.james.lmtpserver; import java.util.LinkedList; import java.util.List; +import java.util.stream.Stream; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; @@ -53,48 +54,29 @@ public class CoreCmdHandlerLoader implements HandlersPackage { private final List<String> commands = new LinkedList<>(); public CoreCmdHandlerLoader() { - // Insert the base commands in the Map - String WELCOMEMESSAGEHANDLER = WelcomeMessageHandler.class.getName(); - commands.add(WELCOMEMESSAGEHANDLER); - String COMMANDDISPATCHER = CommandDispatcher.class.getName(); - commands.add(COMMANDDISPATCHER); - String DATACMDHANDLER = JamesDataCmdHandler.class.getName(); - commands.add(DATACMDHANDLER); - String EXPNCMDHANDLER = ExpnCmdHandler.class.getName(); - commands.add(EXPNCMDHANDLER); - String LHLOCMDHANDLER = LhloCmdHandler.class.getName(); - commands.add(LHLOCMDHANDLER); - String MAILCMDHANDLER = JamesMailCmdHandler.class.getName(); - commands.add(MAILCMDHANDLER); - String NOOPCMDHANDLER = NoopCmdHandler.class.getName(); - commands.add(NOOPCMDHANDLER); - String QUITCMDHANDLER = QuitCmdHandler.class.getName(); - commands.add(QUITCMDHANDLER); - String RCPTCMDHANDLER = JamesRcptCmdHandler.class.getName(); - commands.add(RCPTCMDHANDLER); - String VALIDRCPTHANDLER = ValidRcptHandler.class.getName(); - commands.add(VALIDRCPTHANDLER); - String RSETCMDHANDLER = RsetCmdHandler.class.getName(); - commands.add(RSETCMDHANDLER); - String VRFYCMDHANDLER = VrfyCmdHandler.class.getName(); - commands.add(VRFYCMDHANDLER); - String MAILSIZEHOOK = MailSizeEsmtpExtension.class.getName(); - commands.add(MAILSIZEHOOK); - String AUTHREQUIREDTORELAY = AuthRequiredToRelayRcptHook.class.getName(); - commands.add(AUTHREQUIREDTORELAY); - String POSTMASTERABUSEHOOK = PostmasterAbuseRcptHook.class.getName(); - commands.add(POSTMASTERABUSEHOOK); - String RECEIVEDDATALINEFILTER = ReceivedDataLineFilter.class.getName(); - commands.add(RECEIVEDDATALINEFILTER); - String DATALINEMESSAGEHOOKHANDLER = DataLineLMTPHandler.class.getName(); - commands.add(DATALINEMESSAGEHOOKHANDLER); - String DELIVERTORECIPIENTHANDLER = MailboxDeliverToRecipientHandler.class.getName(); - commands.add(DELIVERTORECIPIENTHANDLER); - // Add logging stuff - String COMMANDHANDLERRESULTLOGGER = CommandHandlerResultLogger.class.getName(); - commands.add(COMMANDHANDLERRESULTLOGGER); - String HOOKRESULTLOGGER = HookResultLogger.class.getName(); - commands.add(HOOKRESULTLOGGER); + Stream.of( + WelcomeMessageHandler.class, + CommandDispatcher.class, + JamesDataCmdHandler.class, + ExpnCmdHandler.class, + LhloCmdHandler.class, + JamesMailCmdHandler.class, + NoopCmdHandler.class, + QuitCmdHandler.class, + JamesRcptCmdHandler.class, + ValidRcptHandler.class, + RsetCmdHandler.class, + VrfyCmdHandler.class, + MailSizeEsmtpExtension.class, + AuthRequiredToRelayRcptHook.class, + PostmasterAbuseRcptHook.class, + ReceivedDataLineFilter.class, + DataLineLMTPHandler.class, + MailboxDeliverToRecipientHandler.class, + CommandHandlerResultLogger.class, + HookResultLogger.class) + .map(Class::getName) + .forEachOrdered(commands::add); } /** http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java index b03f36e..686919b 100644 --- a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java +++ b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java @@ -455,14 +455,14 @@ public class POP3ServerTest { assertEquals(msgCount, uidlEntries.length); assertEquals(msgCount, statInfo.number); - POP3Client m_pop3Protocol2 = new POP3Client(); - m_pop3Protocol2.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); - m_pop3Protocol2.login("foo2", "bar2"); - assertEquals(1, m_pop3Protocol2.getState()); - - POP3MessageInfo[] listEntries2 = m_pop3Protocol2.listMessages(); - POP3MessageInfo[] uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers(); - POP3MessageInfo statInfo2 = m_pop3Protocol2.status(); + POP3Client pop3Protocol2 = new POP3Client(); + pop3Protocol2.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); + pop3Protocol2.login("foo2", "bar2"); + assertEquals(1, pop3Protocol2.getState()); + + POP3MessageInfo[] listEntries2 = pop3Protocol2.listMessages(); + POP3MessageInfo[] uidlEntries2 = pop3Protocol2.listUniqueIdentifiers(); + POP3MessageInfo statInfo2 = pop3Protocol2.status(); assertEquals(msgCount, listEntries2.length); assertEquals(msgCount, uidlEntries2.length); assertEquals(msgCount, statInfo2.number); @@ -477,9 +477,9 @@ public class POP3ServerTest { // even after the message was deleted it should get displayed in the // second connection - listEntries2 = m_pop3Protocol2.listMessages(); - uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers(); - statInfo2 = m_pop3Protocol2.status(); + listEntries2 = pop3Protocol2.listMessages(); + uidlEntries2 = pop3Protocol2.listUniqueIdentifiers(); + statInfo2 = pop3Protocol2.status(); assertEquals(msgCount, listEntries2.length); assertEquals(msgCount, uidlEntries2.length); assertEquals(msgCount, statInfo2.number); @@ -489,19 +489,19 @@ public class POP3ServerTest { // even after the message was deleted and the session was quit it should // get displayed in the second connection - listEntries2 = m_pop3Protocol2.listMessages(); - uidlEntries2 = m_pop3Protocol2.listUniqueIdentifiers(); - statInfo2 = m_pop3Protocol2.status(); + listEntries2 = pop3Protocol2.listMessages(); + uidlEntries2 = pop3Protocol2.listUniqueIdentifiers(); + statInfo2 = pop3Protocol2.status(); assertEquals(msgCount, listEntries2.length); assertEquals(msgCount, uidlEntries2.length); assertEquals(msgCount, statInfo2.number); // This both should error and so return null - assertNull(m_pop3Protocol2.retrieveMessageTop(1, 100)); - assertNull(m_pop3Protocol2.retrieveMessage(1)); + assertNull(pop3Protocol2.retrieveMessageTop(1, 100)); + assertNull(pop3Protocol2.retrieveMessage(1)); - m_pop3Protocol2.sendCommand("quit"); - m_pop3Protocol2.disconnect(); + pop3Protocol2.sendCommand("quit"); + pop3Protocol2.disconnect(); mailboxManager.deleteMailbox(mailboxPath, session); http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java ---------------------------------------------------------------------- diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java index 1fe5a34..4d6376f 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java @@ -21,6 +21,7 @@ package org.apache.james.smtpserver; import java.util.LinkedList; import java.util.List; +import java.util.stream.Stream; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; @@ -52,63 +53,37 @@ public class CoreCmdHandlerLoader implements HandlersPackage { public CoreCmdHandlerLoader() { // Insert the base commands in the Map - String WELCOMEMESSAGEHANDLER = JamesWelcomeMessageHandler.class.getName(); - commands.add(WELCOMEMESSAGEHANDLER); - String COMMANDDISPATCHER = CommandDispatcher.class.getName(); - commands.add(COMMANDDISPATCHER); - String AUTHCMDHANDLER = AuthCmdHandler.class.getName(); - commands.add(AUTHCMDHANDLER); - String DATACMDHANDLER = JamesDataCmdHandler.class.getName(); - commands.add(DATACMDHANDLER); - String EHLOCMDHANDLER = EhloCmdHandler.class.getName(); - commands.add(EHLOCMDHANDLER); - String EXPNCMDHANDLER = ExpnCmdHandler.class.getName(); - commands.add(EXPNCMDHANDLER); - String HELOCMDHANDLER = HeloCmdHandler.class.getName(); - commands.add(HELOCMDHANDLER); - String HELPCMDHANDLER = HelpCmdHandler.class.getName(); - commands.add(HELPCMDHANDLER); - String MAILCMDHANDLER = JamesMailCmdHandler.class.getName(); - commands.add(MAILCMDHANDLER); - String NOOPCMDHANDLER = NoopCmdHandler.class.getName(); - commands.add(NOOPCMDHANDLER); - String QUITCMDHANDLER = QuitCmdHandler.class.getName(); - commands.add(QUITCMDHANDLER); - String RCPTCMDHANDLER = JamesRcptCmdHandler.class.getName(); - commands.add(RCPTCMDHANDLER); - String RSETCMDHANDLER = RsetCmdHandler.class.getName(); - commands.add(RSETCMDHANDLER); - String VRFYCMDHANDLER = VrfyCmdHandler.class.getName(); - commands.add(VRFYCMDHANDLER); - String MAILSIZEHOOK = MailSizeEsmtpExtension.class.getName(); - commands.add(MAILSIZEHOOK); - String USERSREPOSITORYAUTHHANDLER = UsersRepositoryAuthHook.class.getName(); - commands.add(USERSREPOSITORYAUTHHANDLER); - String AUTHREQUIREDTORELAY = AuthRequiredToRelayRcptHook.class.getName(); - commands.add(AUTHREQUIREDTORELAY); - String SENDERAUTHIDENTITYVERIFICATION = SenderAuthIdentifyVerificationRcptHook.class.getName(); - commands.add(SENDERAUTHIDENTITYVERIFICATION); - String POSTMASTERABUSEHOOK = PostmasterAbuseRcptHook.class.getName(); - commands.add(POSTMASTERABUSEHOOK); - String RECEIVEDDATALINEFILTER = ReceivedDataLineFilter.class.getName(); - commands.add(RECEIVEDDATALINEFILTER); - String DATALINEMESSAGEHOOKHANDLER = DataLineJamesMessageHookHandler.class.getName(); - commands.add(DATALINEMESSAGEHOOKHANDLER); - String STARTTLSHANDLER = StartTlsCmdHandler.class.getName(); - commands.add(STARTTLSHANDLER); - // Add the default messageHooks - String ADDDEFAULTATTRIBUTESHANDLER = AddDefaultAttributesMessageHook.class.getName(); - commands.add(ADDDEFAULTATTRIBUTESHANDLER); - String SENDMAILHANDLER = SendMailHandler.class.getName(); - commands.add(SENDMAILHANDLER); - String UNKNOWNCMDHANDLER = UnknownCmdHandler.class.getName(); - commands.add(UNKNOWNCMDHANDLER); - - // Add logging stuff - String COMMANDHANDLERRESULTLOGGER = CommandHandlerResultLogger.class.getName(); - commands.add(COMMANDHANDLERRESULTLOGGER); - String HOOKRESULTLOGGER = HookResultLogger.class.getName(); - commands.add(HOOKRESULTLOGGER); + Stream.of( + JamesWelcomeMessageHandler.class, + CommandDispatcher.class, + AuthCmdHandler.class, + JamesDataCmdHandler.class, + EhloCmdHandler.class, + ExpnCmdHandler.class, + HeloCmdHandler.class, + HelpCmdHandler.class, + JamesMailCmdHandler.class, + NoopCmdHandler.class, + QuitCmdHandler.class, + JamesRcptCmdHandler.class, + RsetCmdHandler.class, + VrfyCmdHandler.class, + MailSizeEsmtpExtension.class, + UsersRepositoryAuthHook.class, + AuthRequiredToRelayRcptHook.class, + SenderAuthIdentifyVerificationRcptHook.class, + PostmasterAbuseRcptHook.class, + ReceivedDataLineFilter.class, + DataLineJamesMessageHookHandler.class, + StartTlsCmdHandler.class, + AddDefaultAttributesMessageHook.class, + SendMailHandler.class, + UnknownCmdHandler.class, + // Add logging stuff + CommandHandlerResultLogger.class, + HookResultLogger.class) + .map(Class::getName) + .forEachOrdered(commands::add); } /** http://git-wip-us.apache.org/repos/asf/james-project/blob/52c18ef6/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPTestConfiguration.java ---------------------------------------------------------------------- diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPTestConfiguration.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPTestConfiguration.java index 0f61b5a..565d550 100644 --- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPTestConfiguration.java +++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPTestConfiguration.java @@ -28,105 +28,105 @@ import org.apache.james.smtpserver.fastfail.ValidSenderDomainHandler; public class SMTPTestConfiguration extends DefaultConfigurationBuilder { - private int m_maxMessageSizeKB = 0; - private String m_authorizedAddresses = "127.0.0.0/8"; - private String m_authorizingMode = "false"; - private boolean m_verifyIdentity = false; - private Integer m_connectionLimit = null; - private Integer m_connectionBacklog = null; - private boolean m_heloResolv = false; - private boolean m_ehloResolv = false; - private boolean m_senderDomainResolv = false; - private boolean m_checkAuthNetworks = false; - private boolean m_heloEhloEnforcement = true; - private boolean m_reverseEqualsHelo = false; - private boolean m_reverseEqualsEhlo = false; - private int m_maxRcpt = 0; - private boolean m_useRBL = false; - private boolean m_addressBracketsEnforcement = true; - private boolean m_startTLS = false; + private int maxMessageSizeKB = 0; + private String authorizedAddresses = "127.0.0.0/8"; + private String authorizingMode = "false"; + private boolean verifyIdentity = false; + private Integer connectionLimit = null; + private Integer connectionBacklog = null; + private boolean heloResolv = false; + private boolean ehloResolv = false; + private boolean senderDomainResolv = false; + private boolean checkAuthNetworks = false; + private boolean heloEhloEnforcement = true; + private boolean reverseEqualsHelo = false; + private boolean reverseEqualsEhlo = false; + private int maxRcpt = 0; + private boolean useRBL = false; + private boolean addressBracketsEnforcement = true; + private boolean startTLS = false; public void setCheckAuthNetworks(boolean checkAuth) { - m_checkAuthNetworks = checkAuth; + checkAuthNetworks = checkAuth; } public void setMaxMessageSize(int kilobytes) { - m_maxMessageSizeKB = kilobytes; + maxMessageSizeKB = kilobytes; } public int getMaxMessageSize() { - return m_maxMessageSizeKB; + return maxMessageSizeKB; } public String getAuthorizedAddresses() { - return m_authorizedAddresses; + return authorizedAddresses; } public void setAuthorizedAddresses(String authorizedAddresses) { - m_authorizedAddresses = authorizedAddresses; + this.authorizedAddresses = authorizedAddresses; } public void setAuthorizingNotRequired() { - m_authorizingMode = "false"; - m_verifyIdentity = false; + authorizingMode = "false"; + verifyIdentity = false; } public void setAuthorizingRequired() { - m_authorizingMode = "true"; - m_verifyIdentity = true; + authorizingMode = "true"; + verifyIdentity = true; } public void setAuthorizingAnnounce() { - m_authorizingMode = "announce"; - m_verifyIdentity = true; + authorizingMode = "announce"; + verifyIdentity = true; } public void setConnectionLimit(int iConnectionLimit) { - m_connectionLimit = iConnectionLimit; + connectionLimit = iConnectionLimit; } public void setConnectionBacklog(int iConnectionBacklog) { - m_connectionBacklog = iConnectionBacklog; + connectionBacklog = iConnectionBacklog; } public void setHeloResolv() { - m_heloResolv = true; + heloResolv = true; } public void setEhloResolv() { - m_ehloResolv = true; + ehloResolv = true; } public void setReverseEqualsHelo() { - m_reverseEqualsHelo = true; + reverseEqualsHelo = true; } public void setReverseEqualsEhlo() { - m_reverseEqualsEhlo = true; + reverseEqualsEhlo = true; } public void setSenderDomainResolv() { - m_senderDomainResolv = true; + senderDomainResolv = true; } public void setMaxRcpt(int maxRcpt) { - m_maxRcpt = maxRcpt; + this.maxRcpt = maxRcpt; } public void setHeloEhloEnforcement(boolean heloEhloEnforcement) { - m_heloEhloEnforcement = heloEhloEnforcement; + this.heloEhloEnforcement = heloEhloEnforcement; } public void useRBL(boolean useRBL) { - m_useRBL = useRBL; + this.useRBL = useRBL; } public void setAddressBracketsEnforcement(boolean addressBracketsEnforcement) { - this.m_addressBracketsEnforcement = addressBracketsEnforcement; + this.addressBracketsEnforcement = addressBracketsEnforcement; } public void setStartTLS() { - m_startTLS = true; + startTLS = true; } public void init() { @@ -134,49 +134,49 @@ public class SMTPTestConfiguration extends DefaultConfigurationBuilder { addProperty("[@enabled]", true); addProperty("bind", "127.0.0.1:0"); - if (m_connectionLimit != null) { - addProperty("connectionLimit", "" + m_connectionLimit); + if (connectionLimit != null) { + addProperty("connectionLimit", "" + connectionLimit); } - if (m_connectionBacklog != null) { - addProperty("connectionBacklog", "" + m_connectionBacklog); + if (connectionBacklog != null) { + addProperty("connectionBacklog", "" + connectionBacklog); } addProperty("helloName", "myMailServer"); addProperty("connectiontimeout", 360000); - addProperty("authorizedAddresses", m_authorizedAddresses); - addProperty("maxmessagesize", m_maxMessageSizeKB); - addProperty("authRequired", m_authorizingMode); - addProperty("heloEhloEnforcement", m_heloEhloEnforcement); - addProperty("addressBracketsEnforcement", m_addressBracketsEnforcement); + addProperty("authorizedAddresses", authorizedAddresses); + addProperty("maxmessagesize", maxMessageSizeKB); + addProperty("authRequired", authorizingMode); + addProperty("heloEhloEnforcement", heloEhloEnforcement); + addProperty("addressBracketsEnforcement", addressBracketsEnforcement); - addProperty("tls.[@startTLS]", m_startTLS); + addProperty("tls.[@startTLS]", startTLS); addProperty("tls.keystore", "file://conf/test_keystore"); addProperty("tls.secret", "jamestest"); - if (m_verifyIdentity) { - addProperty("verifyIdentity", m_verifyIdentity); + if (verifyIdentity) { + addProperty("verifyIdentity", verifyIdentity); } // add the rbl handler - if (m_useRBL) { + if (useRBL) { addProperty("handlerchain.handler.[@class]", DNSRBLHandler.class.getName()); addProperty("handlerchain.handler.rblservers.blacklist", "bl.spamcop.net."); } - if (m_heloResolv || m_ehloResolv) { + if (heloResolv || ehloResolv) { addProperty("handlerchain.handler.[@class]", ResolvableEhloHeloHandler.class.getName()); - addProperty("handlerchain.handler.checkAuthNetworks", m_checkAuthNetworks); + addProperty("handlerchain.handler.checkAuthNetworks", checkAuthNetworks); } - if (m_reverseEqualsHelo || m_reverseEqualsEhlo) { + if (reverseEqualsHelo || reverseEqualsEhlo) { addProperty("handlerchain.handler.[@class]", ReverseEqualsEhloHeloHandler.class.getName()); - addProperty("handlerchain.handler.checkAuthNetworks", m_checkAuthNetworks); + addProperty("handlerchain.handler.checkAuthNetworks", checkAuthNetworks); } - if (m_senderDomainResolv) { + if (senderDomainResolv) { addProperty("handlerchain.handler.[@class]", ValidSenderDomainHandler.class.getName()); - addProperty("handlerchain.handler.checkAuthNetworks", m_checkAuthNetworks); + addProperty("handlerchain.handler.checkAuthNetworks", checkAuthNetworks); } - if (m_maxRcpt > 0) { + if (maxRcpt > 0) { addProperty("handlerchain.handler.[@class]", MaxRcptHandler.class.getName()); - addProperty("handlerchain.handler.maxRcpt", m_maxRcpt); + addProperty("handlerchain.handler.maxRcpt", maxRcpt); } addProperty("handlerchain.[@coreHandlersPackage]", CoreCmdHandlerLoader.class.getName()); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
