2014-06-11 23:40:19 +02:00
|
|
|
/*
|
2017-01-04 14:37:29 +01:00
|
|
|
* Copyright (c) 2012-2017 The original author or authorsgetRockQuestions()
|
2014-06-11 23:40:19 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.server;
|
2014-05-18 12:02:18 +02:00
|
|
|
|
2015-12-08 14:04:35 +01:00
|
|
|
import io.moquette.BrokerConstants;
|
2015-11-20 20:54:27 +01:00
|
|
|
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;
|
2015-11-20 20:54:27 +01:00
|
|
|
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;
|
2015-03-11 10:07:27 -04:00
|
|
|
|
2014-05-18 12:02:18 +02:00
|
|
|
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.
|
|
|
|
|
*
|
2015-11-20 20:54:27 +01:00
|
|
|
* @author andrea
|
2014-05-18 12:02:18 +02:00
|
|
|
*/
|
|
|
|
|
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;
|
2015-08-22 15:35:11 +02:00
|
|
|
IConfig m_config;
|
2014-05-18 12:02:18 +02:00
|
|
|
|
|
|
|
|
protected void startServer() throws IOException {
|
|
|
|
|
m_server = new Server();
|
2016-05-18 00:09:40 +02:00
|
|
|
final Properties configProps = IntegrationUtils.prepareTestProperties();
|
2016-04-25 11:51:57 +02:00
|
|
|
configProps.put(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME, Integer.toString(BrokerConstants.WEBSOCKET_PORT));
|
2015-08-22 15:35:11 +02:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
m_server.stopServer();
|
2015-11-08 18:25:55 +01:00
|
|
|
IntegrationUtils.cleanPersistenceFile(m_config);
|
2014-05-18 12:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void checkPlainConnect() throws Exception {
|
|
|
|
|
LOG.info("*** checkPlainConnect ***");
|
2016-12-30 00:31:41 +01:00
|
|
|
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);
|
2016-12-30 00:31:41 +01:00
|
|
|
LOG.info("Connecting to : {}", echoUri);
|
2014-05-18 12:02:18 +02:00
|
|
|
boolean connected = socket.awaitConnected(4, TimeUnit.SECONDS);
|
2016-12-30 00:31:41 +01:00
|
|
|
LOG.info("Connected was : {}", connected);
|
|
|
|
|
|
2014-05-18 12:02:18 +02:00
|
|
|
assertTrue(connected);
|
|
|
|
|
}
|
|
|
|
|
}
|