Example #1
0
  /**
   * Determines whether this chat transport supports the supplied content type
   *
   * @param contentType the type we want to check
   * @return <tt>true</tt> if the chat transport supports it and <tt>false</tt> otherwise.
   */
  public boolean isContentTypeSupported(String contentType) {
    OperationSetBasicInstantMessaging imOpSet =
        contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class);

    if (imOpSet != null) return imOpSet.isContentTypeSupported(contentType);
    else return false;
  }
  /**
   * Send an instant message from the tested operation set and assert reception by the tester agent.
   */
  public void firstTestReceiveMessage() {
    String body = "This is an IM coming from the tester agent" + " on " + new Date().toString();

    ImEventCollector evtCollector = new ImEventCollector();

    // add a msg listener and register to the op set and send an instant
    // msg from the tester agent.
    opSetBasicIM1.addMessageListener(evtCollector);

    Contact testerAgentContact = opSetPresence2.findContactByID(fixture.userID1);

    logger.debug("Will send message " + body + " to: " + testerAgentContact);

    opSetBasicIM2.sendInstantMessage(testerAgentContact, opSetBasicIM2.createMessage(body));

    evtCollector.waitForEvent(10000);

    opSetBasicIM1.removeMessageListener(evtCollector);

    // assert reception of a message event
    assertTrue(
        "No events delivered upon a received message", evtCollector.collectedEvents.size() > 0);

    // assert event instance of Message Received Evt
    assertTrue(
        "Received evt was not an instance of " + MessageReceivedEvent.class.getName(),
        evtCollector.collectedEvents.get(0) instanceof MessageReceivedEvent);

    // assert source contact == testAgent.uin
    MessageReceivedEvent evt = (MessageReceivedEvent) evtCollector.collectedEvents.get(0);
    assertEquals("message sender ", evt.getSourceContact().getAddress(), fixture.userID2);

    // assert messageBody == body
    assertEquals("message body", body, evt.getSourceMessage().getContent());
  }
  /**
   * Send an instant message from the tested operation set and assert reception by the icq tester
   * agent.
   */
  public void firstTestReceiveMessage() {
    String body = "This is an IM coming from the tester agent" + " on " + new Date().toString();

    ImEventCollector evtCollector = new ImEventCollector();

    // add a msg listener and register to the op set and send an instant
    // msg from the tester agent.
    opSetBasicIM.addMessageListener(evtCollector);

    fixture.testerAgent.sendMessage(fixture.ourUserID, body);

    evtCollector.waitForEvent(10000);

    opSetBasicIM.removeMessageListener(evtCollector);

    // assert reception of a message event
    assertTrue(
        "No events delivered upon a received message", evtCollector.collectedEvents.size() > 0);

    // assert event instance of Message Received Evt
    assertTrue(
        "Received evt was not an instance of " + MessageReceivedEvent.class.getName(),
        evtCollector.collectedEvents.get(0) instanceof MessageReceivedEvent);

    // assert source contact == testAgent.uin
    MessageReceivedEvent evt = (MessageReceivedEvent) evtCollector.collectedEvents.get(0);
    assertEquals(
        "message sender ", evt.getSourceContact().getAddress(), fixture.testerAgent.getIcqUIN());

    // assert messageBody == body
    assertEquals("message body", body, evt.getSourceMessage().getContent());
  }
Example #4
0
  /**
   * If sending im is supported check it for supporting html messages if a font is set. As it can be
   * slow make sure its not on our way
   */
  private void checkImCaps() {
    if (ConfigurationUtils.getChatDefaultFontFamily() != null
        && ConfigurationUtils.getChatDefaultFontSize() > 0) {
      OperationSetBasicInstantMessaging imOpSet =
          contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class);

      if (imOpSet != null)
        imOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE, contact);
    }
  }
