Skip to content

Commit 914f4af

Browse files
author
Chris Wilson
committed
Adding more unit tests to verify issue #57
1 parent 872ef1d commit 914f4af

File tree

2 files changed

+218
-0
lines changed

2 files changed

+218
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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.SendingDomain;
17+
import com.sparkpost.model.VerifyAttributes;
18+
import com.sparkpost.model.responses.Response;
19+
import com.sparkpost.testhelpers.StubRestConnection;
20+
21+
public class ResourceSendingDomainsTests 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 testCreate() throws SparkPostException {
54+
SendingDomain sendingDomain = new SendingDomain();
55+
56+
StubRestConnection conn = buildStubConnection();
57+
Response response = ResourceSendingDomains.create(conn, sendingDomain);
58+
Assert.assertNotNull(response);
59+
60+
Assert.assertEquals(conn.getPath(), "/sending-domains");
61+
verifyWasPost(conn);
62+
}
63+
64+
@Test
65+
public void testRetrieve() throws SparkPostException {
66+
String domainName = "domainName";
67+
68+
StubRestConnection conn = buildStubConnection();
69+
Response response = ResourceSendingDomains.retrieve(conn, domainName);
70+
Assert.assertNotNull(response);
71+
72+
Assert.assertEquals(conn.getPath(), "/sending-domains/" + domainName);
73+
verifyWasGet(conn);
74+
}
75+
76+
@Test
77+
public void testUpdate() throws SparkPostException {
78+
String domainName = "domainName";
79+
SendingDomain sendingDomain = new SendingDomain();
80+
81+
StubRestConnection conn = buildStubConnection();
82+
Response response = ResourceSendingDomains.update(conn, domainName, sendingDomain);
83+
Assert.assertNotNull(response);
84+
85+
Assert.assertEquals(conn.getPath(), "/sending-domains/" + domainName);
86+
verifyWasPut(conn);
87+
}
88+
89+
@Test
90+
public void testVerify() throws SparkPostException {
91+
String domainName = "domainName";
92+
VerifyAttributes verifyAttributes = new VerifyAttributes();
93+
94+
StubRestConnection conn = buildStubConnection();
95+
Response response = ResourceSendingDomains.verify(conn, domainName, verifyAttributes);
96+
Assert.assertNotNull(response);
97+
98+
Assert.assertEquals(conn.getPath(), "/sending-domains/" + domainName + "/verify");
99+
verifyWasPost(conn);
100+
}
101+
102+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)