Search in sources :

Example 1 with MandrillMessageRequest

use of com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MandrillRESTRequestTest method testGetPostDataMandrillMessageRequestWithBCC.

@Test
public void testGetPostDataMandrillMessageRequestWithBCC() throws Exception {
    initRequestWithActualMapper();
    emptyMessageRequest.setMessage(emptyMessage);
    assertEquals("{\"key\":null,\"message\":null}", request.getPostData(emptyMessageRequest));
    mutableMessageRequest = new MandrillMessageRequest();
    mutableMessageRequest.setKey("API Key");
    mutableMessage = new MandrillHtmlMessage();
    mutableMessage.setHtml("Test html");
    mutableMessage.setText("Test text");
    mutableMessage.setSubject("Test subject");
    mutableMessage.setFrom_email("from@email.com");
    mutableMessage.setFrom_name("From Name");
    MandrillRecipient[] to = new MandrillRecipient[2];
    to[0] = new MandrillRecipient("to1", "to1");
    to[1] = new MandrillRecipient("to2", "to2");
    mutableMessage.setTo(to);
    mutableMessage.setBcc_address("bcc@email.com");
    mutableMessage.setTrack_opens(false);
    mutableMessage.setTrack_clicks(true);
    String[] tags = new String[2];
    tags[0] = "tag1";
    tags[1] = "tag2";
    mutableMessage.setTags(tags);
    Map<String, String> headerMap = new HashMap<String, String>();
    headerMap.put("headerName", "headerValue");
    mutableMessage.setHeaders(headerMap);
    mutableMessageRequest.setMessage(mutableMessage);
    //		System.out.println(request.getPostData(mutableMessageRequest));
    StringBuffer sb = new StringBuffer();
    sb.append("{");
    sb.append("\"key\":\"API Key\"");
    sb.append(",\"message\":{");
    sb.append("\"text\":\"Test text\"");
    sb.append(",\"subject\":\"Test subject\"");
    sb.append(",\"from_email\":\"from@email.com\"");
    sb.append(",\"from_name\":\"From Name\"");
    sb.append(",\"subaccount\":null");
    sb.append(",\"to\":[{\"email\":\"to1\",\"name\":\"to1\"},{\"email\":\"to2\",\"name\":\"to2\"}]");
    sb.append(",\"bcc_address\":\"bcc@email.com\"");
    sb.append(",\"track_opens\":false");
    sb.append(",\"track_clicks\":true");
    sb.append(",\"auto_text\":false");
    sb.append(",\"url_strip_qs\":false");
    sb.append(",\"preserve_recipients\":false");
    sb.append(",\"tags\":[\"tag1\",\"tag2\"]");
    sb.append(",\"google_analytics_domains\":[]");
    sb.append(",\"google_analytics_campaign\":[]");
    sb.append(",\"global_merge_vars\":null");
    sb.append(",\"merge_vars\":null");
    sb.append(",\"attachments\":null");
    sb.append(",\"important\":false");
    sb.append(",\"auto_html\":false");
    sb.append(",\"inline_css\":false");
    sb.append(",\"merge\":false");
    sb.append(",\"merge_language\":null");
    sb.append(",\"metadata\":null");
    sb.append(",\"recipient_metadata\":null");
    sb.append(",\"headers\":{\"headerName\":\"headerValue\"},");
    sb.append("\"html\":\"Test html\"");
    sb.append("}}");
    String output = request.getPostData(mutableMessageRequest);
    System.out.println("Comparing:\n" + sb.toString() + "\n" + output);
    assertEquals(sb.toString(), output);
}
Also used : HashMap(java.util.HashMap) MandrillMessageRequest(com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest) MandrillHtmlMessage(com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage) MandrillRecipient(com.cribbstechnologies.clients.mandrill.model.MandrillRecipient) Test(org.junit.Test)

Example 2 with MandrillMessageRequest

use of com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MandrillRESTRequestTest method testGetPostDataMandrillMessageRequest.

