<commit_before>/*
 * Copyright (c) 2008-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.cometd.javascript;

import java.util.Map;

import org.cometd.server.websocket.common.AbstractWebSocketTransport;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CometDWebSocketClientProtocolTest extends AbstractCometDWebSocketTest {
    private static final String PROTOCOL = "bayeux/1.0";

    @Override
    protected void initCometDServer(String transport, Map<String, String> options) throws Exception {
        options.put(AbstractWebSocketTransport.PROTOCOL_OPTION, PROTOCOL);
        super.initCometDServer(transport, options);
    }

    @Test
    public void testClientWithoutWebSocketProtocolServerWithoutWebSocketProtocol() throws Exception {
        evaluateScript("cometd.configure({" +
                "url: '" + cometdURL + "', " +
                "logLevel: '" + getLogLevel() + "'" +
                "});");

        evaluateScript("var latch = new Latch(1);");
        Latch latch = javaScript.get("latch");
        String channelName = "/bar";
        evaluateScript("cometd.addListener('/meta/handshake', function(message) {" +
                "   if (message.successful) {" +
                "       cometd.batch(function() {" +
                "           cometd.subscribe('" + channelName + "', function() { latch.countDown(); });" +
                "           cometd.publish('" + channelName + "', {});" +
                "       });" +
                "   }" +
                "});");

        evaluateScript("cometd.handshake();");
        Assertions.assertTrue(latch.await(5000));

        evaluateScript("var disconnectLatch = new Latch(1);");
        Latch disconnectLatch = javaScript.get("disconnectLatch");
        evaluateScript("cometd.addListener('/meta/disconnect', function() { disconnectLatch.countDown(); });");
        evaluateScript("cometd.disconnect();");
        Assertions.assertTrue(disconnectLatch.await(5000));
    }<commit_msg>Fixed test after merge.<commit_after>/*
 * Copyright (c) 2008-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.cometd.javascript;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CometDWebSocketClientProtocolTest extends AbstractCometDWebSocketTest {
    private static final String PROTOCOL = "bayeux/1.0";

    @Test
    public void testClientWithoutWebSocketProtocolServerWithoutWebSocketProtocol() throws Exception {
        evaluateScript("cometd.configure({" +
                "url: '" + cometdURL + "', " +
                "logLevel: '" + getLogLevel() + "'" +
                "});");

        evaluateScript("var latch = new Latch(1);");
        Latch latch = javaScript.get("latch");
        String channelName = "/bar";
        evaluateScript("cometd.addListener('/meta/handshake', function(message) {" +
                "   if (message.successful) {" +
                "       cometd.batch(function() {" +
                "           cometd.subscribe('" + channelName + "', function() { latch.countDown(); });" +
                "           cometd.publish('" + channelName + "', {});" +
                "       });" +
                "   }" +
                "});");

        evaluateScript("cometd.handshake();");
        Assertions.assertTrue(latch.await(5000));

        evaluateScript("var disconnectLatch = new Latch(1);");
        Latch disconnectLatch = javaScript.get("disconnectLatch");
        evaluateScript("cometd.addListener('/meta/disconnect', function() { disconnectLatch.countDown(); });");
        evaluateScript("cometd.disconnect();");
        Assertions.assertTrue(disconnectLatch.await(5000));
    }
{'fraction_non_alphanumeric': 0.12486992715920915, 'fraction_numerical': 0.009989594172736732, 'mean_word_length': 2.817315329626688, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4828929', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1275, 'n_words': 321}