From 87c7c4158366f8ab01d947fa9df09768756f1693 Mon Sep 17 00:00:00 2001 From: Lodewijck Vogelzang Date: Thu, 26 Jan 2017 15:55:49 +0100 Subject: [PATCH 1/2] Added SMTP data to info response. --- .../lutung/view/MandrillMessageInfo.java | 22 +++++++++- .../controller/MandrillMessagesApiTest.java | 41 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java b/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java index 02f56c4..5f73079 100644 --- a/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java +++ b/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java @@ -140,8 +140,8 @@ public final String getUa() { } public static class SMTPEvent { - private Integer ts; - private String type, diag; + private Integer ts, size; + private String type, diag, source_ip, destination_ip; /** * @return The Unix timestamp when the event occured. @@ -161,6 +161,24 @@ public final String getType() { public final String getDiag() { return diag; } + /** + * @return The sender's IP address. + */ + public final String getSourceIp() { + return source_ip; + } + /** + * @return The recipient's IP address. + */ + public final String getDestinationIp() { + return destination_ip; + } + /** + * @return The SMTP response from the recipient's server. + */ + public final int getSize() { + return size; + } } diff --git a/src/test/java/com/microtripit/mandrillapp/lutung/controller/MandrillMessagesApiTest.java b/src/test/java/com/microtripit/mandrillapp/lutung/controller/MandrillMessagesApiTest.java index a00f458..4080f0b 100644 --- a/src/test/java/com/microtripit/mandrillapp/lutung/controller/MandrillMessagesApiTest.java +++ b/src/test/java/com/microtripit/mandrillapp/lutung/controller/MandrillMessagesApiTest.java @@ -3,6 +3,10 @@ */ package com.microtripit.mandrillapp.lutung.controller; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; @@ -14,12 +18,15 @@ import org.junit.Test; import com.microtripit.mandrillapp.lutung.MandrillTestCase; +import com.microtripit.mandrillapp.lutung.model.LutungGsonUtils; import com.microtripit.mandrillapp.lutung.model.MandrillApiError; +import com.microtripit.mandrillapp.lutung.model.MandrillApiError.MandrillError; import com.microtripit.mandrillapp.lutung.view.MandrillMessage; import com.microtripit.mandrillapp.lutung.view.MandrillMessage.Recipient; import com.microtripit.mandrillapp.lutung.view.MandrillMessage.Recipient.Type; import com.microtripit.mandrillapp.lutung.view.MandrillMessageContent; import com.microtripit.mandrillapp.lutung.view.MandrillMessageInfo; +import com.microtripit.mandrillapp.lutung.view.MandrillMessageInfo.SMTPEvent; import com.microtripit.mandrillapp.lutung.view.MandrillMessageStatus; import com.microtripit.mandrillapp.lutung.view.MandrillSearchMessageParams; import com.microtripit.mandrillapp.lutung.view.MandrillTemplate; @@ -166,4 +173,38 @@ public void testParse02() throws IOException, MandrillApiError { MandrillMessage parsedMessage = mandrillApi.messages().parse(null); Assert.fail(); } + + @Test + public void testSmtpInfoResponse() { + String responseString = "{\"ts\":1234567890," + + "\"_id\":\"12345678901234567890123456789012\"," + + "\"state\":\"sent\"," + + "\"subject\":\"Subject\"," + + "\"email\":\"test@test.com\"," + + "\"tags\":[\"deliverable\"]," + + "\"opens\":0," + + "\"clicks\":0," + + "\"smtp_events\":[" + + "{\"ts\":1234567890,\"type\":\"sent\",\"diag\":\"250 Queued mail for delivery\"," + + "\"source_ip\":\"127.0.0.1\",\"destination_ip\":\"127.0.0.2\",\"size\":12345}," + + "{\"ts\":1234567890,\"type\":\"sent\",\"diag\":\"250 Queued mail for delivery\"," + + "\"source_ip\":\"127.0.0.1\",\"destination_ip\":\"127.0.0.2\",\"size\":12345}]," + + "\"resends\":[]," + + "\"sender\":\"hello@hello.com\"," + + "\"template\":null," + + "\"metadata\":{}," + + "\"opens_detail\":[]," + + "\"clicks_detail\":[]}"; + + MandrillMessageInfo m = LutungGsonUtils.getGson().fromJson(responseString, MandrillMessageInfo.class); + Assert.assertEquals(2, m.getSmtpEvents().size()); + SMTPEvent event = m.getSmtpEvents().get(1); + Assert.assertEquals(1234567890, (int)event.getTs()); + Assert.assertEquals("sent", event.getType()); + Assert.assertEquals("250 Queued mail for delivery", event.getDiag()); + Assert.assertEquals("127.0.0.1", event.getSourceIp()); + Assert.assertEquals("127.0.0.2", event.getDestinationIp()); + Assert.assertEquals(12345, event.getSize()); + + } } From 0e5026a74f5c678e3ca42eabff0ab5b81fafa6ff Mon Sep 17 00:00:00 2001 From: Lodewijck Vogelzang Date: Thu, 26 Jan 2017 16:01:06 +0100 Subject: [PATCH 2/2] Fixed comment mistake. --- .../mandrillapp/lutung/view/MandrillMessageInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java b/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java index 5f73079..c591d63 100644 --- a/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java +++ b/src/main/java/com/microtripit/mandrillapp/lutung/view/MandrillMessageInfo.java @@ -174,7 +174,7 @@ public final String getDestinationIp() { return destination_ip; } /** - * @return The SMTP response from the recipient's server. + * @return The size of event. */ public final int getSize() { return size;