Search in sources :

Example 26 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobClientTest method scheduleUpdateTwinCreateJson.

/* Tests_SRS_JOBCLIENT_21_004: [The scheduleUpdateTwin shall create a json String that represent the twin job using the JobsParser class.] */
@Test
public void scheduleUpdateTwinCreateJson() throws IOException, IotHubException {
    // arrange
    final String connectionString = "testString";
    final String jobId = "validJobId";
    final String deviceId = "validDeviceId";
    final String queryCondition = "validQueryCondition";
    final DeviceTwinDevice updateTwin = mockedDeviceTwinDevice;
    final Date startTimeUtc = new Date();
    final long maxExecutionTimeInSeconds = 10;
    final String json = "validJson";
    Set<Pair> testTags = new HashSet<>();
    testTags.add(new Pair("testTag", "tagObject"));
    // assert
    new Expectations() {

        {
            IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
            result = mockedIotHubConnectionString;
            mockedDeviceTwinDevice.getTags();
            result = testTags;
            mockedDeviceTwinDevice.getDesiredProperties();
            result = null;
            mockedDeviceTwinDevice.getReportedProperties();
            result = null;
            new TwinState((TwinCollection) any, null, null);
            result = mockedTwinState;
            mockedDeviceTwinDevice.getDeviceId();
            result = deviceId;
            mockedDeviceTwinDevice.getETag();
            result = null;
            new JobsParser(jobId, mockedTwinState, queryCondition, startTimeUtc, maxExecutionTimeInSeconds);
            result = mockedJobsParser;
            mockedJobsParser.toJson();
            result = json;
            IotHubConnectionString.getUrlJobs(anyString, jobId);
            result = mockedURL;
            DeviceOperations.request(anyString, mockedURL, HttpMethod.PUT, json.getBytes(StandardCharsets.UTF_8), (String) any, anyInt, anyInt, (Proxy) any);
            result = mockedHttpResponse;
            Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, (byte[]) any);
            result = mockedJobResult;
        }
    };
    JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
    // act
    JobResult jobResult = testJobClient.scheduleUpdateTwin(jobId, queryCondition, updateTwin, startTimeUtc, maxExecutionTimeInSeconds);
}
Also used : Expectations(mockit.Expectations) NonStrictExpectations(mockit.NonStrictExpectations) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) JobsParser(com.microsoft.azure.sdk.iot.deps.serializer.JobsParser) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Date(java.util.Date) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobClientTest method scheduleUpdateTwinCreateJsonWithEtag.

/* Tests_SRS_JOBCLIENT_21_004: [The scheduleUpdateTwin shall create a json String that represent the twin job using the JobsParser class.] */
@Test
public void scheduleUpdateTwinCreateJsonWithEtag() throws IOException, IotHubException {
    // arrange
    final String connectionString = "testString";
    final String jobId = "validJobId";
    final String deviceId = "validDeviceId";
    final String queryCondition = "validQueryCondition";
    final DeviceTwinDevice updateTwin = mockedDeviceTwinDevice;
    final Date startTimeUtc = new Date();
    final long maxExecutionTimeInSeconds = 10;
    final String json = "validJson";
    Set<Pair> testTags = new HashSet<>();
    testTags.add(new Pair("testTag", "tagObject"));
    new Expectations() {

        {
            IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
            result = mockedIotHubConnectionString;
            mockedDeviceTwinDevice.getTags();
            result = testTags;
            mockedDeviceTwinDevice.getDesiredProperties();
            result = null;
            mockedDeviceTwinDevice.getReportedProperties();
            result = null;
            new TwinState((TwinCollection) any, null, null);
            result = mockedTwinState;
            mockedDeviceTwinDevice.getDeviceId();
            result = deviceId;
            mockedDeviceTwinDevice.getETag();
            result = "1234";
            new JobsParser(jobId, mockedTwinState, queryCondition, startTimeUtc, maxExecutionTimeInSeconds);
            result = mockedJobsParser;
            mockedJobsParser.toJson();
            result = json;
            IotHubConnectionString.getUrlJobs(anyString, jobId);
            result = mockedURL;
            DeviceOperations.request(anyString, mockedURL, HttpMethod.PUT, json.getBytes(StandardCharsets.UTF_8), (String) any, anyInt, anyInt, (Proxy) any);
            result = mockedHttpResponse;
            Deencapsulation.newInstance(JobResult.class, new Class[] { byte[].class }, (byte[]) any);
            result = mockedJobResult;
        }
    };
    JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
    // act
    JobResult jobResult = testJobClient.scheduleUpdateTwin(jobId, queryCondition, updateTwin, startTimeUtc, maxExecutionTimeInSeconds);
}
Also used : Expectations(mockit.Expectations) NonStrictExpectations(mockit.NonStrictExpectations) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) JobsParser(com.microsoft.azure.sdk.iot.deps.serializer.JobsParser) JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Date(java.util.Date) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobsParserTest method ConstructorNullUpdateTwinThrows.

/* Tests_SRS_JOBSPARSER_21_010: [If the updateTwin is null, the constructor shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorNullUpdateTwinThrows() {
    // Arrange
    String jobId = "testJobId";
    String queryCondition = "testDeviceId";
    Date startTime = new Date();
    long maxExecutionTimeInSeconds = 10L;
    TwinState twinState = null;
    // 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 29 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobsParserTest method constructorTwinSetJobTypeSucceed.

/* Tests_SRS_JOBSPARSER_21_011: [The constructor shall set the jobType as scheduleUpdateTwin.] */
@Test
public void constructorTwinSetJobTypeSucceed() {
    // 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("scheduleUpdateTwin", Deencapsulation.getField(jobsParser, "jobType"));
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

Example 30 with TwinState

use of com.microsoft.azure.sdk.iot.deps.twin.TwinState in project azure-iot-sdk-java by Azure.

the class JobsParserTest method ConstructorTwinFormatStartTimeSucceed.

/* Tests_SRS_JOBSPARSER_21_007: [The constructor shall evaluate and store the commons parameters using the internal function commonFields.] */
/* Tests_SRS_JOBSPARSER_21_018: [The commonFields shall format startTime as a String and store it.] */
@Test
public void ConstructorTwinFormatStartTimeSucceed() {
    // 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.assertDateWithError(startTime, (String) Deencapsulation.getField(jobsParser, "startTime"));
}
Also used : TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) Date(java.util.Date) Test(org.junit.Test)

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