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());
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations