Search in sources :

Example 6 with State

use of com.microsoft.azure.sdk.iot.device.transport.State in project azure-iot-sdk-java by Azure.

the class AmqpsTransportTest method closeSetsStateToClosed.

// Tests_SRS_AMQPSTRANSPORT_15_009: [The function shall set the transport state to CLOSED.]
@Test
public void closeSetsStateToClosed() throws IOException {
    AmqpsTransport transport = new AmqpsTransport(mockConfig, false);
    transport.open();
    transport.close();
    State actualState = Deencapsulation.getField(transport, "state");
    Assert.assertEquals(State.CLOSED, actualState);
}
Also used : AmqpsTransport(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport) State(com.microsoft.azure.sdk.iot.device.transport.State) Test(org.junit.Test)

Example 7 with State

use of com.microsoft.azure.sdk.iot.device.transport.State 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 8 with State

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

Example 9 with State

use of com.microsoft.azure.sdk.iot.device.transport.State 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

State (com.microsoft.azure.sdk.iot.device.transport.State)9 Test (org.junit.Test)9 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)4 AmqpsTransport (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport)3 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)3 Verifications (mockit.Verifications)3 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)2 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)2 DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)1 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)1 FlowController (org.apache.qpid.proton.reactor.FlowController)1 Handshaker (org.apache.qpid.proton.reactor.Handshaker)1