Search in sources :

Example 11 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobClient method getParserFromDevice.

private TwinState getParserFromDevice(DeviceTwinDevice device) {
    TwinCollection tags = null;
    TwinCollection desired = null;
    TwinCollection reported = null;
    if (device.getTags() != null) {
        tags = setToMap(device.getTags());
    }
    if (device.getDesiredProperties() != null) {
        desired = setToMap(device.getDesiredProperties());
    }
    if (device.getReportedProperties() != null) {
        reported = setToMap(device.getReportedProperties());
    }
    TwinState twinState = new TwinState(tags, desired, reported);
    if (device.getDeviceId() != null) {
        twinState.setDeviceId(device.getDeviceId());
    }
    if (device.getETag() == null) {
        twinState.setETag("*");
    } else {
        twinState.setETag(device.getETag());
    }
    return twinState;
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState)

Example 12 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method updateTwinDoesNotThrowsIfOnlyTagsHasValue.

@Test
public void updateTwinDoesNotThrowsIfOnlyTagsHasValue(@Mocked DeviceTwinDevice mockedDevice) throws Exception {
    // arrange
    final String connectionString = "testString";
    constructorExpectations(connectionString);
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    TwinCollection testMap = new TwinCollection();
    testMap.putFinal("TestKey", "TestValue");
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = "SomeDevID";
            Deencapsulation.invoke(mockedDevice, "getDesiredMap");
            result = null;
            Deencapsulation.invoke(mockedDevice, "getTagsMap");
            result = testMap;
            new TwinState((TwinCollection) any, null, null);
            result = mockedTwinState;
            mockedTwinState.toJsonElement().toString();
            result = "SomeJsonString";
        }
    };
    // act
    testTwin.updateTwin(mockedDevice);
    // assert
    new Verifications() {

        {
            IotHubConnectionString.getUrlTwin(anyString, anyString);
            times = 1;
            mockedHttpRequest.setReadTimeoutMillis(anyInt);
            times = 1;
            mockedHttpRequest.setHeaderField(anyString, anyString);
            times = 6;
            mockedHttpRequest.send();
            times = 1;
        }
    };
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) 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 13 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method updateTwinThrowsVerificationThrows.

@Test(expected = IotHubException.class)
public void updateTwinThrowsVerificationThrows(@Mocked DeviceTwinDevice mockedDevice) throws Exception {
    // arrange
    final String connectionString = "testString";
    constructorExpectations(connectionString);
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    TwinCollection testMap = new TwinCollection();
    testMap.putFinal("TestKey", "TestValue");
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = "SomeDevID";
            Deencapsulation.invoke(mockedDevice, "getDesiredMap");
            result = testMap;
            Deencapsulation.invoke(mockedDevice, "getTagsMap");
            result = testMap;
            new TwinState((TwinCollection) any, (TwinCollection) any, null);
            result = mockedTwinState;
            mockedTwinState.toJsonElement().toString();
            result = "SomeJsonString";
            IotHubExceptionManager.httpResponseVerification(mockedHttpResponse);
            result = new IotHubException();
        }
    };
    // act
    testTwin.updateTwin(mockedDevice);
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) NonStrictExpectations(mockit.NonStrictExpectations) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 14 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobsParserTest method ConstructorTwinStoreUpdateTwinSucceed.

/* Tests_SRS_JOBSPARSER_21_009: [The constructor shall store the JsonElement for the updateTwin.] */
@Test
public void ConstructorTwinStoreUpdateTwinSucceed() {
    // Arrange
    String jobId = "testJobId";
    String queryCondition = "testDeviceId";
    Date startTime = new Date();
    long maxExecutionTimeInSeconds = 10L;
    TwinState twinState = makeTwinSample();
    // Act
    JobsParser jobsParser = new JobsParser(jobId, twinState, queryCondition, startTime, maxExecutionTimeInSeconds);
    // Assert
    Helpers.assertJson(twinState.toJsonElement().toString(), Deencapsulation.getField(jobsParser, "updateTwin").toString());
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Example 15 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobsParserTest method ConstructorTwinSetCloudToDeviceMethodAsNullSucceed.

/* Tests_SRS_JOBSPARSER_21_012: [The constructor shall set the cloudToDeviceMethod as null.] */
@Test
public void ConstructorTwinSetCloudToDeviceMethodAsNullSucceed() {
    // Arrange
    String jobId = "testJobId";
    String queryCondition = "testDeviceId";
    Date startTime = new Date();
    long maxExecutionTimeInSeconds = 10L;
    TwinState twinState = makeTwinSample();
    // Act
    JobsParser jobsParser = new JobsParser(jobId, twinState, queryCondition, startTime, maxExecutionTimeInSeconds);
    // Assert
    assertNull(Deencapsulation.getField(jobsParser, "cloudToDeviceMethod"));
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Aggregations

TwinState (com.microsoft.azure.sdk.iot.deps.twin.TwinState)36 Test (org.junit.Test)31 Date (java.util.Date)27 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)15 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)13 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)12 NonStrictExpectations (mockit.NonStrictExpectations)12 JobsParser (com.microsoft.azure.sdk.iot.deps.serializer.JobsParser)8 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)8 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)8 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)8 HashSet (java.util.HashSet)8 Expectations (mockit.Expectations)5 Verifications (mockit.Verifications)5 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)4 Proxy (java.net.Proxy)3 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)2 HttpResponse (com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse)2 URL (java.net.URL)2 SimpleDateFormat (java.text.SimpleDateFormat)2