You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2020/12/04 22:14:00 UTC

[GitHub] [james-project] rouazana commented on a change in pull request #270: JAMES-2543 Migrate SMTP tests to junit 5

rouazana commented on a change in pull request #270:
URL: https://github.com/apache/james-project/pull/270#discussion_r536413848



##########
File path: mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java
##########
@@ -33,47 +31,42 @@
     public static final String USER_AT_DOMAIN = USER + "@" + DOMAIN;
     public static final String PASSWORD = "secret";
 
-    @Rule
-    public final TemporaryFolder folder = new TemporaryFolder();
-
-    protected abstract SmtpHostSystem createSmtpHostSystem();
-    
-    private SmtpHostSystem hostSystem;
+    protected SmtpHostSystem hostSystem;
     private SimpleScriptedTestProtocol scriptedTest;
 
-    @Before
-    public void setUp() throws Exception {
-        hostSystem = createSmtpHostSystem();
+    @BeforeEach
+    public void setUp(SmtpHostSystem hostSystem) throws Exception {

Review comment:
       ```suggestion
       void setUp(SmtpHostSystem hostSystem) throws Exception {
   ```

##########
File path: server/testing/src/main/java/org/apache/james/utils/FakeSmtpExtension.java
##########
@@ -0,0 +1,168 @@
+/****************************************************************
+ * 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.utils;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.config.EncoderConfig.encoderConfig;
+import static io.restassured.config.RestAssuredConfig.newConfig;
+
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.function.Consumer;
+
+import org.apache.james.util.docker.Images;
+import org.apache.james.util.docker.RateLimiters;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+
+import com.github.dockerjava.api.model.ContainerNetwork;
+
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.builder.ResponseSpecBuilder;
+import io.restassured.http.ContentType;
+import io.restassured.response.ValidatableResponse;
+import io.restassured.specification.RequestSpecification;
+import io.restassured.specification.ResponseSpecification;
+
+
+public class FakeSmtpExtension implements
+        BeforeEachCallback,
+        AfterEachCallback,
+        ParameterResolver {
+
+    private static final int SMTP_PORT = 25;
+
+    public static FakeSmtpExtension withSmtpPort(Integer smtpPort) {
+        GenericContainer<?> container = fakeSmtpContainer()
+                .withExposedPorts(smtpPort)
+                .withCommand("node", "cli", "--listen", "80", "--smtp", smtpPort.toString());
+
+        return new FakeSmtpExtension(container);
+    }
+
+    public static FakeSmtpExtension withDefaultPort() {
+        return withSmtpPort(SMTP_PORT);
+    }
+
+    private static  GenericContainer<?> fakeSmtpContainer() {

Review comment:
       ```suggestion
       private static GenericContainer<?> fakeSmtpContainer() {
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org