use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method sendEventFailsIfConnectionClosed.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_013: [If the MQTT connection is closed,
// the function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void sendEventFailsIfConnectionClosed(@Mocked final Message mockMsg) throws IOException {
baseExpectations();
final byte[] msgBody = { 0x61, 0x62, 0x63 };
new NonStrictExpectations() {
{
mockMsg.getBytes();
result = msgBody;
}
};
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
connection.close();
connection.sendEvent(mockMsg);
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method closeDoesNothingIfConnectionNotYetOpened.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_007: [If the MQTT connection is closed, the function shall do nothing.]
@Test
public void closeDoesNothingIfConnectionNotYetOpened() throws IOException {
baseExpectations();
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.close();
State expectedState = State.CLOSED;
State actualState = Deencapsulation.getField(connection, "state");
assertEquals(expectedState, actualState);
new Verifications() {
{
mockDeviceMessaging.stop();
times = 0;
mockDeviceMethods.stop();
times = 0;
mockDeviceTwin.stop();
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method closeDoesNothingIfConnectionAlreadyClosed.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_007: [If the MQTT connection is closed, the function shall do nothing.]
@Test
public void closeDoesNothingIfConnectionAlreadyClosed() throws IOException {
baseExpectations();
openExpectations();
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
connection.close();
connection.close();
new Verifications() {
{
mockDeviceMessaging.stop();
maxTimes = 1;
mockDeviceMethods.stop();
maxTimes = 1;
mockDeviceTwin.stop();
maxTimes = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method closeClosesMqttConnection.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_005: [The function shall close the MQTT connection.]
@Test
public void closeClosesMqttConnection() throws IOException {
baseExpectations();
openExpectations();
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
connection.close();
State expectedState = State.CLOSED;
State actualState = Deencapsulation.getField(connection, "state");
assertEquals(expectedState, actualState);
MqttDeviceMethod actualDeviceMethods = Deencapsulation.getField(connection, "deviceMethod");
assertNull(actualDeviceMethods);
MqttDeviceTwin actualDeviceTwin = Deencapsulation.getField(connection, "deviceTwin");
assertNull(actualDeviceTwin);
MqttDeviceTwin actualDeviceMessaging = Deencapsulation.getField(connection, "deviceMessaging");
assertNull(actualDeviceMessaging);
new Verifications() {
{
mockDeviceMessaging.stop();
times = 1;
mockDeviceMethods.stop();
times = 1;
mockDeviceTwin.stop();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method receiveDeviceTwinMessageSucceeds.
@Test
public void receiveDeviceTwinMessageSucceeds() throws IOException {
baseExpectations();
openExpectations();
final byte[] expectedMessageBody = { 0x61, 0x62, 0x63 };
new NonStrictExpectations() {
{
mockDeviceMethods.receive();
result = null;
mockDeviceTwin.receive();
result = new DeviceTwinMessage(expectedMessageBody);
}
};
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
Message message = connection.receiveMessage();
byte[] actualMessageBody = message.getBytes();
assertNotNull(message);
for (int i = 0; i < expectedMessageBody.length; i++) {
assertEquals(expectedMessageBody[i], actualMessageBody[i]);
}
new Verifications() {
{
mockDeviceMethods.receive();
times = 1;
mockDeviceMessaging.receive();
times = 0;
}
};
}
Aggregations