Search in sources :

Example 1 with Message

use of com.instructure.canvasapi.model.Message in project instructure-android by instructure.

the class ConversationUnitTest method testConversation.

@Test
public void testConversation() {
    Gson gson = CanvasRestAdapter.getGSONParser();
    // We have a list json and a detailed json
    Conversation[] tempConversations = gson.fromJson(conversationArrayJSON, Conversation[].class);
    Conversation detailedConversation = gson.fromJson(detailedConversationJSON, Conversation.class);
    // merge the two together
    ArrayList<Conversation> conversations = new ArrayList<Conversation>(Arrays.asList(tempConversations));
    conversations.add(detailedConversation);
    assertNotNull(conversations);
    assertEquals(6, conversations.size());
    for (Conversation conversation : conversations) {
        assertNotNull(conversation);
        assertNotNull(conversation.getAllParticipants());
        for (BasicUser basicUser : conversation.getAllParticipants()) {
            assertNotNull(basicUser);
            assertTrue(basicUser.getId() > 0);
            assertNotNull(basicUser.getUsername());
        }
        assertTrue(conversation.getId() > 0);
        assertNotNull(conversation.getAudienceIDs());
        assertNotNull(conversation.getAvatarURL());
        assertNotNull(conversation.getLastMessagePreview());
        assertNotNull(conversation.getLastMessageSent());
        assertTrue(conversation.getMessageCount() > 0);
        if (conversation.getMessages() != null) {
            for (Message message : conversation.getMessages()) {
                testMessage(message);
            }
        }
        assertFalse(conversation.getWorkflowState() == Conversation.WorkflowState.UNKNOWN);
    }
}
Also used : BasicUser(com.instructure.canvasapi.model.BasicUser) Message(com.instructure.canvasapi.model.Message) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Conversation(com.instructure.canvasapi.model.Conversation) Test(org.junit.Test)

Example 2 with Message

use of com.instructure.canvasapi.model.Message in project instructure-android by instructure.

the class ConversationUnitTest method testMessage.

// Gets tested from testConversation()
public static void testMessage(Message message) {
    assertNotNull(message);
    if (message.getAttachments() != null) {
        for (Attachment attachment : message.getAttachments()) {
            assertNotNull(attachment);
            assertTrue(attachment.getId() > 0);
            assertNotNull(attachment.getDisplayName());
            assertNotNull(attachment.getFilename());
            assertNotNull(attachment.getMimeType());
            assertNotNull(attachment.getUrl());
        }
    }
    assertTrue(message.getAuthorID() > 0);
    assertNotNull(message.getBody());
    assertNotNull(message.getCreationDate());
    assertTrue(message.getId() > 0);
    if (message.getForwardedMessages() != null) {
        for (Message replyMessage : message.getForwardedMessages()) {
            testMessage(replyMessage);
        }
    }
}
Also used : Message(com.instructure.canvasapi.model.Message) Attachment(com.instructure.canvasapi.model.Attachment)

Aggregations

Message (com.instructure.canvasapi.model.Message)2 Gson (com.google.gson.Gson)1 Attachment (com.instructure.canvasapi.model.Attachment)1 BasicUser (com.instructure.canvasapi.model.BasicUser)1 Conversation (com.instructure.canvasapi.model.Conversation)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1