Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.classpath
.project
.settings
/target
19 changes: 17 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<groupId>com.cribbstechnologies.clients</groupId>
<artifactId>mandrillClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Java Mandrill Wrapper</name>
<description>A Java wrapper for Mandrill</description>
Expand Down Expand Up @@ -64,4 +64,19 @@


</dependencies>
</project>

<build>
<plugins>
<!-- Compile against 1.5 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
179 changes: 96 additions & 83 deletions src/it/java/com/cribbstechnologies/clients/mandrill/it/UsersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.cribbstechnologies.clients.mandrill.model.MandrillRequestWithEmail;
import com.cribbstechnologies.clients.mandrill.model.response.BaseMandrillStringResponse;
import com.cribbstechnologies.clients.mandrill.model.response.users.DisableResponse;
import com.cribbstechnologies.clients.mandrill.model.response.users.PingResponse;
import com.cribbstechnologies.clients.mandrill.model.response.users.UsersInfoResponse;
import com.cribbstechnologies.clients.mandrill.model.response.users.UsersSendersResponse;
import com.cribbstechnologies.clients.mandrill.model.response.users.VerifyResponse;
Expand All @@ -28,87 +29,99 @@

public class UsersTest {

private static MandrillRESTRequest request = new MandrillRESTRequest();
private static MandrillConfiguration config = new MandrillConfiguration();
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() {
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);
request.setObjectMapper(mapper);
usersRequest.setRequest(request);
}

@Before
public void before() {
client = new DefaultHttpClient();
request.setHttpClient(client);
}

@Test
public void testPing() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
BaseMandrillStringResponse response = usersRequest.performPing(baseRequest);
assertEquals("\"PONG!\"", response.getResponse());
} catch (RequestFailedException e) {
fail(e.getMessage());
}
}

@Test
public void testGetInfo() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
UsersInfoResponse response = usersRequest.getInfo(baseRequest);
} catch (RequestFailedException e) {
fail(e.getMessage());
}
}

@Test
public void testGetSenders() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
UsersSendersResponse response = usersRequest.getSenders(baseRequest);
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void testVerifySender() {
MandrillRequestWithEmail emailRequest = new MandrillRequestWithEmail();
emailRequest.setEmail(props.getProperty("verify.email"));
try {
VerifyResponse response = usersRequest.verifySender(emailRequest);
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void testDisableSender() {
MandrillRequestWithDomain domainRequest = new MandrillRequestWithDomain();
domainRequest.setDomain("google.com");
try {
DisableResponse response = usersRequest.disableSender(domainRequest);
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
private static MandrillRESTRequest request = new MandrillRESTRequest();
private static MandrillConfiguration config = new MandrillConfiguration();
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() {
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);
request.setObjectMapper(mapper);
usersRequest.setRequest(request);
}

@Before
public void before() {
client = new DefaultHttpClient();
request.setHttpClient(client);
}

@Test
public void testPing() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
BaseMandrillStringResponse response = usersRequest.performPing(baseRequest);
assertEquals("\"PONG!\"", response.getResponse());
} catch (RequestFailedException e) {
fail(e.getMessage());
}
}

@Test
public void testPing2() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
PingResponse pingResponse = usersRequest.performPing2(baseRequest);
assertEquals("PONG!", pingResponse.getPingResponse());
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void testGetInfo() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
UsersInfoResponse response = usersRequest.getInfo(baseRequest);
} catch (RequestFailedException e) {
fail(e.getMessage());
}
}

@Test
public void testGetSenders() {
BaseMandrillRequest baseRequest = new BaseMandrillRequest();
try {
UsersSendersResponse response = usersRequest.getSenders(baseRequest);
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void testVerifySender() {
MandrillRequestWithEmail emailRequest = new MandrillRequestWithEmail();
emailRequest.setEmail(props.getProperty("verify.email"));
try {
VerifyResponse response = usersRequest.verifySender(emailRequest);
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void testDisableSender() {
MandrillRequestWithDomain domainRequest = new MandrillRequestWithDomain();
domainRequest.setDomain("google.com");
try {
DisableResponse response = usersRequest.disableSender(domainRequest);
} catch (RequestFailedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.cribbstechnologies.clients.mandrill.model;

/**
*
* @author Martin Zapata
*
*/

public class Attachment {

private String type, name, content;

public Attachment(String type, String name, String content) {
this.type = type;
this.name = name;
this.content = content;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

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;
private String key;

public String getKey() {
return key;
}
public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}
/**
* 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
*
* @param key
*/
public void setKey(String key) {
this.key = key;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class MandrillMessage {
private String[] google_analytics_campaign = new String[0];
private List<MergeVar> global_merge_vars;
List<MessageMergeVars> merge_vars;
private List<Attachment> attachments;

private Map<String, String> headers;

Expand Down Expand Up @@ -142,4 +143,12 @@ public List<MessageMergeVars> getMerge_vars() {
public void setMerge_vars(List<MessageMergeVars> merge_vars) {
this.merge_vars = merge_vars;
}

public List<Attachment> getAttachments() {
return attachments;
}

public void setAttachments(List<Attachment> attachments) {
this.attachments = attachments;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
package com.cribbstechnologies.clients.mandrill.model;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class MandrillResponse {

private String responseString;
private boolean success;
public String getJsonResponse() {
return responseString;
}
public void setResponseString(String jsonResponse) {
this.responseString = jsonResponse;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
private String responseString;
private boolean success;

public String getJsonResponse() {
return responseString;
}

public void setResponseString(String jsonResponse) {
this.responseString = jsonResponse;
}

public boolean isSuccess() {
return success;
}

public void setSuccess(boolean success) {
this.success = success;
}

}
Loading