@@ -0,0 +1,3244 @@
+package org.cometd.javascript.jquery;%0A%0Aimport java.util.Map;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A%0Aimport org.cometd.Bayeux;%0Aimport org.cometd.Client;%0Aimport org.cometd.server.BayeuxService;%0Aimport org.mozilla.javascript.ScriptableObject;%0Aimport org.testng.annotations.Test;%0A%0A/**%0A * @version $Revision$ $Date$%0A */%0Apublic class CometdDeliverTest extends AbstractCometdJQueryTest%0A%7B%0A    private DeliverService service;%0A%0A    protected void customizeBayeux(Bayeux bayeux)%0A    %7B%0A        super.customizeBayeux(bayeux);%0A        service = new DeliverService(bayeux);%0A    %7D%0A%0A    @Test%0A    public void testDeliver() throws Exception%0A    %7B%0A        defineClass(Latch.class);%0A%0A        evaluateScript(%22$.cometd.configure(%7Burl: '%22 + cometURL + %22', logLevel: 'debug'%7D);%22);%0A        evaluateScript(%22var _data;%22);%0A        evaluateScript(%22$.cometd.addListener('/deliver', function(message) %7B _data = message.data; %7D);%22);%0A%0A        evaluateScript(%22$.cometd.handshake();%22);%0A%0A        // Wait for the handshake to complete%0A        Thread.sleep(1000);%0A%0A        evaluateScript(%22var latch = new Latch(1);%22);%0A        Latch latch = get(%22latch%22);%0A        evaluateScript(%22var listener = $.cometd.addListener('/meta/publish', function(message) %7B latch.countDown(); %7D);%22);%0A        evaluateScript(%22$.cometd.publish('/deliver', %7B deliver: false %7D);%22);%0A        assert latch.await(1000);%0A        evaluateScript(%22$.cometd.removeListener(listener);%22);%0A        evaluateScript(%22window.assert(_data === undefined);%22);%0A%0A        evaluateScript(%22latch = new Latch(1);%22);%0A        evaluateScript(%22listener = $.cometd.addListener('/meta/publish', function(message) %7B latch.countDown(); %7D);%22);%0A        evaluateScript(%22$.cometd.publish('/deliver', %7B deliver: true %7D);%22);%0A        assert latch.await(1000);%0A        evaluateScript(%22$.cometd.removeListener(listener);%22);%0A        // Wait for the listener to be notified%0A        Thread.sleep(500);%0A        evaluateScript(%22window.assert(_data !== undefined);%22);%0A%0A        evaluateScript(%22$.cometd.disconnect();%22);%0A        Thread.sleep(500);%0A    %7D%0A%0A    public static class Latch extends ScriptableObject%0A    %7B%0A        private volatile CountDownLatch latch;%0A%0A        public String getClassName()%0A        %7B%0A            return %22Latch%22;%0A        %7D%0A%0A        public void jsConstructor(int count)%0A        %7B%0A            latch = new CountDownLatch(count);%0A        %7D%0A%0A        public boolean await(long timeout) throws InterruptedException%0A        %7B%0A            return latch.await(timeout, TimeUnit.MILLISECONDS);%0A        %7D%0A%0A        public void jsFunction_countDown()%0A        %7B%0A            latch.countDown();%0A        %7D%0A    %7D%0A%0A    public static class DeliverService extends BayeuxService%0A    %7B%0A        public DeliverService(Bayeux bayeux)%0A        %7B%0A            super(bayeux, %22deliver%22);%0A            subscribe(%22/deliver%22, %22deliver%22);%0A        %7D%0A%0A        public void deliver(Client remote, String channel, Object messageData, String messageId)%0A        %7B%0A            Map%3CString, ?%3E data = (Map%3CString,?%3E)messageData;%0A            Boolean deliver = (Boolean) data.get(%22deliver%22);%0A            if (deliver)%0A            %7B%0A                remote.deliver(getClient(), channel, messageData, messageId);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Test for addListener() and deliver().