diff --git a/.travis.yml b/.travis.yml
index dff5f3a5..9e54ddd3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1 +1,4 @@
language: java
+
+jdk:
+ - openjdk8
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 12e09a5c..929270a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.hellosignhellosign-java-sdkjar
- 4.0.12
+ 4.1.0-SNAPSHOTHelloSign Java SDKhttps://github.com/hellosign/hellosign-java-sdk
@@ -169,6 +169,14 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
diff --git a/src/main/java/com/hellosign/sdk/resource/AbstractRequest.java b/src/main/java/com/hellosign/sdk/resource/AbstractRequest.java
index 008f18fe..55a696e1 100644
--- a/src/main/java/com/hellosign/sdk/resource/AbstractRequest.java
+++ b/src/main/java/com/hellosign/sdk/resource/AbstractRequest.java
@@ -2,9 +2,9 @@
/**
* The MIT License (MIT)
- *
+ *
* Copyright (C) 2015 hellosign.com
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@@ -24,6 +24,10 @@
* SOFTWARE.
*/
+import com.hellosign.sdk.HelloSignException;
+import com.hellosign.sdk.resource.support.CustomField;
+import com.hellosign.sdk.resource.support.Document;
+import com.hellosign.sdk.resource.support.Metadata;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
@@ -31,17 +35,13 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-
+import org.json.JSONArray;
import org.json.JSONObject;
-import com.hellosign.sdk.HelloSignException;
-import com.hellosign.sdk.resource.support.Document;
-import com.hellosign.sdk.resource.support.Metadata;
-
/**
* Requests to HelloSign will have common fields such as a request title,
* subject, and message. This class centralizes those fields.
- *
+ *
* @author "Chris Paul (chris@hellosign.com)"
*/
public abstract class AbstractRequest extends AbstractResource {
@@ -59,6 +59,7 @@ public abstract class AbstractRequest extends AbstractResource {
public static final String REQUEST_CLIENT_ID = "client_id";
public static final String REQUEST_ALLOW_DECLINE = "allow_decline";
public static final String REQUEST_ALLOW_REASSIGN = "allow_reassign";
+ public static final String REQUEST_CUSTOM_FIELDS = "custom_fields";
// UX Version 1 = Original, non-responsive signer page is used
public static final int UX_VERSION_1 = 1;
@@ -67,6 +68,7 @@ public abstract class AbstractRequest extends AbstractResource {
public static final int UX_VERSION_2 = 2;
private Metadata metadata;
+ private List customFields = new ArrayList();
private List documents = new ArrayList();
private List fileUrls = new ArrayList();
private boolean orderMatters = false;
@@ -88,7 +90,7 @@ public AbstractRequest(JSONObject json, String optionalKey) throws HelloSignExce
metadata = new Metadata(dataObj);
}
- protected Map getPostFields() throws HelloSignException {
+ public Map getPostFields() throws HelloSignException {
Map fields = new HashMap();
try {
Metadata metadata = getMetadata();
@@ -117,6 +119,13 @@ protected Map getPostFields() throws HelloSignException {
if (hasAllowReassign()) {
fields.put(REQUEST_ALLOW_REASSIGN, isAllowReassign());
}
+ if (customFields.size() > 0) {
+ JSONArray array = new JSONArray();
+ for (CustomField f : customFields) {
+ array.put(f.getJSONObject());
+ }
+ fields.put(REQUEST_CUSTOM_FIELDS, array.toString());
+ }
return fields;
}
@@ -231,7 +240,7 @@ public String getMetadata(String key) {
/**
* Adds the file to the request.
- *
+ *
* @param file File
* @throws HelloSignException thrown if there is a problem attaching the
* File to this request.
@@ -242,12 +251,12 @@ public void addFile(File file) throws HelloSignException {
/**
* Adds the file to the request in the given order.
- *
+ *
* The order should be a 0-based index into the file list. Therefore, the
* first item of the file list is 0, and so forth.
- *
+ *
* If order is null, the document is appended to the end of the file list.
- *
+ *
* @param file File
* @param order Integer or null
* @throws HelloSignException thrown if there is a problem attaching the
@@ -265,7 +274,7 @@ public void addFile(File file, Integer order) throws HelloSignException {
/**
* Adds a Document to the signature request.
- *
+ *
* @param doc Document
* @throws HelloSignException thrown if null is provided
*/
@@ -278,7 +287,7 @@ public void addDocument(Document doc) throws HelloSignException {
/**
* Adds a Document to the signature request at the specific order.
- *
+ *
* @param doc Document
* @param order int
* @throws HelloSignException thrown if null is provided or there is a
@@ -299,7 +308,7 @@ public void addDocument(Document doc, int order) throws HelloSignException {
* Returns a reference to the list of documents for this request. Modifying
* this list will modify the list that will be sent with the request. Useful
* for more fine-grained modification.
- *
+ *
* @return List
*/
public List getDocuments() {
@@ -308,7 +317,7 @@ public List getDocuments() {
/**
* Overwrites this requests document list with the provided document list.
- *
+ *
* @param docs List
*/
public void setDocuments(List docs) {
@@ -324,7 +333,7 @@ public void clearDocuments() {
/**
* Determines whether the order of the signers list is to be enforced.
- *
+ *
* @param b true if the order matters, false otherwise
*/
public void setOrderMatters(boolean b) {
@@ -333,7 +342,7 @@ public void setOrderMatters(boolean b) {
/**
* A flag that determines whether order of the signers list is enforced.
- *
+ *
* @return true if the order matters, false otherwise
*/
public boolean getOrderMatters() {
@@ -342,7 +351,7 @@ public boolean getOrderMatters() {
/**
* Add a file_url to this request.
- *
+ *
* @param url String
*/
public void addFileUrl(String url) {
@@ -351,7 +360,7 @@ public void addFileUrl(String url) {
/**
* Return the current file_url list.
- *
+ *
* @return List
*/
public List getFileUrls() {
@@ -360,7 +369,7 @@ public List getFileUrls() {
/**
* Overwrite the current file_url list.
- *
+ *
* @param fileUrls List
*/
public void setFileUrls(List fileUrls) {
@@ -371,7 +380,7 @@ public void setFileUrls(List fileUrls) {
* Set the UX version for this request. This determines the version of the
* signer page displayed to signer(s). The default is UX_VERSION_1
* (non-responsive). Use UX_VERSION_2 for the responsive signer page.
- *
+ *
* @param uxVersion int
*/
public void setUxVersion(int uxVersion) {
@@ -380,7 +389,7 @@ public void setUxVersion(int uxVersion) {
/**
* Return the UX version for this request.
- *
+ *
* @return int UX version (UX_VERSION_1 or UX_VERSION_2)
*/
public int getUxVersion() {
@@ -389,7 +398,7 @@ public int getUxVersion() {
/**
* Associates this request with an API app.
- *
+ *
* @param clientId String client ID of the API app.
* @throws HelloSignException thrown if clientId is null
*/
@@ -403,7 +412,7 @@ public void setClientId(String clientId) throws HelloSignException {
/**
* The API app client ID that has been associated with this signature
* request.
- *
+ *
* @return String client ID
*/
public String getClientId() {
@@ -412,7 +421,7 @@ public String getClientId() {
/**
* Designate this request as declinable by signers.
- *
+ *
* @param isDeclinable true if declinable, false otherwise (null if the
* parameter should be left off)
*/
@@ -423,13 +432,13 @@ public void setIsDeclinable(Boolean isDeclinable) {
/**
* Retrieve the flag that designates whether this request is declinable by
* signers.
- *
+ *
* @return Boolean or null if the flag has not been set
*/
public Boolean getIsDeclinable() {
return this.isDeclinable;
}
-
+
public boolean hasAllowReassign() {
return has(REQUEST_ALLOW_REASSIGN);
}
@@ -444,4 +453,85 @@ public boolean isAllowReassign() {
public void setAllowReassign(boolean b) {
set(REQUEST_ALLOW_REASSIGN, b);
}
+
+ /**
+ * Add the custom field to this request. This is useful for specifying a
+ * pre-filled value and/or a field editor.
+ *
+ * @param field CustomField
+ */
+ public void addCustomField(CustomField field) {
+ customFields.add(field);
+ }
+
+ /**
+ * Adds the value to fill in for a custom field with the given field name.
+ *
+ * @param fieldNameOrApiId String name (or "Field Label") of the custom field
+ * to be filled in. The "api_id" can also be used instead of the name.
+ * @param value String value
+ */
+ public void setCustomFieldValue(String fieldNameOrApiId, String value) {
+ CustomField f = new CustomField();
+ f.setName(fieldNameOrApiId);
+ f.setValue(value);
+ customFields.add(f);
+ }
+
+ /**
+ * Returns the map of custom fields for the request. This is a map of
+ * String field names to String field values.
+ *
+ * @return Map
+ */
+ public Map getCustomFieldsMap() {
+ Map fields = new HashMap();
+ for (CustomField f : customFields) {
+ fields.put(f.getName(), f.getValue());
+ }
+ return fields;
+ }
+
+ /**
+ * Gets the custom fields associated with this request, set when sending the
+ * request.
+ *
+ * @return List CustomFields
+ */
+ public List getCustomFields() {
+ return customFields;
+ }
+
+ /**
+ * Returns a list of CustomField objects for this request.
+ * @deprecated Use {@link AbstractRequest#getCustomFields()} instead.
+ *
+ * @return List of CustomFields
+ */
+ public List getCustomFieldsList() {
+ return this.getCustomFields();
+ }
+
+ /**
+ * Overwrites the current map of custom fields to the provided map. This is
+ * a map of String field names to String field values.
+ *
+ * @param fields Map
+ */
+ public void setCustomFields(Map fields) {
+ clearCustomFields();
+ for (String key : fields.keySet()) {
+ CustomField f = new CustomField();
+ f.setName(key);
+ f.setValue(fields.get(key));
+ customFields.add(f);
+ }
+ }
+
+ /**
+ * Clears the current custom fields for this request.
+ */
+ public void clearCustomFields() {
+ customFields = new ArrayList();
+ }
}
diff --git a/src/main/java/com/hellosign/sdk/resource/EmbeddedRequest.java b/src/main/java/com/hellosign/sdk/resource/EmbeddedRequest.java
index e5f0bc92..c5f6a9b4 100644
--- a/src/main/java/com/hellosign/sdk/resource/EmbeddedRequest.java
+++ b/src/main/java/com/hellosign/sdk/resource/EmbeddedRequest.java
@@ -24,7 +24,9 @@
* SOFTWARE.
*/
+import com.hellosign.sdk.resource.support.CustomField;
import java.io.Serializable;
+import java.util.List;
import java.util.Map;
import com.hellosign.sdk.HelloSignException;
@@ -50,11 +52,10 @@ private EmbeddedRequest() {
}
/**
- * Creates an Embedded signature request using the client ID and the
- * AbstractRequest object provided. First, instantiate the request object
- * (either a SignatureRequest or TemplateSignatureRequest) and then create
- * your EmbeddedRequest using that object.
- *
+ * Creates an Embedded signature request using the client ID and the AbstractRequest object
+ * provided. First, instantiate the request object (either a SignatureRequest or
+ * TemplateSignatureRequest) and then create your EmbeddedRequest using that object.
+ *
* @param clientId String client ID
* @param request AbstractRequest
*/
@@ -64,9 +65,9 @@ public EmbeddedRequest(String clientId, AbstractRequest request) {
}
/**
- * Set the client ID of the web app you're using to create this embedded
- * signature request. See: http://app.hellosign.com/api/embedded
- *
+ * Set the client ID of the web app you're using to create this embedded signature request. See:
+ * http://app.hellosign.com/api/embedded
+ *
* @return String client ID
*/
public String getClientId() {
@@ -74,9 +75,9 @@ public String getClientId() {
}
/**
- * Set the client ID of the web app you're using to create this embedded
- * signature request. See: http://app.hellosign.com/api/embedded
- *
+ * Set the client ID of the web app you're using to create this embedded signature request. See:
+ * http://app.hellosign.com/api/embedded
+ *
* @param clientId String client ID
*/
public void setClientId(String clientId) {
@@ -85,7 +86,7 @@ public void setClientId(String clientId) {
/**
* Get the AbstractRequest associated with this Embedded signature request.
- *
+ *
* @return AbstractRequest
*/
public AbstractRequest getRequest() {
@@ -94,7 +95,7 @@ public AbstractRequest getRequest() {
/**
* Set the AbstractRequest associated with this Embedded signature request.
- *
+ *
* @param request AbstractRequest
*/
public void setRequest(AbstractRequest request) {
@@ -185,4 +186,34 @@ public boolean hasRedirectUrl() {
public String getId() {
return request.getId();
}
+
+ @Override
+ public void addCustomField(CustomField field) {
+ this.request.addCustomField(field);
+ }
+
+ @Override
+ public void setCustomFieldValue(String fieldNameOrApiId, String value) {
+ this.request.setCustomFieldValue(fieldNameOrApiId, value);
+ }
+
+ @Override
+ public List getCustomFields() {
+ return request.getCustomFields();
+ }
+
+ @Override
+ public Map getCustomFieldsMap() {
+ return request.getCustomFieldsMap();
+ }
+
+ @Override
+ public void setCustomFields(Map fields) {
+ request.setCustomFields(fields);
+ }
+
+ @Override
+ public void clearCustomFields() {
+ request.clearCustomFields();
+ }
}
diff --git a/src/main/java/com/hellosign/sdk/resource/SignatureRequest.java b/src/main/java/com/hellosign/sdk/resource/SignatureRequest.java
index 28c047b0..e91d9cd1 100644
--- a/src/main/java/com/hellosign/sdk/resource/SignatureRequest.java
+++ b/src/main/java/com/hellosign/sdk/resource/SignatureRequest.java
@@ -24,21 +24,18 @@
* SOFTWARE.
*/
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
import com.hellosign.sdk.HelloSignException;
-import com.hellosign.sdk.resource.support.CustomField;
import com.hellosign.sdk.resource.support.Document;
import com.hellosign.sdk.resource.support.FormField;
import com.hellosign.sdk.resource.support.ResponseData;
import com.hellosign.sdk.resource.support.Signature;
import com.hellosign.sdk.resource.support.Signer;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.json.JSONArray;
+import org.json.JSONObject;
/**
* Represents a HelloSign signature request. This object is used to both submit
@@ -66,7 +63,6 @@ public class SignatureRequest extends AbstractRequest {
public static final String SIGREQ_SIGNING_URL = "signing_url";
public static final String SIGREQ_DETAILS_URL = "details_url";
public static final String SIGREQ_IS_DECLINED = "is_declined";
- public static final String SIGREQ_CUSTOM_FIELDS = "custom_fields";
public static final String SIGREQ_FORMAT_ZIP = "zip";
public static final String SIGREQ_FORMAT_PDF = "pdf";
@@ -386,14 +382,4 @@ public boolean isDeclined() {
}
return false;
}
-
- /**
- * Gets the custom fields associated with this request, set when sending the
- * request from a template.
- *
- * @return List CustomFields
- */
- public List getCustomFields() {
- return getList(CustomField.class, SIGREQ_CUSTOM_FIELDS);
- }
}
\ No newline at end of file
diff --git a/src/main/java/com/hellosign/sdk/resource/TemplateDraft.java b/src/main/java/com/hellosign/sdk/resource/TemplateDraft.java
index bc529f51..defbd25a 100644
--- a/src/main/java/com/hellosign/sdk/resource/TemplateDraft.java
+++ b/src/main/java/com/hellosign/sdk/resource/TemplateDraft.java
@@ -24,6 +24,7 @@
* SOFTWARE.
*/
+import com.hellosign.sdk.resource.support.CustomField;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -318,4 +319,47 @@ public Map getPostFields() throws HelloSignException {
}
return fields;
}
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public void addCustomField(CustomField field) { }
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public void setCustomFieldValue(String fieldNameOrApiId, String value) { }
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public Map getCustomFieldsMap() { return null; }
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public List getCustomFields() { return null; }
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public List getCustomFieldsList() { return null; }
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public void setCustomFields(Map fields) { }
+
+ /**
+ * Not implemented for Template Drafts
+ */
+ @Override
+ public void clearCustomFields() { }
+
}
\ No newline at end of file
diff --git a/src/main/java/com/hellosign/sdk/resource/TemplateSignatureRequest.java b/src/main/java/com/hellosign/sdk/resource/TemplateSignatureRequest.java
index 1aabdadd..3e62a35a 100644
--- a/src/main/java/com/hellosign/sdk/resource/TemplateSignatureRequest.java
+++ b/src/main/java/com/hellosign/sdk/resource/TemplateSignatureRequest.java
@@ -24,18 +24,13 @@
* SOFTWARE.
*/
+import com.hellosign.sdk.HelloSignException;
+import com.hellosign.sdk.resource.support.Signer;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.json.JSONArray;
-
-import com.hellosign.sdk.HelloSignException;
-import com.hellosign.sdk.resource.support.CustomField;
-import com.hellosign.sdk.resource.support.Signer;
-
/**
* Represents a HelloSign signature request based on one or more Templates.
*
@@ -53,7 +48,6 @@ public class TemplateSignatureRequest extends AbstractRequest {
private static final String TEMPLATE_SIGNERS_NAME = "name";
private static final String TEMPLATE_CCS = "ccs";
private static final String TEMPLATE_CCS_EMAIL = "email_address";
- private static final String TEMPLATE_CUSTOM_FIELDS = "custom_fields";
// Signers, CC email addresses and custom fields are required
// to have an associated role. We'll manage these in a Map,
@@ -61,7 +55,6 @@ public class TemplateSignatureRequest extends AbstractRequest {
// fields are stored, so we can support this association.
private Map signers = new HashMap();
private Map ccs = new HashMap();
- private List customFields = new ArrayList();
public TemplateSignatureRequest() {
super();
@@ -182,76 +175,6 @@ public void removeSignerByEmail(String email) throws HelloSignException {
}
}
- /**
- * Add the custom field to this request. This is useful for specifying a
- * pre-filled value and/or a field editor.
- *
- * @param field CustomField
- */
- public void addCustomField(CustomField field) {
- customFields.add(field);
- }
-
- /**
- * Adds the value to fill in for a custom field with the given field name.
- *
- * @param fieldNameOrApiId String name (or "Field Label") of the custom field
- * to be filled in. The "api_id" can also be used instead of the name.
- * @param value String value
- */
- public void setCustomFieldValue(String fieldNameOrApiId, String value) {
- CustomField f = new CustomField();
- f.setName(fieldNameOrApiId);
- f.setValue(value);
- customFields.add(f);
- }
-
- /**
- * Returns the map of custom fields for the template. This is a map of
- * String field names to String field values.
- *
- * @return Map
- */
- public Map getCustomFields() {
- Map fields = new HashMap();
- for (CustomField f : customFields) {
- fields.put(f.getName(), f.getValue());
- }
- return fields;
- }
-
- /**
- * Returns a list of CustomField objects for this template.
- *
- * @return List of CustomFields
- */
- public List getCustomFieldsList() {
- return customFields;
- }
-
- /**
- * Overwrites the current map of custom fields to the provided map. This is
- * a map of String field names to String field values.
- *
- * @param fields Map
- */
- public void setCustomFields(Map fields) {
- clearCustomFields();
- for (String key : fields.keySet()) {
- CustomField f = new CustomField();
- f.setName(key);
- f.setValue(fields.get(key));
- customFields.add(f);
- }
- }
-
- /**
- * Clears the current custom fields for this request.
- */
- public void clearCustomFields() {
- customFields = new ArrayList();
- }
-
/**
* Set the template ID of the template that should be used with this
* request.
@@ -373,13 +296,6 @@ public Map getPostFields() throws HelloSignException {
for (String role : ccz.keySet()) {
fields.put(TEMPLATE_CCS + "[" + role + "][" + TEMPLATE_CCS_EMAIL + "]", ccz.get(role));
}
- if (customFields.size() > 0) {
- JSONArray array = new JSONArray();
- for (CustomField f : customFields) {
- array.put(f.getJSONObject());
- }
- fields.put(TEMPLATE_CUSTOM_FIELDS, array.toString());
- }
if (isTestMode()) {
fields.put(REQUEST_TEST_MODE, true);
}
diff --git a/src/main/java/com/hellosign/sdk/resource/UnclaimedDraft.java b/src/main/java/com/hellosign/sdk/resource/UnclaimedDraft.java
index 871ce7dd..5ad5d6ad 100644
--- a/src/main/java/com/hellosign/sdk/resource/UnclaimedDraft.java
+++ b/src/main/java/com/hellosign/sdk/resource/UnclaimedDraft.java
@@ -24,9 +24,11 @@
* SOFTWARE.
*/
+import com.hellosign.sdk.resource.support.CustomField;
import java.io.File;
import java.io.Serializable;
import java.util.Date;
+import java.util.List;
import java.util.Map;
import org.json.JSONObject;
@@ -355,6 +357,37 @@ public String getId() {
return request.getId();
}
+
+ @Override
+ public void addCustomField(CustomField field) {
+ this.request.addCustomField(field);
+ }
+
+ @Override
+ public void setCustomFieldValue(String fieldNameOrApiId, String value) {
+ this.request.setCustomFieldValue(fieldNameOrApiId, value);
+ }
+
+ @Override
+ public List getCustomFields() {
+ return request.getCustomFields();
+ }
+
+ @Override
+ public Map getCustomFieldsMap() {
+ return request.getCustomFieldsMap();
+ }
+
+ @Override
+ public void setCustomFields(Map fields) {
+ request.setCustomFields(fields);
+ }
+
+ @Override
+ public void clearCustomFields() {
+ request.clearCustomFields();
+ }
+
public Date getExpiresAt() {
return getDate(UNCLAIMED_DRAFT_EXPIRES_AT);
}
diff --git a/src/test/java/com/hellosign/sdk/HelloSignClientTest.java b/src/test/java/com/hellosign/sdk/HelloSignClientTest.java
index ae280427..8a5c5ca0 100644
--- a/src/test/java/com/hellosign/sdk/HelloSignClientTest.java
+++ b/src/test/java/com/hellosign/sdk/HelloSignClientTest.java
@@ -1,24 +1,14 @@
package com.hellosign.sdk;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-import static org.mockito.ArgumentMatchers.*;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Scanner;
-import java.util.regex.Pattern;
-
-import org.json.JSONObject;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestName;
import com.hellosign.sdk.http.Authentication;
import com.hellosign.sdk.http.HttpClient;
@@ -45,6 +35,19 @@
import com.hellosign.sdk.resource.support.WhiteLabelingOptions;
import com.hellosign.sdk.resource.support.types.FieldType;
import com.hellosign.sdk.resource.support.types.UnclaimedDraftType;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Scanner;
+import java.util.regex.Pattern;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
/**
* The MIT License (MIT)
@@ -611,10 +614,10 @@ public void testSendTemplateSignatureRequest() throws Exception {
req.setCustomFields(fields);
SignatureRequest sentReq = client.sendTemplateSignatureRequest(req);
assertNotNull(sentReq);
- assertTrue(title.equals(sentReq.getTitle()));
- assertTrue(message.equals(sentReq.getMessage()));
+ assertEquals(title, sentReq.getTitle());
+ assertEquals(message, sentReq.getMessage());
for (CustomField cf : sentReq.getCustomFields()) {
- assertTrue(fields.get(cf.getName()).equals(cf.getValue()));
+ assertEquals(fields.get(cf.getName()), cf.getValue());
}
}
@@ -755,10 +758,19 @@ public void testCreateEmbeddedRequest() throws Exception {
req.setTestMode(true);
req.addMetadata("test_key", "test_value");
EmbeddedRequest embeddedReq = new EmbeddedRequest("034fb51064187cf28e4aad1c2533ad8f", req);
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ fields.put("Checkbox A", "true");
+ fields.put("Checkbox B", "false");
+ embeddedReq.setCustomFields(fields);
AbstractRequest newReq = client.createEmbeddedRequest(embeddedReq);
assertNotNull(newReq);
assertNotNull(newReq.getId());
- assertTrue(req.getMetadata("test_key").equals(newReq.getMetadata("test_key")));
+ assertEquals(req.getMetadata("test_key"), newReq.getMetadata("test_key"));
+ for (CustomField cf : newReq.getCustomFields()) {
+ assertEquals(fields.get(cf.getName()), cf.getValue());
+ }
}
@Test(expected = HelloSignException.class)
diff --git a/src/test/java/com/hellosign/sdk/PostFieldsTest.java b/src/test/java/com/hellosign/sdk/PostFieldsTest.java
new file mode 100644
index 00000000..9319806b
--- /dev/null
+++ b/src/test/java/com/hellosign/sdk/PostFieldsTest.java
@@ -0,0 +1,131 @@
+package com.hellosign.sdk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.hellosign.sdk.resource.EmbeddedRequest;
+import com.hellosign.sdk.resource.SignatureRequest;
+import com.hellosign.sdk.resource.TemplateDraft;
+import com.hellosign.sdk.resource.UnclaimedDraft;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+
+public class PostFieldsTest {
+
+ @Test
+ public void testSignatureRequest() throws Exception {
+ SignatureRequest req = new SignatureRequest();
+ req.addFileUrl("http://www.orimi.com/pdf-test.pdf");
+ req.addSigner("chris@hellosign.com", "Chris");
+ req.setTestMode(true);
+ req.addMetadata("test_key", "test_value");
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ req.setCustomFields(fields);
+
+ Map postFields = req.getPostFields();
+ assertEquals("chris@hellosign.com", postFields.get("signers[0][email_address]"));
+ assertEquals("test_value", postFields.get("metadata[test_key]"));
+ assertEquals(true, postFields.get("test_mode"));
+ assertEquals("[{\"name\":\"Field A\",\"value\":\"Hello\"},{\"name\":\"Field B\",\"value\":\"World!\"}]", postFields.get("custom_fields"));
+ assertEquals("Chris", postFields.get("signers[0][name]"));
+ assertEquals("http://www.orimi.com/pdf-test.pdf", postFields.get("file_url[0]"));
+ }
+
+ @Test
+ public void testEmbeddedSignatureRequest() throws Exception {
+ SignatureRequest req = new SignatureRequest();
+ req.addFileUrl("http://www.orimi.com/pdf-test.pdf");
+ req.addSigner("chris@hellosign.com", "Chris");
+ req.setTestMode(true);
+ req.addMetadata("test_key", "test_value");
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ req.setCustomFields(fields);
+
+ EmbeddedRequest embeddedReq = new EmbeddedRequest("034fb51064187cf28e4aad1c2533ad8f", req);
+
+ Map postFields = embeddedReq.getPostFields();
+ assertEquals("chris@hellosign.com", postFields.get("signers[0][email_address]"));
+ assertEquals("test_value", postFields.get("metadata[test_key]"));
+ assertEquals(true, postFields.get("test_mode"));
+ assertEquals("[{\"name\":\"Field A\",\"value\":\"Hello\"},{\"name\":\"Field B\",\"value\":\"World!\"}]", postFields.get("custom_fields"));
+ assertEquals("Chris", postFields.get("signers[0][name]"));
+ assertEquals("034fb51064187cf28e4aad1c2533ad8f", postFields.get("client_id"));
+ assertEquals("http://www.orimi.com/pdf-test.pdf", postFields.get("file_url[0]"));
+ }
+
+ @Test
+ public void testCustomFieldsOnEmbeddedRequest() throws Exception {
+ SignatureRequest req = new SignatureRequest();
+ EmbeddedRequest embeddedReq = new EmbeddedRequest(null, req);
+
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ req.setCustomFields(fields);
+
+ Map postFields = embeddedReq.getPostFields();
+ assertEquals("[{\"name\":\"Field A\",\"value\":\"Hello\"},{\"name\":\"Field B\",\"value\":\"World!\"}]", postFields.get("custom_fields"));
+ }
+
+ @Test
+ public void testEmbeddedUnclaimedDraft() throws Exception {
+ UnclaimedDraft draft = new UnclaimedDraft();
+ draft.setRequesterEmail("chris@hellosign.com");
+
+ draft.setTestMode(true);
+ draft.addMetadata("test_key", "test_value");
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ draft.setCustomFields(fields);
+
+ EmbeddedRequest embeddedReq = new EmbeddedRequest("034fb51064187cf28e4aad1c2533ad8f", draft);
+
+ Map postFields = embeddedReq.getPostFields();
+ assertEquals("chris@hellosign.com", postFields.get("requester_email_address"));
+ assertEquals(true, postFields.get("test_mode"));
+ assertEquals("[{\"name\":\"Field A\",\"value\":\"Hello\"},{\"name\":\"Field B\",\"value\":\"World!\"}]", postFields.get("custom_fields"));
+ assertEquals("034fb51064187cf28e4aad1c2533ad8f", postFields.get("client_id"));
+ }
+
+ @Test
+ public void testEmbeddedUnclaimedDraftFromSigRequest() throws Exception {
+ SignatureRequest req = new SignatureRequest();
+ req.addFileUrl("http://www.orimi.com/pdf-test.pdf");
+ req.setTestMode(true);
+ req.addMetadata("test_key", "test_value");
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ req.setCustomFields(fields);
+
+ UnclaimedDraft draft = new UnclaimedDraft(req);
+ draft.setRequesterEmail("chris@hellosign.com");
+
+ EmbeddedRequest embeddedReq = new EmbeddedRequest("034fb51064187cf28e4aad1c2533ad8f", draft);
+
+ Map postFields = embeddedReq.getPostFields();
+ assertEquals("chris@hellosign.com", postFields.get("requester_email_address"));
+ assertEquals(true, postFields.get("test_mode"));
+ assertEquals("[{\"name\":\"Field A\",\"value\":\"Hello\"},{\"name\":\"Field B\",\"value\":\"World!\"}]", postFields.get("custom_fields"));
+ assertEquals("034fb51064187cf28e4aad1c2533ad8f", postFields.get("client_id"));
+ }
+
+ @Test
+ public void testTemplateDraftDropsCustomFields() throws Exception {
+ TemplateDraft draft = new TemplateDraft();
+ Map fields = new HashMap<>();
+ fields.put("Field A", "Hello");
+ fields.put("Field B", "World!");
+ draft.setCustomFields(fields);
+
+ Map postFields = draft.getPostFields();
+ assertNull(postFields.get("custom_fields"));
+ }
+}