Mijeong Park Mijeong Park 2018-01-29
noti: Add function for sending email noti with Plain format in case of ISSUE_BODY_CHANGED
@7b05d49a09b10acaa6972d231a24bfbfe1a4c4c2
app/models/NotificationEvent.java
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
@@ -36,6 +36,7 @@
 import javax.naming.LimitExceededException;
 import javax.persistence.*;
 import javax.servlet.ServletException;
+import java.beans.Transient;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -196,6 +197,21 @@
         }
     }
 
+    @Transient
+    public String getPlainMessage() {
+        return getPlainMessage(Lang.defaultLang());
+    }
+
+    @Transient
+    public String getPlainMessage(Lang lang) {
+        switch(eventType) {
+            case ISSUE_BODY_CHANGED:
+                return DiffUtil.getDiffPlainText(oldValue, newValue);
+            default:
+                return null;
+        }
+    }
+
     /**
      * Builds a notification message for a comment on code.
      *
test/models/NotificationEventTest.java
--- test/models/NotificationEventTest.java
+++ test/models/NotificationEventTest.java
@@ -161,4 +161,36 @@
         assertThat(result.length() > 0).isTrue();
     }
 
+  @Test
+  public void getPlainMessage_eventTypeIsIssueBodyChangedWithNoParameter_returnString() {
+
+    // Given
+    NotificationEvent notificationEvent = getNotificationEvent(ResourceType.ISSUE_POST);
+    notificationEvent.eventType = EventType.ISSUE_BODY_CHANGED;
+    notificationEvent.oldValue = "old value";
+    notificationEvent.newValue = "new value";
+
+    // When
+    String result = notificationEvent.getPlainMessage();
+
+    // Then
+    assertThat(result.length() > 0).isTrue();
+  }
+
+  @Test
+  public void getPlainMessage_eventTypeIsIssueBodyChangedWithParameter_returnString() {
+
+    // Given
+    NotificationEvent notificationEvent = getNotificationEvent(ResourceType.ISSUE_POST);
+    notificationEvent.eventType = EventType.ISSUE_BODY_CHANGED;
+    notificationEvent.oldValue = "old value";
+    notificationEvent.newValue = "new value";
+
+    // When
+    String result = notificationEvent.getPlainMessage(Lang.defaultLang());
+
+    // Then
+    assertThat(result.length() > 0).isTrue();
+  }
+
 }
Add a comment
List