diff --git a/pom.xml b/pom.xml index 18e8533..9cfaed5 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ - 1.1.7 + 1.1.8 UTF-8 1.8 2.9.2 diff --git a/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java b/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java index 0ddfab5..f550b97 100644 --- a/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java +++ b/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java @@ -63,5 +63,4 @@ public void addMetadata(String key, String value) { } metadata.put(key,value); } - } diff --git a/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java b/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java index 2bb9018..df530bd 100644 --- a/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java +++ b/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java @@ -1,5 +1,7 @@ package com.wildbit.java.postmark.client.data.model.templates; +import java.util.HashMap; + /** * Template Message with all details object. */ @@ -19,6 +21,19 @@ public enum TRACK_LINKS { private Boolean trackOpens; private String trackLinks; + private HashMap 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 @@ -30,16 +45,14 @@ public enum TRACK_LINKS { public void setTrackLinks(String trackLinks) { this.trackLinks = trackLinks; } - public TemplatedMessage() { - super(); - } + public HashMap getMetadata() { return metadata; } - public TemplatedMessage(String from, String to) { - super(from, to); - } + public void setMetadata(HashMap 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); } - } diff --git a/src/test/java/integration/TemplatedMessageTest.java b/src/test/java/integration/TemplatedMessageTest.java new file mode 100644 index 0000000..6d9876b --- /dev/null +++ b/src/test/java/integration/TemplatedMessageTest.java @@ -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("from@example.com", "to@example.com", 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("from@example.com", "to@example.com", 1); + + HashMap metadata = new HashMap(); + metadata.put("test1","value1"); + + message.setMetadata(metadata); + message.addMetadata("test2","value2"); + message.addMetadata("test3","value3"); + + HashMap templatedMessageMetadata = message.getMetadata(); + assertEquals(templatedMessageMetadata.get("test1"), "value1"); + assertEquals(templatedMessageMetadata.get("test2"), "value2"); + assertEquals(templatedMessageMetadata.get("test3"), "value3"); + } +}