use of jetbrains.communicator.p2p.MockXmlMessage in project intellij-plugins by JetBrains.
the class P2PNetworkXmlMessageTest method testProcessResponse.
public void testProcessResponse() throws Throwable {
final boolean[] processed = new boolean[1];
MockXmlMessage xmlMessage = new MockXmlMessage() {
@Override
public void processResponse(Element responseElement) {
assertEquals("fee", responseElement.getName());
processed[0] = true;
}
};
xmlMessage.setShouldWaitForResponse(true);
P2PNetworkXmlMessage p2PNetworkXmlMessage = new P2PNetworkXmlMessage("str", xmlMessage);
p2PNetworkXmlMessage.setResponse("<fee/>");
p2PNetworkXmlMessage.processResponse();
assertTrue("Xml Response should be processed", processed[0]);
processed[0] = false;
xmlMessage.setShouldWaitForResponse(false);
p2PNetworkXmlMessage.processResponse();
assertFalse("Xml Response should not be processed", processed[0]);
}
use of jetbrains.communicator.p2p.MockXmlMessage 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]);
}
Aggregations