Search in sources :

Example 31 with TwinState

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);
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Example 32 with TwinState

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);
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Example 33 with TwinState

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"));
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Example 34 with TwinState

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);
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Example 35 with TwinState

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());
}
Also used : Proxy(java.net.Proxy) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) ProxyOptions(com.microsoft.azure.sdk.iot.service.ProxyOptions) HttpResponse(com.microsoft.azure.sdk.iot.service.transport.http.HttpResponse) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString)

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