james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [49/50] [abbrv] james-project git commit: MAILET-115 DSNBounceTest was system dependant (timezone handling improved)
Date Wed, 11 Jan 2017 09:26:37 GMT
MAILET-115 DSNBounceTest was system dependant (timezone handling improved)


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1fd49113
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1fd49113
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1fd49113

Branch: refs/heads/master
Commit: 1fd491138c29387878cb9febd21fb8fd528f7def
Parents: 3fe5e06
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Jan 11 10:56:21 2017 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 11:02:15 2017 +0700

----------------------------------------------------------------------
 .../java/org/apache/mailet/base/DateFormats.java    | 16 +++++++++++-----
 .../apache/james/transport/mailets/DSNBounce.java   | 11 +++++++++--
 .../james/transport/mailets/DSNBounceTest.java      | 13 ++-----------
 3 files changed, 22 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1fd49113/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java b/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
index 0120a81..2527090 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/DateFormats.java
@@ -21,13 +21,19 @@
 package org.apache.mailet.base;
 
 import java.util.Locale;
+import java.util.TimeZone;
 
 import org.apache.commons.lang.time.FastDateFormat;
 
-public interface DateFormats {
-    FastDateFormat RFC822_DATE_FORMAT = FastDateFormat.getInstance("EEE, d MMM yyyy HH:mm:ss
'XXXXX' (z)", Locale.US);
-    FastDateFormat RFC977_SHORT_DATE_FORMAT = FastDateFormat.getInstance("yyMMdd HHmmss",
Locale.US);
-    FastDateFormat RFC977_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMdd HHmmss",
Locale.US);
-    FastDateFormat RFC2980_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss",
Locale.US);
+public class DateFormats {
+
+    public static FastDateFormat getRFC822FormatForTimeZone(TimeZone timeZone) {
+        return FastDateFormat.getInstance("EEE, d MMM yyyy HH:mm:ss 'XXXXX' (z)", timeZone,
Locale.US);
+    }
+
+    public static FastDateFormat RFC822_DATE_FORMAT = FastDateFormat.getInstance("EEE, d
MMM yyyy HH:mm:ss 'XXXXX' (z)", Locale.US);
+    public static FastDateFormat RFC977_SHORT_DATE_FORMAT = FastDateFormat.getInstance("yyMMdd
HHmmss", Locale.US);
+    public static FastDateFormat RFC977_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMdd
HHmmss", Locale.US);
+    public static FastDateFormat RFC2980_LONG_DATE_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss",
Locale.US);
 }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1fd49113/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
index abce80b..b40a542 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
@@ -32,6 +32,7 @@ import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.lang.time.FastDateFormat;
 import org.apache.james.core.MailImpl;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.transport.mailets.redirect.InitParameters;
@@ -112,11 +113,17 @@ public class DSNBounce extends GenericMailet implements RedirectNotify
{
     private static final String LINE_BREAK = "\n";
 
     private final DNSService dns;
+    private final FastDateFormat dateFormatter;
     private String messageString = null;
 
     @Inject
     public DSNBounce(DNSService dns) {
+        this(dns, DateFormats.RFC822_DATE_FORMAT);
+    }
+
+    public DSNBounce(DNSService dns, FastDateFormat dateFormatter) {
         this.dns = dns;
+        this.dateFormatter = dateFormatter;
     }
 
     @Override
@@ -281,7 +288,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify
{
     private String getDateHeader(Mail originalMail) throws MessagingException {
         String[] date = originalMail.getMessage().getHeader(RFC2822Headers.DATE);
         if (date == null) {
-            return DateFormats.RFC822_DATE_FORMAT.format(new Date());
+            return dateFormatter.format(new Date());
         }
         return date[0];
     }
@@ -401,7 +408,7 @@ public class DSNBounce extends GenericMailet implements RedirectNotify
{
         buffer.append("Action: failed").append(LINE_BREAK);
         buffer.append("Status: " + deliveryError).append(LINE_BREAK);
         buffer.append("Diagnostic-Code: " + getDiagnosticType(deliveryError) + "; " + deliveryError).append(LINE_BREAK);
-        buffer.append("Last-Attempt-Date: " + DateFormats.RFC822_DATE_FORMAT.format(lastUpdated))
+        buffer.append("Last-Attempt-Date: " + dateFormatter.format(lastUpdated))
             .append(LINE_BREAK);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/1fd49113/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
index 5f4e249..13d2152 100644
--- a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
+++ b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
@@ -39,6 +39,7 @@ import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
+import org.apache.mailet.base.DateFormats;
 import org.apache.mailet.base.MailAddressFixture;
 import org.apache.mailet.base.RFC2822Headers;
 import org.apache.mailet.base.mail.MimeMultipartReport;
@@ -47,7 +48,6 @@ import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailContext.SentMail;
 import org.apache.mailet.base.test.FakeMailetConfig;
 import org.joda.time.DateTime;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -62,15 +62,11 @@ public class DSNBounceTest {
 
     private DSNBounce dsnBounce;
     private FakeMailContext fakeMailContext;
-    private TimeZone timeZone;
 
     @Before
     public void setUp() throws Exception {
-        timeZone = TimeZone.getDefault();
-        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
-
         DNSService dnsService = mock(DNSService.class);
-        dsnBounce = new DSNBounce(dnsService);
+        dsnBounce = new DSNBounce(dnsService, DateFormats.getRFC822FormatForTimeZone(TimeZone.getTimeZone("UTC")));
         fakeMailContext = FakeMailContext.defaultContext();
 
         InetAddress localHost = InetAddress.getLocalHost();
@@ -80,11 +76,6 @@ public class DSNBounceTest {
             .thenReturn("myhost");
     }
 
-    @After
-    public void tearDown() {
-        TimeZone.setDefault(timeZone);
-    }
-
     @Test
     public void getMailetInfoShouldReturnValue() {
         assertThat(dsnBounce.getMailetInfo()).isEqualTo("DSNBounce Mailet");


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


Mime
View raw message