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 <[email protected]>
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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to