|
| 1 | + |
| 2 | +package com.sparkpost.model.webhook.event; |
| 3 | + |
| 4 | +import org.apache.log4j.Level; |
| 5 | +import org.apache.log4j.Logger; |
| 6 | +import org.junit.After; |
| 7 | +import org.junit.AfterClass; |
| 8 | +import org.junit.Assert; |
| 9 | +import org.junit.Before; |
| 10 | +import org.junit.BeforeClass; |
| 11 | +import org.junit.Test; |
| 12 | + |
| 13 | +import com.google.gson.Gson; |
| 14 | + |
| 15 | +public class GenerationRejectionEventTest { |
| 16 | + |
| 17 | + private static final String EVENT_DATA = "{\n" |
| 18 | + + " \"type\": \"generation_rejection\",\n" |
| 19 | + + " \"recv_method\": \"esmtp\",\n" |
| 20 | + + " \"timestamp\": \"1416500167.242\",\n" |
| 21 | + + " \"node_name\": \"Test-Node\",\n" |
| 22 | + + " \"reason\": \"Example Generation Rejection Reason\",\n" |
| 23 | + + " \"campaign_id\": \"Test Campaign Name\",\n" |
| 24 | + + " \"template_id\": \"Test Template Name\",\n" |
| 25 | + + " \"message_id\": \"eaa89490-183d-4976-a217-0756bdf9b823\",\n" |
| 26 | + + " \"rcpt_to\": \"rcptTo@example.com\",\n" |
| 27 | + + " \"binding\": \"default\",\n" |
| 28 | + + " \"template_version\": \"0\",\n" |
| 29 | + + " \"error_code\": \"553\",\n" |
| 30 | + + " \"customer_id\": \"1\",\n" |
| 31 | + + " \"routing_domain\": \"example.com\",\n" |
| 32 | + + " \"rcpt_tags\": [],\n" |
| 33 | + + " \"transmission_id\": \"65832150921904142\",\n" |
| 34 | + + " \"rcpt_subs\": {},\n" |
| 35 | + + " \"binding_group\": \"default\",\n" |
| 36 | + + " \"rcpt_meta\": {}\n" |
| 37 | + + "}"; |
| 38 | + |
| 39 | + @BeforeClass |
| 40 | + public static void setUpClass() { |
| 41 | + Logger.getRootLogger().setLevel(Level.DEBUG); |
| 42 | + } |
| 43 | + |
| 44 | + @AfterClass |
| 45 | + public static void tearDownClass() { |
| 46 | + } |
| 47 | + |
| 48 | + @Before |
| 49 | + public void setUp() { |
| 50 | + } |
| 51 | + |
| 52 | + @After |
| 53 | + public void tearDown() { |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * |
| 58 | + */ |
| 59 | + @Test |
| 60 | + public void testDecodeRecipientAttributes() { |
| 61 | + Gson gson = new Gson(); |
| 62 | + //System.out.println("JSON: " + EVENT_DATA); |
| 63 | + GenerationRejectionEvent event = gson.fromJson(EVENT_DATA, GenerationRejectionEvent.class); |
| 64 | + |
| 65 | + Assert.assertNotNull(event); |
| 66 | + |
| 67 | + Assert.assertEquals(event.getReason(), "Example Generation Rejection Reason"); |
| 68 | + Assert.assertEquals(event.getTemplateVersion(), "0"); |
| 69 | + Assert.assertNull(event.getFriendlyFrom()); |
| 70 | + Assert.assertNull(event.getIpPool()); |
| 71 | + Assert.assertNotNull(event.getRcptMeta()); |
| 72 | + Assert.assertNotNull(event.getRcptTags()); |
| 73 | + Assert.assertEquals(event.getType(), "generation_rejection"); |
| 74 | + Assert.assertNull(event.getRawRcptTo()); |
| 75 | + Assert.assertNull(event.getEventId()); |
| 76 | + Assert.assertEquals(event.getRcptTo(), "rcptTo@example.com"); |
| 77 | + Assert.assertEquals(event.getRoutingDomain(), "example.com"); |
| 78 | + Assert.assertNull(event.getSendingIp()); |
| 79 | + Assert.assertNotNull(event.getRcptSubs()); |
| 80 | + Assert.assertNull(event.getRawReason()); |
| 81 | + Assert.assertEquals(event.getErrorCode(), "553"); |
| 82 | + Assert.assertNull(event.getSubaccountId()); |
| 83 | + Assert.assertEquals(event.getTemplateId(), "Test Template Name"); |
| 84 | + Assert.assertEquals(event.getTransmissionId(), "65832150921904142"); |
| 85 | + Assert.assertEquals(event.getCustomerId(), "1"); |
| 86 | + Assert.assertEquals(event.getCampaignId(), "Test Campaign Name"); |
| 87 | + Assert.assertEquals(event.getTimestamp(), "1416500167.242"); |
| 88 | + |
| 89 | + } |
| 90 | +} |
0 commit comments