Search in sources :

Example 1 with MockXmlResponseProvider

use of jetbrains.communicator.p2p.MockXmlResponseProvider 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

Transport (jetbrains.communicator.core.transport.Transport)1 MockXmlMessage (jetbrains.communicator.p2p.MockXmlMessage)1 MockXmlResponseProvider (jetbrains.communicator.p2p.MockXmlResponseProvider)1 WaitFor (jetbrains.communicator.util.WaitFor)1 Element (org.jdom.Element)1 Disposable (org.picocontainer.Disposable)1