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 d0922c47283c4e2ffb78af1922a590a1174dd93f
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Fri Sep 6 09:47:27 2019 +0700

    JAMES-2865 Use behavior builder directly in tests
---
 .../james/mailets/RemoteDeliveryErrorTest.java     | 169 ++++++++++-----------
 1 file changed, 79 insertions(+), 90 deletions(-)

diff --git 
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RemoteDeliveryErrorTest.java
 
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RemoteDeliveryErrorTest.java
index 720c335..0832d10 100644
--- 
a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RemoteDeliveryErrorTest.java
+++ 
b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/RemoteDeliveryErrorTest.java
@@ -82,8 +82,8 @@ import net.javacrumbs.jsonunit.core.Option;
 
 public class RemoteDeliveryErrorTest {
     private static final Logger LOGGER = 
LoggerFactory.getLogger(RemoteDeliveryErrorTest.class);
-    private static final String ANOTHER_DOMAIN = "other.com";
 
+    private static final String ANOTHER_DOMAIN = "other.com";
     private static final String FROM = "from@" + DEFAULT_DOMAIN;
     private static final String MIME_MESSAGE = "FROM: " + FROM + "\r\n" +
         "subject: test\r\n" +
@@ -93,90 +93,13 @@ public class RemoteDeliveryErrorTest {
     private static final String RECIPIENT = "touser@" + ANOTHER_DOMAIN;
     private static final String RECIPIENT1 = "touser1@" + ANOTHER_DOMAIN;
     private static final String RECIPIENT2 = "touser2@" + ANOTHER_DOMAIN;
-
-    private static final MockSmtpBehaviors ALWAYS_421_RCPT_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.RCPT_TO)
-        .matching(anyInput())
-        .thenRespond(serviceNotAvailable("mock response"))
-        .anyTimes()
-        .build();
-    private static final MockSmtpBehaviors ALWAYS_421_FROM_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.MAIL_FROM)
-        .matching(anyInput())
-        .thenRespond(serviceNotAvailable("mock response"))
-        .anyTimes()
-        .build();
-    private static final MockSmtpBehaviors ALWAYS_421_DATA_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.DATA)
-        .matching(anyInput())
-        .thenRespond(serviceNotAvailable("mock response"))
-        .anyTimes()
-        .build();
-    private static final MockSmtpBehaviors TWICE_421_RCPT_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.RCPT_TO)
-        .matching(anyInput())
-        .thenRespond(serviceNotAvailable("mock response"))
-        .onlySomeTimes(2)
-        .build();
-    private static final MockSmtpBehaviors TWICE_421_FROM_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.MAIL_FROM)
-        .matching(anyInput())
-        .thenRespond(serviceNotAvailable("mock response"))
-        .onlySomeTimes(2)
-        .build();
-    private static final MockSmtpBehaviors TWICE_421_DATA_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.DATA)
-        .matching(anyInput())
-        .thenRespond(serviceNotAvailable("mock response"))
-        .onlySomeTimes(2)
-        .build();
-    private static final MockSmtpBehaviors SINGLE_500_RCPT_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.RCPT_TO)
-        .matching(anyInput())
-        .thenRespond(doesNotAcceptAnyMail("mock message"))
-        .onlySomeTimes(1)
-        .build();
-    private static final MockSmtpBehaviors SINGLE_500_FROM_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.MAIL_FROM)
-        .matching(anyInput())
-        .thenRespond(doesNotAcceptAnyMail("mock message"))
-        .onlySomeTimes(1)
-        .build();
-    private static final MockSmtpBehaviors SINGLE_500_DATA_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.DATA)
-        .matching(anyInput())
-        .thenRespond(doesNotAcceptAnyMail("mock message"))
-        .onlySomeTimes(1)
-        .build();
-    private static final MockSmtpBehaviors SINGLE_PARTIAL_RCPT_421_BEHAVIOR = 
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.RCPT_TO)
-        .matching(inputContaining(RECIPIENT1))
-        .thenRespond(serviceNotAvailable("mock response"))
-        .onlySomeTimes(1)
-        .build();
-    private static final MockSmtpBehaviors ALWAYS_PARTIAL_RCPT_421_BEHAVIOR =  
MockSmtpBehaviors.builder()
-        .addNewBehavior()
-        .expect(SMTPCommand.RCPT_TO)
-        .matching(inputContaining(RECIPIENT2))
-        .thenRespond(serviceNotAvailable("mock response"))
-        .anyTimes()
-        .build();
     private static final String BOUNCE_MESSAGE = "Hi. This is the James mail 
