use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobsParserTest method ConstructorInvalidJobIdThrows.
/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_015: [If the jobId is null, empty, or invalid, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorInvalidJobIdThrows() {
// Arrange
String jobId = "test\u1234JobId";
String queryCondition = "testDeviceId";
Date startTime = new Date();
long maxExecutionTimeInSeconds = 10L;
TwinState twinState = makeTwinSample();
// Act
JobsParser jobsParser = new JobsParser(jobId, twinState, queryCondition, startTime, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobsParserTest method ConstructorTwinNullJobIdThrows.
/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_015: [If the jobId is null, empty, or invalid, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorTwinNullJobIdThrows() {
// Arrange
String jobId = null;
String queryCondition = "testDeviceId";
Date startTime = new Date();
long maxExecutionTimeInSeconds = 10L;
TwinState twinState = makeTwinSample();
// Act
JobsParser jobsParser = new JobsParser(jobId, twinState, queryCondition, startTime, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobsParserTest method ConstructorNullStartTimeThrows.
/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_019: [If the startTime is null, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorNullStartTimeThrows() {
// Arrange
String jobId = "testJobId";
String queryCondition = "testDeviceId";
Date startTime = null;
long maxExecutionTimeInSeconds = 10L;
TwinState twinState = makeTwinSample();
// Act
JobsParser jobsParser = new JobsParser(jobId, twinState, queryCondition, startTime, maxExecutionTimeInSeconds);
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class DeviceTwinTest method updateTwinDoesNotThrowsIfOnlyDesiredHasValue.
@Test
public void updateTwinDoesNotThrowsIfOnlyDesiredHasValue(@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 Expectations() {
{
mockedDevice.getDeviceId();
result = "SomeDevID";
Deencapsulation.invoke(mockedDevice, "getDesiredMap");
result = testMap;
Deencapsulation.invoke(mockedDevice, "getTagsMap");
result = null;
new TwinState(null, (TwinCollection) any, 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 updateTwinSucceeds.
/*
**Tests_SRS_DEVICETWIN_25_030: [** The function shall build the URL for this operation by calling getUrlTwinDesired **]**
**Tests_SRS_DEVICETWIN_25_031: [** The function shall serialize the desired properties map by calling resetDesiredProperty Api on the twin object for the device provided by the user**]**
**Tests_SRS_DEVICETWIN_25_016: [** The function shall create a new SAS token **]**
**Tests_SRS_DEVICETWIN_25_017: [** The function shall create a new HttpRequest with http method as Patch **]**
**Tests_SRS_DEVICETWIN_25_018: [** 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_019: [** The function shall send the created request and get the response **]**
**Tests_SRS_DEVICETWIN_25_020: [** The function shall verify the response status and throw proper Exception **]**
*Tests_SRS_DEVICETWIN_25_036: [** The function shall verify the response status and throw proper Exception **]**
*/
@Test
public void updateTwinSucceeds(@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";
}
};
// 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;
}
};
}
Aggregations