Search in sources :

Example 1 with WaitFor

use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method testSendCustomMessage_WithoutProvider.

public void testSendCustomMessage_WithoutProvider() throws Exception {
    addEventListener();
    myTransport.sendXmlMessage(mySelf, new TextXmlMessage("some text") {

        @Override
        public String getTagNamespace() {
            return "some namespace";
        }
    });
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return myEvents.size() > 1;
        }
    };
    IDEtalkEvent event = myEvents.get(1);
    assertTrue("Expect message Event for unknown provider", event instanceof MessageEvent);
    assertEquals("Expect message text", "some text", ((MessageEvent) event).getMessage());
}
Also used : WaitFor(jetbrains.communicator.util.WaitFor) IDEtalkEvent(jetbrains.communicator.core.IDEtalkEvent) MessageEvent(jetbrains.communicator.core.transport.MessageEvent) TextXmlMessage(jetbrains.communicator.core.transport.TextXmlMessage)

Example 2 with WaitFor

use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.

the class P2PTransportTest method testSetOwnPresence.

public void testSetOwnPresence() throws Exception {
    registerResponseProviders(myUserModel, myIdeFacade);
    // Add self to contact list
    User self = myUserModel.createUser(StringUtil.getMyUsername(), myTransport.getName());
    myUserModel.addUser(self);
    // Wait for next cycle of user finding
    new WaitFor(1000) {

        @Override
        protected boolean condition() {
            return !myTransport.getUserMonitorThread().isFinding();
        }
    };
    // make self away
    UserPresence presence = new UserPresence(PresenceMode.AWAY);
    assert presence.isOnline();
    myTransport.setOwnPresence(presence);
    // make sure that away status will be updated
    myTransport.findUsers(new NullProgressIndicator());
    assert PresenceMode.AWAY == self.getPresence().getPresenceMode();
    // Now, test itself. We go online and want this status to be updated almost immediately.
    myEvents.clear();
    addEventListener();
    myTransport.setOwnPresence(new UserPresence(PresenceMode.AVAILABLE));
    final User self1 = self;
    new WaitFor(200) {

        @Override
        protected boolean condition() {
            return self1.getPresence().getPresenceMode() == PresenceMode.AVAILABLE;
        }
    };
    assertSame("Should provide correct presence mode", PresenceMode.AVAILABLE, myTransport.getUserPresence(self).getPresenceMode());
    UserEvent.Updated event = (UserEvent.Updated) checkEvent(true);
    assertNotNull("Expect go online event", event);
    assertEquals("presence", event.getPropertyName());
}
Also used : MockUser(jetbrains.communicator.mock.MockUser) WaitFor(jetbrains.communicator.util.WaitFor) NullProgressIndicator(jetbrains.communicator.ide.NullProgressIndicator)

Example 3 with WaitFor

use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method testTimeIsSetInSimpleMessage.

public void testTimeIsSetInSimpleMessage() throws Throwable {
    Message baseMessage = myTransport.createBaseMessage(mySelf, "some text");
    myTransport.getFacade().getConnection().sendPacket(baseMessage);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return myEvents.size() > 0;
        }
    };
    long diff = ((MessageEvent) myEvents.get(1)).getWhen().getTime() - System.currentTimeMillis();
    assertTrue("Time should be set for simple Jabber messages: " + diff, Math.abs(diff) < 150);
}
Also used : TextXmlMessage(jetbrains.communicator.core.transport.TextXmlMessage) Message(org.jivesoftware.smack.packet.Message) WaitFor(jetbrains.communicator.util.WaitFor) MessageEvent(jetbrains.communicator.core.transport.MessageEvent)

Example 4 with WaitFor

use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method testLocalChanges_UpdateRoster.

public void testLocalChanges_UpdateRoster() throws Throwable {
    addEventListener();
    addUserFred();
    User user = myUserModel.getAllUsers()[0];
    final Roster roster = myFacade.getConnection().getRoster();
    // Change group:
    user.setGroup("someOtherGroup", myUserModel);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return roster.getGroupCount() == 1 && roster.getGroup("someOtherGroup") != null;
        }
    };
    assertEquals("One group expected", 1, roster.getGroupCount());
    RosterGroup group = roster.getGroup("someOtherGroup");
    assertNotNull(group);
    assertEquals(1, group.getEntryCount());
    assertNotNull(group.getEntry(FRED));
    // Change Display name:
    user.setDisplayName("Some new name", myUserModel);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return "Some new name".equals(roster.getEntry(FRED).getName());
        }
    };
    assertEquals("User name in Roster should have changed", "Some new name", roster.getEntry(FRED).getName());
    // Delete user:
    myUserModel.removeUser(user);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return roster.getEntryCount() == 0;
        }
    };
    assertEquals("User should be removed from Roster", 0, roster.getEntryCount());
}
Also used : User(jetbrains.communicator.core.users.User) WaitFor(jetbrains.communicator.util.WaitFor)

Example 5 with WaitFor

use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method testSimpleJabberMessage.

public void testSimpleJabberMessage() throws Throwable {
    Message message = new Message(mySelf.getName(), Message.Type.NORMAL);
    String body = "some текст <>#$%^";
    message.setThread("someThreadId");
    message.setBody(body);
    addEventListener();
    myFacade.getConnection().sendPacket(message);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return myEvents.size() > 1;
        }
    };
    IDEtalkEvent event = myEvents.get(1);
    assertTrue("Expect message Event", event instanceof MessageEvent);
    assertEquals("Expect message text", body, ((MessageEvent) event).getMessage());
    assertEquals("Should remember threadId for incoming messages", "someThreadId", myTransport.getThreadId(mySelf));
}
Also used : TextXmlMessage(jetbrains.communicator.core.transport.TextXmlMessage) Message(org.jivesoftware.smack.packet.Message) WaitFor(jetbrains.communicator.util.WaitFor) IDEtalkEvent(jetbrains.communicator.core.IDEtalkEvent) MessageEvent(jetbrains.communicator.core.transport.MessageEvent)

Aggregations

WaitFor (jetbrains.communicator.util.WaitFor)17 IDEtalkEvent (jetbrains.communicator.core.IDEtalkEvent)5 MessageEvent (jetbrains.communicator.core.transport.MessageEvent)4 User (jetbrains.communicator.core.users.User)4 UserPresence (jetbrains.communicator.core.users.UserPresence)4 Presence (org.jivesoftware.smack.packet.Presence)4 TextXmlMessage (jetbrains.communicator.core.transport.TextXmlMessage)3 UserEvent (jetbrains.communicator.core.users.UserEvent)3 MockUser (jetbrains.communicator.mock.MockUser)3 EventVisitor (jetbrains.communicator.core.EventVisitor)2 IDEtalkAdapter (jetbrains.communicator.core.IDEtalkAdapter)2 Message (org.jivesoftware.smack.packet.Message)2 CodePointerEvent (jetbrains.communicator.core.transport.CodePointerEvent)1 Transport (jetbrains.communicator.core.transport.Transport)1 CodePointer (jetbrains.communicator.core.vfs.CodePointer)1 VFile (jetbrains.communicator.core.vfs.VFile)1 NullProgressIndicator (jetbrains.communicator.ide.NullProgressIndicator)1 MockIDEFacade (jetbrains.communicator.mock.MockIDEFacade)1 MockMessage (jetbrains.communicator.mock.MockMessage)1 MockXmlMessage (jetbrains.communicator.p2p.MockXmlMessage)1