Search in sources :

Example 26 with DeviceTwin

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

the class DeviceTwinTest method replaceTagsThrowsIfDeviceIDIsEmpty.

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

        {
            mockedDevice.getDeviceId();
            result = "";
        }
    };
    //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 27 with DeviceTwin

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

the class DeviceTwinTest method updateTwinThrowsIfDeviceIDIsEmpty.

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

        {
            mockedDevice.getDeviceId();
            result = "";
        }
    };
    //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 28 with DeviceTwin

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

the class DeviceTwinTest method replaceDesiredPropertiesThrowsIfDeviceIDIsEmpty.

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

        {
            mockedDevice.getDeviceId();
            result = "";
        }
    };
    //act
    testTwin.replaceDesiredProperties(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 29 with DeviceTwin

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

the class DeviceTwinTest method updateTwinThrowsIfJsonIsNull.

/*
     **Tests_SRS_DEVICETWIN_25_046: [** The function shall throw IOException if updateTwin Api call returned an empty or null json**]**
     */
@Test(expected = IOException.class)
public void updateTwinThrowsIfJsonIsNull() throws Exception {
    //arrange
    final String connectionString = "testString";
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    Map<String, Object> testMap = new HashMap<>();
    testMap.put("TestKey", "TestValue");
    new NonStrictExpectations() {

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

        {
            mockedConnectionString.getUrlTwin(anyString);
            times = 1;
            mockedTwinParser.updateTwin((Map<String, Object>) any, null, (Map<String, Object>) any);
            times = 1;
        }
    };
}
Also used : HashMap(java.util.HashMap) 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 30 with DeviceTwin

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

the class DeviceTwinTest method replaceDesiredPropertiesThrowsIfJsonIsNull.

/*
     **Tests_SRS_DEVICETWIN_25_045: [** If resetDesiredProperty call returns null or empty string then this method shall throw IOException**]**
     */
@Test(expected = IOException.class)
public void replaceDesiredPropertiesThrowsIfJsonIsNull() 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 = null;
        }
    };
    //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)

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