You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/08/26 11:38:23 UTC
[james-project] branch master updated (863ef50 -> d6ad1d2)
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.
from 863ef50 JAMES-2858 Fix plugin cannot found issue maven-mailetdocs-plugin -> mailetdocs-maven-plugin
new 3c51db2 JAMES-2178 Reindent Upload requests in JMAP integration tests
new c4543b5 JAMES-2178 Decrease size of request for upload authentication
new f71cc86 JAMES-2864 Operator POJO for matching SMTP client lines
new 0b62377 JAMES-2864 Condition POJO for matching SMTP lines
new 62c2963 JAMES-2864 Response POJO for SMTP server
new d48ece8 JAMES-2864 MockSMTPBehavior POJO for Mock SMTP server
new 94ebf32 JAMES-2864 equals % hashCode overriding
new 382dfac JAMES-2864 Mail POJO for the Mock SMTP server
new be8a19e JAMES-2864 Fluent Operators
new 84c6ceb JAMES-2864 SMTPStatusCode contains all valid SMTP codes
new d6ad1d2 JAMES-2864 Replace Optional<Condition> by Condition with MATCH_ALL capability
The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../mock-smtp-server}/pom.xml | 34 +++---
.../apache/james/mock/smtp/server/Condition.java | 46 ++++----
.../org/apache/james/mock/smtp/server/Mail.java | 102 +++++++++++++++++
.../james/mock/smtp/server/MockSMTPBehavior.java | 115 ++++++++++++++++++++
.../apache/james/mock/smtp/server/Operator.java | 25 +++--
.../apache/james/mock/smtp/server/Response.java | 110 +++++++++++++++++++
.../apache/james/mock/smtp/server/SMTPCommand.java | 21 ++--
.../james/mock/smtp/server/ConditionTest.java | 63 ++++++-----
.../apache/james/mock/smtp/server/MailTest.java | 89 +++++++++++++++
.../mock/smtp/server/MockSMTPBehaviorTest.java | 98 +++++++++++++++++
.../james/mock/smtp/server/OperatorTest.java | 121 +++++++++++++++++++++
.../james/mock/smtp/server/ResponseTest.java | 47 ++++----
server/pom.xml | 1 +
.../integration/cucumber/UploadStepdefs.java | 18 ++-
14 files changed, 773 insertions(+), 117 deletions(-)
copy server/{blob/blob-export-api => mailet/mock-smtp-server}/pom.xml (77%)
copy mailbox/plugin/quota-search/src/main/java/org/apache/james/quota/search/Offset.java => server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java (62%)
create mode 100644 server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java
create mode 100644 server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java
copy mailbox/api/src/main/java/org/apache/james/mailbox/exception/SubscriptionException.java => server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java (74%)
create mode 100644 server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
copy backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/AliasNameTest.java => server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPCommand.java (78%)
copy mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/RetentionConfigurationTest.java => server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java (51%)
create mode 100644 server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java
create mode 100644 server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
create mode 100644 server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java
copy mailbox/plugin/quota-search/src/test/java/org/apache/james/quota/search/LimitTest.java => server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java (55%)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 02/11: JAMES-2178 Decrease size of request for
upload authentication
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit c4543b58bb085562fb8f37add4917cb50c902dd6
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Aug 26 15:06:11 2019 +0700
JAMES-2178 Decrease size of request for upload authentication
Otherwize James throws a 401 and closes the connection before the client finished streaming the content, resulting in a Connection reset error
---
.../apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
index e1a1ab1..32454cc 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
@@ -55,6 +55,7 @@ import cucumber.runtime.java.guice.ScenarioScoped;
@ScenarioScoped
public class UploadStepdefs {
+ private static final int _24K = 24 * 1024;
private static final int _1M = 1024 * 1024;
private static final int _10M = 10 * _1M;
@@ -118,7 +119,7 @@ public class UploadStepdefs {
@When("^someone upload a content without authentification$")
public void userUploadContentWithoutAuthentification() throws Throwable {
Request request = Request.Post(uploadUri)
- .bodyStream(new BufferedInputStream(new ZeroedInputStream(_1M), _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
+ .bodyStream(new BufferedInputStream(new ZeroedInputStream(_24K), _24K), org.apache.http.entity.ContentType.DEFAULT_BINARY);
response = Executor.newInstance(newClient())
.execute(request)
.returnResponse();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 11/11: JAMES-2864 Replace Optional by
Condition with MATCH_ALL capability
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d6ad1d251fba90442c28a518193b2697cc04ad93
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Aug 22 15:43:37 2019 +0700
JAMES-2864 Replace Optional<Condition> by Condition with MATCH_ALL capability
---
.../apache/james/mock/smtp/server/Condition.java | 3 +++
.../org/apache/james/mock/smtp/server/Operator.java | 1 +
.../james/mock/smtp/server/ConditionTest.java | 21 +++++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
index 2fde09a..422eea7 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
@@ -24,6 +24,9 @@ import java.util.Objects;
import com.google.common.base.Preconditions;
class Condition {
+
+ static final Condition MATCH_ALL = new Condition(Operator.MATCH_ALL, "any");
+
private final Operator operator;
private final String matchingValue;
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
index 992343f..26947c0 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
@@ -32,6 +32,7 @@ public interface Operator {
}
Operator CONTAINS = actual -> expected -> () -> actual.contains(expected);
+ Operator MATCH_ALL = actual -> expected -> () -> true;
Expected actual(String actual);
}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
index dff65dc..e5fe70a 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
@@ -68,4 +68,25 @@ class ConditionTest {
assertThatThrownBy(() -> condition.matches(null))
.isInstanceOf(NullPointerException.class);
}
+
+ @Test
+ void matchAllShouldReturnTrue() {
+ assertThat(Condition.MATCH_ALL
+ .matches("this contains another string"))
+ .isTrue();
+ }
+
+ @Test
+ void matchAllShouldReturnTrueEvenWhenLineIsNull() {
+ assertThat(Condition.MATCH_ALL
+ .matches(null))
+ .isTrue();
+ }
+
+ @Test
+ void matchAllShouldReturnTrueEvenWhenLineIsEmpty() {
+ assertThat(Condition.MATCH_ALL
+ .matches(""))
+ .isTrue();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 03/11: JAMES-2864 Operator POJO for matching SMTP
client lines
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit f71cc86ab8f1519de525d2c1e15822311255c1c8
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Aug 21 10:03:30 2019 +0700
JAMES-2864 Operator POJO for matching SMTP client lines
---
server/mailet/mock-smtp-server/pom.xml | 51 ++++++++++++
.../apache/james/mock/smtp/server/Operator.java | 26 ++++++
.../james/mock/smtp/server/OperatorTest.java | 92 ++++++++++++++++++++++
server/pom.xml | 1 +
4 files changed, 170 insertions(+)
diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml
new file mode 100644
index 0000000..c532536
--- /dev/null
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server</artifactId>
+ <version>3.4.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>mock-smtp-server</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Apache James :: Server :: Mailet :: Mock SMTP Server</name>
+ <description>
+ Provide a standalone mock SMTP server that could be configured over HTTP.
+ Dockerized it can be used for advanced error testing for SMTP clients.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
new file mode 100644
index 0000000..fa81b3f
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+public interface Operator {
+ Operator CONTAINS = String::contains;
+
+ boolean matches(String testedValue, String referenceValue);
+}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java
new file mode 100644
index 0000000..aa6421a
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+class OperatorTest {
+
+ @Nested
+ class ContainsTest {
+ @Test
+ void containsShouldReturnTrueWhenTestedValueContainsReferenceValue() {
+ assertThat(Operator.CONTAINS.matches("this contains matchme string", "matchme"))
+ .isTrue();
+ }
+
+ @Test
+ void containsShouldReturnTrueWhenBothValuesAreEqual() {
+ assertThat(Operator.CONTAINS.matches("matchme", "matchme"))
+ .isTrue();
+ }
+
+ @Test
+ void containsShouldReturnFalseWhenTestedValueDoesNotContainReferenceValue() {
+ assertThat(Operator.CONTAINS.matches("this contains an other string", "matchme"))
+ .isFalse();
+ }
+
+ @Test
+ void containsShouldReturnFalseWhenReferenceValueContainsTestedValue() {
+ assertThat(Operator.CONTAINS.matches("matchme", "this contains matchme"))
+ .isFalse();
+ }
+
+ @Test
+ void containsShouldBeCaseSensitive() {
+ assertThat(Operator.CONTAINS.matches("this contains matchme string", "Matchme"))
+ .isFalse();
+ }
+
+ @Test
+ void containsShouldThrowOnNullTestedValue() {
+ assertThatThrownBy(() -> Operator.CONTAINS.matches(null, "matchme"))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void containsShouldThrowOnNullReferenceValue() {
+ assertThatThrownBy(() -> Operator.CONTAINS.matches("this contains matchme string", null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void containsShouldReturnTrueWhenReferenceValueIsEmpty() {
+ assertThat(Operator.CONTAINS.matches("this contains matchme string", ""))
+ .isTrue();
+ }
+
+ @Test
+ void containsShouldReturnFalseWhenTestedValueIsEmpty() {
+ assertThat(Operator.CONTAINS.matches("", "matchme"))
+ .isFalse();
+ }
+
+ @Test
+ void containsShouldReturnTrueWhenBothValuesAreEmpty() {
+ assertThat(Operator.CONTAINS.matches("", ""))
+ .isTrue();
+ }
+ }
+}
diff --git a/server/pom.xml b/server/pom.xml
index 6447abd..7fef183 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -77,6 +77,7 @@
<module>mailet/mailetcontainer-api</module>
<module>mailet/mailetcontainer-camel</module>
<module>mailet/mailets</module>
+ <module>mailet/mock-smtp-server</module>
<module>mailrepository/mailrepository-api</module>
<module>mailrepository/mailrepository-cassandra</module>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 05/11: JAMES-2864 Response POJO for SMTP server
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 62c296365795c36a1799fd1cd493226a4280877d
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Aug 21 11:03:43 2019 +0700
JAMES-2864 Response POJO for SMTP server
---
.../apache/james/mock/smtp/server/Response.java | 71 +++++++++++++++
.../james/mock/smtp/server/ResponseTest.java | 100 +++++++++++++++++++++
2 files changed, 171 insertions(+)
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
new file mode 100644
index 0000000..c82e699
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import com.google.common.base.Preconditions;
+
+class Response {
+ static class SMTPStatusCode {
+ public static SMTPStatusCode of(int code) {
+ return new SMTPStatusCode(code);
+ }
+
+ private final int code;
+
+ private SMTPStatusCode(int code) {
+ Preconditions.checkArgument(code >= 100 && code < 600, "statusCode needs to be within the 1xx - 5xx range");
+
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+ }
+
+ public static Response serverReject(SMTPStatusCode code, String message) {
+ return new Response(code, message, true);
+ }
+
+ public static Response serverAccept(SMTPStatusCode code, String message) {
+ return new Response(code, message, false);
+ }
+
+ private final SMTPStatusCode code;
+ private final String message;
+ private final boolean serverRejected;
+
+ private Response(SMTPStatusCode code, String message, boolean serverRejected) {
+ Preconditions.checkNotNull(message);
+ Preconditions.checkNotNull(code);
+
+ this.code = code;
+ this.message = message;
+ this.serverRejected = serverRejected;
+ }
+
+ String asReplyString() {
+ return code.getCode() + " " + message;
+ }
+
+ boolean isServerRejected() {
+ return serverRejected;
+ }
+}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
new file mode 100644
index 0000000..21d07d7
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
@@ -0,0 +1,100 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+class ResponseTest {
+ static final int OK_250_CODE = 250;
+ static final Response.SMTPStatusCode OK_250 = Response.SMTPStatusCode.of(OK_250_CODE);
+
+ @Nested
+ class SMTPStatusCodeTest {
+ @Test
+ void constructorShouldThrowWhenStatusCodeIsNegative() {
+ assertThatThrownBy(() -> Response.SMTPStatusCode.of(-1))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenStatusCodeIsZero() {
+ assertThatThrownBy(() -> Response.SMTPStatusCode.of(0))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenStatusCodeIsTooBig() {
+ assertThatThrownBy(() -> Response.SMTPStatusCode.of(600))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenStatusCodeIsTooLittle() {
+ assertThatThrownBy(() -> Response.SMTPStatusCode.of(99))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void getCodeShouldReturnInternalValue() {
+ assertThat(OK_250.getCode())
+ .isEqualTo(OK_250_CODE);
+ }
+ }
+
+ @Test
+ void constructorShouldThrowWhenMessageIsNull() {
+ assertThatThrownBy(() -> Response.serverReject(OK_250, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenCodeIsNull() {
+ assertThatThrownBy(() -> Response.serverReject(null, "message"))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void asReplyStringShouldReturnASMTPResponseLine() {
+ assertThat(Response.serverReject(OK_250, "message").asReplyString())
+ .isEqualTo("250 message");
+ }
+
+ @Test
+ void asReplyStringShouldReturnASMTPResponseLineWhenEmptyMessage() {
+ assertThat(Response.serverReject(OK_250, "").asReplyString())
+ .isEqualTo("250 ");
+ }
+
+ @Test
+ void isServerRejectedShouldReturnTrueWhenServerReject() {
+ assertThat(Response.serverReject(OK_250, "message").isServerRejected())
+ .isTrue();
+ }
+
+ @Test
+ void isServerRejectedShouldReturnFalseWhenServerAccept() {
+ assertThat(Response.serverAccept(OK_250, "message").isServerRejected())
+ .isFalse();
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 04/11: JAMES-2864 Condition POJO for matching SMTP
lines
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 0b62377c2930f3f2bad009db2d9b2c945f478118
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Aug 21 10:22:48 2019 +0700
JAMES-2864 Condition POJO for matching SMTP lines
---
server/mailet/mock-smtp-server/pom.xml | 4 ++
.../apache/james/mock/smtp/server/Condition.java | 39 ++++++++++++++
.../james/mock/smtp/server/ConditionTest.java | 63 ++++++++++++++++++++++
3 files changed, 106 insertions(+)
diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml
index c532536..78ec7c1 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -38,6 +38,10 @@
<dependencies>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
new file mode 100644
index 0000000..92c95cb
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import com.google.common.base.Preconditions;
+
+class Condition {
+ private final Operator operator;
+ private final String matchingValue;
+
+ Condition(Operator operator, String matchingValue) {
+ Preconditions.checkNotNull(operator);
+ Preconditions.checkNotNull(matchingValue);
+
+ this.operator = operator;
+ this.matchingValue = matchingValue;
+ }
+
+ boolean matches(String line) {
+ return operator.matches(line, matchingValue);
+ }
+}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
new file mode 100644
index 0000000..ac400d9
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+
+class ConditionTest {
+ @Test
+ void constructorShouldThrowWhenNullOperator() {
+ assertThatThrownBy(() -> new Condition(null, "matchingValue"))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenNullMatchingValue() {
+ assertThatThrownBy(() -> new Condition(Operator.CONTAINS, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void matchesShouldReturnTrueWhenOperatorMatches() {
+ Condition condition = new Condition(Operator.CONTAINS, "match me");
+
+ assertThat(condition.matches("this contains match me string"))
+ .isTrue();
+ }
+
+ @Test
+ void matchesShouldReturnFalseWhenOperatorDoesNotMatch() {
+ Condition condition = new Condition(Operator.CONTAINS, "match me");
+
+ assertThat(condition.matches("this contains another string"))
+ .isFalse();
+ }
+
+ @Test
+ void matchesShouldThrowWhenNullLine() {
+ Condition condition = new Condition(Operator.CONTAINS, "match me");
+
+ assertThatThrownBy(() -> condition.matches(null))
+ .isInstanceOf(NullPointerException.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 09/11: JAMES-2864 Fluent Operators
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit be8a19e2bd42bcfede9974332476eb96b2694f85
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Aug 22 15:10:07 2019 +0700
JAMES-2864 Fluent Operators
---
.../apache/james/mock/smtp/server/Condition.java | 4 +-
.../apache/james/mock/smtp/server/Operator.java | 15 +++++-
.../james/mock/smtp/server/OperatorTest.java | 63 ++++++++++++++++------
3 files changed, 62 insertions(+), 20 deletions(-)
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
index 4700ac3..2fde09a 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
@@ -36,7 +36,9 @@ class Condition {
}
boolean matches(String line) {
- return operator.matches(line, matchingValue);
+ return operator.actual(line)
+ .expected(matchingValue)
+ .matches();
}
@Override
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
index fa81b3f..992343f 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Operator.java
@@ -20,7 +20,18 @@
package org.apache.james.mock.smtp.server;
public interface Operator {
- Operator CONTAINS = String::contains;
- boolean matches(String testedValue, String referenceValue);
+ @FunctionalInterface
+ interface Expected {
+ Matcher expected(String expected);
+ }
+
+ @FunctionalInterface
+ interface Matcher {
+ boolean matches();
+ }
+
+ Operator CONTAINS = actual -> expected -> () -> actual.contains(expected);
+
+ Expected actual(String actual);
}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java
index aa6421a..bd2eedd 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/OperatorTest.java
@@ -30,62 +30,91 @@ class OperatorTest {
@Nested
class ContainsTest {
@Test
- void containsShouldReturnTrueWhenTestedValueContainsReferenceValue() {
- assertThat(Operator.CONTAINS.matches("this contains matchme string", "matchme"))
+ void containsShouldReturnTrueWhenActualContainsExpected() {
+ assertThat(Operator.CONTAINS
+ .actual("this contains matchme string")
+ .expected("matchme")
+ .matches())
.isTrue();
}
@Test
void containsShouldReturnTrueWhenBothValuesAreEqual() {
- assertThat(Operator.CONTAINS.matches("matchme", "matchme"))
+ assertThat(Operator.CONTAINS
+ .actual("matchme")
+ .expected("matchme")
+ .matches())
.isTrue();
}
@Test
- void containsShouldReturnFalseWhenTestedValueDoesNotContainReferenceValue() {
- assertThat(Operator.CONTAINS.matches("this contains an other string", "matchme"))
+ void containsShouldReturnFalseWhenActualDoesNotContainExpected() {
+ assertThat(Operator.CONTAINS
+ .actual("this contains an other string")
+ .expected("matchme")
+ .matches())
.isFalse();
}
@Test
- void containsShouldReturnFalseWhenReferenceValueContainsTestedValue() {
- assertThat(Operator.CONTAINS.matches("matchme", "this contains matchme"))
+ void containsShouldReturnFalseWhenExpectedContainsActual() {
+ assertThat(Operator.CONTAINS
+ .actual("matchme")
+ .expected("this contains matchme")
+ .matches())
.isFalse();
}
@Test
void containsShouldBeCaseSensitive() {
- assertThat(Operator.CONTAINS.matches("this contains matchme string", "Matchme"))
+ assertThat(Operator.CONTAINS.actual("this contains matchme string")
+ .expected("Matchme")
+ .matches())
.isFalse();
}
@Test
- void containsShouldThrowOnNullTestedValue() {
- assertThatThrownBy(() -> Operator.CONTAINS.matches(null, "matchme"))
+ void containsShouldThrowOnNullActual() {
+ assertThatThrownBy(() -> Operator.CONTAINS
+ .actual(null)
+ .expected("matchme")
+ .matches())
.isInstanceOf(NullPointerException.class);
}
@Test
- void containsShouldThrowOnNullReferenceValue() {
- assertThatThrownBy(() -> Operator.CONTAINS.matches("this contains matchme string", null))
+ void containsShouldThrowOnNullExpected() {
+ assertThatThrownBy(() -> Operator.CONTAINS
+ .actual("this contains matchme string")
+ .expected(null)
+ .matches())
.isInstanceOf(NullPointerException.class);
}
@Test
- void containsShouldReturnTrueWhenReferenceValueIsEmpty() {
- assertThat(Operator.CONTAINS.matches("this contains matchme string", ""))
+ void containsShouldReturnTrueWhenExpectedIsEmpty() {
+ assertThat(Operator.CONTAINS
+ .actual("this contains matchme string")
+ .expected("")
+ .matches())
.isTrue();
}
@Test
- void containsShouldReturnFalseWhenTestedValueIsEmpty() {
- assertThat(Operator.CONTAINS.matches("", "matchme"))
+ void containsShouldReturnFalseWhenActualIsEmpty() {
+ assertThat(Operator.CONTAINS
+ .actual("")
+ .expected("matchme")
+ .matches())
.isFalse();
}
@Test
void containsShouldReturnTrueWhenBothValuesAreEmpty() {
- assertThat(Operator.CONTAINS.matches("", ""))
+ assertThat(Operator.CONTAINS
+ .actual("")
+ .expected("")
+ .matches())
.isTrue();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 06/11: JAMES-2864 MockSMTPBehavior POJO for Mock
SMTP server
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit d48ece8d451988f3ed503f30f02f5adde423e6cd
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Aug 21 11:28:28 2019 +0700
JAMES-2864 MockSMTPBehavior POJO for Mock SMTP server
---
.../james/mock/smtp/server/MockSMTPBehavior.java | 81 +++++++++++++++++++++
.../apache/james/mock/smtp/server/SMTPCommand.java | 37 ++++++++++
.../mock/smtp/server/MockSMTPBehaviorTest.java | 83 ++++++++++++++++++++++
3 files changed, 201 insertions(+)
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java
new file mode 100644
index 0000000..5d1d7b4
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import java.util.Optional;
+
+import com.google.common.base.Preconditions;
+
+public class MockSMTPBehavior {
+ public static final class NumberOfAnswersPolicy {
+
+ public static NumberOfAnswersPolicy anytime() {
+ return new NumberOfAnswersPolicy(Optional.empty());
+ }
+
+ public static NumberOfAnswersPolicy times(int times) {
+ Preconditions.checkArgument(times > 0, "times should be positive");
+ return new NumberOfAnswersPolicy(Optional.of(times));
+ }
+
+ private final Optional<Integer> numberOfAnswers;
+
+ private NumberOfAnswersPolicy(Optional<Integer> numberOfAnswers) {
+ this.numberOfAnswers = numberOfAnswers;
+ }
+
+ public Optional<Integer> getNumberOfAnswers() {
+ return numberOfAnswers;
+ }
+ }
+
+ private final SMTPCommand smtpCommand;
+ private final Optional<Condition> condition;
+ private final Response response;
+ private final NumberOfAnswersPolicy numberOfAnswers;
+
+ public MockSMTPBehavior(SMTPCommand smtpCommand, Optional<Condition> condition, Response response, NumberOfAnswersPolicy numberOfAnswers) {
+ Preconditions.checkNotNull(smtpCommand);
+ Preconditions.checkNotNull(condition);
+ Preconditions.checkNotNull(response);
+ Preconditions.checkNotNull(numberOfAnswers);
+
+ this.smtpCommand = smtpCommand;
+ this.condition = condition;
+ this.response = response;
+ this.numberOfAnswers = numberOfAnswers;
+ }
+
+ public SMTPCommand getSmtpCommand() {
+ return smtpCommand;
+ }
+
+ public Optional<Condition> getCondition() {
+ return condition;
+ }
+
+ public Response getResponse() {
+ return response;
+ }
+
+ public NumberOfAnswersPolicy getNumberOfAnswers() {
+ return numberOfAnswers;
+ }
+}
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPCommand.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPCommand.java
new file mode 100644
index 0000000..024b662
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/SMTPCommand.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+enum SMTPCommand {
+ RCPT_TO("RCPT TO"),
+ EHLO("EHLO"),
+ MAIL_FROM("MAIL FROM"),
+ DATA("DATA"),
+ RSET("RSET"),
+ VRFY("VRFY"),
+ NOOP("NOOP"),
+ QUIT("QUIT");
+
+ private final String commandName;
+
+ SMTPCommand(String commandName) {
+ this.commandName = commandName;
+ }
+}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
new file mode 100644
index 0000000..5fbeb51
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Optional;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+class MockSMTPBehaviorTest {
+ private static final Response RESPONSE = Response.serverAccept(Response.SMTPStatusCode.of(250), "message");
+
+ @Nested
+ class NumberOfAnswersPolicyTest {
+ @Test
+ void timesShouldThrowWhenNegativeValue() {
+ assertThatThrownBy(() -> MockSMTPBehavior.NumberOfAnswersPolicy.times(-1))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void timesShouldThrowWhenZero() {
+ assertThatThrownBy(() -> MockSMTPBehavior.NumberOfAnswersPolicy.times(0))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ void getNumberOfAnswersShouldReturnEmptyWhenAlways() {
+ assertThat(MockSMTPBehavior.NumberOfAnswersPolicy.anytime().getNumberOfAnswers())
+ .isEmpty();
+ }
+
+ @Test
+ void getNumberOfAnswersShouldReturnSpecifiedNumberWhenTimes() {
+ assertThat(MockSMTPBehavior.NumberOfAnswersPolicy.times(5).getNumberOfAnswers())
+ .contains(5);
+ }
+ }
+
+ @Test
+ void constructorShouldThrowWhenCommandIsNull() {
+ assertThatThrownBy(() -> new MockSMTPBehavior(null, Optional.empty(), RESPONSE, MockSMTPBehavior.NumberOfAnswersPolicy.anytime()))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenConditionIsNull() {
+ assertThatThrownBy(() -> new MockSMTPBehavior(SMTPCommand.NOOP, null, RESPONSE, MockSMTPBehavior.NumberOfAnswersPolicy.anytime()))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenResponseIsNull() {
+ assertThatThrownBy(() -> new MockSMTPBehavior(SMTPCommand.NOOP, Optional.empty(), null, MockSMTPBehavior.NumberOfAnswersPolicy.anytime()))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenNumberOfAnswersIsNull() {
+ assertThatThrownBy(() -> new MockSMTPBehavior(SMTPCommand.NOOP, Optional.empty(), RESPONSE, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 01/11: JAMES-2178 Reindent Upload requests in JMAP
integration tests
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 3c51db285b43fbac9d712b891dbe2bbad6365955
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Aug 26 15:04:36 2019 +0700
JAMES-2178 Reindent Upload requests in JMAP integration tests
---
.../jmap/methods/integration/cucumber/UploadStepdefs.java | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
index 757bd26..e1a1ab1 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UploadStepdefs.java
@@ -38,6 +38,7 @@ import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.apache.http.concurrent.FutureCallback;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.james.jmap.api.access.AccessToken;
import org.apache.james.util.CountDownConsumeInputStream;
@@ -109,14 +110,24 @@ public class UploadStepdefs {
.bodyStream(new BufferedInputStream(new ZeroedInputStream(_1M), _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
request.addHeader("Authorization", accessToken.serialize());
- response = Executor.newInstance(HttpClientBuilder.create().disableAutomaticRetries().build()).execute(request).returnResponse();
+ response = Executor.newInstance(newClient())
+ .execute(request)
+ .returnResponse();
}
@When("^someone upload a content without authentification$")
public void userUploadContentWithoutAuthentification() throws Throwable {
Request request = Request.Post(uploadUri)
.bodyStream(new BufferedInputStream(new ZeroedInputStream(_1M), _1M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
- response = Executor.newInstance(HttpClientBuilder.create().disableAutomaticRetries().build()).execute(request).returnResponse();
+ response = Executor.newInstance(newClient())
+ .execute(request)
+ .returnResponse();
+ }
+
+ private CloseableHttpClient newClient() {
+ return HttpClientBuilder.create()
+ .disableAutomaticRetries()
+ .build();
}
@When("^\"([^\"]*)\" upload a content without content type$")
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 08/11: JAMES-2864 Mail POJO for the Mock SMTP server
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 382dfacb94269daecb00160792145221d8e6c445
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Aug 21 11:53:56 2019 +0700
JAMES-2864 Mail POJO for the Mock SMTP server
Will be used to verify email and their envelopes after interacting with
the mockSMTPServer
---
server/mailet/mock-smtp-server/pom.xml | 4 +
.../org/apache/james/mock/smtp/server/Mail.java | 102 +++++++++++++++++++++
.../apache/james/mock/smtp/server/MailTest.java | 89 ++++++++++++++++++
3 files changed, 195 insertions(+)
diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml
index a66b34f..d79081f 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -38,6 +38,10 @@
<dependencies>
<dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>james-core</artifactId>
+ </dependency>
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java
new file mode 100644
index 0000000..e977334
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Mail.java
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.james.core.MailAddress;
+
+import com.google.common.base.Preconditions;
+
+class Mail {
+ static class Envelope {
+ private final MailAddress from;
+ private final List<MailAddress> recipients;
+
+ Envelope(MailAddress from, List<MailAddress> recipients) {
+ Preconditions.checkNotNull(from);
+ Preconditions.checkNotNull(recipients);
+ Preconditions.checkArgument(!recipients.isEmpty(), "'recipients' field should not be empty");
+
+ this.from = from;
+ this.recipients = recipients;
+ }
+
+ public MailAddress getFrom() {
+ return from;
+ }
+
+ public List<MailAddress> getRecipients() {
+ return recipients;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof Envelope) {
+ Envelope envelope = (Envelope) o;
+
+ return Objects.equals(this.from, envelope.from)
+ && Objects.equals(this.recipients, envelope.recipients);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(from, recipients);
+ }
+ }
+
+ private final Envelope envelope;
+ private final String message;
+
+ Mail(Envelope envelope, String message) {
+ Preconditions.checkNotNull(envelope);
+ Preconditions.checkNotNull(message);
+
+ this.envelope = envelope;
+ this.message = message;
+ }
+
+ public Envelope getEnvelope() {
+ return envelope;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof Mail) {
+ Mail mail = (Mail) o;
+
+ return Objects.equals(this.envelope, mail.envelope)
+ && Objects.equals(this.message, mail.message);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(envelope, message);
+ }
+}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java
new file mode 100644
index 0000000..b21082f
--- /dev/null
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MailTest.java
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.mock.smtp.server;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.james.core.MailAddress;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableList;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class MailTest {
+ private MailAddress bob;
+ private MailAddress alice;
+ private Mail.Envelope envelope;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ bob = new MailAddress("bob@domain.tld");
+ alice = new MailAddress("alice@domain.tld");
+ envelope = new Mail.Envelope(alice, ImmutableList.of(bob));
+ }
+
+ @Nested
+ class EnvelopeTest {
+ @Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(Mail.Envelope.class)
+ .verify();
+ }
+
+ @Test
+ void constructorShouldThrowWhenNullFrom() {
+ assertThatThrownBy(() -> new Mail.Envelope(null, ImmutableList.of(bob)))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenNullRecipients() {
+ assertThatThrownBy(() -> new Mail.Envelope(bob, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenEmptyRecipients() {
+ assertThatThrownBy(() -> new Mail.Envelope(bob, ImmutableList.of()))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+ }
+
+ @Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(Mail.class)
+ .verify();
+ }
+
+ @Test
+ void constructorShouldThrowWhenNullMessage() {
+ assertThatThrownBy(() -> new Mail(envelope, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void constructorShouldThrowWhenNullEnvelope() {
+ assertThatThrownBy(() -> new Mail(null, "header: single header message dude"))
+ .isInstanceOf(NullPointerException.class);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 10/11: JAMES-2864 SMTPStatusCode contains all valid
SMTP codes
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 84c6ceb647485b06715c5492bdd917aab34c0bd7
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Thu Aug 22 15:25:41 2019 +0700
JAMES-2864 SMTPStatusCode contains all valid SMTP codes
---
.../apache/james/mock/smtp/server/Response.java | 47 ++++++++++---------
.../mock/smtp/server/MockSMTPBehaviorTest.java | 3 +-
.../james/mock/smtp/server/ResponseTest.java | 53 +++-------------------
3 files changed, 34 insertions(+), 69 deletions(-)
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
index 3156394..9adb043 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
@@ -24,37 +24,42 @@ import java.util.Objects;
import com.google.common.base.Preconditions;
class Response {
- static class SMTPStatusCode {
- public static SMTPStatusCode of(int code) {
- return new SMTPStatusCode(code);
- }
+ enum SMTPStatusCode {
+ OK_200(200),
+ SYSTEM_STATUS_211(211),
+ HELP_214(214),
+ SERVICE_READY(220),
+ SERVICE_CLOSING_CHANNEL_221(221),
+ ACTION_COMPLETE_250(250),
+ USER_NOT_LOCAL_251(251),
+ UNKNOW_USER_252(252),
+ START_MAIL_INPUT_354(354),
+ SERVICE_NOT_AVAILABLE_421(421),
+ REQUESTED_MAIL_ACTION_NOT_TAKEN_450(450),
+ REQUESTED_ACTION_ABORTED_451(451),
+ REQUESTED_ACTION_NOT_TAKEN_452(452),
+ SYNTAX_ERROR_500(500),
+ SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS_501(501),
+ COMMAND_NOT_IMPLEMENTED_502(502),
+ BAD_SEQUENCE_OF_COMMANDS_503(503),
+ COMMAND_PARAMETER_NOT_IMPLEMENTED_504(504),
+ DOES_NOT_ACCEPT_MAIL_521(521),
+ ACCESS_DENIED_530(530),
+ REQUESTED_ACTION_NOT_TAKEN_550(550),
+ USER_NOT_LOCAL_551(551),
+ REQUESTED_MAIL_ACTION_ABORTED_552(552),
+ REQUESTED_ACTION_NOT_TAKEN_553(553),
+ TRANSACTION_FAILED_554(554);
private final int code;
private SMTPStatusCode(int code) {
- Preconditions.checkArgument(code >= 100 && code < 600, "statusCode needs to be within the 1xx - 5xx range");
-
this.code = code;
}
public int getCode() {
return code;
}
-
- @Override
- public final boolean equals(Object o) {
- if (o instanceof SMTPStatusCode) {
- SMTPStatusCode that = (SMTPStatusCode) o;
-
- return Objects.equals(this.code, that.code);
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- return Objects.hash(code);
- }
}
public static Response serverReject(SMTPStatusCode code, String message) {
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
index 68c3e27..57f16cd 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
@@ -24,13 +24,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Optional;
+import org.apache.james.mock.smtp.server.Response.SMTPStatusCode;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
class MockSMTPBehaviorTest {
- private static final Response RESPONSE = Response.serverAccept(Response.SMTPStatusCode.of(250), "message");
+ private static final Response RESPONSE = Response.serverAccept(SMTPStatusCode.ACTION_COMPLETE_250, "message");
@Nested
class NumberOfAnswersPolicyTest {
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
index 512f2b3..cd5f39f 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
@@ -22,53 +22,12 @@ package org.apache.james.mock.smtp.server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import org.junit.jupiter.api.Nested;
+import org.apache.james.mock.smtp.server.Response.SMTPStatusCode;
import org.junit.jupiter.api.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
class ResponseTest {
- static final int OK_250_CODE = 250;
- static final Response.SMTPStatusCode OK_250 = Response.SMTPStatusCode.of(OK_250_CODE);
-
- @Nested
- class SMTPStatusCodeTest {
- @Test
- void shouldMatchBeanContract() {
- EqualsVerifier.forClass(Response.SMTPStatusCode.class)
- .verify();
- }
-
- @Test
- void constructorShouldThrowWhenStatusCodeIsNegative() {
- assertThatThrownBy(() -> Response.SMTPStatusCode.of(-1))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void constructorShouldThrowWhenStatusCodeIsZero() {
- assertThatThrownBy(() -> Response.SMTPStatusCode.of(0))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void constructorShouldThrowWhenStatusCodeIsTooBig() {
- assertThatThrownBy(() -> Response.SMTPStatusCode.of(600))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void constructorShouldThrowWhenStatusCodeIsTooLittle() {
- assertThatThrownBy(() -> Response.SMTPStatusCode.of(99))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @Test
- void getCodeShouldReturnInternalValue() {
- assertThat(OK_250.getCode())
- .isEqualTo(OK_250_CODE);
- }
- }
@Test
void shouldMatchBeanContract() {
@@ -78,7 +37,7 @@ class ResponseTest {
@Test
void constructorShouldThrowWhenMessageIsNull() {
- assertThatThrownBy(() -> Response.serverReject(OK_250, null))
+ assertThatThrownBy(() -> Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, null))
.isInstanceOf(NullPointerException.class);
}
@@ -90,25 +49,25 @@ class ResponseTest {
@Test
void asReplyStringShouldReturnASMTPResponseLine() {
- assertThat(Response.serverReject(OK_250, "message").asReplyString())
+ assertThat(Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, "message").asReplyString())
.isEqualTo("250 message");
}
@Test
void asReplyStringShouldReturnASMTPResponseLineWhenEmptyMessage() {
- assertThat(Response.serverReject(OK_250, "").asReplyString())
+ assertThat(Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, "").asReplyString())
.isEqualTo("250 ");
}
@Test
void isServerRejectedShouldReturnTrueWhenServerReject() {
- assertThat(Response.serverReject(OK_250, "message").isServerRejected())
+ assertThat(Response.serverReject(SMTPStatusCode.ACTION_COMPLETE_250, "message").isServerRejected())
.isTrue();
}
@Test
void isServerRejectedShouldReturnFalseWhenServerAccept() {
- assertThat(Response.serverAccept(OK_250, "message").isServerRejected())
+ assertThat(Response.serverAccept(SMTPStatusCode.ACTION_COMPLETE_250, "message").isServerRejected())
.isFalse();
}
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[james-project] 07/11: JAMES-2864 equals % hashCode overriding
Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 94ebf32ca71f562e2a43336425e7bd3506edaeb8
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Aug 21 11:35:00 2019 +0700
JAMES-2864 equals % hashCode overriding
---
server/mailet/mock-smtp-server/pom.xml | 5 ++++
.../apache/james/mock/smtp/server/Condition.java | 18 ++++++++++++
.../james/mock/smtp/server/MockSMTPBehavior.java | 34 ++++++++++++++++++++++
.../apache/james/mock/smtp/server/Response.java | 34 ++++++++++++++++++++++
.../james/mock/smtp/server/ConditionTest.java | 8 +++++
.../mock/smtp/server/MockSMTPBehaviorTest.java | 14 +++++++++
.../james/mock/smtp/server/ResponseTest.java | 14 +++++++++
7 files changed, 127 insertions(+)
diff --git a/server/mailet/mock-smtp-server/pom.xml b/server/mailet/mock-smtp-server/pom.xml
index 78ec7c1..a66b34f 100644
--- a/server/mailet/mock-smtp-server/pom.xml
+++ b/server/mailet/mock-smtp-server/pom.xml
@@ -42,6 +42,11 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
+ <groupId>nl.jqno.equalsverifier</groupId>
+ <artifactId>equalsverifier</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
index 92c95cb..4700ac3 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Condition.java
@@ -19,6 +19,8 @@
package org.apache.james.mock.smtp.server;
+import java.util.Objects;
+
import com.google.common.base.Preconditions;
class Condition {
@@ -36,4 +38,20 @@ class Condition {
boolean matches(String line) {
return operator.matches(line, matchingValue);
}
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof Condition) {
+ Condition condition = (Condition) o;
+
+ return Objects.equals(this.operator, condition.operator)
+ && Objects.equals(this.matchingValue, condition.matchingValue);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(operator, matchingValue);
+ }
}
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java
index 5d1d7b4..371b2ea 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/MockSMTPBehavior.java
@@ -19,6 +19,7 @@
package org.apache.james.mock.smtp.server;
+import java.util.Objects;
import java.util.Optional;
import com.google.common.base.Preconditions;
@@ -44,6 +45,21 @@ public class MockSMTPBehavior {
public Optional<Integer> getNumberOfAnswers() {
return numberOfAnswers;
}
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof NumberOfAnswersPolicy) {
+ NumberOfAnswersPolicy that = (NumberOfAnswersPolicy) o;
+
+ return Objects.equals(this.numberOfAnswers, that.numberOfAnswers);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(numberOfAnswers);
+ }
}
private final SMTPCommand smtpCommand;
@@ -78,4 +94,22 @@ public class MockSMTPBehavior {
public NumberOfAnswersPolicy getNumberOfAnswers() {
return numberOfAnswers;
}
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof MockSMTPBehavior) {
+ MockSMTPBehavior that = (MockSMTPBehavior) o;
+
+ return Objects.equals(this.smtpCommand, that.smtpCommand)
+ && Objects.equals(this.condition, that.condition)
+ && Objects.equals(this.response, that.response)
+ && Objects.equals(this.numberOfAnswers, that.numberOfAnswers);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(smtpCommand, condition, response, numberOfAnswers);
+ }
}
diff --git a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
index c82e699..3156394 100644
--- a/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
+++ b/server/mailet/mock-smtp-server/src/main/java/org/apache/james/mock/smtp/server/Response.java
@@ -19,6 +19,8 @@
package org.apache.james.mock.smtp.server;
+import java.util.Objects;
+
import com.google.common.base.Preconditions;
class Response {
@@ -38,6 +40,21 @@ class Response {
public int getCode() {
return code;
}
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof SMTPStatusCode) {
+ SMTPStatusCode that = (SMTPStatusCode) o;
+
+ return Objects.equals(this.code, that.code);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(code);
+ }
}
public static Response serverReject(SMTPStatusCode code, String message) {
@@ -68,4 +85,21 @@ class Response {
boolean isServerRejected() {
return serverRejected;
}
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof Response) {
+ Response response = (Response) o;
+
+ return Objects.equals(this.serverRejected, response.serverRejected)
+ && Objects.equals(this.code, response.code)
+ && Objects.equals(this.message, response.message);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(code, message, serverRejected);
+ }
}
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
index ac400d9..dff65dc 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ConditionTest.java
@@ -24,8 +24,16 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test;
+import nl.jqno.equalsverifier.EqualsVerifier;
+
class ConditionTest {
@Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(Condition.class)
+ .verify();
+ }
+
+ @Test
void constructorShouldThrowWhenNullOperator() {
assertThatThrownBy(() -> new Condition(null, "matchingValue"))
.isInstanceOf(NullPointerException.class);
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
index 5fbeb51..68c3e27 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/MockSMTPBehaviorTest.java
@@ -27,12 +27,20 @@ import java.util.Optional;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import nl.jqno.equalsverifier.EqualsVerifier;
+
class MockSMTPBehaviorTest {
private static final Response RESPONSE = Response.serverAccept(Response.SMTPStatusCode.of(250), "message");
@Nested
class NumberOfAnswersPolicyTest {
@Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(MockSMTPBehavior.NumberOfAnswersPolicy.class)
+ .verify();
+ }
+
+ @Test
void timesShouldThrowWhenNegativeValue() {
assertThatThrownBy(() -> MockSMTPBehavior.NumberOfAnswersPolicy.times(-1))
.isInstanceOf(IllegalArgumentException.class);
@@ -58,6 +66,12 @@ class MockSMTPBehaviorTest {
}
@Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(MockSMTPBehavior.class)
+ .verify();
+ }
+
+ @Test
void constructorShouldThrowWhenCommandIsNull() {
assertThatThrownBy(() -> new MockSMTPBehavior(null, Optional.empty(), RESPONSE, MockSMTPBehavior.NumberOfAnswersPolicy.anytime()))
.isInstanceOf(NullPointerException.class);
diff --git a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
index 21d07d7..512f2b3 100644
--- a/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
+++ b/server/mailet/mock-smtp-server/src/test/java/org/apache/james/mock/smtp/server/ResponseTest.java
@@ -25,6 +25,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import nl.jqno.equalsverifier.EqualsVerifier;
+
class ResponseTest {
static final int OK_250_CODE = 250;
static final Response.SMTPStatusCode OK_250 = Response.SMTPStatusCode.of(OK_250_CODE);
@@ -32,6 +34,12 @@ class ResponseTest {
@Nested
class SMTPStatusCodeTest {
@Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(Response.SMTPStatusCode.class)
+ .verify();
+ }
+
+ @Test
void constructorShouldThrowWhenStatusCodeIsNegative() {
assertThatThrownBy(() -> Response.SMTPStatusCode.of(-1))
.isInstanceOf(IllegalArgumentException.class);
@@ -63,6 +71,12 @@ class ResponseTest {
}
@Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(Response.class)
+ .verify();
+ }
+
+ @Test
void constructorShouldThrowWhenMessageIsNull() {
assertThatThrownBy(() -> Response.serverReject(OK_250, null))
.isInstanceOf(NullPointerException.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org