@Override public Resource create(XingApi api) { return new MessagesResource(api); } };
"/v1/users/me/conversations/{conversation_id}/attachments") .pathParam("conversation_id", conversationId) .responseAs(list(MessageAttachment.class, "attachments", "items")) .build();
@Test public void getAttachmentsOfConversation() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/attachments.json"))); Response<List<MessageAttachment>, HttpError> response = resource.getAttachmentsOfConversation("123").execute(); assertThat(response.body().size()).isEqualTo(1); assertThat(response.body().get(0).getId()).isEqualTo("4321_xyza"); }
@Test public void getConversationMessages() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/conversation_messages.json"))); Response<List<ConversationMessage>, HttpError> response = resource.getConversationMessages("123", "123").execute(); assertThat(response.body().size()).isEqualTo(2); assertThat(response.body().get(0).getContent()).isEqualTo("Yes of course!"); }
@Test public void getSingleConversation() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/single_conversation.json"))); Response<Conversation, HttpError> response = resource.getSingleConversation("conversationid", "myUserId").execute(); Conversation conversation = response.body(); assertThat(conversation.getId()).isEqualTo("51626_4be761"); assertThat(conversation.getSubject()).isEqualTo("Business opportunities"); assertThat(conversation.getTotalMsgCount()).isEqualTo(2); assertThat(conversation.getUnreadMessageCount()).isEqualTo(1); assertThat(conversation.isReadOnly()).isFalse(); assertThat(conversation.getParticipants()).hasSize(2); assertThat(conversation.getLatestMessages()).hasSize(2); }
@Test public void getConversationsByUserId() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/list_of_conversations.json"))); Response<List<Conversation>, HttpError> response = resource.getConversationsByUserId("").execute(); assertThat(response.body().size()).isEqualTo(2); }
@Test public void deleteConversation() throws Exception { server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)); Response<Void, HttpError> response = resource.deleteConversation("123", "123").execute(); assertThat(response.code()).isEqualTo(HttpURLConnection.HTTP_OK); }
@Test public void getAttachmentDownloadLink() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/attachment_download.json"))); Response<String, HttpError> response = resource.getAttachmentDownloadLink("123", "4321_xyza").execute(); assertThat(response.body()).isEqualTo("https://swift.xingassets" + ".com/v1/AUTH_messages/xing-message-production/-a4eq2LSuUUPGbmbUSZCIaSDRrVx8Vc49yYfvXR4mZw?temp_url_sig" + "=873add36a595df38097a2a9de56da1a4ff67cdac&temp_url_expires=1418399892"); }
@Test public void getSingleConversationMessage() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/conversation_single_message.json"))); Response<ConversationMessage, HttpError> response = resource.getSingleConversationMessage("123", "123", "123") .execute(); assertThat(response.body().getContent()).isEqualTo("Wait a minute"); }
@Test public void createConversation() throws Exception { server.enqueue(new MockResponse().setBody(file("messages/conversation.json"))); Response<Conversation, HttpError> response = resource.createConversation("", "", "", "").execute(); assertThat(response.body().getSubject()).isEqualTo("The subject!"); }
return Resource.<List<Conversation>, HttpError>newGetSpec(api, "/v1/users/{id}/conversations") .pathParam("id", userId) .responseAs(list(Conversation.class, "conversations", "items")) .build();
.pathParam("user_id", userId) .pathParam("conversation_id", conversationId) .responseAs(list(ConversationMessage.class, "messages", "items")) .build();