/** * Sends the necessary network messages to log the user onto the network * and query for the users and state. */ private void sendLogOn() { networkMessages.sendLogonMessage(); networkMessages.sendClient(); networkMessages.sendExposeMessage(); networkMessages.sendGetTopicMessage(); }
/** * Sends a message over the network to identify this client. */ public void sendExposingMessage() { networkMessages.sendExposingMessage(); }
/** * Sends a message over the network to notify the file sender that you * aborted the file transfer. * * @param user The user sending a file. * @param fileHash The unique hash code of the file. * @param fileName The name of the file. */ public void sendFileAbort(final User user, final int fileHash, final String fileName) { networkMessages.sendFileAbort(user, fileHash, fileName); }
/** * Makes sure the application reacts when the network is available. * * @param silent If true, wont show the "you are connected..." message to the user. */ @Override public void networkCameUp(final boolean silent) { // Network came up after a logon if (!isLoggedOn()) { runDelayedLogon(); sendLogOn(); } // Network came up after a timeout else { ui.showTopic(); if (!silent) { msgController.showSystemMessage(coreMessages.getMessage("core.network.systemMessage.connectionBack")); } networkMessages.sendTopicRequestedMessage(getTopic()); networkMessages.sendExposingMessage(); networkMessages.sendGetTopicMessage(); networkMessages.sendExposeMessage(); networkMessages.sendIdleMessage(); } }
/** * Updates the away status and the away message for the user. * * @param code The user code for the user to update. * @param away If the user is away or not. * @param awaymsg The away message for that user. Will be trimmed. * @throws CommandException If there is no connection to the network, * or the user tries to set an away message that is to long. */ public void changeAwayStatus(final int code, final boolean away, final String awaymsg) throws CommandException { if (code == me.getCode() && !isLoggedOn()) { throw new CommandException(coreMessages.getMessage("core.away.error.notConnected")); } else if (Tools.getBytes(awaymsg) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.away.error.awayMessageTooLong", Constants.MESSAGE_MAX_BYTES)); } final String trimmedAwayMessage = awaymsg.trim(); if (code == me.getCode()) { if (away) { networkMessages.sendAwayMessage(trimmedAwayMessage); } else { networkMessages.sendBackMessage(); } } userListController.changeAwayStatus(code, away, trimmedAwayMessage); }
/** * Sends a message over the network, asking the other clients to identify * themselves. */ public void sendExposeMessage() { networkMessages.sendExposeMessage(); }
@Test public void sendFileShouldSendFileIfEverythingValidatedOK() throws CommandException { when(networkService.isNetworkUp()).thenReturn(true); controller.getChatState().setLoggedOn(true); final FileToSend file = mock(FileToSend.class); when(file.getName()).thenReturn("file.txt"); final User user = mock(User.class); controller.sendFile(user, file); verify(networkMessages).sendFile(user, file); }
@Test public void sendChatMessageShouldSendMessageUsingNetworkMessages() throws CommandException { doReturn(true).when(controller).isConnected(); controller.sendChatMessage("the message"); verify(networkMessages).sendChatMessage("the message"); }
/** * Tests sendAwayMessage(). * * Expects: 11515687!AWAY#Christian:I am away */ @Test public void testSendAwayMessage() { final String awayMsg = "I am away"; messages.sendAwayMessage(awayMsg); verify(service).sendMessageToAllUsers(createMessage("AWAY") + awayMsg); }
/** * Sends a message over the network with more information about this client. */ public void sendClientInfo() { networkMessages.sendClient(); }
/** * Constructor. */ public NetworkMessagesTest() { settings = mock(Settings.class); me = new User("TestUser", 123); me.setPrivateChatPort(2222); me.setTcpChatPort(4444); when(settings.getMe()).thenReturn(me); service = mock(NetworkService.class); when(service.sendMessageToAllUsers(anyString())).thenReturn(true); when(service.sendMessageToUser(anyString(), any(User.class))).thenReturn(true); messages = new NetworkMessages(service, settings); }
/** * Sends a message over the network to notify the file sender that you * accepted the file transfer. * * @param user The user sending a file. * @param port The port the file sender can connect to on this client * to start the file transfer. * @param fileHash The unique hash code of the file. * @param fileName The name of the file. * @throws CommandException If the message was not sent successfully. */ public void sendFileAccept(final User user, final int port, final int fileHash, final String fileName) throws CommandException { networkMessages.sendFileAccept(user, port, fileHash, fileName); }
/** * Tests sendBackMessage(). * * Expects: 12485102!BACK#Christian: */ @Test public void testSendBackMessage() { messages.sendBackMessage(); verify(service).sendMessageToAllUsers(createMessage("BACK")); }
/** * Makes sure the application reacts when the network is available. * * @param silent If true, wont show the "you are connected..." message to the user. */ @Override public void networkCameUp(final boolean silent) { // Network came up after a logon if (!isLoggedOn()) { runDelayedLogon(); sendLogOn(); } // Network came up after a timeout else { ui.showTopic(); if (!silent) { msgController.showSystemMessage(coreMessages.getMessage("core.network.systemMessage.connectionBack")); } networkMessages.sendTopicRequestedMessage(getTopic()); networkMessages.sendExposingMessage(); networkMessages.sendGetTopicMessage(); networkMessages.sendExposeMessage(); networkMessages.sendIdleMessage(); } }
/** * Updates the away status and the away message for the user. * * @param code The user code for the user to update. * @param away If the user is away or not. * @param awaymsg The away message for that user. Will be trimmed. * @throws CommandException If there is no connection to the network, * or the user tries to set an away message that is to long. */ public void changeAwayStatus(final int code, final boolean away, final String awaymsg) throws CommandException { if (code == me.getCode() && !isLoggedOn()) { throw new CommandException(coreMessages.getMessage("core.away.error.notConnected")); } else if (Tools.getBytes(awaymsg) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.away.error.awayMessageTooLong", Constants.MESSAGE_MAX_BYTES)); } final String trimmedAwayMessage = awaymsg.trim(); if (code == me.getCode()) { if (away) { networkMessages.sendAwayMessage(trimmedAwayMessage); } else { networkMessages.sendBackMessage(); } } userListController.changeAwayStatus(code, away, trimmedAwayMessage); }
/** * Sends a message over the network, asking the other clients to identify * themselves. */ public void sendExposeMessage() { networkMessages.sendExposeMessage(); }
/** * Tests sendFile(). * * Expects: 14394329!SENDFILE#Christian:(1234)[80800]{37563645}a_file.txt * * @throws CommandException In case the message could not be sent. */ @Test public void testSendFileMessage() throws CommandException { final int userCode = 1234; final long fileLength = 80800L; final String fileName = "a_file.txt"; final FileToSend file = mock(FileToSend.class); when(file.getName()).thenReturn(fileName); when(file.length()).thenReturn(fileLength); final int fileHash = file.hashCode(); // Cannot be mocked it seems final String info = "(" + userCode + ")" + "[" + fileLength + "]" + "{" + fileHash + "}" + fileName; final User user = new User("TestUser", userCode); messages.sendFile(user, file); verify(service).sendMessageToAllUsers(createMessage("SENDFILE") + info); }
/** * Tests sendChatMessage(). * * Expects: 16899115!MSG#Christian:[-15987646]Some chat message * * @throws CommandException In case the message could not be sent. */ @Test public void testSendChatMessage() throws CommandException { final String msg = "Some chat message"; messages.sendChatMessage(msg); verify(service).sendMessageToAllUsers(createMessage("MSG") + "[" + settings.getOwnColor() + "]" + msg); }
@Test public void changeAwayStatusToAwayShouldTrimAwayMessage() throws CommandException { when(controller.isLoggedOn()).thenReturn(true); final UserListController userListController = TestUtils.setFieldValueWithMock(controller, "userListController", UserListController.class); controller.changeAwayStatus(me.getCode(), true, " trim me "); verify(networkMessages).sendAwayMessage("trim me"); verify(userListController).changeAwayStatus(me.getCode(), true, "trim me"); }
/** * Sends a message over the network with more information about this client. */ public void sendClientInfo() { networkMessages.sendClient(); }