broker/ConnectionIT: code formatter used
This commit is contained in:
@@ -13,14 +13,13 @@
|
|||||||
*
|
*
|
||||||
* You may elect to redistribute this code under either of these licenses.
|
* You may elect to redistribute this code under either of these licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.moquette.spec.v3_1_1.connection;
|
package io.moquette.spec.v3_1_1.connection;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import io.moquette.BrokerConstants;
|
import io.moquette.BrokerConstants;
|
||||||
import io.moquette.server.Server;
|
import io.moquette.server.Server;
|
||||||
import io.moquette.testclient.RawClient;
|
import io.moquette.testclient.RawClient;
|
||||||
@@ -32,12 +31,12 @@ import org.junit.Test;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author pkhanal
|
* @author pkhanal
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ConnectionIT {
|
public class ConnectionIT {
|
||||||
|
|
||||||
Server m_server;
|
Server m_server;
|
||||||
|
|
||||||
protected void startServer() throws IOException {
|
protected void startServer() throws IOException {
|
||||||
m_server = new Server();
|
m_server = new Server();
|
||||||
m_server.startServer();
|
m_server.startServer();
|
||||||
@@ -54,7 +53,9 @@ public class ConnectionIT {
|
|||||||
|
|
||||||
File dbFile = new File(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
File dbFile = new File(BrokerConstants.DEFAULT_PERSISTENT_PATH);
|
||||||
if (dbFile.exists()) {
|
if (dbFile.exists()) {
|
||||||
assertTrue("Error deleting the moquette db file " + BrokerConstants.DEFAULT_PERSISTENT_PATH, dbFile.delete());
|
assertTrue(
|
||||||
|
"Error deleting the moquette db file " + BrokerConstants.DEFAULT_PERSISTENT_PATH,
|
||||||
|
dbFile.delete());
|
||||||
}
|
}
|
||||||
assertFalse(dbFile.exists());
|
assertFalse(dbFile.exists());
|
||||||
}
|
}
|
||||||
@@ -62,100 +63,103 @@ public class ConnectionIT {
|
|||||||
@Test(timeout = 3000)
|
@Test(timeout = 3000)
|
||||||
public void testConnectThenClose() throws Exception {
|
public void testConnectThenClose() throws Exception {
|
||||||
RawClient.connect("127.0.0.1", 1883).isConnected()
|
RawClient.connect("127.0.0.1", 1883).isConnected()
|
||||||
//CONNECT
|
// CONNECT
|
||||||
.write(0x10) //MQTT Control Packet type(1)
|
.write(0x10) // MQTT Control Packet type(1)
|
||||||
.write(0x13) // Remaining Length
|
.write(0x13) // Remaining Length
|
||||||
.write(0x00, 0x04) // Protocol Name Length
|
.write(0x00, 0x04) // Protocol Name Length
|
||||||
.write("MQTT") // Protocol Name
|
.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)
|
.write(0x04) // The value of the Protocol Level field for the version 3.1.1 of the
|
||||||
|
// protocol is 4 (0x04)
|
||||||
|
|
||||||
//Connect Flags
|
// Connect Flags
|
||||||
//User Name Flag(0)
|
// User Name Flag(0)
|
||||||
//Password Flag(0)
|
// Password Flag(0)
|
||||||
//Will Retain(0)
|
// Will Retain(0)
|
||||||
//Will QoS(00)
|
// Will QoS(00)
|
||||||
//Will Flag(0)
|
// Will Flag(0)
|
||||||
//Clean Session(1)
|
// Clean Session(1)
|
||||||
.write(0x02) // Reserved(0)
|
.write(0x02) // Reserved(0)
|
||||||
.write(0x00, 0x00) // Keep Alive
|
.write(0x00, 0x00) // Keep Alive
|
||||||
|
|
||||||
// Payload
|
// Payload
|
||||||
.write(0x00, 0x07) // Client Identifier Length
|
.write(0x00, 0x07) // Client Identifier Length
|
||||||
.write("client1") // Client Identifier
|
.write("client1") // Client Identifier
|
||||||
.flush()
|
.flush()
|
||||||
|
|
||||||
//CONNACK
|
// CONNACK
|
||||||
.read(0x20) // MQTT Control Packet type(2)
|
.read(0x20) // MQTT Control Packet type(2)
|
||||||
.read(0x02) // Remaining Length
|
.read(0x02) // Remaining Length
|
||||||
|
|
||||||
//Connect Acknowledge Flags
|
// Connect Acknowledge Flags
|
||||||
.read(0x00) // Session Present Flag(0)
|
.read(0x00) // Session Present Flag(0)
|
||||||
|
|
||||||
//Connect Return code
|
// Connect Return code
|
||||||
.read(0x00) // Connection Accepted
|
.read(0x00) // Connection Accepted
|
||||||
|
|
||||||
//DISCONNECT
|
// DISCONNECT
|
||||||
.write(0xE0) // MQTT Control Packet type(14)
|
.write(0xE0) // MQTT Control Packet type(14)
|
||||||
.write(0x00) // Remaining Length
|
.write(0x00) // Remaining Length
|
||||||
.closed(1000);
|
.closed(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 3000)
|
@Test(timeout = 3000)
|
||||||
public void testConnectWithInvalidWillQoS() throws Exception {
|
public void testConnectWithInvalidWillQoS() throws Exception {
|
||||||
RawClient.connect("127.0.0.1", 1883).isConnected()
|
RawClient.connect("127.0.0.1", 1883).isConnected()
|
||||||
//CONNECT
|
// CONNECT
|
||||||
.write(0x10) //MQTT Control Packet type(1)
|
.write(0x10) // MQTT Control Packet type(1)
|
||||||
.write(0x13) // Remaining Length
|
.write(0x13) // Remaining Length
|
||||||
.write(0x00, 0x04) // Protocol Name Length
|
.write(0x00, 0x04) // Protocol Name Length
|
||||||
.write("MQTT") // Protocol Name
|
.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)
|
.write(0x04) // The value of the Protocol Level field for the version 3.1.1 of the
|
||||||
|
// protocol is 4 (0x04)
|
||||||
|
|
||||||
//Connect Flags
|
// Connect Flags
|
||||||
//User Name Flag(0)
|
// User Name Flag(0)
|
||||||
//Password Flag(0)
|
// Password Flag(0)
|
||||||
//Will Retain(0)
|
// Will Retain(0)
|
||||||
//Will QoS(11) - It MUST NOT be 3 (0x03). Server should close the connection.
|
// Will QoS(11) - It MUST NOT be 3 (0x03). Server should close the connection.
|
||||||
//Will Flag(1)
|
// Will Flag(1)
|
||||||
//Clean Session(1)
|
// Clean Session(1)
|
||||||
.write(0x1E) // Reserved(0)
|
.write(0x1E) // Reserved(0)
|
||||||
.write(0x00, 0x00) // Keep Alive
|
.write(0x00, 0x00) // Keep Alive
|
||||||
|
|
||||||
// Payload
|
// Payload
|
||||||
.write(0x00, 0x07) // Client Identifier Length
|
.write(0x00, 0x07) // Client Identifier Length
|
||||||
.write("client1") // Client Identifier
|
.write("client1") // Client Identifier
|
||||||
.flush()
|
.flush()
|
||||||
|
|
||||||
.closed(1000);
|
.closed(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Need to validate the test case.")
|
@Ignore("Need to validate the test case.")
|
||||||
@Test(timeout = 15000)
|
@Test(timeout = 15000)
|
||||||
public void testConnectWithWillFlagSetToZeroButWillQoSFlagSetToNonZero() throws Exception {
|
public void testConnectWithWillFlagSetToZeroButWillQoSFlagSetToNonZero() throws Exception {
|
||||||
RawClient.connect("127.0.0.1", 1883).isConnected()
|
RawClient.connect("127.0.0.1", 1883).isConnected()
|
||||||
// CONNECT
|
// CONNECT
|
||||||
.write(0x10) // MQTT Control Packet type(1)
|
.write(0x10) // MQTT Control Packet type(1)
|
||||||
.write(0x12) // Remaining Length
|
.write(0x12) // Remaining Length
|
||||||
.write(0x00, 0x04) // Protocol Name Length
|
.write(0x00, 0x04) // Protocol Name Length
|
||||||
.write("MQTT") // Protocol Name
|
.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)
|
.write(0x04) // The value of the Protocol Level field for the version 3.1.1 of the
|
||||||
|
// protocol is 4 (0x04)
|
||||||
|
|
||||||
// Connect Flags
|
// Connect Flags
|
||||||
// User Name Flag(0)
|
// User Name Flag(0)
|
||||||
// Password Flag(0)
|
// Password Flag(0)
|
||||||
// Will Retain(0)
|
// Will Retain(0)
|
||||||
// Will QoS(01) - If the Will Flag is set to 0, then the Will QoS MUST be set to 0
|
// Will QoS(01) - If the Will Flag is set to 0, then the Will QoS MUST be set to 0
|
||||||
// Will Flag(0)
|
// Will Flag(0)
|
||||||
//Clean Session(1)
|
// Clean Session(1)
|
||||||
.write(0x0A) // Reserved(0)
|
.write(0x0A) // Reserved(0)
|
||||||
|
|
||||||
.write(0x00, 0x00) // Keep Alive
|
.write(0x00, 0x00) // Keep Alive
|
||||||
|
|
||||||
// Payload
|
// Payload
|
||||||
.write(0x00, 0x07) // Client Identifier Length
|
.write(0x00, 0x07) // Client Identifier Length
|
||||||
.write("client1") //Client Identifier
|
.write("client1") // Client Identifier
|
||||||
|
|
||||||
//Server MUST close the Network Connection due to invalid Will QoS flag
|
// Server MUST close the Network Connection due to invalid Will QoS flag
|
||||||
.closed();
|
.closed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user