Search in sources :

Example 16 with Job

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

the class JobTest method getInvokeJobClient.

/* Tests_SRS_JOB_21_018: [The get shall invoke getJob on JobClient with the current jobId and return its result.] */
@Test
public void getInvokeJobClient() throws IOException, IotHubException {
    // arrange
    final String connectionString = "validConnectionString";
    // assert
    new NonStrictExpectations() {

        {
            JobClient.createFromConnectionString(connectionString);
            result = mockedJobClient;
            mockedJobClient.getJob((String) any);
            result = mockedJobResult;
            times = 1;
        }
    };
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // act
    JobResult jobResult = job.get();
    // assert
    assertNotNull(jobResult);
}
Also used : JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Test(org.junit.Test)

Example 17 with Job

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

the class JobTest method constructorCreateUniqueJobId.

/* Tests_SRS_JOB_21_003: [If no jobId is provided, the constructor shall generate a unique jobId to identify the Job in the Iothub.] */
@Test
public void constructorCreateUniqueJobId() {
    // arrange
    final String connectionString = "validConnectionString";
    // act
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // assert
    assertNotNull(Deencapsulation.getField(job, "jobId"));
    assertFalse(Deencapsulation.getField(job, "jobId").toString().isEmpty());
}
Also used : Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) Test(org.junit.Test)

Example 18 with Job

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

the class JobTest method scheduleUpdateTwinThrowOnScheduleUpdateTwin.

/* Tests_SRS_JOB_21_010: [If scheduleUpdateTwin failed, the scheduleUpdateTwin shall throws IotHubException. Threw by the scheduleUpdateTwin.] */
@Test(expected = IotHubException.class)
public void scheduleUpdateTwinThrowOnScheduleUpdateTwin() 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 = new IotHubException();
            times = 1;
        }
    };
    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) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 19 with Job

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

the class JobTest method scheduleDeviceMethodThrowOnNullStartTimeUtc.

/* Tests_SRS_JOB_21_013: [If the startTimeUtc is null, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowOnNullStartTimeUtc() throws IOException {
    // arrange
    final String queryCondition = "validQueryCondition";
    final String methodName = "validMethodName";
    final String payload = "validPayload";
    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, "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 20 with Job

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

the class JobTest method cancelInvokeJobClient.

/* Tests_SRS_JOB_21_020: [The cancel shall invoke cancelJob on JobClient with the current jobId and return its result.] */
@Test
public void cancelInvokeJobClient() throws IOException, IotHubException {
    // arrange
    final String connectionString = "validConnectionString";
    // assert
    new NonStrictExpectations() {

        {
            JobClient.createFromConnectionString(connectionString);
            result = mockedJobClient;
            mockedJobClient.cancelJob((String) any);
            result = mockedJobResult;
            times = 1;
        }
    };
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // act
    JobResult jobResult = job.cancel();
    // assert
    assertNotNull(jobResult);
}
Also used : JobResult(com.microsoft.azure.sdk.iot.service.jobs.JobResult) Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) 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