Example #5
0
  /**
   * Removes the instant message listener from this chat transport.
   *
   * @param l The message listener to remove.
   */
  public void removeInstantMessageListener(MessageListener l) {
    // If this chat transport does not support instant messaging we do
    // nothing here.
    if (!allowsInstantMessage()) return;

    OperationSetBasicInstantMessaging imOpSet =
        contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class);

    imOpSet.removeMessageListener(l);
  }
  /**
   * Send an instant message from the tester agent and assert reception by the tested implementation
   */
  public void thenTestSendMessage() {
    String body =
        "This is an IM coming from the tested implementation" + " on " + new Date().toString();

    // create the message
    net.java.sip.communicator.service.protocol.Message msg = opSetBasicIM.createMessage(body);

    // register a listener in the op set
    ImEventCollector imEvtCollector = new ImEventCollector();
    opSetBasicIM.addMessageListener(imEvtCollector);

    // register a listener in the tester agent
    JoustSimMessageEventCollector jsEvtCollector = new JoustSimMessageEventCollector();
    fixture.testerAgent.addConversationListener(fixture.ourUserID, jsEvtCollector);

    Contact testerAgentContact = opSetPresence.findContactByID(fixture.testerAgent.getIcqUIN());

    opSetBasicIM.sendInstantMessage(testerAgentContact, msg);

    imEvtCollector.waitForEvent(10000);
    jsEvtCollector.waitForEvent(10000);

    fixture.testerAgent.removeConversationListener(fixture.ourUserID, jsEvtCollector);
    opSetBasicIM.removeMessageListener(imEvtCollector);

    // verify that the message delivered event was dispatched
    assertTrue(
        "No events delivered when sending a message", imEvtCollector.collectedEvents.size() > 0);

    assertTrue(
        "Received evt was not an instance of " + MessageDeliveredEvent.class.getName(),
        imEvtCollector.collectedEvents.get(0) instanceof MessageDeliveredEvent);

    MessageDeliveredEvent evt = (MessageDeliveredEvent) imEvtCollector.collectedEvents.get(0);
    assertEquals(
        "message destination ",
        evt.getDestinationContact().getAddress(),
        fixture.testerAgent.getIcqUIN());

    assertSame("source message", msg, evt.getSourceMessage());

    // verify that the message has successfully arived at the destination
    assertTrue(
        "No messages received by the tester agent", jsEvtCollector.collectedMessageInfo.size() > 0);
    String receivedBody =
        ((MessageInfo) jsEvtCollector.collectedMessageInfo.get(0)).getMessage().getMessageBody();

    assertEquals("received message body", msg.getContent(), receivedBody);
  }
  /** Creates an Message through the advance createMessage() method and inspects its parameters. */
  public void testCreateMessage2() {
    String body =
        "This is an IM coming from the tested implementation" + " on " + new Date().toString();
    String contentType = "text/html";
    String encoding = "UTF-16";
    String subject = "test message";
    net.java.sip.communicator.service.protocol.Message msg =
        opSetBasicIM.createMessage(body.getBytes(), contentType, encoding, subject);

    assertEquals("message body", body, msg.getContent());
    assertTrue("message body bytes", Arrays.equals(body.getBytes(), msg.getRawData()));
    assertEquals("message length", body.length(), msg.getSize());
    assertEquals("message content type", contentType, msg.getContentType());
    assertEquals("message encoding", encoding, msg.getEncoding());
    assertNotNull("message uid", msg.getMessageUID());

    // a further test on message uid.
    net.java.sip.communicator.service.protocol.Message msg2 = opSetBasicIM.createMessage(body);
    assertFalse("message uid", msg.getMessageUID().equals(msg2.getMessageUID()));
  }
  /** Creates an Message through the simple createMessage() method and inspects its parameters. */
  public void testCreateMessage1() {
    String body =
        "This is an IM coming from the tested implementation" + " on " + new Date().toString();
    net.java.sip.communicator.service.protocol.Message msg = opSetBasicIM1.createMessage(body);

    assertEquals("message body", body, msg.getContent());
    assertTrue("message body bytes", Arrays.equals(body.getBytes(), msg.getRawData()));
    assertEquals("message length", body.length(), msg.getSize());
    assertEquals(
        "message content type",
        OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE,
        msg.getContentType());

    assertEquals(
        "message encoding",
        OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING,
        msg.getEncoding());

    assertNotNull("message uid", msg.getMessageUID());

    // a further test on message uid.
    net.java.sip.communicator.service.protocol.Message msg2 = opSetBasicIM1.createMessage(body);
    assertFalse("message uid", msg.getMessageUID().equals(msg2.getMessageUID()));
  }
