use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobsParserTest method ConstructorEmptyJobIdThrows.
/* 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 ConstructorEmptyJobIdThrows() {
// Arrange
String jobId = "";
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 toJsonTwinSucceed.
/* Tests_SRS_JOBSPARSER_21_013: [The toJson shall return a String with a json that represents the content of this class.] */
@Test
public void toJsonTwinSucceed() {
// Arrange
String jobId = "testJobId";
String queryCondition = "testDeviceId";
Date startTime = new Date();
long maxExecutionTimeInSeconds = 10L;
TwinState twinState = makeTwinSample();
JobsParser jobsParser = new JobsParser(jobId, twinState, queryCondition, startTime, maxExecutionTimeInSeconds);
String expectedJson = "{" + "\"jobId\":\"" + jobId + "\"," + "\"type\":\"scheduleUpdateTwin\"," + "\"cloudToDeviceMethod\":null," + "\"updateTwin\":" + twinState.toJsonElement().toString() + "," + "\"queryCondition\":\"" + queryCondition + "\"," + "\"startTime\":\"" + Helpers.formatUTC(startTime) + "\"," + "\"maxExecutionTimeInSeconds\":" + maxExecutionTimeInSeconds + "}";
// Act
String json = jobsParser.toJson();
// Assert
Helpers.assertJson(json, expectedJson);
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobsParserTest method ConstructorTwinCommonParsSucceed.
/* Tests_SRS_JOBSPARSER_21_007: [The constructor shall evaluate and store the commons parameters using the internal function commonFields.] */
/* Tests_SRS_JOBSPARSER_21_014: [The commonFields shall store the jobId, queryCondition, and maxExecutionTimeInSeconds.] */
@Test
public void ConstructorTwinCommonParsSucceed() {
// 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
assertEquals(jobId, Deencapsulation.getField(jobsParser, "jobId"));
assertEquals(queryCondition, Deencapsulation.getField(jobsParser, "queryCondition"));
assertEquals(maxExecutionTimeInSeconds, Deencapsulation.getField(jobsParser, "maxExecutionTimeInSeconds"));
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class JobsParserTest method ConstructorInvalidMaxExecutionTimeInSecondsThrows.
/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_017: [If the maxExecutionTimeInSeconds is negative, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorInvalidMaxExecutionTimeInSecondsThrows() {
// 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);
}
use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.
the class DeviceTwin method getTwinOperation.
private void getTwinOperation(URL url, DeviceTwinDevice device) throws IotHubException, IOException {
ProxyOptions proxyOptions = options.getProxyOptions();
Proxy proxy = proxyOptions != null ? proxyOptions.getProxy() : null;
HttpResponse response = DeviceOperations.request(this.getAuthenticationToken(), url, HttpMethod.GET, new byte[0], String.valueOf(requestId++), options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
String twin = new String(response.getBody(), StandardCharsets.UTF_8);
TwinState twinState = TwinState.createFromTwinJson(twin);
device.setVersion(twinState.getVersion());
device.setModelId(twinState.getModelId());
device.setETag(twinState.getETag());
device.setTags(twinState.getTags());
device.setDesiredProperties(twinState.getDesiredProperty());
device.setReportedProperties(twinState.getReportedProperty());
device.setCapabilities(twinState.getCapabilities());
device.setConfigurations(twinState.getConfigurations());
device.setConnectionState(twinState.getConnectionState());
}
Aggregations