Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merging latest version

  • Loading branch information...
commit 68b9362ba6d837fc2547307cec78a67b49bbc99b 2 parents 4bc1056 + 5cd2c3b
@pbackx authored
View
72 src/it/java/com/cribbstechnologies/clients/mandrill/it/MessagesTest.java
@@ -2,14 +2,12 @@
import static org.junit.Assert.fail;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import com.cribbstechnologies.clients.mandrill.model.*;
@@ -35,10 +33,16 @@
private static MandrillMessagesRequest messagesRequest = new MandrillMessagesRequest();
private static HttpClient client;
private static ObjectMapper mapper = new ObjectMapper();
+ private static Properties props = new Properties();
@BeforeClass
public static void beforeClass() {
- config.setApiKey("b9fe9170-08f7-4f56-b0d1-e56ce1e426e7");
+ try {
+ props.load(MessagesTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
+ } catch (IOException e) {
+ fail ("properties file not loaded");
+ }
+ config.setApiKey(props.getProperty("apiKey"));
config.setApiVersion("1.0");
config.setBaseURL("https://mandrillapp.com/api");
request.setConfig(config);
@@ -52,42 +56,42 @@ public void before() {
// request.setHttpClient(client);
}
-// @Test
-// public void testSendMessage() {
-// MandrillMessageRequest mmr = new MandrillMessageRequest();
-// MandrillHtmlMessage message = new MandrillHtmlMessage();
-// Map<String, String> headers = new HashMap<String, String>();
-// message.setFrom_email("peter.backx@fctr.be");
-// message.setFrom_name("Peter Backx");
-// message.setHeaders(headers);
-// message.setHtml("<html><body><h1>Oh snap!</h1>Guess what I saw?<a href=\"http://www.google.com\">google</a></body></html>");
-// message.setSubject("This is the subject");
-// MandrillRecipient[] recipients = new MandrillRecipient[]{new MandrillRecipient("Peter Backx", "peter.backx@gmail.com")}; //, new MandrillRecipient("Brian Cribbs", "brian@cribbstechnologies.com")};
-// message.setTo(recipients);
-// message.setTrack_clicks(true);
-// message.setTrack_opens(true);
-// String[] tags = new String[]{"tag1", "tag2", "tag3"};
-// message.setTags(tags);
-// mmr.setMessage(message);
-//
-// try {
-// SendMessageResponse response = messagesRequest.sendMessage(mmr);
-// } catch (RequestFailedException e) {
-// e.printStackTrace();
-// fail(e.getMessage());
-// }
-// }
+ @Test
+ public void testSendMessage() {
+ MandrillMessageRequest mmr = new MandrillMessageRequest();
+ MandrillHtmlMessage message = new MandrillHtmlMessage();
+ Map<String, String> headers = new HashMap<String, String>();
+ message.setFrom_email(props.getProperty("email.from"));
+ message.setFrom_name("Big Jimmy");
+ message.setHeaders(headers);
+ message.setHtml("<html><body><h1>Oh snap!</h1>Guess what I saw?<a href=\"http://www.google.com\">google</a></body></html>");
+ message.setSubject("This is the subject");
+ MandrillRecipient[] recipients = new MandrillRecipient[]{new MandrillRecipient(props.getProperty("email.to.name1"), props.getProperty("email.to.address1")), new MandrillRecipient(props.getProperty("email.to.name2"), props.getProperty("email.to.address2"))};
+ message.setTo(recipients);
+ message.setTrack_clicks(true);
+ message.setTrack_opens(true);
+ String[] tags = new String[]{"tag1", "tag2", "tag3"};
+ message.setTags(tags);
+ mmr.setMessage(message);
+
+ try {
+ SendMessageResponse response = messagesRequest.sendMessage(mmr);
+ } catch (RequestFailedException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
@Test
public void testSendTemplatedMessage() throws Exception {
MandrillTemplatedMessageRequest request = new MandrillTemplatedMessageRequest();
MandrillMessage message = new MandrillMessage();
Map<String, String> headers = new HashMap<String, String>();
- message.setFrom_email("peter.backx@fctr.be");
- message.setFrom_name("Peter Backx");
+ message.setFrom_email(props.getProperty("email.from"));
+ message.setFrom_name("Big Jimmy");
message.setHeaders(headers);
- message.setSubject("Activeren, nu met attachment");
- MandrillRecipient[] recipients = new MandrillRecipient[]{new MandrillRecipient("Peter Backx", "peter.backx@gmail.com")}; //, new MandrillRecipient("Brian Cribbs", "brian@cribbstechnologies.com")};
+ message.setSubject("This is the subject");
+ MandrillRecipient[] recipients = new MandrillRecipient[]{new MandrillRecipient(props.getProperty("email.to.name1"), props.getProperty("email.to.address1")), new MandrillRecipient(props.getProperty("email.to.name2"), props.getProperty("email.to.address2"))};
message.setTo(recipients);
message.setTrack_clicks(true);
message.setTrack_opens(true);
View
11 src/it/java/com/cribbstechnologies/clients/mandrill/it/TagsTest.java
@@ -2,6 +2,9 @@
import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.util.Properties;
+
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.codehaus.jackson.map.ObjectMapper;
@@ -28,7 +31,13 @@
@BeforeClass
public static void beforeClass() {
- config.setApiKey("a2d9f0f9-5646-4af2-a507-76758c71631b");
+ Properties props = new Properties();
+ try {
+ props.load(TagsTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
+ } catch (IOException e) {
+ fail ("properties file not loaded");
+ }
+ config.setApiKey(props.getProperty("apiKey"));
config.setApiVersion("1.0");
config.setBaseURL("https://mandrillapp.com/api");
request.setConfig(config);
View
11 src/it/java/com/cribbstechnologies/clients/mandrill/it/TemplatesTest.java
@@ -4,6 +4,9 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.util.Properties;
+
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.codehaus.jackson.map.ObjectMapper;
@@ -30,7 +33,13 @@
@BeforeClass
public static void beforeClass() {
- config.setApiKey("a2d9f0f9-5646-4af2-a507-76758c71631b");
+ Properties props = new Properties();
+ try {
+ props.load(TemplatesTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
+ } catch (IOException e) {
+ fail ("properties file not loaded");
+ }
+ config.setApiKey(props.getProperty("apiKey"));
config.setApiVersion("1.0");
config.setBaseURL("https://mandrillapp.com/api");
request.setConfig(config);
View
11 src/it/java/com/cribbstechnologies/clients/mandrill/it/UrlsTest.java
@@ -2,6 +2,9 @@
import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.util.Properties;
+
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.codehaus.jackson.map.ObjectMapper;
@@ -28,7 +31,13 @@
@BeforeClass
public static void beforeClass() {
- config.setApiKey("a2d9f0f9-5646-4af2-a507-76758c71631b");
+ Properties props = new Properties();
+ try {
+ props.load(UrlsTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
+ } catch (IOException e) {
+ fail ("properties file not loaded");
+ }
+ config.setApiKey(props.getProperty("apiKey"));
config.setApiVersion("1.0");
config.setBaseURL("https://mandrillapp.com/api");
request.setConfig(config);
View
13 src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java
@@ -3,6 +3,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.util.Properties;
+
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.codehaus.jackson.map.ObjectMapper;
@@ -30,10 +33,16 @@
private static MandrillUsersRequest usersRequest = new MandrillUsersRequest();
private static HttpClient client;
private static ObjectMapper mapper = new ObjectMapper();
+ private static Properties props = new Properties();
@BeforeClass
public static void beforeClass() {
- config.setApiKey("a2d9f0f9-5646-4af2-a507-76758c71631b");
+ try {
+ props.load(UsersTest.class.getClassLoader().getResourceAsStream("mandrill.properties"));
+ } catch (IOException e) {
+ fail ("properties file not loaded");
+ }
+ config.setApiKey(props.getProperty("apiKey"));
config.setApiVersion("1.0");
config.setBaseURL("https://mandrillapp.com/api");
request.setConfig(config);
@@ -82,7 +91,7 @@ public void testGetSenders() {
@Test
public void testVerifySender() {
MandrillRequestWithEmail emailRequest = new MandrillRequestWithEmail();
- emailRequest.setEmail("radar@cribbstechnologies.com");
+ emailRequest.setEmail(props.getProperty("verify.email"));
try {
VerifyResponse response = usersRequest.verifySender(emailRequest);
} catch (RequestFailedException e) {
View
6 src/main/java/com/cribbstechnologies/clients/mandrill/model/BaseMandrillRequest.java
@@ -1,7 +1,11 @@
package com.cribbstechnologies.clients.mandrill.model;
public class BaseMandrillRequest {
-
+
+ /*
+ * It's not necessary to set this field manually as the MandrillRESTRequest pulls the property
+ * from the configuration and populates this object with it on every request.
+ */
private String key;
public String getKey() {
View
2  src/main/java/com/cribbstechnologies/clients/mandrill/model/response/templates/TemplateResponse.java
@@ -1,7 +1,9 @@
package com.cribbstechnologies.clients.mandrill.model.response.templates;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillResponse;
+@JsonIgnoreProperties(ignoreUnknown=true)
public class TemplateResponse extends BaseMandrillResponse {
String id;
View
11 src/main/java/com/cribbstechnologies/clients/mandrill/model/response/users/UsersInfoResponse.java
@@ -9,6 +9,7 @@
String created_at;
int reputation;
int hourly_quota;
+ int backlog;
StatsResponseMap stats;
@@ -52,4 +53,14 @@ public void setStats(StatsResponseMap stats) {
this.stats = stats;
}
+ public int getBacklog() {
+ return backlog;
+ }
+
+ public void setBacklog(int backlog) {
+ this.backlog = backlog;
+ }
+
+
+
}
View
6 src/main/java/com/cribbstechnologies/clients/mandrill/request/MandrillRESTRequest.java
@@ -79,10 +79,10 @@ private BaseMandrillResponse performPostRequest(BaseMandrillRequest request, Str
StringBuffer sb = new StringBuffer();
String output;
- System.out.println("Output from Server .... \n");
+ //System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
sb.append(output);
- System.out.println(output);
+ //System.out.println(output);
}
String responseString = sb.toString();
@@ -143,4 +143,4 @@ public void setObjectMapper(ObjectMapper objectMapper) {
}
-}
+}
View
33 src/main/resources/spring/mandrillConfig.xml
@@ -0,0 +1,33 @@
+<bean id="defaultMandrillConfiguration" class="com.cribbstechnologies.clients.mandrill.util.MandrillConfiguration">
+ <property name="apiVersion" value=""/>
+ <property name="baseURL" value="https://mandrillapp.com/api"/>
+ <property name="apiKey" value="1.0"/>
+</bean>
+
+<bean id="apacheHttpClient" class="org.apache.http.impl.client.DefaultHttpClient"/>
+<bean id="defaultObjectMapper" class="org.codehaus.jackson.map.ObjectMapper"/>
+
+<bean id="mandrillRESTRequest" class="com.cribbstechnologies.clients.mandrill.request.MandrillRestRequest">
+ <property name="config" ref="defaultMandrillConfiguration"/>
+ <property name="httpClient" ref="apacheHttpClient"/>
+ <property name="objectMapper" ref="defaultObjectMapper"/>
+</bean>
+
+
+<!-- Request Classes -->
+
+<bean id="messagesRequest" class="com.cribbstechnologies.clients.mandrill.request.MandrillMessagesRequest">
+ <property name="request" value="mandrillRESTRequest"/>
+</bean>
+<bean id="tagsRequest" class="com.cribbstechnologies.clients.mandrill.request.MandrillTagsRequest">
+ <property name="request" value="mandrillRESTRequest"/>
+</bean>
+<bean id="templatesRequest" class="com.cribbstechnologies.clients.mandrill.request.MandrillTemplatesRequest">
+ <property name="request" value="mandrillRESTRequest"/>
+</bean>
+<bean id="urlsRequest" class="com.cribbstechnologies.clients.mandrill.request.MandrillUrlsRequest">
+ <property name="request" value="mandrillRESTRequest"/>
+</bean>
+<bean id="usersRequest" class="com.cribbstechnologies.clients.mandrill.request.MandrillUsersRequest">
+ <property name="request" value="mandrillRESTRequest"/>
+</bean>
View
7 src/test/resources/mandrill.properties
@@ -0,0 +1,7 @@
+apiKey=a2d9f0f9-5646-4af2-a507-76758c71631b
+email.from=jim@cribbstechnologies.com
+email.to.name1=Brian Cribbs
+email.to.address1=brian@cribbstechnologies.com
+email.to.name2=Brian Cribbs
+email.to.address2=briancribbs@gmail.com
+verify.email=radar@cribbstechnologies.com
Please sign in to comment.
Something went wrong with that request. Please try again.