Files
IM-server-new/broker/src/test/java/io/moquette/server/ServerIntegrationWebSocketTest.java
T

85 lines
2.7 KiB
Java
Raw Normal View History

/*
2017-03-19 22:01:23 +01:00
* Copyright (c) 2012-2017 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.moquette.server;
2014-05-18 12:02:18 +02:00
import io.moquette.BrokerConstants;
import io.moquette.server.config.MemoryConfig;
2015-03-15 16:45:11 +01:00
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import io.moquette.server.config.IConfig;
2015-03-15 16:45:11 +01:00
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2014-05-18 12:02:18 +02:00
import java.io.IOException;
import java.net.URI;
2015-03-11 10:07:27 -04:00
import java.util.Properties;
2014-05-18 12:02:18 +02:00
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertTrue;
2015-03-11 10:07:27 -04:00
2014-05-18 12:02:18 +02:00
/**
* Integration test to check the function of Moquette with a WebSocket channel.
*/
public class ServerIntegrationWebSocketTest {
2015-11-16 23:53:10 +01:00
private static final Logger LOG = LoggerFactory.getLogger(ServerIntegrationWebSocketTest.class);
2014-05-18 12:02:18 +02:00
Server m_server;
WebSocketClient client;
IConfig m_config;
2014-05-18 12:02:18 +02:00
protected void startServer() throws IOException {
m_server = new Server();
final Properties configProps = IntegrationUtils.prepareTestProperties();
configProps
.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
m_config = new MemoryConfig(configProps);
m_server.startServer(m_config);
2014-05-18 12:02:18 +02:00
}
@Before
public void setUp() throws Exception {
startServer();
client = new WebSocketClient();
}
@After
public void tearDown() throws Exception {
client.stop();
2014-05-18 12:02:18 +02:00
m_server.stopServer();
}
2014-05-18 12:02:18 +02:00
@Test
public void checkPlainConnect() throws Exception {
LOG.info("*** checkPlainConnect ***");
String destUri = "ws://localhost:" + BrokerConstants.WEBSOCKET_PORT + "/mqtt";
2014-05-18 12:02:18 +02:00
MQTTWebSocket socket = new MQTTWebSocket();
client.start();
URI echoUri = new URI(destUri);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(socket, echoUri, request);
LOG.info("Connecting to : {}", echoUri);
2014-05-18 12:02:18 +02:00
boolean connected = socket.awaitConnected(4, TimeUnit.SECONDS);
LOG.info("Connected was : {}", connected);
2014-05-18 12:02:18 +02:00
assertTrue(connected);
}
}