Files
IM-server-new/broker/src/test/java/io/moquette/spi/impl/NettyChannelAssertions.java
T
Kevin Berendsen bc6525e431 MQTT3.1.3-6 stated that the client can connect without giving up an client identifier. However, the broker should generate one for the client id as of the client gave the identifier to broker. The client will now disconnect if the client hasn't given up an identifier with clean session set to 0. Done this regarding issue #190
NettyChannelAssertions class has been modified so you could add a message to the assertion.

Unit tests have been added to test the modified processConnect() method.

The server can allow zero byte client identifiers through moquette configuration.
2016-08-07 13:17:41 +02:00

58 lines
2.0 KiB
Java

/*
* Copyright (c) 2012-2015 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.spi.impl;
import io.moquette.parser.proto.messages.ConnAckMessage;
import io.moquette.parser.proto.messages.SubAckMessage;
import io.netty.channel.embedded.EmbeddedChannel;
import static io.moquette.parser.proto.messages.ConnAckMessage.CONNECTION_ACCEPTED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Some useful assertions used by Netty's EmbeddedChannel in tests.
*/
class NettyChannelAssertions {
static void assertEqualsConnAck(byte expectedCode, Object connAck) {
assertEqualsConnAck(null, expectedCode, connAck);
}
static void assertEqualsConnAck(String msg, byte expectedCode, Object connAck) {
assertTrue("connAck is not an instance of ConnAckMessage", connAck instanceof ConnAckMessage);
ConnAckMessage connAckMsg = (ConnAckMessage) connAck;
if(msg == null)
assertEquals(expectedCode, connAckMsg.getReturnCode());
else
assertEquals(msg, expectedCode, connAckMsg.getReturnCode());
}
static void assertConnAckAccepted(EmbeddedChannel channel) {
channel.flush();
assertEqualsConnAck(CONNECTION_ACCEPTED, channel.readOutbound());
}
static void assertEqualsSubAck(/*byte expectedCode,*/ Object subAck) {
assertTrue(subAck instanceof SubAckMessage);
//SubAckMessage connAckMsg = (SubAckMessage) connAck;
//assertEquals(expectedCode, connAckMsg.getReturnCode());
}
}