Skip to content

Commit

Permalink
add support for using metadata to sending email with template
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Dec 17, 2018
1 parent 827c786 commit ea23c38
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</developers>

<properties>
<postmark.version>1.1.7</postmark.version>
<postmark.version>1.1.8</postmark.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jackson.minimum.version>2.9.2</jackson.minimum.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ public void addMetadata(String key, String value) {
}
metadata.put(key,value);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.wildbit.java.postmark.client.data.model.templates;

import java.util.HashMap;

/**
* Template Message with all details object.
*/
Expand All @@ -19,6 +21,19 @@ public enum TRACK_LINKS {

private Boolean trackOpens;
private String trackLinks;
private HashMap<String, String> metadata;

public TemplatedMessage() {
super();
}

public TemplatedMessage(String from, String to) {
super(from, to);
}

public TemplatedMessage(String from, String to, Integer templateId) {
super(from, to, templateId);
}

// SETTERS AND GETTERS

Expand All @@ -30,16 +45,14 @@ public enum TRACK_LINKS {

public void setTrackLinks(String trackLinks) { this.trackLinks = trackLinks; }

public TemplatedMessage() {
super();
}
public HashMap<String, String> getMetadata() { return metadata; }

public TemplatedMessage(String from, String to) {
super(from, to);
}
public void setMetadata(HashMap<String, String> metadata) { this.metadata = metadata; }

public TemplatedMessage(String from, String to, Integer templateId) {
super(from, to, templateId);
public void addMetadata(String key, String value) {
if (metadata == null) {
metadata = new HashMap<>();
}
metadata.put(key,value);
}

}
47 changes: 47 additions & 0 deletions src/test/java/integration/TemplatedMessageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package integration;

import base.BaseTest;
import com.wildbit.java.postmark.Postmark;
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.data.model.templates.TemplatedMessage;
import com.wildbit.java.postmark.client.exception.InvalidAPIKeyException;
import com.wildbit.java.postmark.client.exception.InvalidMessageException;
import com.wildbit.java.postmark.client.exception.PostmarkException;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.util.HashMap;

public class TemplatedMessageTest extends BaseTest {

ApiClient client = Postmark.getApiClient("POSTMARK_API_TEST", true);

@Test
void send() throws PostmarkException, IOException {
TemplatedMessage message = new TemplatedMessage("[email protected]", "[email protected]", 1);

Throwable exception = assertThrows(InvalidMessageException.class, () -> client.deliverMessageWithTemplate(message));
assertEquals("The 'TemplateId' associated with this request is not valid or was not found.", exception.getMessage());
}

@Test
void metadata() throws PostmarkException, IOException {
TemplatedMessage message = new TemplatedMessage("[email protected]", "[email protected]", 1);

HashMap<String,String> metadata = new HashMap<String, String>();
metadata.put("test1","value1");

message.setMetadata(metadata);
message.addMetadata("test2","value2");
message.addMetadata("test3","value3");

HashMap<String,String> templatedMessageMetadata = message.getMetadata();
assertEquals(templatedMessageMetadata.get("test1"), "value1");
assertEquals(templatedMessageMetadata.get("test2"), "value2");
assertEquals(templatedMessageMetadata.get("test3"), "value3");
}
}

0 comments on commit ea23c38

Please sign in to comment.