Search in sources :

Example 1 with Disposable

use of org.picocontainer.Disposable in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method createLocalConnectionWithJabberUser.

private XMPPConnection createLocalConnectionWithJabberUser(String userName, String resource) throws XMPPException, InterruptedException {
    final XMPPConnection conn = new XMPPConnection("localhost");
    conn.getAccountManager().createAccount(userName, "123456");
    if (resource == null) {
        resource = "test";
    }
    conn.login(userName, "123456", resource);
    conn.getRoster().setSubscriptionMode(Roster.SubscriptionMode.accept_all);
    Presence presence = new Presence(Presence.Type.available);
    conn.sendPacket(presence);
    disposeOnTearDown(new Disposable() {

        @Override
        public void dispose() {
            try {
                if (conn.isConnected()) {
                    conn.getAccountManager().deleteAccount();
                }
            } catch (XMPPException e) {
                throw new RuntimeException(e);
            } finally {
                Thread thread = new Thread("jabber conn test") {

                    @Override
                    public void run() {
                        conn.close();
                    }
                };
                thread.start();
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    });
    return conn;
}
Also used : Disposable(org.picocontainer.Disposable) Presence(org.jivesoftware.smack.packet.Presence) UserPresence(jetbrains.communicator.core.users.UserPresence)

Example 2 with Disposable

use of org.picocontainer.Disposable in project intellij-plugins by JetBrains.

the class BaseTestCase method registerResponseProviders.

protected void registerResponseProviders(UserModel userModel, IDEFacade ideFacade) {
    final XmlResponseProvider[] providers = { new GetVFileContentsProvider(ideFacade, userModel), new GetProjectsDataProvider(ideFacade, userModel), new CodePointerEventProvider(getBroadcaster()), new TextMessageEventProvider(getBroadcaster()), new BecomeAvailableXmlMessage() };
    for (XmlResponseProvider provider : providers) {
        Pico.getInstance().registerComponentInstance(provider);
    }
    disposeOnTearDown(new Disposable() {

        @Override
        public void dispose() {
            for (XmlResponseProvider provider : providers) {
                Pico.getInstance().unregisterComponentByInstance(provider);
            }
        }
    });
}
Also used : Disposable(org.picocontainer.Disposable) GetProjectsDataProvider(jetbrains.communicator.core.impl.transport.GetProjectsDataProvider) XmlResponseProvider(jetbrains.communicator.core.transport.XmlResponseProvider) BecomeAvailableXmlMessage(jetbrains.communicator.p2p.BecomeAvailableXmlMessage) CodePointerEventProvider(jetbrains.communicator.core.impl.transport.CodePointerEventProvider) TextMessageEventProvider(jetbrains.communicator.core.transport.TextMessageEventProvider) GetVFileContentsProvider(jetbrains.communicator.core.impl.transport.GetVFileContentsProvider)

Example 3 with Disposable

use of org.picocontainer.Disposable in project intellij-plugins by JetBrains.

the class LightTestCase method tearDown.

@Override
protected void tearDown() throws Exception {
    while (!myDisposables.isEmpty()) {
        Disposable disposable = myDisposables.pop();
        //WatchDog watchDog = new WatchDog(disposable.toString());
        disposable.dispose();
    //watchDog.stop();
    }
    super.tearDown();
    if (ourShouldFail) {
        fail("Test marked as failed. See console for exceptions");
    }
}
Also used : Disposable(org.picocontainer.Disposable)

Example 4 with Disposable

use of org.picocontainer.Disposable 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)

Example 5 with Disposable

use of org.picocontainer.Disposable in project intellij-plugins by JetBrains.

the class BaseTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    StringUtil.setMyUsername("user_" + getName());
    disposeOnTearDown(new Disposable() {

        @Override
        public void dispose() {
            StringUtil.setMyUsername(null);
        }
    });
    TestFactory.init();
    myOptions = Pico.getOptions();
    LightPlatformTestCase.initApplication();
}
Also used : Disposable(org.picocontainer.Disposable)

Aggregations

Disposable (org.picocontainer.Disposable)6 CodePointerEventProvider (jetbrains.communicator.core.impl.transport.CodePointerEventProvider)1 GetProjectsDataProvider (jetbrains.communicator.core.impl.transport.GetProjectsDataProvider)1 GetVFileContentsProvider (jetbrains.communicator.core.impl.transport.GetVFileContentsProvider)1 TextMessageEventProvider (jetbrains.communicator.core.transport.TextMessageEventProvider)1 Transport (jetbrains.communicator.core.transport.Transport)1 XmlResponseProvider (jetbrains.communicator.core.transport.XmlResponseProvider)1 UserPresence (jetbrains.communicator.core.users.UserPresence)1 BecomeAvailableXmlMessage (jetbrains.communicator.p2p.BecomeAvailableXmlMessage)1 MockXmlMessage (jetbrains.communicator.p2p.MockXmlMessage)1 MockXmlResponseProvider (jetbrains.communicator.p2p.MockXmlResponseProvider)1 WaitFor (jetbrains.communicator.util.WaitFor)1 Element (org.jdom.Element)1 Presence (org.jivesoftware.smack.packet.Presence)1