Search in sources :

Example 1 with IotHubSasToken

use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnectionTest method openCreatesSasToken.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_008: [The function shall create a new sasToken valid for the duration
// specified in config to be used for the communication with IoTHub.]
@Test
public void openCreatesSasToken() throws IOException, InterruptedException {
    baseExpectations();
    AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    connection.open();
    new Verifications() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) Test(org.junit.Test)

Example 2 with IotHubSasToken

use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnectionTest method openTriggersProtonReactor.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_009: [The function shall trigger the Reactor (Proton) to begin running.]
@Test
public void openTriggersProtonReactor() throws IOException, InterruptedException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            new IotHubReactor((Reactor) any);
            result = mockIotHubReactor;
            mockIotHubReactor.run();
            mockOpenLock.waitLock(anyLong);
        }
    };
    AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "openLock", mockOpenLock);
    connection.open();
    new Verifications() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            times = 1;
            new IotHubReactor((Reactor) any);
            times = 1;
            mockOpenLock.waitLock(anyLong);
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IotHubReactor(com.microsoft.azure.sdk.iot.device.transport.amqps.IotHubReactor) Test(org.junit.Test)

Example 3 with IotHubSasToken

use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnectionTest method openDoesNothingIfTheConnectionIsAlreadyOpen.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_007: [If the AMQPS connection is already open, the function shall do nothing.]
@Test
public void openDoesNothingIfTheConnectionIsAlreadyOpen() throws IOException, InterruptedException {
    baseExpectations();
    AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "state", State.OPEN);
    connection.open();
    new Verifications() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            times = 0;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) Test(org.junit.Test)

Example 4 with IotHubSasToken

use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.

the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInTwin.

@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInTwin() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            result = mockToken;
            new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
            result = mockDeviceMessaging;
            new MqttDeviceMethod();
            result = mockDeviceMethods;
            new MqttDeviceTwin();
            result = new IOException(anyString);
        }
    };
    try {
        MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
        connection.open();
    } catch (Exception e) {
        new Verifications() {

            {
                mockDeviceMessaging.stop();
                times = 1;
                mockDeviceMethods.stop();
                times = 1;
            }
        };
        throw e;
    }
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IOException(java.io.IOException) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) IOException(java.io.IOException) MqttDeviceTwin(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin) Test(org.junit.Test)

Example 5 with IotHubSasToken

use of com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken in project azure-iot-sdk-java by Azure.

the class MqttIotHubConnectionTest method openThrowsIOExceptionIfConnectionFailsInMethod.

@Test(expected = IOException.class)
public void openThrowsIOExceptionIfConnectionFailsInMethod() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            new IotHubSasToken(mockConfig, anyLong);
            result = mockToken;
            new MqttMessaging(sslPrefix + iotHubHostName + sslPortSuffix, deviceId, anyString, anyString, mockIotHubSSLContext);
            result = mockDeviceMessaging;
            new MqttDeviceMethod();
            result = new IOException(anyString);
        }
    };
    try {
        MqttIotHubConnection connection = new MqttIotHubConnection(mockConfig);
        connection.open();
    } catch (Exception e) {
        new Verifications() {

            {
                mockDeviceMessaging.stop();
                times = 1;
            }
        };
        throw e;
    }
}
Also used : MqttIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection) MqttMessaging(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging) MqttDeviceMethod(com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod) IotHubSasToken(com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken) IOException(java.io.IOException) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IotHubSasToken (com.microsoft.azure.sdk.iot.device.auth.IotHubSasToken)19 Test (org.junit.Test)15 DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)9 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)9 NonStrictExpectations (mockit.NonStrictExpectations)6 IOException (java.io.IOException)5 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)3 MqttIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection)3 MqttMessaging (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttMessaging)3 URL (java.net.URL)3 Verifications (mockit.Verifications)3 MqttDeviceMethod (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceMethod)2 IotHubReactor (com.microsoft.azure.sdk.iot.device.transport.amqps.IotHubReactor)1 MqttDeviceTwin (com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttDeviceTwin)1