Search in sources :

Example 6 with DeviceTwin

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method replaceDesiredPropertiesThrowsIfJsonIsEmpty.

@Test(expected = IOException.class)
public void replaceDesiredPropertiesThrowsIfJsonIsEmpty() throws Exception {
    //arrange
    final String connectionString = "testString";
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = "SomeDevID";
            Deencapsulation.invoke(mockedDevice, "getTwinParser");
            result = mockedTwinParser;
            mockedTwinParser.resetDesiredProperty((Map<String, Object>) any);
            result = "";
        }
    };
    //act
    testTwin.replaceDesiredProperties(mockedDevice);
    //assert
    new Verifications() {

        {
            mockedConnectionString.getUrlTwinDesired(anyString);
            times = 1;
            mockedTwinParser.resetDesiredProperty((Map<String, Object>) any);
            times = 1;
        }
    };
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 7 with DeviceTwin

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method updateTwinThrowsIfDeviceIDIsNull.

@Test(expected = IllegalArgumentException.class)
public void updateTwinThrowsIfDeviceIDIsNull() throws Exception {
    //arrange
    final String connectionString = "testString";
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = null;
        }
    };
    //act
    testTwin.updateTwin(mockedDevice);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) NonStrictExpectations(mockit.NonStrictExpectations) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 8 with DeviceTwin

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method replaceTagsThrowsIfDeviceIDIsNull.

@Test(expected = IllegalArgumentException.class)
public void replaceTagsThrowsIfDeviceIDIsNull() throws Exception {
    //arrange
    final String connectionString = "testString";
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = null;
        }
    };
    //act
    testTwin.replaceTags(mockedDevice);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) NonStrictExpectations(mockit.NonStrictExpectations) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 9 with DeviceTwin

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method getTwinThrowsOnNullDevice.

/*
    **Tests_SRS_DEVICETWIN_25_004: [** The function shall throw IllegalArgumentException if the input device is null or if deviceId is null or empty **]**
     */
@Test(expected = IllegalArgumentException.class)
public void getTwinThrowsOnNullDevice() throws Exception {
    //arrange
    final String connectionString = "testString";
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    //act
    testTwin.getTwin(null);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 10 with DeviceTwin

use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method constructorThrowsOnNullCS.

/*
    **Tests_SRS_DEVICETWIN_25_001: [** The constructor shall throw IllegalArgumentException if the input string is null or empty **]**
     */
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnNullCS() throws Exception {
    //arrange
    final String connectionString = null;
    //act
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Aggregations

DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)30 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)29 Test (org.junit.Test)29 NonStrictExpectations (mockit.NonStrictExpectations)22 Verifications (mockit.Verifications)10 HashMap (java.util.HashMap)8 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)1 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1