|
| 1 | + |
| 2 | +package com.sparkpost.resources; |
| 3 | + |
| 4 | +import java.lang.reflect.Type; |
| 5 | + |
| 6 | +import org.apache.log4j.Level; |
| 7 | +import org.apache.log4j.Logger; |
| 8 | +import org.junit.After; |
| 9 | +import org.junit.AfterClass; |
| 10 | +import org.junit.Assert; |
| 11 | +import org.junit.Before; |
| 12 | +import org.junit.BeforeClass; |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +import com.sparkpost.exception.SparkPostException; |
| 16 | +import com.sparkpost.model.SuppressionList; |
| 17 | +import com.sparkpost.model.SuppressionListEntry; |
| 18 | +import com.sparkpost.model.responses.Response; |
| 19 | +import com.sparkpost.testhelpers.StubRestConnection; |
| 20 | + |
| 21 | +public class ResourceSuppressionListTests extends BaseResourceTest { |
| 22 | + |
| 23 | + @BeforeClass |
| 24 | + public static void setUpClass() { |
| 25 | + Logger.getRootLogger().setLevel(Level.DEBUG); |
| 26 | + } |
| 27 | + |
| 28 | + @AfterClass |
| 29 | + public static void tearDownClass() { |
| 30 | + } |
| 31 | + |
| 32 | + @Before |
| 33 | + public void setUp() { |
| 34 | + } |
| 35 | + |
| 36 | + @After |
| 37 | + public void tearDown() { |
| 38 | + } |
| 39 | + |
| 40 | + private static final class StubResponse extends Response { |
| 41 | + |
| 42 | + public static Response decode(Response response, Type typeOfT) { |
| 43 | + return new StubResponse(); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + private StubRestConnection buildStubConnection() { |
| 48 | + StubRestConnection conn = new StubRestConnection(new StubResponse()); |
| 49 | + return conn; |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testInsertOrUpdate() throws SparkPostException { |
| 54 | + String email = "email"; |
| 55 | + SuppressionListEntry entry = new SuppressionListEntry(); |
| 56 | + |
| 57 | + StubRestConnection conn = buildStubConnection(); |
| 58 | + Response response = ResourceSuppressionList.insertOrUpdate(conn, email, entry); |
| 59 | + Assert.assertNotNull(response); |
| 60 | + |
| 61 | + Assert.assertEquals(conn.getPath(), "/suppression-list/" + email); |
| 62 | + verifyWasPut(conn); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + public void testInsertOrUpdateBulk() throws SparkPostException { |
| 67 | + SuppressionList suppressionList = new SuppressionList(); |
| 68 | + |
| 69 | + StubRestConnection conn = buildStubConnection(); |
| 70 | + Response response = ResourceSuppressionList.insertOrUpdateBulk(conn, suppressionList); |
| 71 | + Assert.assertNotNull(response); |
| 72 | + |
| 73 | + Assert.assertEquals(conn.getPath(), "/suppression-list/"); |
| 74 | + verifyWasPut(conn); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testSearch() throws SparkPostException { |
| 79 | + String to = "to"; |
| 80 | + String from = "from"; |
| 81 | + String types = "types"; |
| 82 | + String limit = "limit"; |
| 83 | + |
| 84 | + StubRestConnection conn = buildStubConnection(); |
| 85 | + Response response = ResourceSuppressionList.search(conn, to, from, types, limit); |
| 86 | + Assert.assertNotNull(response); |
| 87 | + |
| 88 | + Assert.assertEquals(conn.getPath(), "/suppression-list?to=to&from=from&types=types&limit=limit"); |
| 89 | + verifyWasGet(conn); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void testCheck() throws SparkPostException { |
| 94 | + String email = "email"; |
| 95 | + |
| 96 | + StubRestConnection conn = buildStubConnection(); |
| 97 | + Response response = ResourceSuppressionList.check(conn, email); |
| 98 | + Assert.assertNotNull(response); |
| 99 | + |
| 100 | + Assert.assertEquals(conn.getPath(), "/suppression-list/" + email); |
| 101 | + verifyWasGet(conn); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void testRemove() throws SparkPostException { |
| 106 | + String email = "email"; |
| 107 | + |
| 108 | + StubRestConnection conn = buildStubConnection(); |
| 109 | + Response response = ResourceSuppressionList.remove(conn, email); |
| 110 | + Assert.assertNotNull(response); |
| 111 | + |
| 112 | + Assert.assertEquals(conn.getPath(), "/suppression-list/" + email); |
| 113 | + verifyWasDelete(conn); |
| 114 | + } |
| 115 | + |
| 116 | +} |
0 commit comments