Search in sources :

Example 11 with Job

use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.

the class JobTest method scheduleUpdateTwinThrowOnInvalidMaxExecutionTimeInSeconds.

/* Tests_SRS_JOB_21_008: [If the maxExecutionTimeInSeconds is negative, the scheduleUpdateTwin shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleUpdateTwinThrowOnInvalidMaxExecutionTimeInSeconds() throws IOException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final DeviceTwinDevice deviceTwin = mockedDeviceTwinDevice;
    final Date now = new Date();
    final long maxExecutionTimeInSeconds = -100;
    final String connectionString = "validConnectionString";
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // act
    Deencapsulation.invoke(job, "scheduleUpdateTwin", new Class[] { String.class, DeviceTwinDevice.class, Date.class, Long.class }, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Date(java.util.Date) Test(org.junit.Test)

Example 12 with Job

use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.

the class DeviceMethodTest method scheduleDeviceMethodScheduleDeviceMethodSucceed.

/* Tests_SRS_DEVICEMETHOD_21_021: [The scheduleDeviceMethod shall invoke the scheduleDeviceMethod in the Job class with the received parameters.] */
@Test
public void scheduleDeviceMethodScheduleDeviceMethodSucceed(@Mocked Job mockedJob) throws IOException, IotHubException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final Date now = new Date();
    final long maxExecutionTimeInSeconds = 100;
    constructorExpectations();
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            mockedIotHubConnectionString.toString();
            result = STANDARD_CONNECTIONSTRING;
            Deencapsulation.newInstance(Job.class, new Class[] { String.class }, anyString);
            result = mockedJob;
        }
    };
    // act
    Job job = testMethod.scheduleDeviceMethod(queryCondition, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP, now, maxExecutionTimeInSeconds);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedJob, "scheduleDeviceMethod", queryCondition, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP, now, maxExecutionTimeInSeconds);
            times = 1;
        }
    };
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Verifications(mockit.Verifications) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) NonStrictExpectations(mockit.NonStrictExpectations) Date(java.util.Date) Test(org.junit.Test)

Example 13 with Job

use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.

the class DeviceMethodTest method scheduleDeviceMethodCreateJobSucceed.

/* Tests_SRS_DEVICEMETHOD_21_019: [The scheduleDeviceMethod shall create a new instance of the Job class.] */
/* Tests_SRS_DEVICEMETHOD_21_023: [The scheduleDeviceMethod shall return the created instance of the Job class.] */
@Test
public void scheduleDeviceMethodCreateJobSucceed(@Mocked Job mockedJob) throws IOException, IotHubException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final Date now = new Date();
    final long maxExecutionTimeInSeconds = 100;
    constructorExpectations();
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            mockedIotHubConnectionString.toString();
            result = STANDARD_CONNECTIONSTRING;
            Deencapsulation.newInstance(Job.class, new Class[] { String.class }, anyString);
            result = mockedJob;
            times = 1;
        }
    };
    // act
    Job job = testMethod.scheduleDeviceMethod(queryCondition, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP, now, maxExecutionTimeInSeconds);
    // assert
    assertNotNull(job);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) NonStrictExpectations(mockit.NonStrictExpectations) Date(java.util.Date) Test(org.junit.Test)

Example 14 with Job

use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.

the class DeviceTwinTest method schedule.

// Tests_SRS_DEVICETWIN_21_066: [The scheduleUpdateTwin shall invoke the scheduleUpdateTwin in the Job class with the received parameters ]
@Test
public void schedule(@Mocked Job mockedJob, @Mocked DeviceTwinDevice mockedDevice) throws IOException, IotHubException {
    // arrange
    final String connectionString = "testString";
    final String queryCondition = "validQueryCondition";
    final Date now = new Date();
    final long maxExecutionTimeInSeconds = 100;
    constructorExpectations(connectionString);
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    new NonStrictExpectations() {

        {
            mockedConnectionString.toString();
            result = connectionString;
            Deencapsulation.newInstance(Job.class, new Class[] { String.class }, anyString);
            result = mockedJob;
        }
    };
    // act
    Job job = testTwin.scheduleUpdateTwin(queryCondition, mockedDevice, now, maxExecutionTimeInSeconds);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedJob, "scheduleUpdateTwin", queryCondition, mockedDevice, now, maxExecutionTimeInSeconds);
            times = 1;
        }
    };
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Date(java.util.Date) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 15 with Job

use of com.microsoft.azure.sdk.iot.service.devicetwin.Job in project azure-iot-sdk-java by Azure.

the class JobTest method scheduleUpdateTwinThrowOnNullStartTimeUTC.

/* Tests_SRS_JOB_21_007: [If the startTimeUtc is null, the scheduleUpdateTwin shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleUpdateTwinThrowOnNullStartTimeUTC() throws IOException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final DeviceTwinDevice deviceTwin = mockedDeviceTwinDevice;
    final Date now = null;
    final long maxExecutionTimeInSeconds = 100;
    final String connectionString = "validConnectionString";
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // act
    Deencapsulation.invoke(job, "scheduleUpdateTwin", new Class[] { String.class, DeviceTwinDevice.class, Date.class, Long.class }, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Job (com.microsoft.azure.sdk.iot.service.devicetwin.Job)25 Test (org.junit.Test)23 Date (java.util.Date)19 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)6 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)4 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)4 NonStrictExpectations (mockit.NonStrictExpectations)4 IOException (java.io.IOException)3 DeviceMethod (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod)2 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)2 Verifications (mockit.Verifications)2 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)1 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)1