Search in sources :

Example 41 with MqttDeviceTwin

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;
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) State(com.microsoft.azure.sdk.iot.device.transport.State) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 42 with MqttDeviceTwin

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;
        }
    };
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) State(com.microsoft.azure.sdk.iot.device.transport.State) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) Verifications(mockit.Verifications) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Aggregations

MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)42 Test (org.junit.Test)42 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)23 DeviceTwinMessage (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceTwinMessage)17 DeviceOperations (com.microsoft.azure.sdk.iot.device.DeviceTwin.DeviceOperations)8 HashMap (java.util.HashMap)8 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)3 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)3 Verifications (mockit.Verifications)3 State (com.microsoft.azure.sdk.iot.device.transport.State)2 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)2 IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)1 IOException (java.io.IOException)1 NonStrictExpectations (mockit.NonStrictExpectations)1