Search in sources :

Example 6 with Job

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

the class JobTest method scheduleDeviceMethodThrowOnInvalidMaxExecutionTimeInSeconds.

/* Tests_SRS_JOB_21_014: [If the maxExecutionTimeInSeconds is negative, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowOnInvalidMaxExecutionTimeInSeconds() throws IOException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final String methodName = "validMethodName";
    final String payload = "validPayload";
    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, "scheduleDeviceMethod", new Class[] { String.class, String.class, Long.class, Long.class, Object.class, Date.class, Long.class }, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
}
Also used : Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Job

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

the class JobTest method scheduleDeviceMethodThrowOnEmptyMethodName.

/* Tests_SRS_JOB_21_012: [If the methodName is null or empty, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowOnEmptyMethodName() throws IOException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final String methodName = "";
    final String payload = "validPayload";
    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, "scheduleDeviceMethod", new Class[] { String.class, String.class, Long.class, Long.class, Object.class, Date.class, Long.class }, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
}
Also used : Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Job

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

the class JobTest method scheduleUpdateTwinCallJobClient.

/* Tests_SRS_JOB_21_009: [The scheduleUpdateTwin shall invoke the scheduleUpdateTwin in the JobClient class with the received parameters.] */
@Test
public void scheduleUpdateTwinCallJobClient() throws IOException, IotHubException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final DeviceTwinDevice deviceTwin = mockedDeviceTwinDevice;
    final Date now = new Date();
    final long maxExecutionTimeInSeconds = 100;
    final String connectionString = "validConnectionString";
    // assert
    new NonStrictExpectations() {

        {
            JobClient.createFromConnectionString(connectionString);
            result = mockedJobClient;
            mockedJobClient.scheduleUpdateTwin((String) any, queryCondition, deviceTwin, now, maxExecutionTimeInSeconds);
            result = mockedJobResult;
            times = 1;
            mockedJobResult.getJobStatus();
            result = JobStatus.enqueued;
        }
    };
    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 9 with Job

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

the class JobTest method scheduleDeviceMethodThrowOnInvokeJobClientFail.

/* Tests_SRS_JOB_21_017: [If the Iothub reported fail as result of the scheduleDeviceMethod, the scheduleDeviceMethod shall throws IotHubException.] */
@Test(expected = IotHubException.class)
public void scheduleDeviceMethodThrowOnInvokeJobClientFail() throws IOException, IotHubException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final String methodName = "validMethodName";
    final String payload = "validPayload";
    final Date now = new Date();
    final long maxExecutionTimeInSeconds = 100;
    final String connectionString = "validConnectionString";
    // assert
    new NonStrictExpectations() {

        {
            JobClient.createFromConnectionString(connectionString);
            result = mockedJobClient;
            mockedJobClient.scheduleDeviceMethod((String) any, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
            result = mockedJobResult;
            mockedJobResult.getJobStatus();
            result = JobStatus.failed;
        }
    };
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // act
    Deencapsulation.invoke(job, "scheduleDeviceMethod", new Class[] { String.class, String.class, Long.class, Long.class, Object.class, Date.class, Long.class }, queryCondition, methodName, null, null, payload, now, maxExecutionTimeInSeconds);
}
Also used : Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Job

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

the class JobTest method scheduleUpdateTwinThrowOnNullDeviceTwinDevice.

/* Tests_SRS_JOB_21_006: [If the updateTwin is null, the scheduleUpdateTwin shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleUpdateTwinThrowOnNullDeviceTwinDevice() throws IOException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final DeviceTwinDevice deviceTwin = null;
    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)

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