Search in sources :

Example 6 with WaitFor

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

the class TestUtil method testSendMessage_Functional.

public static void testSendMessage_Functional(BaseTestCase testCase, User self) {
    final String[] log = new String[] { "" };
    final long[] whenSent = new long[1];
    testCase.getBroadcaster().addListener(new IDEtalkAdapter() {

        @Override
        public void afterChange(IDEtalkEvent event) {
            event.accept(new EventVisitor() {

                @Override
                public void visitMessageEvent(MessageEvent event) {
                    super.visitMessageEvent(event);
                    log[0] += event.getRemoteUser() + ' ' + event.getMessage();
                    if (event.getWhen().getTime() - whenSent[0] < 150) {
                        log[0] += " timingOK";
                    } else {
                        log[0] += (event.getWhen().getTime() - whenSent[0]);
                    }
                }
            });
        }
    });
    testCase.markLastListenerForCleanup();
    log[0] = "";
    String comment = "SS��� messa&&ge";
    whenSent[0] = System.currentTimeMillis();
    self.sendMessage(comment, testCase.getBroadcaster());
    new WaitFor(500) {

        @Override
        protected boolean condition() {
            return log[0].length() > 0;
        }
    };
    assertEquals("Message expected", self.getName() + ' ' + comment + " timingOK", log[0]);
}
Also used : EventVisitor(jetbrains.communicator.core.EventVisitor) WaitFor(jetbrains.communicator.util.WaitFor) IDEtalkEvent(jetbrains.communicator.core.IDEtalkEvent) MessageEvent(jetbrains.communicator.core.transport.MessageEvent) IDEtalkAdapter(jetbrains.communicator.core.IDEtalkAdapter)

Example 7 with WaitFor

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

the class TestUtil method testSendCodePointer_Functional.

public static void testSendCodePointer_Functional(BaseTestCase testCase, User self) {
    final String[] log = new String[] { "" };
    testCase.getBroadcaster().addListener(new IDEtalkAdapter() {

        @Override
        public void afterChange(IDEtalkEvent event) {
            event.accept(new EventVisitor() {

                @Override
                public void visitCodePointerEvent(CodePointerEvent event) {
                    log[0] += event.getRemoteUser() + ' ';
                    log[0] += event.getComment();
                    log[0] += event.getCodePointer().toString();
                    log[0] += event.getFile().toString();
                }
            });
        }
    });
    testCase.markLastListenerForCleanup();
    log[0] = "";
    CodePointer pointer = new CodePointer(0, 1);
    VFile file = VFile.create("path");
    self.sendCodeIntervalPointer(file, pointer, "comment���< && 53", testCase.getBroadcaster());
    new WaitFor(2000) {

        @Override
        protected boolean condition() {
            return log[0].length() > 0;
        }
    };
    Assert.assertEquals("Code Pointer expected", self.getName() + " comment���< && 53" + pointer + file, log[0]);
}
Also used : EventVisitor(jetbrains.communicator.core.EventVisitor) WaitFor(jetbrains.communicator.util.WaitFor) IDEtalkEvent(jetbrains.communicator.core.IDEtalkEvent) CodePointerEvent(jetbrains.communicator.core.transport.CodePointerEvent) CodePointer(jetbrains.communicator.core.vfs.CodePointer) IDEtalkAdapter(jetbrains.communicator.core.IDEtalkAdapter) VFile(jetbrains.communicator.core.vfs.VFile)

Example 8 with WaitFor

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

the class AsyncMessageDispatcherTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myIdeFacade = new MockIDEFacade(getClass());
    myUser = new MockUser("user", null);
    myUser.setOnline(true);
    myDispatcher = new AsyncMessageDispatcherImpl(getBroadcaster(), myIdeFacade);
    new WaitFor(1000) {

        @Override
        protected boolean condition() {
            return myDispatcher.isRunning();
        }
    };
    myLog = new String[] { "" };
}
Also used : WaitFor(jetbrains.communicator.util.WaitFor) MockIDEFacade(jetbrains.communicator.mock.MockIDEFacade) MockUser(jetbrains.communicator.mock.MockUser)

Example 9 with WaitFor

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

the class AsyncMessageDispatcherTest method testAddMessagesWhileDispatching.

public void testAddMessagesWhileDispatching() throws Exception {
    NotifyableMessage mockMessage = new NotifyableMessage(true, myLog);
    MockUser user1 = new MockUser("user1", null);
    MockUser user2 = new MockUser("user2", null);
    user1.setOnline(true);
    user2.setOnline(true);
    myDispatcher.sendLater(user1, mockMessage);
    mockMessage.waitUntilDispatchingStarted();
    myDispatcher.sendLater(user2, new MockMessage(true));
    assertEquals("Messages not delivered yet", 2, myDispatcher.getUsersWithMessages().length);
    triggerMessageProcessing(mockMessage);
    new WaitFor(200) {

        @Override
        protected boolean condition() {
            return myDispatcher.getUsersWithMessages().length == 0;
        }
    };
    assertEquals("All messages should be delivered", 0, myDispatcher.getUsersWithMessages().length);
}
Also used : WaitFor(jetbrains.communicator.util.WaitFor) MockMessage(jetbrains.communicator.mock.MockMessage) MockUser(jetbrains.communicator.mock.MockUser)

Example 10 with WaitFor

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

the class TestUtil method testSendXmlMessage_Functional.

public static void testSendXmlMessage_Functional(BaseTestCase testCase, User self, final boolean checkResponse) {
    final String[] log = new String[] { "" };
    log[0] = "";
    final String comment = "��� mes&&<>sage";
    MockXmlMessage message = new MockXmlMessage("tagName", "myNamespace") {

        @Override
        public boolean needsResponse() {
            return checkResponse;
        }

        @Override
        public void fillRequest(Element element) {
            element.setText(comment);
        }

        @Override
        public void processResponse(Element responseElement) {
            log[0] += responseElement.getAttributeValue("foo");
        }
    };
    final MockXmlResponseProvider mockXmlResponseProvider = new MockXmlResponseProvider("tagName", "myNamespace", testCase.getBroadcaster()) {

        @Override
        public boolean processAndFillResponse(Element response, Element request, Transport transport, String remoteUser) {
            log[0] += remoteUser + " " + request.getName() + " " + request.getText();
            assertEquals("root element expected", "tagName", request.getName());
            response.setAttribute("foo", "gar");
            return true;
        }
    };
    Pico.getInstance().registerComponentInstance(mockXmlResponseProvider);
    testCase.disposeOnTearDown(new Disposable() {

        @Override
        public void dispose() {
            Pico.getInstance().unregisterComponentByInstance(mockXmlResponseProvider);
        }
    });
    self.sendXmlMessage(message);
    new WaitFor(500) {

        @Override
        protected boolean condition() {
            if (checkResponse) {
                return log[0].endsWith("gar");
            } else {
                return log[0].length() > 0;
            }
        }
    };
    String expectedLog = self.getName() + " tagName " + comment;
    expectedLog += checkResponse ? "gar" : "";
    assertEquals("Message expected", expectedLog, log[0]);
}
Also used : Disposable(org.picocontainer.Disposable) WaitFor(jetbrains.communicator.util.WaitFor) Element(org.jdom.Element) MockXmlMessage(jetbrains.communicator.p2p.MockXmlMessage) Transport(jetbrains.communicator.core.transport.Transport) MockXmlResponseProvider(jetbrains.communicator.p2p.MockXmlResponseProvider)

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