|
| 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.RecipientList; |
| 17 | +import com.sparkpost.model.responses.RecipientListRetrieveResponse; |
| 18 | +import com.sparkpost.model.responses.RecipientListsListAllResponse; |
| 19 | +import com.sparkpost.model.responses.Response; |
| 20 | +import com.sparkpost.testhelpers.StubRestConnection; |
| 21 | + |
| 22 | +public class ResourceRecipientListsTests extends BaseResourceTest { |
| 23 | + |
| 24 | + @BeforeClass |
| 25 | + public static void setUpClass() { |
| 26 | + Logger.getRootLogger().setLevel(Level.DEBUG); |
| 27 | + } |
| 28 | + |
| 29 | + @AfterClass |
| 30 | + public static void tearDownClass() { |
| 31 | + } |
| 32 | + |
| 33 | + @Before |
| 34 | + public void setUp() { |
| 35 | + } |
| 36 | + |
| 37 | + @After |
| 38 | + public void tearDown() { |
| 39 | + } |
| 40 | + |
| 41 | + private static final class StubResponse extends Response { |
| 42 | + |
| 43 | + public static Response decode(Response response, Type typeOfT) { |
| 44 | + return new StubResponse(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + private static final class StubRecipientListRetrieveResponse extends RecipientListRetrieveResponse { |
| 49 | + |
| 50 | + public static RecipientListRetrieveResponse decode(Response response, Type typeOfT) { |
| 51 | + return new StubRecipientListRetrieveResponse(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private static final class StubRecipientListsListAllResponse extends RecipientListsListAllResponse { |
| 56 | + |
| 57 | + public static RecipientListsListAllResponse decode(Response response, Type typeOfT) { |
| 58 | + return new StubRecipientListsListAllResponse(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + private StubRestConnection buildStubConnection(Response response) { |
| 63 | + StubRestConnection conn = new StubRestConnection(response); |
| 64 | + return conn; |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void testCreate() throws SparkPostException { |
| 69 | + Integer maxNumberOfRecipientErrors = 0; |
| 70 | + RecipientList recipientList = new RecipientList(); |
| 71 | + |
| 72 | + StubRestConnection conn = buildStubConnection(new StubResponse()); |
| 73 | + Response response = ResourceRecipientLists.create(conn, maxNumberOfRecipientErrors, recipientList); |
| 74 | + Assert.assertNotNull(response); |
| 75 | + |
| 76 | + Assert.assertEquals(conn.getPath(), "/recipient-lists?num_rcpt_errors=0"); |
| 77 | + verifyWasPost(conn); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testRetrieve() throws SparkPostException { |
| 82 | + String recipientListId = "recipientListId"; |
| 83 | + |
| 84 | + StubRestConnection conn = buildStubConnection(new StubRecipientListRetrieveResponse()); |
| 85 | + Response response = ResourceRecipientLists.retrieve(conn, recipientListId, Boolean.TRUE); |
| 86 | + Assert.assertNotNull(response); |
| 87 | + |
| 88 | + Assert.assertEquals(conn.getPath(), "/recipient-lists/recipientListId?show_recipients=true"); |
| 89 | + verifyWasGet(conn); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void testListAll() throws SparkPostException { |
| 94 | + StubRestConnection conn = buildStubConnection(new StubRecipientListsListAllResponse()); |
| 95 | + Response response = ResourceRecipientLists.listAll(conn); |
| 96 | + Assert.assertNotNull(response); |
| 97 | + |
| 98 | + Assert.assertEquals(conn.getPath(), "/recipient-lists"); |
| 99 | + verifyWasGet(conn); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void testDelete() throws SparkPostException { |
| 104 | + String recipientListId = "recipientListId"; |
| 105 | + |
| 106 | + StubRestConnection conn = buildStubConnection(new StubRecipientListsListAllResponse()); |
| 107 | + Response response = ResourceRecipientLists.delete(conn, recipientListId); |
| 108 | + Assert.assertNotNull(response); |
| 109 | + |
| 110 | + Assert.assertEquals(conn.getPath(), "/recipient-lists/recipientListId"); |
| 111 | + verifyWasDelete(conn); |
| 112 | + } |
| 113 | + |
| 114 | +} |
0 commit comments