Example #9
0
  /**
   * Sends the given instant message through this chat transport, by specifying the mime type (html
   * or plain text).
   *
   * @param message The message to send.
   * @param mimeType The mime type of the message to send: text/html or text/plain.
   * @throws Exception if the send operation is interrupted
   */
  public void sendInstantMessage(String message, String mimeType) throws Exception {
    // If this chat transport does not support instant messaging we do
    // nothing here.
    if (!allowsInstantMessage()) return;

    OperationSetBasicInstantMessaging imOpSet =
        contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class);

    Message msg;
    if (mimeType.equals(OperationSetBasicInstantMessaging.HTML_MIME_TYPE)
        && imOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE)) {
      msg =
          imOpSet.createMessage(
              message, OperationSetBasicInstantMessaging.HTML_MIME_TYPE, "utf-8", "");
    } else {
      msg = imOpSet.createMessage(message);
    }

    if (contactResource != null) imOpSet.sendInstantMessage(contact, contactResource, msg);
    else imOpSet.sendInstantMessage(contact, ContactResource.BASE_RESOURCE, msg);
  }
  /**
   * Send an instant message from the tester agent and assert reception by the tested implementation
   */
  public void thenTestSendMessage() {
    logger.debug(
        "Printing Server Stored list to see if message fails are contacts in each other lists");
    ContactGroup rootGroup1 =
        ((OperationSetPersistentPresence) opSetPresence1).getServerStoredContactListRoot();

    logger.debug("=========== Server Stored Contact List 1 =================");

    logger.debug(
        "rootGroup="
            + rootGroup1.getGroupName()
            + " rootGroup.childContacts="
            + rootGroup1.countContacts()
            + "rootGroup.childGroups="
            + rootGroup1.countSubgroups()
            + "Printing rootGroupContents=\n"
            + rootGroup1.toString());

    ContactGroup rootGroup2 =
        ((OperationSetPersistentPresence) opSetPresence2).getServerStoredContactListRoot();

    logger.debug("=========== Server Stored Contact List 2 =================");

    logger.debug(
        "rootGroup="
            + rootGroup2.getGroupName()
            + " rootGroup.childContacts="
            + rootGroup2.countContacts()
            + "rootGroup.childGroups="
            + rootGroup2.countSubgroups()
            + "Printing rootGroupContents=\n"
            + rootGroup2.toString());

    String body =
        "This is an IM coming from the tested implementation" + " on " + new Date().toString();

    // create the message
    net.java.sip.communicator.service.protocol.Message msg = opSetBasicIM1.createMessage(body);

    // register a listener in the op set
    ImEventCollector imEvtCollector1 = new ImEventCollector();
    opSetBasicIM1.addMessageListener(imEvtCollector1);

    // register a listener in the tester agent
    ImEventCollector imEvtCollector2 = new ImEventCollector();
    opSetBasicIM2.addMessageListener(imEvtCollector2);

    Contact testerAgentContact = opSetPresence1.findContactByID(fixture.userID2);

    opSetBasicIM1.sendInstantMessage(testerAgentContact, msg);

    imEvtCollector1.waitForEvent(10000);
    imEvtCollector2.waitForEvent(10000);

    opSetBasicIM1.removeMessageListener(imEvtCollector1);
    opSetBasicIM2.removeMessageListener(imEvtCollector2);

    // verify that the message delivered event was dispatched
    assertTrue(
        "No events delivered when sending a message", imEvtCollector1.collectedEvents.size() > 0);

    assertTrue(
        "Received evt was not an instance of " + MessageDeliveredEvent.class.getName(),
        imEvtCollector1.collectedEvents.get(0) instanceof MessageDeliveredEvent);

    MessageDeliveredEvent evt = (MessageDeliveredEvent) imEvtCollector1.collectedEvents.get(0);
    assertEquals("message destination ", evt.getDestinationContact().getAddress(), fixture.userID2);

    assertSame("source message", msg, evt.getSourceMessage());

    // verify that the message has successfully arived at the destination
    assertTrue(
        "No messages received by the tester agent", imEvtCollector2.collectedEvents.size() > 0);

    assertFalse(
        "Message was unable to deliver !",
        imEvtCollector2.collectedEvents.get(0) instanceof MessageDeliveryFailedEvent);

    String receivedBody =
        ((MessageReceivedEvent) imEvtCollector2.collectedEvents.get(0))
            .getSourceMessage()
            .getContent();

    assertEquals("received message body", msg.getContent(), receivedBody);
  }
