use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin in project azure-iot-sdk-java by Azure.
the class MqttIotHubConnectionTest method openEstablishesConnectionUsingCorrectConfig.
// Tests_SRS_MQTTIOTHUBCONNECTION_15_004: [The function shall establish an MQTT connection with an IoT Hub
// using the provided host name, user name, device ID, and sas token.]
@Test
public void openEstablishesConnectionUsingCorrectConfig() throws IOException {
baseExpectations();
openExpectations();
MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
connection.open();
final String actualIotHubUserName = Deencapsulation.getField(connection, "iotHubUserName");
String clientIdentifier = "DeviceClientType=" + URLEncoder.encode(TransportUtils.JAVA_DEVICE_CLIENT_IDENTIFIER + TransportUtils.CLIENT_VERSION, "UTF-8");
assertEquals(iotHubHostName + "/" + deviceId + "/" + API_VERSION + "/" + clientIdentifier, actualIotHubUserName);
String expectedSasToken = mockToken.toString();
String actualUserPassword = Deencapsulation.getField(connection, "iotHubUserPassword");
assertEquals(expectedSasToken, actualUserPassword);
State expectedState = State.OPEN;
State actualState = Deencapsulation.getField(connection, "state");
assertEquals(expectedState, actualState);
new Verifications() {
{
new MqttDeviceMethod();
times = 1;
new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
mockDeviceMessaging.start();
times = 1;
new MqttDeviceTwin();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin 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;
}
};
}
Aggregations