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;
}
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;
}
};
}
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);
}
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());
}
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"));
}
Aggregations