예제 #1
0
  /**
   * Test of handleEvent method, of class Conversation. Tests both local and remote side
   *
   * @throws UnknownHostException
   * @throws InterruptedException
   * @throws IOException
   */
  @Test
  public void testHandleEvent() throws UnknownHostException, IOException, InterruptedException {
    // clear the converstion created in setUp()
    EventPool.getAppPool().removeListener(conversation);

    // get the local app-pool and let it start
    EventPool localPool = EventPool.getAppPool();
    Thread.sleep(100);

    // create a remote eventpool and connect it to the local one
    EventPool remotePool = new EventPool();
    Connection remoteConnection = new Connection(InetAddress.getLocalHost(), remotePool, null);
    Thread.sleep(100);

    // create a contact out of the local user (as seen from the other side)
    Account localAccount = ChatApplication.getInstance().getAccount();
    Contact localContact = new Contact(localAccount.getUsername(), InetAddress.getLocalHost());
    Contact remoteContact = new Contact("Jaspervdj", InetAddress.getLocalHost());

    // add both of these contacts to our list, so we can look them up later
    ContactList contactList = localAccount.getContactList();
    contactList.addContact(localContact);
    contactList.addContact(remoteContact);

    // conversation manager will contain the conversation with the remote user, as
    // well as the conversation with the local one
    ConversationManager conversationManager =
        ChatApplication.getInstance().getConversationManager();
    Conversation localConversation = conversationManager.startConversation(remoteContact, false);
    Conversation remoteConversation = conversationManager.startConversation(localContact, false);

    // register the remoteConversation specifically with the remote pool
    remotePool.addListener(remoteConversation, new ConversationEventFilter(remoteConversation));
    // remove remoteListener from localPool
    localPool.removeListener(remoteConversation);

    // now everything is setup, and a user can type a message
    ChatMessage chatMessage =
        new ChatMessage(localContact.getUsername(), "Dag Javache, jij jij remoteUser!");
    ConversationEvent localEvent = new NewChatMessageEvent(localConversation, chatMessage);

    // raise the event on the local pool, should get sent to remotePool too
    localPool.raiseNetworkEvent(localEvent);
    Thread.sleep(100);

    // let's check the results!
    assertEquals(1, remoteConversation.getChatMessages(10).length);
    assertEquals(
        "Dag Javache, jij jij remoteUser!", remoteConversation.getChatMessages(1)[0].getText());

    assertEquals(1, localConversation.getChatMessages(10).length);
    assertEquals(
        "Dag Javache, jij jij remoteUser!", localConversation.getChatMessages(1)[0].getText());
  }
예제 #2
0
 @After
 public void tearDown() {
   EventPool.getAppPool().clearListeners();
   ChatApplication.getInstance().logoff(false);
 }
예제 #3
0
 @Before
 public void setUp() throws UnknownHostException {
   ChatApplication.getInstance().performTestLogin();
   contact = new Contact("JPanneel", InetAddress.getByName("google.be"));
   conversation = new Conversation(contact, true);
 }