-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
251 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package integration; | ||
|
||
import base.BaseTest; | ||
import com.wildbit.java.postmark.client.AccountApiClient; | ||
import com.wildbit.java.postmark.client.ApiClient; | ||
import com.wildbit.java.postmark.client.Parameters; | ||
import com.wildbit.java.postmark.client.data.model.domains.DomainDetails; | ||
import com.wildbit.java.postmark.client.data.model.domains.Domains; | ||
import com.wildbit.java.postmark.client.data.model.templates.*; | ||
import com.wildbit.java.postmark.client.exception.PostmarkException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Created by bash on 11/14/17. | ||
*/ | ||
public class DomainTest extends BaseTest { | ||
|
||
AccountApiClient client = getDefaultAccountApiClient(); | ||
|
||
@Test | ||
void list() throws PostmarkException, IOException { | ||
Domains domains = client.getDomains(Parameters.init().build("count",6).build("offset",0)); | ||
assertTrue(domains.getDomains().size() > 0); | ||
} | ||
|
||
@Test | ||
void listById() throws PostmarkException, IOException { | ||
Domains domains = client.getDomains(Parameters.init().build("count",6).build("offset",0)); | ||
Integer domainId = domains.getDomains().get(0).getId(); | ||
DomainDetails domainDetails = client.getDomainDetails(domainId); | ||
assertNotNull(domainDetails.getDkimTextValue()); | ||
} | ||
|
||
@Test | ||
void verifySPF() throws PostmarkException, IOException { | ||
Domains domains = client.getDomains(Parameters.init().build("count",6).build("offset",0)); | ||
Integer domainId = domains.getDomains().get(0).getId(); | ||
String response = client.verifyDomainSPF(domainId); | ||
assertNotNull(response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import com.wildbit.java.postmark.client.ApiClient; | ||
import com.wildbit.java.postmark.client.data.model.message.Message; | ||
import com.wildbit.java.postmark.client.data.model.message.MessageResponse; | ||
import com.wildbit.java.postmark.client.exception.InvalidAPIKeyException; | ||
import com.wildbit.java.postmark.client.exception.InvalidMessageException; | ||
import com.wildbit.java.postmark.client.exception.PostmarkException; | ||
|
||
|
@@ -36,4 +37,11 @@ void invalidMessagetoSend() throws PostmarkException, IOException { | |
Throwable exception = assertThrows(InvalidMessageException.class, () -> client.deliverMessage(message)); | ||
assertEquals("Zero recipients specified", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void invalidApiToken() throws PostmarkException, IOException { | ||
ApiClient client = Postmark.getApiClient("1991892", true); | ||
Message message = new Message("[email protected]", "[email protected]", "Hello from Postmark!", "Hello body"); | ||
assertThrows(InvalidAPIKeyException.class, () -> client.deliverMessage(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package integration; | ||
|
||
import base.BaseTest; | ||
import com.wildbit.java.postmark.client.AccountApiClient; | ||
import com.wildbit.java.postmark.client.Parameters; | ||
import com.wildbit.java.postmark.client.data.model.domains.DomainDetails; | ||
import com.wildbit.java.postmark.client.data.model.domains.Domains; | ||
import com.wildbit.java.postmark.client.data.model.senders.SignatureDetails; | ||
import com.wildbit.java.postmark.client.data.model.senders.Signatures; | ||
import com.wildbit.java.postmark.client.exception.PostmarkException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Created by bash on 11/14/17. | ||
*/ | ||
public class SendersTest extends BaseTest { | ||
|
||
AccountApiClient client = getDefaultAccountApiClient(); | ||
|
||
@Test | ||
void list() throws PostmarkException, IOException { | ||
Signatures senders = client.getSenderSignatures(Parameters.init().build("count",6).build("offset",0)); | ||
assertTrue(senders.getTotalCount() > 0); | ||
assertTrue(senders.getSenderSignatures().size() > 0); | ||
|
||
} | ||
|
||
@Test | ||
void listById() throws PostmarkException, IOException { | ||
Signatures senders = client.getSenderSignatures(Parameters.init().build("count",6).build("offset",0)); | ||
Integer senderId = senders.getSenderSignatures().get(0).getId(); | ||
SignatureDetails senderDetails = client.getSenderSignatureDetails(senderId); | ||
assertNotNull(senderDetails.getConfirmed()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package integration; | ||
|
||
import base.BaseTest; | ||
import com.wildbit.java.postmark.client.ApiClient; | ||
import com.wildbit.java.postmark.client.Parameters; | ||
import com.wildbit.java.postmark.client.data.model.bounces.Bounce; | ||
import com.wildbit.java.postmark.client.data.model.bounces.BounceDump; | ||
import com.wildbit.java.postmark.client.data.model.bounces.Bounces; | ||
import com.wildbit.java.postmark.client.data.model.bounces.DeliveryStats; | ||
import com.wildbit.java.postmark.client.data.model.templates.*; | ||
import com.wildbit.java.postmark.client.exception.PostmarkException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Created by bash on 11/14/17. | ||
*/ | ||
public class TemplateTest extends BaseTest { | ||
|
||
ApiClient client = getDefaultApiClient(); | ||
|
||
@Test | ||
void validateHtmlBody() throws PostmarkException, IOException { | ||
TemplateToValidate templateToValidate = new TemplateToValidate(); | ||
templateToValidate.setSubject("{{#company}}{{name}}{{/company}} {{subjectHeadline}}"); | ||
templateToValidate.setHtmlBody("{{#company}}{{name}}{{/company}} {{subjectHeadline}}"); | ||
templateToValidate.setTextBody("{{#company}}{{phone}}{{/company}}{{#each person}} {{name}} {{/each}}"); | ||
|
||
HashMap renderModel = new HashMap<String, Object>(); | ||
renderModel.put("userName", "bobby joe"); | ||
templateToValidate.setTestRenderModel(renderModel); | ||
|
||
TemplateValidation validation = client.validateTemplate(templateToValidate); | ||
assertEquals(validation.getHtmlBody().getContentIsValid(), true); | ||
assertEquals(validation.getHtmlBody().getValidationErrors().size(),0); | ||
assertNotNull(validation.getHtmlBody().getRenderedContent()); | ||
|
||
} | ||
|
||
@Test | ||
void validateTextBody() throws PostmarkException, IOException { | ||
TemplateToValidate templateToValidate = new TemplateToValidate(); | ||
templateToValidate.setSubject("{{#company}}{{name}}{{/company}} {{subjectHeadline}}"); | ||
templateToValidate.setHtmlBody("{{#company}}{{name}}{{/company}} {{subjectHeadline}}"); | ||
templateToValidate.setTextBody("{{#company}}{{phone}}{{/company}}{{#each person}} {{name}} {{/each}}"); | ||
|
||
HashMap renderModel = new HashMap<String, Object>(); | ||
renderModel.put("userName", "bobby joe"); | ||
templateToValidate.setTestRenderModel(renderModel); | ||
|
||
TemplateValidation validation = client.validateTemplate(templateToValidate); | ||
assertEquals(validation.getTextBody().getContentIsValid(), true); | ||
assertEquals(validation.getTextBody().getValidationErrors().size(),0); | ||
assertNotNull(validation.getTextBody().getRenderedContent()); | ||
} | ||
|
||
@Test | ||
void createTemplate() throws PostmarkException, IOException { | ||
|
||
String templateName = "name"; | ||
|
||
TemplateContent templateContent = new TemplateContent(); | ||
templateContent.setHtmlBody("test html"); | ||
templateContent.setTextBody("test text"); | ||
templateContent.setName(templateName); | ||
templateContent.setSubject("subject"); | ||
|
||
BaseTemplate response = client.createTemplate(templateContent); | ||
assertEquals(response.getName(),templateName); | ||
|
||
Integer id = response.getTemplateId(); | ||
client.deleteTemplate(id); | ||
|
||
} | ||
|
||
@Test | ||
void deleteTemplate() throws PostmarkException, IOException { | ||
String templateName = "deleteName"; | ||
|
||
TemplateContent templateContent = new TemplateContent(); | ||
templateContent.setHtmlBody("test html"); | ||
templateContent.setTextBody("test text"); | ||
templateContent.setName(templateName); | ||
templateContent.setSubject("subject"); | ||
|
||
BaseTemplate response = client.createTemplate(templateContent); | ||
Integer id = response.getTemplateId(); | ||
String stringResponse = client.deleteTemplate(id); | ||
assertNotNull(stringResponse); | ||
|
||
} | ||
|
||
@Test | ||
void list() throws PostmarkException, IOException { | ||
Templates templates = client.getTemplates(Parameters.init().build("offset", 0).build("count", 4)); | ||
assertNotNull(templates.getTotalCount()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
package unit.data; | ||
|
||
|
||
import base.BaseTest; | ||
import com.wildbit.java.postmark.client.Parameters; | ||
import com.wildbit.java.postmark.client.data.DataHandler; | ||
import com.wildbit.java.postmark.client.data.model.message.Message; | ||
import com.wildbit.java.postmark.client.exception.InvalidMessageException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* Created by bash on 11/13/17. | ||
*/ | ||
public class MessageTest { | ||
public class MessageTest extends BaseTest { | ||
|
||
DataHandler dataHandler = new DataHandler(); | ||
String fromAddress = "[email protected]"; | ||
|
@@ -148,4 +155,29 @@ void simpleMessageBcccRecipientsFullName() throws IOException { | |
|
||
} | ||
|
||
@Test | ||
void attachmentException() throws IOException { | ||
Message message = new Message(); | ||
assertThrows(java.nio.file.NoSuchFileException.class, () -> message.addAttachment("test")); | ||
} | ||
|
||
@Test | ||
void addAttachment() throws IOException { | ||
Message message = new Message("[email protected]","[email protected]","Hello world", "Hello world"); | ||
message.addAttachment(getDefaultFilePath()); | ||
|
||
HashMap<String,String> attachment = message.getAttachments().get(0); | ||
assertEquals(attachment.get("ContentType"), "application/pdf"); | ||
assertEquals(attachment.get("Name"), new File(getDefaultFilePath()).getName()); | ||
assertNotNull(attachment.get("Content")); | ||
} | ||
|
||
@Test | ||
void addMultipleAttachments() throws IOException { | ||
Message message = new Message("[email protected]","[email protected]","Hello world", "Hello world"); | ||
message.addAttachment(getDefaultFilePath()); | ||
message.addAttachment(getDefaultFilePath()); | ||
assertEquals(message.getAttachments().size(), 2); | ||
} | ||
|
||
} |