Search in sources :

Example 31 with JobClient

use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.

the class JobTest method constructor1CreateJobClient.

/* Tests_SRS_JOB_21_004: [The constructor shall create a new instance of JobClient to manage the Job.] */
@Test
public void constructor1CreateJobClient() throws IOException {
    // arrange
    final String connectionString = "validConnectionString";
    // act
    Job job = Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
    // assert
    assertNotNull(Deencapsulation.getField(job, "jobClient"));
    new Verifications() {

        {
            new JobClient(connectionString);
            times = 1;
        }
    };
}
Also used : Job(com.microsoft.azure.sdk.iot.service.devicetwin.Job) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Test(org.junit.Test)

Example 32 with JobClient

use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.

the class JobTest method constructor1ThrowOnJobClientCreation.

/* Tests_SRS_JOB_21_005: [The constructor shall throw IOException if it failed to create a new instance of the JobClient. Threw by the JobClient constructor.] */
@Test(expected = IOException.class)
public void constructor1ThrowOnJobClientCreation() throws IOException {
    // arrange
    final String connectionString = "validConnectionString";
    new NonStrictExpectations() {

        {
            new JobClient(connectionString);
            result = new IOException();
            times = 1;
        }
    };
    // act
    Deencapsulation.newInstance(Job.class, new Class[] { String.class }, connectionString);
}
Also used : IOException(java.io.IOException) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Test(org.junit.Test)

Example 33 with JobClient

use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.

the class JobClientTest method scheduleDeviceMethodSendPUT.

/* Tests_SRS_JOBCLIENT_21_020: [The scheduleDeviceMethod shall send a PUT request to the iothub using the created url and json.] */
@Test
public void scheduleDeviceMethodSendPUT() throws IOException, IotHubException {
    // arrange
    final String connectionString = "testString";
    final String jobId = "validJobId";
    final String queryCondition = "validQueryCondition";
    final String methodName = "validMethodName";
    final Set<String> payload = new HashSet<>();
    final Date startTimeUtc = new Date();
    final long maxExecutionTimeInSeconds = 10;
    final String json = "validJson";
    new NonStrictExpectations() {

        {
            IotHubConnectionStringBuilder.createIotHubConnectionString(connectionString);
            result = mockedIotHubConnectionString;
            new MethodParser(methodName, null, null, payload);
            result = mockedMethodParser;
            new JobsParser(jobId, mockedMethodParser, 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
    testJobClient.scheduleDeviceMethod(jobId, queryCondition, methodName, null, null, payload, startTimeUtc, maxExecutionTimeInSeconds);
    // assert
    new Verifications() {

        {
            DeviceOperations.request(anyString, mockedURL, HttpMethod.PUT, json.getBytes(StandardCharsets.UTF_8), (String) any, anyInt, anyInt, (Proxy) any);
            times = 1;
        }
    };
}
Also used : JobsParser(com.microsoft.azure.sdk.iot.deps.serializer.JobsParser) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Date(java.util.Date) HashSet(java.util.HashSet) MethodParser(com.microsoft.azure.sdk.iot.deps.serializer.MethodParser) Test(org.junit.Test)

Example 34 with JobClient

use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.

the class JobClientTest method scheduleDeviceMethodThrowsOnNullMethodName.

/* Tests_SRS_JOBCLIENT_21_015: [If the methodName is null or empty, the scheduleDeviceMethod shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void scheduleDeviceMethodThrowsOnNullMethodName() throws IOException, IotHubException {
    // arrange
    final String connectionString = "testString";
    final String jobId = "ValidJobId";
    final String queryCondition = "validQueryCondition";
    final String methodName = null;
    final Set<String> payload = new HashSet<>();
    final Date startTimeUtc = new Date();
    final long maxExecutionTimeInSeconds = 10;
    JobClient testJobClient = null;
    try {
        testJobClient = JobClient.createFromConnectionString(connectionString);
    } catch (IllegalArgumentException e) {
        assertTrue("Test did not run because createFromConnectionString failed to create new instance of the JobClient", true);
    }
    // act
    testJobClient.scheduleDeviceMethod(jobId, queryCondition, methodName, null, null, payload, startTimeUtc, maxExecutionTimeInSeconds);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with JobClient

use of com.microsoft.azure.sdk.iot.service.jobs.JobClient in project azure-iot-sdk-java by Azure.

the class JobClientTest method constructorSucceed.

/* Tests_SRS_JOBCLIENT_21_002: [The constructor shall create an IotHubConnectionStringBuilder object from the given connection string.] */
/* Tests_SRS_JOBCLIENT_21_003: [The constructor shall create a new DeviceMethod instance and return it.] */
@Test
public void constructorSucceed() throws IOException {
    // arrange
    final String connectionString = "testString";
    // act
    JobClient testJobClient = JobClient.createFromConnectionString(connectionString);
    // assert
    assertNotNull(testJobClient);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) JobClient(com.microsoft.azure.sdk.iot.service.jobs.JobClient) Test(org.junit.Test)

Aggregations

JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)67 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)61 Test (org.junit.Test)61 NonStrictExpectations (mockit.NonStrictExpectations)36 Date (java.util.Date)26 HashSet (java.util.HashSet)21 JobsParser (com.microsoft.azure.sdk.iot.deps.serializer.JobsParser)14 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)14 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)13 Verifications (mockit.Verifications)13 Expectations (mockit.Expectations)11 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)10 SqlQuery (com.microsoft.azure.sdk.iot.service.devicetwin.SqlQuery)10 TwinState (com.microsoft.azure.sdk.iot.deps.twin.TwinState)8 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)8 MethodParser (com.microsoft.azure.sdk.iot.deps.serializer.MethodParser)7 IOException (java.io.IOException)6 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)5 MalformedURLException (java.net.MalformedURLException)4 JobClientOptions (com.microsoft.azure.sdk.iot.service.jobs.JobClientOptions)3