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;
}
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);
}
}
});
}
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");
}
}
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]);
}
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();
}
Aggregations