server at localhost.\n" +
         "I'm afraid I wasn't able to deliver your message to the following 
addresses.\n" +
         "This is a permanent error; I've given up. Sorry it didn't work out. 
Below\n" +
         "I include the list of recipients and the reason why I was unable to 
deliver\n" +
         "your message.";
     private static final ResponseSpecification RESPONSE_SPECIFICATION = new 
ResponseSpecBuilder().build();
+
     private InMemoryDNSService inMemoryDNSService;
     private RequestSpecification requestSpecificationForMockSMTP1;
     private RequestSpecification requestSpecificationForMockSMTP2;
@@ -232,7 +155,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldBounceWhenAlwaysRCPT421() throws Exception 
{
         with()
-            .body(ALWAYS_421_RCPT_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.RCPT_TO)
+                .matching(anyInput())
+                .thenRespond(serviceNotAvailable("mock response"))
+                .anyTimes()
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -249,7 +178,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldBounceWhenAlwaysFROM421() throws Exception 
{
         with()
-            .body(ALWAYS_421_FROM_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.MAIL_FROM)
+                .matching(anyInput())
+                .thenRespond(serviceNotAvailable("mock response"))
+                .anyTimes()
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -266,7 +201,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldBounceWhenAlwaysDATA421() throws Exception 
{
         with()
-            .body(ALWAYS_421_DATA_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.DATA)
+                .matching(anyInput())
+                .thenRespond(serviceNotAvailable("mock response"))
+                .anyTimes()
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -283,7 +224,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldNotRetryWhenRCPT500() throws Exception {
         with()
-            .body(SINGLE_500_RCPT_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.RCPT_TO)
+                .matching(anyInput())
+                .thenRespond(doesNotAcceptAnyMail("mock message"))
+                .onlySomeTimes(1)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -300,7 +247,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldNotRetryWhenFROM500() throws Exception {
         with()
-            .body(SINGLE_500_FROM_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.MAIL_FROM)
+                .matching(anyInput())
+                .thenRespond(doesNotAcceptAnyMail("mock message"))
+                .onlySomeTimes(1)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -317,7 +270,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldNotRetryWhenDATA500() throws Exception {
         with()
-            .body(SINGLE_500_DATA_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.DATA)
+                .matching(anyInput())
+                .thenRespond(doesNotAcceptAnyMail("mock message"))
+                .onlySomeTimes(1)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -334,7 +293,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldRetryWhenRCPT421() throws Exception {
         with()
-            .body(TWICE_421_RCPT_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.RCPT_TO)
+                .matching(anyInput())
+                .thenRespond(serviceNotAvailable("mock response"))
+                .onlySomeTimes(2)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -353,7 +318,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldRetryWhenFROM421() throws Exception {
         with()
-            .body(TWICE_421_FROM_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.MAIL_FROM)
+                .matching(anyInput())
+                .thenRespond(serviceNotAvailable("mock response"))
+                .onlySomeTimes(2)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -372,7 +343,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldRetryWhenDATA421() throws Exception {
         with()
-            .body(TWICE_421_DATA_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.DATA)
+                .matching(anyInput())
+                .thenRespond(serviceNotAvailable("mock response"))
+                .onlySomeTimes(2)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -391,7 +368,13 @@ public class RemoteDeliveryErrorTest {
     @Test
     public void remoteDeliveryShouldNotDuplicateContentWhenSendPartial() 
throws Exception {
         with()
-            .body(SINGLE_PARTIAL_RCPT_421_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.RCPT_TO)
+                .matching(inputContaining(RECIPIENT1))
+                .thenRespond(serviceNotAvailable("mock response"))
+                .onlySomeTimes(1)
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())
@@ -444,7 +427,13 @@ public class RemoteDeliveryErrorTest {
             .registerMxRecord(mockSmtp2.getContainerIp(), 
mockSmtp2.getContainerIp());
 
         given(requestSpecificationForMockSMTP1)
-            .body(ALWAYS_PARTIAL_RCPT_421_BEHAVIOR)
+            .body(MockSmtpBehaviors.builder()
+                .addNewBehavior()
+                .expect(SMTPCommand.RCPT_TO)
+                .matching(inputContaining(RECIPIENT2))
+                .thenRespond(serviceNotAvailable("mock response"))
+                .anyTimes()
+                .build())
             .put("/smtpBehaviors");
 
         messageSender.connect(LOCALHOST_IP, 
jamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort())


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to