diff --git a/.gitignore b/.gitignore index d4932f1e..552eb122 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,9 @@ broker/runner /bundle/runner/ *~ *log* +.DS_Store +.settings/ +.project +.classpath +*.swp + diff --git a/broker/pom.xml b/broker/pom.xml index 49659947..b69f1807 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -119,6 +119,13 @@ 4.8.2 test + + + org.kaazing + robot.junit + 0.0.0.12 + test + @@ -170,6 +177,39 @@ + + + org.kaazing + robot-maven-plugin + 0.0.0.12 + + ${skipITs} + + + + + start + stop + + + + + + maven-failsafe-plugin + 2.17 + + ${skipITs} + + + + + integration-test + verify + + + + + diff --git a/broker/src/test/java/org/dna/mqtt/moquette/server/ConnectionIT.java b/broker/src/test/java/org/dna/mqtt/moquette/server/ConnectionIT.java new file mode 100644 index 00000000..944260ab --- /dev/null +++ b/broker/src/test/java/org/dna/mqtt/moquette/server/ConnectionIT.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012-2014 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 org.dna.mqtt.moquette.server; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.kaazing.robot.junit.annotation.Robotic; +import org.kaazing.robot.junit.rules.RobotRule; + +/** + * This class runs the robot test scripts to run the TCK for Moquette broker, before remember to run + * mvn -Dmaven.robot.daemon=false robot:start from broker submodule folder + * + * + * @author pkhanal + * + */ +public class ConnectionIT { + + @Rule + public RobotRule robot = new RobotRule(); + + Server m_server; + + protected void startServer() throws IOException { + m_server = new Server(); + m_server.startServer(); + } + + @Before + public void setUp() throws Exception { + startServer(); + } + + @After + public void tearDown() throws Exception { + m_server.stopServer(); + } + + // The test starts the server during setUp + // The network communication is driven by the script. + @Robotic(script = "connect.then.close") + @Test(timeout = 1000) + public void shouldConnectThenClose() throws Exception { + robot.join(); + } + +} diff --git a/broker/src/test/scripts/org/dna/mqtt/moquette/server/connect.then.close.rpt b/broker/src/test/scripts/org/dna/mqtt/moquette/server/connect.then.close.rpt new file mode 100644 index 00000000..315c7ed5 --- /dev/null +++ b/broker/src/test/scripts/org/dna/mqtt/moquette/server/connect.then.close.rpt @@ -0,0 +1,62 @@ +# Copyright (c) 2012-2014 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. + +# MQTT 3.1.1 + +# Script that sends the CONNECT control packet to broker and expects +# CONNACK control packet from the broker followed by sending the DISCONNECT +# control packet to the broker and expects server to close the network connection + +connect tcp://127.0.0.1:1883 +connected + +# CONNECT +write [0x10] # MQTT Control Packet type(1) +write [0x12] # Remaining Length +write [0x00 0x04] # Protocol Name Length +write "MQTT" # Protocol Name +write [0x04] # The value of the Protocol Level field for the version 3.1.1 of the protocol is 4 (0x04) + + # Connect Flags + # User Name Flag(0) + # Password Flag(0) +write [0x02] # Will Retain(0) + # Will QoS(00) + # Will Flag(0) + # Clean Session(1) + # Reserved(0) + +write [0x00 0x00] # Keep Alive + + # Payload +write [0x00 0x07] # Client Identifier Length +write "client1" # Client Identifier + +# CONNACK +read [0x20] # MQTT Control Packet type(2) +read [0x02] # Remaining Length + + # Connect Acknowledge Flags +read [0x00] # Session Present Flag(0) + + # Connect Return code +read [0x00] # Connection Accepted + + +# DISCONNECT +write [0xE0] # MQTT Control Packet type(14) +write [0x00] # Remaining Length + +# Server MUST close the Network Connection +closed