Search in sources :

Example 1 with RequestFailedException

use of com.cribbstechnologies.clients.mandrill.exception.RequestFailedException in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MessagesTest method testSendTemplatedMessage.

@Test
public void testSendTemplatedMessage() {
    MandrillTemplatedMessageRequest request = new MandrillTemplatedMessageRequest();
    MandrillMessage message = new MandrillMessage();
    Map<String, String> headers = new HashMap<String, String>();
    message.setFrom_email(props.getProperty("email.from"));
    message.setFrom_name("Big Jimmy");
    message.setHeaders(headers);
    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);
    request.setMessage(message);
    List<TemplateContent> content = new ArrayList<TemplateContent>();
    request.setTemplate_content(content);
    request.setTemplate_name("template2");
    List<MergeVar> globalMergeVars = new ArrayList<MergeVar>();
    globalMergeVars.add(new MergeVar("username", "bcribs"));
    globalMergeVars.add(new MergeVar("registration_url", "http://myserver.com/register?userid=bcribs"));
    message.setGlobal_merge_vars(globalMergeVars);
    try {
        messagesRequest.sendTemplatedMessage(request);
    } catch (RequestFailedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) TemplateContent(com.cribbstechnologies.clients.mandrill.model.TemplateContent) MandrillTemplatedMessageRequest(com.cribbstechnologies.clients.mandrill.model.MandrillTemplatedMessageRequest) ArrayList(java.util.ArrayList) MandrillMessage(com.cribbstechnologies.clients.mandrill.model.MandrillMessage) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) MergeVar(com.cribbstechnologies.clients.mandrill.model.MergeVar) MandrillRecipient(com.cribbstechnologies.clients.mandrill.model.MandrillRecipient) Test(org.junit.Test)

Example 2 with RequestFailedException

use of com.cribbstechnologies.clients.mandrill.exception.RequestFailedException in project Java-Mandrill-Wrapper by cribbstechnologies.

the class MandrillRESTRequestTest method testPostRequestMapperExceptions.

@Test
public void testPostRequestMapperExceptions() throws ClientProtocolException, IOException {
    this.request = new MandrillRESTRequest();
    this.request.setHttpClient(this.client);
    this.request.setConfig(this.config);
    this.request.setObjectMapper(this.mapper);
    doThrow(new JsonGenerationException("Mockito!")).when(this.mapper).writeValueAsString(isA(BaseMandrillRequest.class));
    try {
        this.request.postRequest(this.emptyBaseRequest, "test", null);
        fail("Exception not thrown");
    } catch (RequestFailedException e) {
        assertEquals("Json Generation Exception", e.getMessage());
    }
    doThrow(new JsonMappingException("Mockito!")).when(this.mapper).writeValueAsString(isA(BaseMandrillRequest.class));
    try {
        this.request.postRequest(this.emptyBaseRequest, "test", null);
        fail("Exception not thrown");
    } catch (RequestFailedException e) {
        assertEquals("Json Mapping Exception", e.getMessage());
    }
}
Also used : RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BaseMandrillRequest(com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) Test(org.junit.Test)

Example 3 with RequestFailedException

use of com.cribbstechnologies.clients.mandrill.exception.RequestFailedException in project Java-Mandrill-Wrapper by cribbstechnologies.

the class TemplatesTest method testAddTemplate.

@Test
public void testAddTemplate() {
    MandrillRequestWithCode request = new MandrillRequestWithCode();
    request.setCode("<html><body>template</body></html>");
    request.setName("template1");
    try {
        templatesRequest.addTemplate(request);
    } catch (RequestFailedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) MandrillRequestWithCode(com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithCode) Test(org.junit.Test)

Example 4 with RequestFailedException

use of com.cribbstechnologies.clients.mandrill.exception.RequestFailedException in project Java-Mandrill-Wrapper by cribbstechnologies.

the class TemplatesTest method deleteTemplate.

@Test
public void deleteTemplate() {
    MandrillRequestWithName request = new MandrillRequestWithName();
    request.setName("template1");
    try {
        templatesRequest.deleteTemplate(request);
    } catch (RequestFailedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MandrillRequestWithName(com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithName) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) Test(org.junit.Test)

Example 5 with RequestFailedException

use of com.cribbstechnologies.clients.mandrill.exception.RequestFailedException in project Java-Mandrill-Wrapper by cribbstechnologies.

the class UrlsTest method testQuery.

@Test
public void testQuery() {
    MandrillRequestWithQuery request = new MandrillRequestWithQuery();
    request.setQ("http://www.google.com");
    try {
        UrlListResponse response = urlsRequest.doSearch(request);
    } catch (RequestFailedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MandrillRequestWithQuery(com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithQuery) RequestFailedException(com.cribbstechnologies.clients.mandrill.exception.RequestFailedException) UrlListResponse(com.cribbstechnologies.clients.mandrill.model.response.urls.UrlListResponse) Test(org.junit.Test)

Aggregations

RequestFailedException (com.cribbstechnologies.clients.mandrill.exception.RequestFailedException)17 Test (org.junit.Test)16 BaseMandrillRequest (com.cribbstechnologies.clients.mandrill.model.BaseMandrillRequest)3 MandrillRequestWithName (com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithName)3 IOException (java.io.IOException)3 HttpPost (org.apache.http.client.methods.HttpPost)3 MandrillRecipient (com.cribbstechnologies.clients.mandrill.model.MandrillRecipient)2 MandrillRequestWithCode (com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithCode)2 BaseMandrillStringResponse (com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse)2 UrlListResponse (com.cribbstechnologies.clients.mandrill.model.response.urls.UrlListResponse)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 MandrillError (com.cribbstechnologies.clients.mandrill.model.MandrillError)1 MandrillHtmlMessage (com.cribbstechnologies.clients.mandrill.model.MandrillHtmlMessage)1 MandrillMessage (com.cribbstechnologies.clients.mandrill.model.MandrillMessage)1 MandrillMessageRequest (com.cribbstechnologies.clients.mandrill.model.MandrillMessageRequest)1 MandrillRequestWithDomain (com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithDomain)1 MandrillRequestWithEmail (com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail)1