public Map<String, String> getMessageTemplates() { return (Map<String, String>) GsonUtils.getObjectFromJson(sharedPreferences.getString(CUSTOM_MESSAGE_TEMPLATE, null), Map.class); }
public String[] getConnectedUsers() { try { String response = getMessages(null, null, null, null, null); if (response == null || TextUtils.isEmpty(response) || response.equals("UnAuthorized Access") || !response.contains("{")) { return null; } JsonParser parser = new JsonParser(); String element = parser.parse(response).getAsJsonObject().get("connectedUsers").toString(); return (String[]) GsonUtils.getObjectFromJson(element, String[].class); } catch (Exception e) { e.printStackTrace(); } return null; }
public SyncBlockUserApiResponse getSyncUserBlockList(String lastSyncTime) { try { String url = getBlockUserSyncUrl() + "?lastSyncTime=" + lastSyncTime; String response = httpRequestUtils.getResponse(url, "application/json", "application/json"); if (response == null || TextUtils.isEmpty(response) || response.equals("UnAuthorized Access")) { return null; } return (SyncBlockUserApiResponse) GsonUtils.getObjectFromJson(response, SyncBlockUserApiResponse.class); } catch (Exception e) { e.printStackTrace(); return null; } }
/** * Convenience method for enqueuing work in to this service. */ static public void enqueueWork(Context context, Intent work, Handler handler) { enqueueWork(context, MessageIntentService.class, JOB_ID, work); if (work != null) { final Message message = (Message) GsonUtils.getObjectFromJson(work.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT), Message.class); if (uploadQueueMap != null && handler != null) { uploadQueueMap.put(message.getCreatedAtTime(), handler); } } }
public MessageInfoResponse getMessageInfoList(String messageKey) { String url = getMessageInfoUrl() + "?key=" + messageKey; String response = httpRequestUtils.getResponse(url, "application/json", "application/json"); if (response == null || TextUtils.isEmpty(response) || response.equals("UnAuthorized Access")) { return null; } MessageInfoResponse messageInfoResponse = (MessageInfoResponse) GsonUtils.getObjectFromJson(response, MessageInfoResponse.class); return messageInfoResponse; }
public ApiResponse userLogoutResponse() { String response = ""; ApiResponse apiResponse = null; try { response = httpRequestUtils.postData(getUserLogout(), "application/json", "application/json", null); if (!TextUtils.isEmpty(response)) { apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class); } } catch (Exception e) { e.printStackTrace(); } return apiResponse; }
public synchronized void processUserDetails(Set<String> userIds) { String response = userClientService.getUserDetails(userIds); if (!TextUtils.isEmpty(response)) { UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(response, UserDetail[].class); for (UserDetail userDetail : userDetails) { processUser(userDetail); } } }
public void processUserDetailsResponse(String response) { if (!TextUtils.isEmpty(response)) { List<UserDetail> userDetails = (List<UserDetail>) GsonUtils.getObjectFromJson(response, new TypeToken<List<UserDetail>>() { }.getType()); for (UserDetail userDetail : userDetails) { processUser(userDetail); } } }
@Override protected void onHandleWork(@NonNull Intent intent) { messageClientService = new MessageClientService(MessageIntentService.this); final Message message = (Message) GsonUtils.getObjectFromJson(intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT), Message.class); try { Thread thread = new Thread(new MessageSender(message, uploadQueueMap.get(message.getCreatedAtTime()))); thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND); thread.start(); } catch (Exception e) { e.printStackTrace(); } }
public SyncApiResponse getSyncCall(Long syncTime, SyncType syncType) { try { String response = httpRequestUtils.getResponse(getSyncUrl() + "?syncTime=" + syncTime + "&syncType=" + syncType.getValue() , "application/json", "application/json"); if(response != null) { Log.i(TAG,"Sync call response: "+ response); return (SyncApiResponse) GsonUtils.getObjectFromJson(response, SyncApiResponse.class); } } catch (Exception e) { e.printStackTrace(); } return null; }
public ChannelFeedApiResponse createChannelWithReponse(ChannelInfo channelInfo) throws Exception { String jsonFromObject = GsonUtils.getJsonFromObject(channelInfo, channelInfo.getClass()); String createChannelResponse = httpRequestUtils.postData(getCreateChannelUrl(), "application/json", "application/json", jsonFromObject); Utils.printLog(context, TAG, "Create channel Response :" + createChannelResponse); return (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(createChannelResponse, ChannelFeedApiResponse.class); }
@Test public void removeMemberFromChannel_withError() { ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants .removeMemberErrorResponse, ApiResponse.class); when(channelClientService.removeMemberFromChannel(8905836, "reytum700")).thenReturn (response); assertEquals(AlResponse.ERROR, channelService.removeMemberFromChannelProcess(8905836, "reytum700")); }
@Test public void addMemberToChannel_withSuccess() { ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants .addMemberSuccessResponse, ApiResponse.class); when(channelClientService.addMemberToChannel(8905836, "reytum6")).thenReturn(response); assertEquals(AlResponse.SUCCESS, channelService.addMemberToChannelProcess(8905836, "reytum6")); }
@Test public void addMemberToChannel_withError() { ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants .addMemberErrorResponse, ApiResponse.class); when(channelClientService.addMemberToChannel(8905836, "reytum6")).thenReturn(response); assertEquals(AlResponse.ERROR, channelService.addMemberToChannelProcess(8905836, "reytum6")); }
@Test public void removeMemberFromChannel_withSuccess() { ApiResponse response = (ApiResponse) GsonUtils.getObjectFromJson(MockConstants .removeMemberSuccessResponse, ApiResponse.class); when(channelClientService.removeMemberFromChannel(8905836, "reytum7")).thenReturn (response); String status = channelService.removeMemberFromChannelProcess(8905836, "reytum7"); assertEquals(AlResponse.SUCCESS, status); }
@Test public void getLatestMessageList_WithWrongArgs() { try { Type type = new TypeToken<List<Message>>(){}.getType(); List<Message> messageList = (List<Message>) GsonUtils.getObjectFromJson(MockConstants.getLatestMessageListResponse_WithWrongArgs, type); when(messageDatabaseService.getMessages(0011L, "nullnull", 12311)).thenReturn(messageList); assertEquals(messageList, mobiComConversationService.getLatestMessagesGroupByPeople(0011L, "nullnull", 12311)); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testDeleteMessage() { try { Message message = (Message) GsonUtils.getObjectFromJson(MockConstants.Message, Message.class); Mockito.when(messageDatabaseService.deleteMessage(any(Message.class), anyString())).thenReturn("checkMe"); Mockito.when(messageClientService.deleteMessage(any(Message.class), nullable(Contact.class))).thenReturn("success"); mobiComConversationService.deleteMessage(message, new Contact()); Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteMessage(any(Message.class), nullable(String.class)); } catch (Exception e) { e.printStackTrace(); } }
@Test public void getLatestMessageList_WithNoArgs() { try { Type type = new TypeToken<List<Message>>(){}.getType(); List<Message> messageList = (List<Message>) GsonUtils.getObjectFromJson(MockConstants.getLatestMessageListResponse_WithNoArgs, type); when(messageDatabaseService.getMessages(null, null, null)).thenReturn(messageList); assertEquals(messageList, mobiComConversationService.getLatestMessagesGroupByPeople()); } catch (Exception e) { e.printStackTrace(); } }
@Test public void getLatestMessageList_WithSearchString() { try { Type type = new TypeToken<List<Message>>(){}.getType(); List<Message> messageList = (List<Message>) GsonUtils.getObjectFromJson(MockConstants.getLatestMessageListResponse_WithSearchString, type); when(messageDatabaseService.getMessages(null, "h", null)).thenReturn(messageList); assertEquals(messageList, mobiComConversationService.getLatestMessagesGroupByPeople(null, "h", null)); } catch (Exception e) { e.printStackTrace(); } }
@Test public void getMessageList_forOneToOneChat() { try { Type type = new TypeToken<List<Message>>(){}.getType(); List<Message> messageList = (List<Message>) GsonUtils.getObjectFromJson(MockConstants.getMessagesForContactResponse, type); when(messageDatabaseService.getMessages(null, null, null, null, null)).thenReturn(messageList); assertEquals(messageList, mobiComConversationService.getMessages(null, null, null, null, null, false)); } catch (Exception e) { e.printStackTrace(); } }