Example #11
0
  /**
   * Implements the ContactListListener.contactSelected method.
   *
   * @param evt the <tt>ContactListEvent</tt> that notified us
   */
  public void contactClicked(ContactListEvent evt) {
    // We're interested only in two click events.
    if (evt.getClickCount() < 2) return;

    UIContact descriptor = evt.getSourceContact();

    // We're currently only interested in MetaContacts.
    if (descriptor.getDescriptor() instanceof MetaContact) {
      MetaContact metaContact = (MetaContact) descriptor.getDescriptor();

      // Searching for the right proto contact to use as default for the
      // chat conversation.
      Contact defaultContact =
          metaContact.getDefaultContact(OperationSetBasicInstantMessaging.class);

      // do nothing
      if (defaultContact == null) {
        defaultContact = metaContact.getDefaultContact(OperationSetSmsMessaging.class);

        if (defaultContact == null) return;
      }

      ProtocolProviderService defaultProvider = defaultContact.getProtocolProvider();

      OperationSetBasicInstantMessaging defaultIM =
          defaultProvider.getOperationSet(OperationSetBasicInstantMessaging.class);

      ProtocolProviderService protoContactProvider;
      OperationSetBasicInstantMessaging protoContactIM;

      boolean isOfflineMessagingSupported =
          defaultIM != null && !defaultIM.isOfflineMessagingSupported();

      if (defaultContact.getPresenceStatus().getStatus() < 1
          && (!isOfflineMessagingSupported || !defaultProvider.isRegistered())) {
        Iterator<Contact> protoContacts = metaContact.getContacts();

        while (protoContacts.hasNext()) {
          Contact contact = protoContacts.next();

          protoContactProvider = contact.getProtocolProvider();

          protoContactIM =
              protoContactProvider.getOperationSet(OperationSetBasicInstantMessaging.class);

          if (protoContactIM != null
              && protoContactIM.isOfflineMessagingSupported()
              && protoContactProvider.isRegistered()) {
            defaultContact = contact;
          }
        }
      }

      ContactEventHandler contactHandler =
          mainFrame.getContactHandler(defaultContact.getProtocolProvider());

      contactHandler.contactClicked(defaultContact, evt.getClickCount());
    } else if (descriptor.getDescriptor() instanceof SourceContact) {
      SourceContact contact = (SourceContact) descriptor.getDescriptor();

      List<ContactDetail> imDetails =
          contact.getContactDetails(OperationSetBasicInstantMessaging.class);
      List<ContactDetail> mucDetails = contact.getContactDetails(OperationSetMultiUserChat.class);

      if (imDetails != null && imDetails.size() > 0) {
        ProtocolProviderService pps =
            imDetails.get(0).getPreferredProtocolProvider(OperationSetBasicInstantMessaging.class);

        GuiActivator.getUIService()
            .getChatWindowManager()
            .startChat(contact.getContactAddress(), pps);
      } else if (mucDetails != null && mucDetails.size() > 0) {
        ChatRoomWrapper room =
            GuiActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);

        if (room == null) {
          // lets check by id
          ProtocolProviderService pps =
              mucDetails.get(0).getPreferredProtocolProvider(OperationSetMultiUserChat.class);

          room =
              GuiActivator.getMUCService()
                  .findChatRoomWrapperFromChatRoomID(contact.getContactAddress(), pps);

          if (room == null) {
            GuiActivator.getMUCService()
                .createChatRoom(
                    contact.getContactAddress(),
                    pps,
                    new ArrayList<String>(),
                    "",
                    false,
                    false,
                    false);
          }
        }

        if (room != null) GuiActivator.getMUCService().openChatRoom(room);
      } else {
        List<ContactDetail> smsDetails = contact.getContactDetails(OperationSetSmsMessaging.class);

        if (smsDetails != null && smsDetails.size() > 0) {
          GuiActivator.getUIService()
              .getChatWindowManager()
              .startChat(contact.getContactAddress(), true);
        }
      }
    }
  }