From 23a8a0dbb5c1dd0e470e6840b585903b8738d0c8 Mon Sep 17 00:00:00 2001 From: Alex Shults Date: Wed, 4 Dec 2019 16:12:14 -0500 Subject: [PATCH 1/3] Include delevered_as in conversation message --- .../io/intercom/api/ConversationMessage.java | 224 +++++++++--------- 1 file changed, 117 insertions(+), 107 deletions(-) diff --git a/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java b/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java index 54c909b4..82364ebf 100644 --- a/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java +++ b/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java @@ -1,107 +1,117 @@ -package io.intercom.api; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -@SuppressWarnings("UnusedDeclaration") -@JsonIgnoreProperties(ignoreUnknown = true) -public class ConversationMessage extends TypedData { - - @SuppressWarnings("FieldCanBeLocal") - @JsonProperty("type") - private final String type = "conversation_message"; - - @JsonProperty - private String id; - - @JsonProperty - private String subject; - - @JsonProperty - private String body; - - @JsonProperty - private Author author; - - @JsonProperty - private String url; - - @JsonProperty("attachments") - private List attachments; - - public ConversationMessage() { - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public String getSubject() { - return subject; - } - - public String getBody() { - return body; - } - - public Author getAuthor() { - return author; - } - - public String getUrl() { - return url; - } - - public List getAttachments() { - return attachments; - } - - @Override - public int hashCode() { - int result = subject != null ? subject.hashCode() : 0; - result = 31 * result + (body != null ? body.hashCode() : 0); - result = 31 * result + (author != null ? author.hashCode() : 0); - result = 31 * result + (id != null ? id.hashCode() : 0); - result = 31 * result + (url != null ? url.hashCode() : 0); - result = 31 * result + (attachments != null ? attachments.hashCode() : 0); - - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ConversationMessage that = (ConversationMessage) o; - - if (author != null ? !author.equals(that.author) : that.author != null) return false; - if (body != null ? !body.equals(that.body) : that.body != null) return false; - //noinspection RedundantIfStatement - if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (url != null ? !url.equals(that.url) : that.url != null) return false; - if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false; - - return true; - } - - @Override - public String toString() { - return "ConversationMessage{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", subject='" + subject + '\'' + - ", body='" + body + '\'' + - ", author=" + author + - ", url=" + url + - ", attachments=" + attachments + - "} " + super.toString(); - } -} +package io.intercom.api; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@SuppressWarnings("UnusedDeclaration") +@JsonIgnoreProperties(ignoreUnknown = true) +public class ConversationMessage extends TypedData { + + @SuppressWarnings("FieldCanBeLocal") + @JsonProperty("type") + private final String type = "conversation_message"; + + @JsonProperty + private String id; + + @JsonProperty + private String subject; + + @JsonProperty + private String body; + + @JsonProperty + private Author author; + + @JsonProperty + private String url; + + @JsonProperty("delivered_as") + private String deliveredAs; + + @JsonProperty("attachments") + private List attachments; + + public ConversationMessage() { + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public String getSubject() { + return subject; + } + + public String getBody() { + return body; + } + + public Author getAuthor() { + return author; + } + + public String getUrl() { + return url; + } + + public String getDeliveredAs() { + return deliveredAs; + } + + public List getAttachments() { + return attachments; + } + + @Override + public int hashCode() { + int result = subject != null ? subject.hashCode() : 0; + result = 31 * result + (body != null ? body.hashCode() : 0); + result = 31 * result + (author != null ? author.hashCode() : 0); + result = 31 * result + (deliveredAs != null ? deliveredAs.hashCode() : 0); + result = 31 * result + (id != null ? id.hashCode() : 0); + result = 31 * result + (url != null ? url.hashCode() : 0); + result = 31 * result + (attachments != null ? attachments.hashCode() : 0); + + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ConversationMessage that = (ConversationMessage) o; + + if (author != null ? !author.equals(that.author) : that.author != null) return false; + if (body != null ? !body.equals(that.body) : that.body != null) return false; + //noinspection RedundantIfStatement + if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (url != null ? !url.equals(that.url) : that.url != null) return false; + if (deliveredAs != null ? !deliveredAs.equals(that.deliveredAs) : that.deliveredAs != null) return false; + if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false; + + return true; + } + + @Override + public String toString() { + return "ConversationMessage{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", subject='" + subject + '\'' + + ", body='" + body + '\'' + + ", author=" + author + + ", url=" + url + + ", deliveredAs=" + deliveredAs + + ", attachments=" + attachments + + "} " + super.toString(); + } +} From 0004f711ac6b1f1c12685048545d7208af3cfa30 Mon Sep 17 00:00:00 2001 From: Alex Shults Date: Wed, 4 Dec 2019 16:24:46 -0500 Subject: [PATCH 2/3] Unit tests for delivered_as --- .../io/intercom/api/ConversationTest.java | 546 +++++++++--------- .../src/test/resources/conversation.json | 197 +++---- .../conversation_no_attachments.json | 165 +++--- .../src/test/resources/conversations.json | 201 +++---- 4 files changed, 558 insertions(+), 551 deletions(-) diff --git a/intercom-java/src/test/java/io/intercom/api/ConversationTest.java b/intercom-java/src/test/java/io/intercom/api/ConversationTest.java index 2c57a928..59b38905 100644 --- a/intercom-java/src/test/java/io/intercom/api/ConversationTest.java +++ b/intercom-java/src/test/java/io/intercom/api/ConversationTest.java @@ -1,272 +1,274 @@ -package io.intercom.api; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Maps; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.io.IOException; -import java.util.Map; - -import static io.intercom.api.TestSupport.load; -import static org.junit.Assert.*; -import static org.junit.Assert.assertTrue; - -@RunWith(PowerMockRunner.class) -@PrepareForTest( { Conversation.class }) -public class ConversationTest { - - private static ObjectMapper objectMapper; - - @BeforeClass - public static void beforeClass() { - objectMapper = MapperSupport.objectMapper(); - } - - @Test - public void testIsNullOrBlank() { - assertTrue(Conversation.isNullOrBlank(null)); - assertTrue(Conversation.isNullOrBlank("")); - assertTrue(Conversation.isNullOrBlank(" ")); - assertTrue(Conversation.isNullOrBlank("\n")); - assertTrue(Conversation.isNullOrBlank("\r")); - assertFalse(Conversation.isNullOrBlank("reply")); - } - - @Test - public void testAdminReply() { - - AdminReply adminReply = new AdminReply(null); - adminReply.setAssigneeID("1"); - assertEquals(Conversation.MESSAGE_TYPE_ASSIGNMENT, adminReply.getMessageType()); - - try { - Conversation.validateAdminReplyRequest(adminReply); - } catch (InvalidException e) { - fail(); - } - - adminReply = new AdminReply(null); - adminReply.setMessageType("comment"); - try { - Conversation.validateAdminReplyRequest(adminReply); - fail(); - } catch (InvalidException e) { - assertTrue(e.getMessage() - .contains("a comment or note reply must have a body")); - } - - adminReply.setBody(" "); - try { - Conversation.validateAdminReplyRequest(adminReply); - fail(); - } catch (InvalidException e) { - assertTrue(e.getMessage() - .contains("a comment or note reply must have a body")); - } - - adminReply.setBody("Once, in flight school, I was laconic"); - try { - Conversation.validateAdminReplyRequest(adminReply); - } catch (InvalidException e) { - fail(); - } - - adminReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); - try { - Conversation.validateAdminReplyRequest(adminReply); - } catch (InvalidException e) { - fail(); - } - } - - @Test - public void testDisplayAs() { - - try { - Conversation.list(buildRequestParameters("pdf")); - fail(); - } catch (InvalidException e) { - assertTrue(e.getMessage() - .contains("A display_as parameter must have one of the values plaintext, html")); - } - - try { - Conversation.validateListRequest(buildRequestParameters("plaintext")); - } catch (InvalidException e) { - fail(); - } - - try { - Conversation.validateListRequest(buildRequestParameters("html")); - } catch (InvalidException e) { - fail(); - } - } - - @Test - public void testGetConversationMessageDetailsFromConversation() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - final ConversationMessage conversationMessage = conversation.getConversationMessage(); - - assertEquals("33954111", conversationMessage.getId()); - assertEquals("

test

", conversationMessage.getBody()); - assertEquals("Email subject", conversationMessage.getSubject()); - assertEquals("https://intercom.com/", conversationMessage.getUrl()); - - assertEquals("lead", conversationMessage.getAuthor().getType()); - assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); - - assertEquals(2, conversationMessage.getAttachments().size()); - - final Attachment firstAttachment = conversationMessage.getAttachments().get(0); - final Attachment lastAttachment = conversationMessage.getAttachments().get(1); - assertEquals("upload", firstAttachment.getType()); - assertEquals("123.csv", firstAttachment.getName()); - assertEquals("https://downloads.intercomcdn.com/123.csv", firstAttachment.getUrl()); - assertEquals("text/csv", firstAttachment.getContentType()); - assertEquals(147, firstAttachment.getFilesize()); - assertEquals(0, firstAttachment.getWidth()); - assertEquals(0, firstAttachment.getHeight()); - - assertEquals("upload", lastAttachment.getType()); - assertEquals("abc.txt", lastAttachment.getName()); - assertEquals("https://downloads.intercomcdn.com/txt", lastAttachment.getUrl()); - assertEquals("text/csv", lastAttachment.getContentType()); - assertEquals(100, lastAttachment.getFilesize()); - assertEquals(1, lastAttachment.getWidth()); - assertEquals(2, lastAttachment.getHeight()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetConversationMessageDetailsFromConversationNoAttachments() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation_no_attachments.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - final ConversationMessage conversationMessage = conversation.getConversationMessage(); - - assertEquals("33954111", conversationMessage.getId()); - assertEquals("

test

", conversationMessage.getBody()); - assertEquals("Email subject", conversationMessage.getSubject()); - assertEquals("https://intercom.com/", conversationMessage.getUrl()); - - assertEquals("lead", conversationMessage.getAuthor().getType()); - assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); - - assertEquals(0, conversationMessage.getAttachments().size()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetConversationsPartFromConversation() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - assertEquals(2, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetConversationsPartFromConversationCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation.json"); - final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); - assertEquals(2, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetEmptyConversationsPartFromConversationCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation_no_parts.json"); - final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); - assertEquals(0, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetTagsFromConversation() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - assertEquals(2, conversation.getTagCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetTagFromTagCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation.json"); - final Conversation conversationWithTags = objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); - assertEquals(2, conversation.getTagCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetEmptyTagFromTagCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation_no_tags.json"); - final Conversation conversationWithTags= objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); - assertEquals(0, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - private Map buildRequestParameters(String html) { - Map params2 = Maps.newHashMap(); - params2.put("type", "admin"); - params2.put("admin_id", "1"); - params2.put("display_as", html); - return params2; - } -} +package io.intercom.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Maps; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.io.IOException; +import java.util.Map; + +import static io.intercom.api.TestSupport.load; +import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; + +@RunWith(PowerMockRunner.class) +@PrepareForTest( { Conversation.class }) +public class ConversationTest { + + private static ObjectMapper objectMapper; + + @BeforeClass + public static void beforeClass() { + objectMapper = MapperSupport.objectMapper(); + } + + @Test + public void testIsNullOrBlank() { + assertTrue(Conversation.isNullOrBlank(null)); + assertTrue(Conversation.isNullOrBlank("")); + assertTrue(Conversation.isNullOrBlank(" ")); + assertTrue(Conversation.isNullOrBlank("\n")); + assertTrue(Conversation.isNullOrBlank("\r")); + assertFalse(Conversation.isNullOrBlank("reply")); + } + + @Test + public void testAdminReply() { + + AdminReply adminReply = new AdminReply(null); + adminReply.setAssigneeID("1"); + assertEquals(Conversation.MESSAGE_TYPE_ASSIGNMENT, adminReply.getMessageType()); + + try { + Conversation.validateAdminReplyRequest(adminReply); + } catch (InvalidException e) { + fail(); + } + + adminReply = new AdminReply(null); + adminReply.setMessageType("comment"); + try { + Conversation.validateAdminReplyRequest(adminReply); + fail(); + } catch (InvalidException e) { + assertTrue(e.getMessage() + .contains("a comment or note reply must have a body")); + } + + adminReply.setBody(" "); + try { + Conversation.validateAdminReplyRequest(adminReply); + fail(); + } catch (InvalidException e) { + assertTrue(e.getMessage() + .contains("a comment or note reply must have a body")); + } + + adminReply.setBody("Once, in flight school, I was laconic"); + try { + Conversation.validateAdminReplyRequest(adminReply); + } catch (InvalidException e) { + fail(); + } + + adminReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); + try { + Conversation.validateAdminReplyRequest(adminReply); + } catch (InvalidException e) { + fail(); + } + } + + @Test + public void testDisplayAs() { + + try { + Conversation.list(buildRequestParameters("pdf")); + fail(); + } catch (InvalidException e) { + assertTrue(e.getMessage() + .contains("A display_as parameter must have one of the values plaintext, html")); + } + + try { + Conversation.validateListRequest(buildRequestParameters("plaintext")); + } catch (InvalidException e) { + fail(); + } + + try { + Conversation.validateListRequest(buildRequestParameters("html")); + } catch (InvalidException e) { + fail(); + } + } + + @Test + public void testGetConversationMessageDetailsFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + final ConversationMessage conversationMessage = conversation.getConversationMessage(); + + assertEquals("33954111", conversationMessage.getId()); + assertEquals("

test

", conversationMessage.getBody()); + assertEquals("Email subject", conversationMessage.getSubject()); + assertEquals("https://intercom.com/", conversationMessage.getUrl()); + assertEquals("customer_initiated", conversationMessage.getDeliveredAs()); + + assertEquals("lead", conversationMessage.getAuthor().getType()); + assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); + + assertEquals(2, conversationMessage.getAttachments().size()); + + final Attachment firstAttachment = conversationMessage.getAttachments().get(0); + final Attachment lastAttachment = conversationMessage.getAttachments().get(1); + assertEquals("upload", firstAttachment.getType()); + assertEquals("123.csv", firstAttachment.getName()); + assertEquals("https://downloads.intercomcdn.com/123.csv", firstAttachment.getUrl()); + assertEquals("text/csv", firstAttachment.getContentType()); + assertEquals(147, firstAttachment.getFilesize()); + assertEquals(0, firstAttachment.getWidth()); + assertEquals(0, firstAttachment.getHeight()); + + assertEquals("upload", lastAttachment.getType()); + assertEquals("abc.txt", lastAttachment.getName()); + assertEquals("https://downloads.intercomcdn.com/txt", lastAttachment.getUrl()); + assertEquals("text/csv", lastAttachment.getContentType()); + assertEquals(100, lastAttachment.getFilesize()); + assertEquals(1, lastAttachment.getWidth()); + assertEquals(2, lastAttachment.getHeight()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationMessageDetailsFromConversationNoAttachments() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation_no_attachments.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + final ConversationMessage conversationMessage = conversation.getConversationMessage(); + + assertEquals("33954111", conversationMessage.getId()); + assertEquals("

test

", conversationMessage.getBody()); + assertEquals("Email subject", conversationMessage.getSubject()); + assertEquals("https://intercom.com/", conversationMessage.getUrl()); + assertEquals("customer_initiated", conversationMessage.getDeliveredAs()); + + assertEquals("lead", conversationMessage.getAuthor().getType()); + assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); + + assertEquals(0, conversationMessage.getAttachments().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationsPartFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + assertEquals(2, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationsPartFromConversationCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation.json"); + final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); + assertEquals(2, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetEmptyConversationsPartFromConversationCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation_no_parts.json"); + final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); + assertEquals(0, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetTagsFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + assertEquals(2, conversation.getTagCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetTagFromTagCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation.json"); + final Conversation conversationWithTags = objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); + assertEquals(2, conversation.getTagCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetEmptyTagFromTagCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation_no_tags.json"); + final Conversation conversationWithTags= objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); + assertEquals(0, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + private Map buildRequestParameters(String html) { + Map params2 = Maps.newHashMap(); + params2.put("type", "admin"); + params2.put("admin_id", "1"); + params2.put("display_as", html); + return params2; + } +} diff --git a/intercom-java/src/test/resources/conversation.json b/intercom-java/src/test/resources/conversation.json index 03ef074e..83e819c3 100644 --- a/intercom-java/src/test/resources/conversation.json +++ b/intercom-java/src/test/resources/conversation.json @@ -1,98 +1,99 @@ -{ - "type": "conversation", - "id": "5143511111", - "created_at": 1466703132, - "updated_at": 1468236397, - "waiting_since": 1468236397, - "conversation_message": { - "type": "conversation_message", - "id": "33954111", - "subject": "Email subject", - "body": "

test

", - "author": { - "type": "lead", - "id": "576c1a139d0baad1010011111" - }, - "attachments": [{ - "type": "upload", - "name": "123.csv", - "url": "https://downloads.intercomcdn.com/123.csv", - "content_type": "text/csv", - "filesize": 147, - "width": null, - "height": null - },{ - "type": "upload", - "name": "abc.txt", - "url": "https://downloads.intercomcdn.com/txt", - "content_type": "text/csv", - "filesize": 100, - "width": 1, - "height": 2 - }], - "url": "https://intercom.com/" - }, - "user": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "assignee": { - "type": "admin", - "id": "358111" - }, - "conversation_parts": { - "type": "conversation_part.list", - "conversation_parts": [ - { - "type": "conversation_part", - "id": "142533411", - "part_type": "comment", - "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", - "created_at": 1468031160, - "updated_at": 1468031160, - "notified_at": 1468031160, - "assigned_to": null, - "author": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "attachments": [], - "external_id": null - }, - { - "type": "conversation_part", - "id": "142533511", - "part_type": "comment", - "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", - "created_at": 1468031171, - "updated_at": 1468031171, - "notified_at": 1468031171, - "assigned_to": null, - "author": { - "type": "admin", - "id": "358111" - }, - "attachments": [], - "external_id": null - } - ], - "total_count": 2 - }, - "open": true, - "read": false, - "tags": { - "type": "tag.list", - "tags": [ - { - "type": "tag", - "id": "123", - "name": "Tag 1" - }, - { - "type": "tag", - "id": "456", - "name": "Tag 2" - } - ] - } -} +{ + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "conversation_message": { + "type": "conversation_message", + "id": "33954111", + "subject": "Email subject", + "body": "

test

", + "delivered_as": "customer_initiated", + "author": { + "type": "lead", + "id": "576c1a139d0baad1010011111" + }, + "attachments": [{ + "type": "upload", + "name": "123.csv", + "url": "https://downloads.intercomcdn.com/123.csv", + "content_type": "text/csv", + "filesize": 147, + "width": null, + "height": null + },{ + "type": "upload", + "name": "abc.txt", + "url": "https://downloads.intercomcdn.com/txt", + "content_type": "text/csv", + "filesize": 100, + "width": 1, + "height": 2 + }], + "url": "https://intercom.com/" + }, + "user": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_parts": { + "type": "conversation_part.list", + "conversation_parts": [ + { + "type": "conversation_part", + "id": "142533411", + "part_type": "comment", + "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", + "created_at": 1468031160, + "updated_at": 1468031160, + "notified_at": 1468031160, + "assigned_to": null, + "author": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "attachments": [], + "external_id": null + }, + { + "type": "conversation_part", + "id": "142533511", + "part_type": "comment", + "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", + "created_at": 1468031171, + "updated_at": 1468031171, + "notified_at": 1468031171, + "assigned_to": null, + "author": { + "type": "admin", + "id": "358111" + }, + "attachments": [], + "external_id": null + } + ], + "total_count": 2 + }, + "open": true, + "read": false, + "tags": { + "type": "tag.list", + "tags": [ + { + "type": "tag", + "id": "123", + "name": "Tag 1" + }, + { + "type": "tag", + "id": "456", + "name": "Tag 2" + } + ] + } +} diff --git a/intercom-java/src/test/resources/conversation_no_attachments.json b/intercom-java/src/test/resources/conversation_no_attachments.json index 1881bd7e..9c1193cf 100644 --- a/intercom-java/src/test/resources/conversation_no_attachments.json +++ b/intercom-java/src/test/resources/conversation_no_attachments.json @@ -1,82 +1,83 @@ -{ - "type": "conversation", - "id": "5143511111", - "created_at": 1466703132, - "updated_at": 1468236397, - "waiting_since": 1468236397, - "conversation_message": { - "type": "conversation_message", - "id": "33954111", - "subject": "Email subject", - "body": "

test

", - "author": { - "type": "lead", - "id": "576c1a139d0baad1010011111" - }, - "attachments": [], - "url": "https://intercom.com/" - }, - "user": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "assignee": { - "type": "admin", - "id": "358111" - }, - "conversation_parts": { - "type": "conversation_part.list", - "conversation_parts": [ - { - "type": "conversation_part", - "id": "142533411", - "part_type": "comment", - "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", - "created_at": 1468031160, - "updated_at": 1468031160, - "notified_at": 1468031160, - "assigned_to": null, - "author": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "attachments": [], - "external_id": null - }, - { - "type": "conversation_part", - "id": "142533511", - "part_type": "comment", - "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", - "created_at": 1468031171, - "updated_at": 1468031171, - "notified_at": 1468031171, - "assigned_to": null, - "author": { - "type": "admin", - "id": "358111" - }, - "attachments": [], - "external_id": null - } - ], - "total_count": 2 - }, - "open": true, - "read": false, - "tags": { - "type": "tag.list", - "tags": [ - { - "type": "tag", - "id": "123", - "name": "Tag 1" - }, - { - "type": "tag", - "id": "456", - "name": "Tag 2" - } - ] - } -} +{ + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "conversation_message": { + "type": "conversation_message", + "id": "33954111", + "subject": "Email subject", + "body": "

test

", + "delivered_as": "customer_initiated", + "author": { + "type": "lead", + "id": "576c1a139d0baad1010011111" + }, + "attachments": [], + "url": "https://intercom.com/" + }, + "user": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_parts": { + "type": "conversation_part.list", + "conversation_parts": [ + { + "type": "conversation_part", + "id": "142533411", + "part_type": "comment", + "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", + "created_at": 1468031160, + "updated_at": 1468031160, + "notified_at": 1468031160, + "assigned_to": null, + "author": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "attachments": [], + "external_id": null + }, + { + "type": "conversation_part", + "id": "142533511", + "part_type": "comment", + "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", + "created_at": 1468031171, + "updated_at": 1468031171, + "notified_at": 1468031171, + "assigned_to": null, + "author": { + "type": "admin", + "id": "358111" + }, + "attachments": [], + "external_id": null + } + ], + "total_count": 2 + }, + "open": true, + "read": false, + "tags": { + "type": "tag.list", + "tags": [ + { + "type": "tag", + "id": "123", + "name": "Tag 1" + }, + { + "type": "tag", + "id": "456", + "name": "Tag 2" + } + ] + } +} diff --git a/intercom-java/src/test/resources/conversations.json b/intercom-java/src/test/resources/conversations.json index 5105dbd3..922fdaad 100644 --- a/intercom-java/src/test/resources/conversations.json +++ b/intercom-java/src/test/resources/conversations.json @@ -1,99 +1,102 @@ -{ - "type": "conversation.list", - "pages": { - "type": "pages", - "next": null, - "page": 1, - "per_page": 20, - "total_pages": 1 - }, - "conversations": [ - { - "type": "conversation", - "id": "5680931777", - "created_at": 1471438637, - "updated_at": 1471438637, - "waiting_since": 1468236397, - "user": { - "type": "user", - "id": "57b45f16d1aad7e69e011111" - }, - "assignee": { - "type": "nobody_admin", - "id": null - }, - "conversation_message": { - "type": "conversation_message", - "id": "41111111", - "subject": "", - "body": "

Hey2

", - "author": { - "type": "user", - "id": "57b45f16d1aad7e69e011111" - }, - "attachments": [], - "url": null - }, - "open": true, - "read": true - }, - { - "type": "conversation", - "id": "5680912811", - "created_at": 1471438151, - "updated_at": 1471438151, - "waiting_since": 1468236397, - "user": { - "type": "user", - "id": "57b45bfef436c8d78611111" - }, - "assignee": { - "type": "nobody_admin", - "id": null - }, - "conversation_message": { - "type": "conversation_message", - "id": "41141111", - "subject": "", - "body": "

Hey

", - "author": { - "type": "user", - "id": "57b45bfef436c8d786000111" - }, - "attachments": [], - "url": null - }, - "open": true, - "read": true - }, - { - "type": "conversation", - "id": "5143511111", - "created_at": 1466703132, - "updated_at": 1468236397, - "waiting_since": 1468236397, - "user": { - "type": "lead", - "id": "576c1a139d0baad101001111" - }, - "assignee": { - "type": "admin", - "id": "358111" - }, - "conversation_message": { - "type": "conversation_message", - "id": "33954838", - "subject": "", - "body": "

test

", - "author": { - "type": "lead", - "id": "576c1a139d0baad101001111" - }, - "attachments": [], - "url": null - }, - "open": true, - "read": false - } - ] -} +{ + "type": "conversation.list", + "pages": { + "type": "pages", + "next": null, + "page": 1, + "per_page": 20, + "total_pages": 1 + }, + "conversations": [ + { + "type": "conversation", + "id": "5680931777", + "created_at": 1471438637, + "updated_at": 1471438637, + "waiting_since": 1468236397, + "user": { + "type": "user", + "id": "57b45f16d1aad7e69e011111" + }, + "assignee": { + "type": "nobody_admin", + "id": null + }, + "conversation_message": { + "type": "conversation_message", + "id": "41111111", + "subject": "", + "body": "

Hey2

", + "delivered_as": "customer_initiated", + "author": { + "type": "user", + "id": "57b45f16d1aad7e69e011111" + }, + "attachments": [], + "url": null + }, + "open": true, + "read": true + }, + { + "type": "conversation", + "id": "5680912811", + "created_at": 1471438151, + "updated_at": 1471438151, + "waiting_since": 1468236397, + "user": { + "type": "user", + "id": "57b45bfef436c8d78611111" + }, + "assignee": { + "type": "nobody_admin", + "id": null + }, + "conversation_message": { + "type": "conversation_message", + "id": "41141111", + "subject": "", + "body": "

Hey

", + "delivered_as": "customer_initiated", + "author": { + "type": "user", + "id": "57b45bfef436c8d786000111" + }, + "attachments": [], + "url": null + }, + "open": true, + "read": true + }, + { + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "user": { + "type": "lead", + "id": "576c1a139d0baad101001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_message": { + "type": "conversation_message", + "id": "33954838", + "subject": "", + "body": "

test

", + "delivered_as": "customer_initiated", + "author": { + "type": "lead", + "id": "576c1a139d0baad101001111" + }, + "attachments": [], + "url": null + }, + "open": true, + "read": false + } + ] +} From 755e748db7836adac24d6a9e0c5853e86a7a0d6e Mon Sep 17 00:00:00 2001 From: Alex Shults Date: Thu, 5 Dec 2019 11:18:40 -0500 Subject: [PATCH 3/3] Fix for accidental EOL change --- .../io/intercom/api/ConversationMessage.java | 234 ++++---- .../io/intercom/api/ConversationTest.java | 548 +++++++++--------- .../src/test/resources/conversation.json | 198 +++---- .../conversation_no_attachments.json | 166 +++--- .../src/test/resources/conversations.json | 204 +++---- 5 files changed, 675 insertions(+), 675 deletions(-) diff --git a/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java b/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java index 82364ebf..c225ced3 100644 --- a/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java +++ b/intercom-java/src/main/java/io/intercom/api/ConversationMessage.java @@ -1,117 +1,117 @@ -package io.intercom.api; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -@SuppressWarnings("UnusedDeclaration") -@JsonIgnoreProperties(ignoreUnknown = true) -public class ConversationMessage extends TypedData { - - @SuppressWarnings("FieldCanBeLocal") - @JsonProperty("type") - private final String type = "conversation_message"; - - @JsonProperty - private String id; - - @JsonProperty - private String subject; - - @JsonProperty - private String body; - - @JsonProperty - private Author author; - - @JsonProperty - private String url; - - @JsonProperty("delivered_as") - private String deliveredAs; - - @JsonProperty("attachments") - private List attachments; - - public ConversationMessage() { - } - - public String getType() { - return type; - } - - public String getId() { - return id; - } - - public String getSubject() { - return subject; - } - - public String getBody() { - return body; - } - - public Author getAuthor() { - return author; - } - - public String getUrl() { - return url; - } - - public String getDeliveredAs() { - return deliveredAs; - } - - public List getAttachments() { - return attachments; - } - - @Override - public int hashCode() { - int result = subject != null ? subject.hashCode() : 0; - result = 31 * result + (body != null ? body.hashCode() : 0); - result = 31 * result + (author != null ? author.hashCode() : 0); - result = 31 * result + (deliveredAs != null ? deliveredAs.hashCode() : 0); - result = 31 * result + (id != null ? id.hashCode() : 0); - result = 31 * result + (url != null ? url.hashCode() : 0); - result = 31 * result + (attachments != null ? attachments.hashCode() : 0); - - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ConversationMessage that = (ConversationMessage) o; - - if (author != null ? !author.equals(that.author) : that.author != null) return false; - if (body != null ? !body.equals(that.body) : that.body != null) return false; - //noinspection RedundantIfStatement - if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - if (url != null ? !url.equals(that.url) : that.url != null) return false; - if (deliveredAs != null ? !deliveredAs.equals(that.deliveredAs) : that.deliveredAs != null) return false; - if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false; - - return true; - } - - @Override - public String toString() { - return "ConversationMessage{" + - "type='" + type + '\'' + - ", id='" + id + '\'' + - ", subject='" + subject + '\'' + - ", body='" + body + '\'' + - ", author=" + author + - ", url=" + url + - ", deliveredAs=" + deliveredAs + - ", attachments=" + attachments + - "} " + super.toString(); - } -} +package io.intercom.api; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +@SuppressWarnings("UnusedDeclaration") +@JsonIgnoreProperties(ignoreUnknown = true) +public class ConversationMessage extends TypedData { + + @SuppressWarnings("FieldCanBeLocal") + @JsonProperty("type") + private final String type = "conversation_message"; + + @JsonProperty + private String id; + + @JsonProperty + private String subject; + + @JsonProperty + private String body; + + @JsonProperty + private Author author; + + @JsonProperty + private String url; + + @JsonProperty("delivered_as") + private String deliveredAs; + + @JsonProperty("attachments") + private List attachments; + + public ConversationMessage() { + } + + public String getType() { + return type; + } + + public String getId() { + return id; + } + + public String getSubject() { + return subject; + } + + public String getBody() { + return body; + } + + public Author getAuthor() { + return author; + } + + public String getUrl() { + return url; + } + + public String getDeliveredAs() { + return deliveredAs; + } + + public List getAttachments() { + return attachments; + } + + @Override + public int hashCode() { + int result = subject != null ? subject.hashCode() : 0; + result = 31 * result + (body != null ? body.hashCode() : 0); + result = 31 * result + (author != null ? author.hashCode() : 0); + result = 31 * result + (deliveredAs != null ? deliveredAs.hashCode() : 0); + result = 31 * result + (id != null ? id.hashCode() : 0); + result = 31 * result + (url != null ? url.hashCode() : 0); + result = 31 * result + (attachments != null ? attachments.hashCode() : 0); + + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ConversationMessage that = (ConversationMessage) o; + + if (author != null ? !author.equals(that.author) : that.author != null) return false; + if (body != null ? !body.equals(that.body) : that.body != null) return false; + //noinspection RedundantIfStatement + if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false; + if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (url != null ? !url.equals(that.url) : that.url != null) return false; + if (deliveredAs != null ? !deliveredAs.equals(that.deliveredAs) : that.deliveredAs != null) return false; + if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false; + + return true; + } + + @Override + public String toString() { + return "ConversationMessage{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", subject='" + subject + '\'' + + ", body='" + body + '\'' + + ", author=" + author + + ", url=" + url + + ", deliveredAs=" + deliveredAs + + ", attachments=" + attachments + + "} " + super.toString(); + } +} diff --git a/intercom-java/src/test/java/io/intercom/api/ConversationTest.java b/intercom-java/src/test/java/io/intercom/api/ConversationTest.java index 59b38905..e08d7247 100644 --- a/intercom-java/src/test/java/io/intercom/api/ConversationTest.java +++ b/intercom-java/src/test/java/io/intercom/api/ConversationTest.java @@ -1,274 +1,274 @@ -package io.intercom.api; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Maps; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.io.IOException; -import java.util.Map; - -import static io.intercom.api.TestSupport.load; -import static org.junit.Assert.*; -import static org.junit.Assert.assertTrue; - -@RunWith(PowerMockRunner.class) -@PrepareForTest( { Conversation.class }) -public class ConversationTest { - - private static ObjectMapper objectMapper; - - @BeforeClass - public static void beforeClass() { - objectMapper = MapperSupport.objectMapper(); - } - - @Test - public void testIsNullOrBlank() { - assertTrue(Conversation.isNullOrBlank(null)); - assertTrue(Conversation.isNullOrBlank("")); - assertTrue(Conversation.isNullOrBlank(" ")); - assertTrue(Conversation.isNullOrBlank("\n")); - assertTrue(Conversation.isNullOrBlank("\r")); - assertFalse(Conversation.isNullOrBlank("reply")); - } - - @Test - public void testAdminReply() { - - AdminReply adminReply = new AdminReply(null); - adminReply.setAssigneeID("1"); - assertEquals(Conversation.MESSAGE_TYPE_ASSIGNMENT, adminReply.getMessageType()); - - try { - Conversation.validateAdminReplyRequest(adminReply); - } catch (InvalidException e) { - fail(); - } - - adminReply = new AdminReply(null); - adminReply.setMessageType("comment"); - try { - Conversation.validateAdminReplyRequest(adminReply); - fail(); - } catch (InvalidException e) { - assertTrue(e.getMessage() - .contains("a comment or note reply must have a body")); - } - - adminReply.setBody(" "); - try { - Conversation.validateAdminReplyRequest(adminReply); - fail(); - } catch (InvalidException e) { - assertTrue(e.getMessage() - .contains("a comment or note reply must have a body")); - } - - adminReply.setBody("Once, in flight school, I was laconic"); - try { - Conversation.validateAdminReplyRequest(adminReply); - } catch (InvalidException e) { - fail(); - } - - adminReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); - try { - Conversation.validateAdminReplyRequest(adminReply); - } catch (InvalidException e) { - fail(); - } - } - - @Test - public void testDisplayAs() { - - try { - Conversation.list(buildRequestParameters("pdf")); - fail(); - } catch (InvalidException e) { - assertTrue(e.getMessage() - .contains("A display_as parameter must have one of the values plaintext, html")); - } - - try { - Conversation.validateListRequest(buildRequestParameters("plaintext")); - } catch (InvalidException e) { - fail(); - } - - try { - Conversation.validateListRequest(buildRequestParameters("html")); - } catch (InvalidException e) { - fail(); - } - } - - @Test - public void testGetConversationMessageDetailsFromConversation() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - final ConversationMessage conversationMessage = conversation.getConversationMessage(); - - assertEquals("33954111", conversationMessage.getId()); - assertEquals("

test

", conversationMessage.getBody()); - assertEquals("Email subject", conversationMessage.getSubject()); - assertEquals("https://intercom.com/", conversationMessage.getUrl()); - assertEquals("customer_initiated", conversationMessage.getDeliveredAs()); - - assertEquals("lead", conversationMessage.getAuthor().getType()); - assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); - - assertEquals(2, conversationMessage.getAttachments().size()); - - final Attachment firstAttachment = conversationMessage.getAttachments().get(0); - final Attachment lastAttachment = conversationMessage.getAttachments().get(1); - assertEquals("upload", firstAttachment.getType()); - assertEquals("123.csv", firstAttachment.getName()); - assertEquals("https://downloads.intercomcdn.com/123.csv", firstAttachment.getUrl()); - assertEquals("text/csv", firstAttachment.getContentType()); - assertEquals(147, firstAttachment.getFilesize()); - assertEquals(0, firstAttachment.getWidth()); - assertEquals(0, firstAttachment.getHeight()); - - assertEquals("upload", lastAttachment.getType()); - assertEquals("abc.txt", lastAttachment.getName()); - assertEquals("https://downloads.intercomcdn.com/txt", lastAttachment.getUrl()); - assertEquals("text/csv", lastAttachment.getContentType()); - assertEquals(100, lastAttachment.getFilesize()); - assertEquals(1, lastAttachment.getWidth()); - assertEquals(2, lastAttachment.getHeight()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetConversationMessageDetailsFromConversationNoAttachments() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation_no_attachments.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - final ConversationMessage conversationMessage = conversation.getConversationMessage(); - - assertEquals("33954111", conversationMessage.getId()); - assertEquals("

test

", conversationMessage.getBody()); - assertEquals("Email subject", conversationMessage.getSubject()); - assertEquals("https://intercom.com/", conversationMessage.getUrl()); - assertEquals("customer_initiated", conversationMessage.getDeliveredAs()); - - assertEquals("lead", conversationMessage.getAuthor().getType()); - assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); - - assertEquals(0, conversationMessage.getAttachments().size()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetConversationsPartFromConversation() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - assertEquals(2, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetConversationsPartFromConversationCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation.json"); - final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); - assertEquals(2, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetEmptyConversationsPartFromConversationCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation_no_parts.json"); - final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); - assertEquals(0, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetTagsFromConversation() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String json = load("conversation.json"); - final Conversation conversation = objectMapper.readValue(json, Conversation.class); - assertEquals(2, conversation.getTagCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.never()); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetTagFromTagCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation.json"); - final Conversation conversationWithTags = objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); - assertEquals(2, conversation.getTagCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - - @Test - public void testGetEmptyTagFromTagCollection() throws IOException { - PowerMockito.mockStatic(Conversation.class); - - String conversationsJson = load("conversations.json"); - final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); - final Conversation conversation = conversationCollection.getPage().get(0); - - String conversationJson = load("conversation_no_tags.json"); - final Conversation conversationWithTags= objectMapper.readValue(conversationJson, Conversation.class); - Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); - assertEquals(0, conversation.getConversationPartCollection().getPage().size()); - - PowerMockito.verifyStatic(Mockito.times(1)); - Conversation.find(conversation.getId()); - } - private Map buildRequestParameters(String html) { - Map params2 = Maps.newHashMap(); - params2.put("type", "admin"); - params2.put("admin_id", "1"); - params2.put("display_as", html); - return params2; - } -} +package io.intercom.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Maps; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.io.IOException; +import java.util.Map; + +import static io.intercom.api.TestSupport.load; +import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; + +@RunWith(PowerMockRunner.class) +@PrepareForTest( { Conversation.class }) +public class ConversationTest { + + private static ObjectMapper objectMapper; + + @BeforeClass + public static void beforeClass() { + objectMapper = MapperSupport.objectMapper(); + } + + @Test + public void testIsNullOrBlank() { + assertTrue(Conversation.isNullOrBlank(null)); + assertTrue(Conversation.isNullOrBlank("")); + assertTrue(Conversation.isNullOrBlank(" ")); + assertTrue(Conversation.isNullOrBlank("\n")); + assertTrue(Conversation.isNullOrBlank("\r")); + assertFalse(Conversation.isNullOrBlank("reply")); + } + + @Test + public void testAdminReply() { + + AdminReply adminReply = new AdminReply(null); + adminReply.setAssigneeID("1"); + assertEquals(Conversation.MESSAGE_TYPE_ASSIGNMENT, adminReply.getMessageType()); + + try { + Conversation.validateAdminReplyRequest(adminReply); + } catch (InvalidException e) { + fail(); + } + + adminReply = new AdminReply(null); + adminReply.setMessageType("comment"); + try { + Conversation.validateAdminReplyRequest(adminReply); + fail(); + } catch (InvalidException e) { + assertTrue(e.getMessage() + .contains("a comment or note reply must have a body")); + } + + adminReply.setBody(" "); + try { + Conversation.validateAdminReplyRequest(adminReply); + fail(); + } catch (InvalidException e) { + assertTrue(e.getMessage() + .contains("a comment or note reply must have a body")); + } + + adminReply.setBody("Once, in flight school, I was laconic"); + try { + Conversation.validateAdminReplyRequest(adminReply); + } catch (InvalidException e) { + fail(); + } + + adminReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); + try { + Conversation.validateAdminReplyRequest(adminReply); + } catch (InvalidException e) { + fail(); + } + } + + @Test + public void testDisplayAs() { + + try { + Conversation.list(buildRequestParameters("pdf")); + fail(); + } catch (InvalidException e) { + assertTrue(e.getMessage() + .contains("A display_as parameter must have one of the values plaintext, html")); + } + + try { + Conversation.validateListRequest(buildRequestParameters("plaintext")); + } catch (InvalidException e) { + fail(); + } + + try { + Conversation.validateListRequest(buildRequestParameters("html")); + } catch (InvalidException e) { + fail(); + } + } + + @Test + public void testGetConversationMessageDetailsFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + final ConversationMessage conversationMessage = conversation.getConversationMessage(); + + assertEquals("33954111", conversationMessage.getId()); + assertEquals("

test

", conversationMessage.getBody()); + assertEquals("Email subject", conversationMessage.getSubject()); + assertEquals("https://intercom.com/", conversationMessage.getUrl()); + assertEquals("customer_initiated", conversationMessage.getDeliveredAs()); + + assertEquals("lead", conversationMessage.getAuthor().getType()); + assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); + + assertEquals(2, conversationMessage.getAttachments().size()); + + final Attachment firstAttachment = conversationMessage.getAttachments().get(0); + final Attachment lastAttachment = conversationMessage.getAttachments().get(1); + assertEquals("upload", firstAttachment.getType()); + assertEquals("123.csv", firstAttachment.getName()); + assertEquals("https://downloads.intercomcdn.com/123.csv", firstAttachment.getUrl()); + assertEquals("text/csv", firstAttachment.getContentType()); + assertEquals(147, firstAttachment.getFilesize()); + assertEquals(0, firstAttachment.getWidth()); + assertEquals(0, firstAttachment.getHeight()); + + assertEquals("upload", lastAttachment.getType()); + assertEquals("abc.txt", lastAttachment.getName()); + assertEquals("https://downloads.intercomcdn.com/txt", lastAttachment.getUrl()); + assertEquals("text/csv", lastAttachment.getContentType()); + assertEquals(100, lastAttachment.getFilesize()); + assertEquals(1, lastAttachment.getWidth()); + assertEquals(2, lastAttachment.getHeight()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationMessageDetailsFromConversationNoAttachments() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation_no_attachments.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + final ConversationMessage conversationMessage = conversation.getConversationMessage(); + + assertEquals("33954111", conversationMessage.getId()); + assertEquals("

test

", conversationMessage.getBody()); + assertEquals("Email subject", conversationMessage.getSubject()); + assertEquals("https://intercom.com/", conversationMessage.getUrl()); + assertEquals("customer_initiated", conversationMessage.getDeliveredAs()); + + assertEquals("lead", conversationMessage.getAuthor().getType()); + assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId()); + + assertEquals(0, conversationMessage.getAttachments().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationsPartFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + assertEquals(2, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetConversationsPartFromConversationCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation.json"); + final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); + assertEquals(2, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetEmptyConversationsPartFromConversationCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation_no_parts.json"); + final Conversation conversationWithParts = objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithParts); + assertEquals(0, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetTagsFromConversation() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String json = load("conversation.json"); + final Conversation conversation = objectMapper.readValue(json, Conversation.class); + assertEquals(2, conversation.getTagCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.never()); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetTagFromTagCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation.json"); + final Conversation conversationWithTags = objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); + assertEquals(2, conversation.getTagCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + + @Test + public void testGetEmptyTagFromTagCollection() throws IOException { + PowerMockito.mockStatic(Conversation.class); + + String conversationsJson = load("conversations.json"); + final ConversationCollection conversationCollection = objectMapper.readValue(conversationsJson, ConversationCollection.class); + final Conversation conversation = conversationCollection.getPage().get(0); + + String conversationJson = load("conversation_no_tags.json"); + final Conversation conversationWithTags= objectMapper.readValue(conversationJson, Conversation.class); + Mockito.when(Conversation.find(conversation.getId())).thenReturn(conversationWithTags); + assertEquals(0, conversation.getConversationPartCollection().getPage().size()); + + PowerMockito.verifyStatic(Mockito.times(1)); + Conversation.find(conversation.getId()); + } + private Map buildRequestParameters(String html) { + Map params2 = Maps.newHashMap(); + params2.put("type", "admin"); + params2.put("admin_id", "1"); + params2.put("display_as", html); + return params2; + } +} diff --git a/intercom-java/src/test/resources/conversation.json b/intercom-java/src/test/resources/conversation.json index 83e819c3..9622235a 100644 --- a/intercom-java/src/test/resources/conversation.json +++ b/intercom-java/src/test/resources/conversation.json @@ -1,99 +1,99 @@ -{ - "type": "conversation", - "id": "5143511111", - "created_at": 1466703132, - "updated_at": 1468236397, - "waiting_since": 1468236397, - "conversation_message": { - "type": "conversation_message", - "id": "33954111", - "subject": "Email subject", - "body": "

test

", - "delivered_as": "customer_initiated", - "author": { - "type": "lead", - "id": "576c1a139d0baad1010011111" - }, - "attachments": [{ - "type": "upload", - "name": "123.csv", - "url": "https://downloads.intercomcdn.com/123.csv", - "content_type": "text/csv", - "filesize": 147, - "width": null, - "height": null - },{ - "type": "upload", - "name": "abc.txt", - "url": "https://downloads.intercomcdn.com/txt", - "content_type": "text/csv", - "filesize": 100, - "width": 1, - "height": 2 - }], - "url": "https://intercom.com/" - }, - "user": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "assignee": { - "type": "admin", - "id": "358111" - }, - "conversation_parts": { - "type": "conversation_part.list", - "conversation_parts": [ - { - "type": "conversation_part", - "id": "142533411", - "part_type": "comment", - "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", - "created_at": 1468031160, - "updated_at": 1468031160, - "notified_at": 1468031160, - "assigned_to": null, - "author": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "attachments": [], - "external_id": null - }, - { - "type": "conversation_part", - "id": "142533511", - "part_type": "comment", - "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", - "created_at": 1468031171, - "updated_at": 1468031171, - "notified_at": 1468031171, - "assigned_to": null, - "author": { - "type": "admin", - "id": "358111" - }, - "attachments": [], - "external_id": null - } - ], - "total_count": 2 - }, - "open": true, - "read": false, - "tags": { - "type": "tag.list", - "tags": [ - { - "type": "tag", - "id": "123", - "name": "Tag 1" - }, - { - "type": "tag", - "id": "456", - "name": "Tag 2" - } - ] - } -} +{ + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "conversation_message": { + "type": "conversation_message", + "id": "33954111", + "subject": "Email subject", + "body": "

test

", + "delivered_as": "customer_initiated", + "author": { + "type": "lead", + "id": "576c1a139d0baad1010011111" + }, + "attachments": [{ + "type": "upload", + "name": "123.csv", + "url": "https://downloads.intercomcdn.com/123.csv", + "content_type": "text/csv", + "filesize": 147, + "width": null, + "height": null + },{ + "type": "upload", + "name": "abc.txt", + "url": "https://downloads.intercomcdn.com/txt", + "content_type": "text/csv", + "filesize": 100, + "width": 1, + "height": 2 + }], + "url": "https://intercom.com/" + }, + "user": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_parts": { + "type": "conversation_part.list", + "conversation_parts": [ + { + "type": "conversation_part", + "id": "142533411", + "part_type": "comment", + "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", + "created_at": 1468031160, + "updated_at": 1468031160, + "notified_at": 1468031160, + "assigned_to": null, + "author": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "attachments": [], + "external_id": null + }, + { + "type": "conversation_part", + "id": "142533511", + "part_type": "comment", + "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", + "created_at": 1468031171, + "updated_at": 1468031171, + "notified_at": 1468031171, + "assigned_to": null, + "author": { + "type": "admin", + "id": "358111" + }, + "attachments": [], + "external_id": null + } + ], + "total_count": 2 + }, + "open": true, + "read": false, + "tags": { + "type": "tag.list", + "tags": [ + { + "type": "tag", + "id": "123", + "name": "Tag 1" + }, + { + "type": "tag", + "id": "456", + "name": "Tag 2" + } + ] + } +} diff --git a/intercom-java/src/test/resources/conversation_no_attachments.json b/intercom-java/src/test/resources/conversation_no_attachments.json index 9c1193cf..0f395873 100644 --- a/intercom-java/src/test/resources/conversation_no_attachments.json +++ b/intercom-java/src/test/resources/conversation_no_attachments.json @@ -1,83 +1,83 @@ -{ - "type": "conversation", - "id": "5143511111", - "created_at": 1466703132, - "updated_at": 1468236397, - "waiting_since": 1468236397, - "conversation_message": { - "type": "conversation_message", - "id": "33954111", - "subject": "Email subject", - "body": "

test

", - "delivered_as": "customer_initiated", - "author": { - "type": "lead", - "id": "576c1a139d0baad1010011111" - }, - "attachments": [], - "url": "https://intercom.com/" - }, - "user": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "assignee": { - "type": "admin", - "id": "358111" - }, - "conversation_parts": { - "type": "conversation_part.list", - "conversation_parts": [ - { - "type": "conversation_part", - "id": "142533411", - "part_type": "comment", - "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", - "created_at": 1468031160, - "updated_at": 1468031160, - "notified_at": 1468031160, - "assigned_to": null, - "author": { - "type": "user", - "id": "576c1a139d0baad1010001111" - }, - "attachments": [], - "external_id": null - }, - { - "type": "conversation_part", - "id": "142533511", - "part_type": "comment", - "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", - "created_at": 1468031171, - "updated_at": 1468031171, - "notified_at": 1468031171, - "assigned_to": null, - "author": { - "type": "admin", - "id": "358111" - }, - "attachments": [], - "external_id": null - } - ], - "total_count": 2 - }, - "open": true, - "read": false, - "tags": { - "type": "tag.list", - "tags": [ - { - "type": "tag", - "id": "123", - "name": "Tag 1" - }, - { - "type": "tag", - "id": "456", - "name": "Tag 2" - } - ] - } -} +{ + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "conversation_message": { + "type": "conversation_message", + "id": "33954111", + "subject": "Email subject", + "body": "

test

", + "delivered_as": "customer_initiated", + "author": { + "type": "lead", + "id": "576c1a139d0baad1010011111" + }, + "attachments": [], + "url": "https://intercom.com/" + }, + "user": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_parts": { + "type": "conversation_part.list", + "conversation_parts": [ + { + "type": "conversation_part", + "id": "142533411", + "part_type": "comment", + "body": "

dm-9187dba8-fb3b-cb99-da05-37a932d3d678

", + "created_at": 1468031160, + "updated_at": 1468031160, + "notified_at": 1468031160, + "assigned_to": null, + "author": { + "type": "user", + "id": "576c1a139d0baad1010001111" + }, + "attachments": [], + "external_id": null + }, + { + "type": "conversation_part", + "id": "142533511", + "part_type": "comment", + "body": "

im-99a3a78f-5105-449d-a114-a7b5eb7e5b80

", + "created_at": 1468031171, + "updated_at": 1468031171, + "notified_at": 1468031171, + "assigned_to": null, + "author": { + "type": "admin", + "id": "358111" + }, + "attachments": [], + "external_id": null + } + ], + "total_count": 2 + }, + "open": true, + "read": false, + "tags": { + "type": "tag.list", + "tags": [ + { + "type": "tag", + "id": "123", + "name": "Tag 1" + }, + { + "type": "tag", + "id": "456", + "name": "Tag 2" + } + ] + } +} diff --git a/intercom-java/src/test/resources/conversations.json b/intercom-java/src/test/resources/conversations.json index 922fdaad..e1909803 100644 --- a/intercom-java/src/test/resources/conversations.json +++ b/intercom-java/src/test/resources/conversations.json @@ -1,102 +1,102 @@ -{ - "type": "conversation.list", - "pages": { - "type": "pages", - "next": null, - "page": 1, - "per_page": 20, - "total_pages": 1 - }, - "conversations": [ - { - "type": "conversation", - "id": "5680931777", - "created_at": 1471438637, - "updated_at": 1471438637, - "waiting_since": 1468236397, - "user": { - "type": "user", - "id": "57b45f16d1aad7e69e011111" - }, - "assignee": { - "type": "nobody_admin", - "id": null - }, - "conversation_message": { - "type": "conversation_message", - "id": "41111111", - "subject": "", - "body": "

Hey2

", - "delivered_as": "customer_initiated", - "author": { - "type": "user", - "id": "57b45f16d1aad7e69e011111" - }, - "attachments": [], - "url": null - }, - "open": true, - "read": true - }, - { - "type": "conversation", - "id": "5680912811", - "created_at": 1471438151, - "updated_at": 1471438151, - "waiting_since": 1468236397, - "user": { - "type": "user", - "id": "57b45bfef436c8d78611111" - }, - "assignee": { - "type": "nobody_admin", - "id": null - }, - "conversation_message": { - "type": "conversation_message", - "id": "41141111", - "subject": "", - "body": "

Hey

", - "delivered_as": "customer_initiated", - "author": { - "type": "user", - "id": "57b45bfef436c8d786000111" - }, - "attachments": [], - "url": null - }, - "open": true, - "read": true - }, - { - "type": "conversation", - "id": "5143511111", - "created_at": 1466703132, - "updated_at": 1468236397, - "waiting_since": 1468236397, - "user": { - "type": "lead", - "id": "576c1a139d0baad101001111" - }, - "assignee": { - "type": "admin", - "id": "358111" - }, - "conversation_message": { - "type": "conversation_message", - "id": "33954838", - "subject": "", - "body": "

test

", - "delivered_as": "customer_initiated", - "author": { - "type": "lead", - "id": "576c1a139d0baad101001111" - }, - "attachments": [], - "url": null - }, - "open": true, - "read": false - } - ] -} +{ + "type": "conversation.list", + "pages": { + "type": "pages", + "next": null, + "page": 1, + "per_page": 20, + "total_pages": 1 + }, + "conversations": [ + { + "type": "conversation", + "id": "5680931777", + "created_at": 1471438637, + "updated_at": 1471438637, + "waiting_since": 1468236397, + "user": { + "type": "user", + "id": "57b45f16d1aad7e69e011111" + }, + "assignee": { + "type": "nobody_admin", + "id": null + }, + "conversation_message": { + "type": "conversation_message", + "id": "41111111", + "subject": "", + "body": "

Hey2

", + "delivered_as": "customer_initiated", + "author": { + "type": "user", + "id": "57b45f16d1aad7e69e011111" + }, + "attachments": [], + "url": null + }, + "open": true, + "read": true + }, + { + "type": "conversation", + "id": "5680912811", + "created_at": 1471438151, + "updated_at": 1471438151, + "waiting_since": 1468236397, + "user": { + "type": "user", + "id": "57b45bfef436c8d78611111" + }, + "assignee": { + "type": "nobody_admin", + "id": null + }, + "conversation_message": { + "type": "conversation_message", + "id": "41141111", + "subject": "", + "body": "

Hey

", + "delivered_as": "customer_initiated", + "author": { + "type": "user", + "id": "57b45bfef436c8d786000111" + }, + "attachments": [], + "url": null + }, + "open": true, + "read": true + }, + { + "type": "conversation", + "id": "5143511111", + "created_at": 1466703132, + "updated_at": 1468236397, + "waiting_since": 1468236397, + "user": { + "type": "lead", + "id": "576c1a139d0baad101001111" + }, + "assignee": { + "type": "admin", + "id": "358111" + }, + "conversation_message": { + "type": "conversation_message", + "id": "33954838", + "subject": "", + "body": "

test

", + "delivered_as": "customer_initiated", + "author": { + "type": "lead", + "id": "576c1a139d0baad101001111" + }, + "attachments": [], + "url": null + }, + "open": true, + "read": false + } + ] +}