use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method constructorThrowsOnEmptyCS.
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsOnEmptyCS() throws Exception {
//arrange
final String connectionString = "";
//act
DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method getTwinSucceeds.
/*
**Tests_SRS_DEVICETWIN_25_005: [** The function shall build the URL for this operation by calling getUrlTwin **]**
**Tests_SRS_DEVICETWIN_25_006: [** The function shall create a new SAS token **]**
**Tests_SRS_DEVICETWIN_25_007: [** The function shall create a new HttpRequest with http method as Get **]**
**Tests_SRS_DEVICETWIN_25_008: [** The function shall set the following HTTP headers specified in the IotHub DeviceTwin doc.
1. Key as authorization with value as sastoken
2. Key as request id with a new string value for every request
3. Key as User-Agent with value specified by the clientIdentifier and its version
4. Key as Accept with value as application/json
5. Key as Content-Type and value as application/json
6. Key as charset and value as utf-8
7. Key as If-Match and value as '*' **]**
**Tests_SRS_DEVICETWIN_25_009: [** The function shall send the created request and get the response **]**
**Tests_SRS_DEVICETWIN_25_011: [** The function shall deserialize the payload by calling updateTwin Api on the twin object **]**
**Tests_SRS_DEVICETWIN_25_012: [** The function shall set tags, desired property map, reported property map on the user device **]**
*/
@Test
public void getTwinSucceeds() throws Exception {
//arrange
final String connectionString = "testString";
DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
Map<String, Object> testMap = new HashMap<>();
new NonStrictExpectations() {
{
mockedDevice.getDeviceId();
result = "SomeDevID";
Deencapsulation.invoke(mockedDevice, "getTwinParser");
result = mockedTwinParser;
}
};
//act
testTwin.getTwin(mockedDevice);
//assert
new Verifications() {
{
mockedConnectionString.getUrlTwin(anyString);
times = 1;
mockedHttpRequest.setReadTimeoutMillis(anyInt);
times = 1;
mockedHttpRequest.setHeaderField(anyString, anyString);
times = 5;
mockedHttpRequest.send();
times = 1;
mockedTwinParser.updateTwin(anyString);
times = 1;
Deencapsulation.invoke(mockedDevice, "getTwinParser");
times = 4;
mockedTwinParser.getTagsMap();
times = 1;
Deencapsulation.invoke(mockedDevice, "setTags", testMap);
times = 1;
Deencapsulation.invoke(mockedDevice, "setDesiredProperties", testMap);
times = 1;
Deencapsulation.invoke(mockedDevice, "setReportedProperties", testMap);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method replaceDesiredPropertiesThrowsIfDeviceIDIsNull.
@Test(expected = IllegalArgumentException.class)
public void replaceDesiredPropertiesThrowsIfDeviceIDIsNull() throws Exception {
//arrange
final String connectionString = "testString";
DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
new NonStrictExpectations() {
{
mockedDevice.getDeviceId();
result = null;
}
};
//act
testTwin.replaceDesiredProperties(mockedDevice);
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method updateTwinDoesNotThrowsIfOnlyDesiredHasValue.
@Test
public void updateTwinDoesNotThrowsIfOnlyDesiredHasValue() 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 = null;
mockedTwinParser.updateTwin((Map<String, Object>) any, null, (Map<String, Object>) any);
result = "SomeJsonString";
}
};
//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;
mockedHttpRequest.setReadTimeoutMillis(anyInt);
times = 1;
mockedHttpRequest.setHeaderField(anyString, anyString);
times = 5;
mockedHttpRequest.send();
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method replaceTagsThrowsJsonIsEmpty.
@Test(expected = IOException.class)
public void replaceTagsThrowsJsonIsEmpty() throws Exception {
//arrange
final String connectionString = "testString";
DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
new NonStrictExpectations() {
{
mockedDevice.getDeviceId();
result = "SomeDevID";
mockedTwinParser.resetTags((Map<String, Object>) any);
result = "";
}
};
//act
testTwin.replaceTags(mockedDevice);
//assert
new Verifications() {
{
mockedConnectionString.getUrlTwinTags(anyString);
times = 1;
mockedTwinParser.resetTags((Map<String, Object>) any);
times = 1;
}
};
}
Aggregations