@Test
public void testGetPostDataMandrillMessageRequest() throws Exception {
    this.initRequestWithActualMapper();
    this.emptyMessageRequest.setMessage(this.emptyMessage);
    assertEquals("{\"key\":null,\"message\":null}", this.request.getPostData(this.emptyMessageRequest));
    this.mutableMessageRequest = new MandrillMessageRequest();
    this.mutableMessageRequest.setKey("API Key");
    this.mutableMessage = new MandrillHtmlMessage();
    this.mutableMessage.setHtml("Test html");
    this.mutableMessage.setText("Test text");
    this.mutableMessage.setSubject("Test subject");
    this.mutableMessage.setFrom_email("from@email.com");
    this.mutableMessage.setFrom_name("From Name");
    this.mutableMessage.setSubaccount("test");
    MandrillRecipient[] to = new MandrillRecipient[2];
    to[0] = new MandrillRecipient("to1", "to1");
    to[1] = new MandrillRecipient("to2", "to2");
    this.mutableMessage.setTo(to);
    this.mutableMessage.setTrack_opens(false);
    this.mutableMessage.setTrack_clicks(true);
    String[] tags = new String[2];
    tags[0] = "tag1";
    tags[1] = "tag2";
    this.mutableMessage.setTags(tags);
    Map<String, String> headerMap = new HashMap<String, String>();
    headerMap.put("headerName", "headerValue");
    this.mutableMessage.setHeaders(headerMap);
    this.mutableMessageRequest.setMessage(this.mutableMessage);
    // System.out.println(request.getPostData(mutableMessageRequest));
    StringBuffer sb = new StringBuffer();
    sb.append("{");
    sb.append("\"key\":\"API Key\"");
    sb.append(",\"message\":{");
    sb.append("\"text\":\"Test text\"");
    sb.append(",\"subject\":\"Test subject\"");
    sb.append(",\"from_email\":\"from@email.com\"");
    sb.append(",\"from_name\":\"From Name\"");
    sb.append(",\"subaccount\":\"test\"");
    sb.append(",\"to\":[{\"email\":\"to1\",\"name\":\"to1\"},{\"email\":\"to2\",\"name\":\"to2\"}]");
    sb.append(",\"bcc_address\":null");
    sb.append(",\"track_opens\":false");
    sb.append(",\"track_clicks\":true");
    sb.append(",\"auto_text\":false");
    sb.append(",\"url_strip_qs\":false");
    sb.append(",\"preserve_recipients\":false");
    sb.append(",\"tags\":[\"tag1\",\"tag2\"]");
    sb.append(",\"google_analytics_domains\":[]");
    sb.append(",\"google_analytics_campaign\":[]");
    sb.append(",\"global_merge_vars\":null");
    sb.append(",\"merge_vars\":null");
    sb.append(",\"attachments\":null");
    sb.append(",\"important\":false");
    sb.append(",\"auto_html\":false");
    sb.append(",\"inline_css\":false");
    sb.append(",\"merge\":false");
    sb.append(",\"merge_language\":null");
    sb.append(",\"metadata\":null");
    sb.append(",\"recipient_metadata\":null");
    sb.append(",\"headers\":{\"headerName\":\"headerValue\"},");
    sb.append("\"html\":\"Test html\"");
    sb.append("}}");
    String output = this.request.getPostData(this.mutableMessageRequest);
    System.out.println("Comparing:\n" + sb.toString() + "\n" + output);
    assertEquals(sb.toString(), output);
}
Also used : HashMap(java.util.HashMap) MandrillMessageRequest(com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest) MandrillHtmlMessage(com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage) MandrillRecipient(com.cribbstechnologies.clients.mandrill.model.MandrillRecipient) Test(org.junit.Test)

Example 3 with MandrillMessageRequest

use of com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MessagesTest method testSendMessage.

@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());
    }
}
Also used : SendMessageResponse(com.cribbstechnologies.clients.mandrill.model.response.message.SendMessageResponse) HashMap(java.util.HashMap) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) MandrillMessageRequest(com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest) MandrillHtmlMessage(com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage) MandrillRecipient(com.cribbstechnologies.clients.mandrill.model.MandrillRecipient) Test(org.junit.Test)

Aggregations

MandrillHtmlMessage (com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage)3 MandrillMessageRequest (com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest)3 MandrillRecipient (com.cribbstechnologies.clients.mandrill.model.MandrillRecipient)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 RequestFailedException (com.cribbstechnologies.clients.mandrill.exception.RequestFailedException)1 SendMessageResponse (com.cribbstechnologies.clients.mandrill.model.response.message.SendMessageResponse)1