Search in sources :

Example 16 with TwinState

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

the class JobsParserTest method ConstructorInvalidJobIdThrows.

/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_015: [If the jobId is null, empty, or invalid, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorInvalidJobIdThrows() {
    // Arrange
    String jobId = "test\u1234JobId";
    String queryCondition = "testDeviceId";
    Date startTime = new Date();
    long maxExecutionTimeInSeconds = 10L;
    TwinState twinState = makeTwinSample();
    // 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 17 with TwinState

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

the class JobsParserTest method ConstructorTwinNullJobIdThrows.

/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_015: [If the jobId is null, empty, or invalid, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorTwinNullJobIdThrows() {
    // Arrange
    String jobId = null;
    String queryCondition = "testDeviceId";
    Date startTime = new Date();
    long maxExecutionTimeInSeconds = 10L;
    TwinState twinState = makeTwinSample();
    // 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 18 with TwinState

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

the class JobsParserTest method ConstructorNullStartTimeThrows.

/* Tests_SRS_JOBSPARSER_21_008: [If any common parameter is invalid, the constructor shall throws IllegalArgumentException.] */
/* Tests_SRS_JOBSPARSER_21_019: [If the startTime is null, the commonFields shall throws IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void ConstructorNullStartTimeThrows() {
    // Arrange
    String jobId = "testJobId";
    String queryCondition = "testDeviceId";
    Date startTime = null;
    long maxExecutionTimeInSeconds = 10L;
    TwinState twinState = makeTwinSample();
    // 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 19 with TwinState

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

the class DeviceTwinTest method updateTwinDoesNotThrowsIfOnlyDesiredHasValue.

@Test
public void updateTwinDoesNotThrowsIfOnlyDesiredHasValue(@Mocked DeviceTwinDevice mockedDevice) throws Exception {
    // arrange
    final String connectionString = "testString";
    constructorExpectations(connectionString);
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    TwinCollection testMap = new TwinCollection();
    testMap.putFinal("TestKey", "TestValue");
    new Expectations() {

        {
            mockedDevice.getDeviceId();
            result = "SomeDevID";
            Deencapsulation.invoke(mockedDevice, "getDesiredMap");
            result = testMap;
            Deencapsulation.invoke(mockedDevice, "getTagsMap");
            result = null;
            new TwinState(null, (TwinCollection) any, null);
            result = mockedTwinState;
            mockedTwinState.toJsonElement().toString();
            result = "SomeJsonString";
        }
    };
    // act
    testTwin.updateTwin(mockedDevice);
    // assert
    new Verifications() {

        {
            IotHubConnectionString.getUrlTwin(anyString, anyString);
            times = 1;
            mockedHttpRequest.setReadTimeoutMillis(anyInt);
            times = 1;
            mockedHttpRequest.setHeaderField(anyString, anyString);
            times = 6;
            mockedHttpRequest.send();
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) StrictExpectations(mockit.StrictExpectations) NonStrictExpectations(mockit.NonStrictExpectations) TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Verifications(mockit.Verifications) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) Test(org.junit.Test)

Example 20 with TwinState

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

the class DeviceTwinTest method updateTwinSucceeds.

/*
    **Tests_SRS_DEVICETWIN_25_030: [** The function shall build the URL for this operation by calling getUrlTwinDesired **]**
    **Tests_SRS_DEVICETWIN_25_031: [** The function shall serialize the desired properties map by calling resetDesiredProperty Api on the twin object for the device provided by the user**]**
    **Tests_SRS_DEVICETWIN_25_016: [** The function shall create a new SAS token **]**

    **Tests_SRS_DEVICETWIN_25_017: [** The function shall create a new HttpRequest with http method as Patch **]**

    **Tests_SRS_DEVICETWIN_25_018: [** The function shall set the following HTTP headers specified in the IotHub DeviceTwin doc.
                                                1. Key as authorization with value as sastoken
                                                2. Key as request id with a new string value for every request
                                                3. Key as User-Agent with value specified by the clientIdentifier and its version
                                                4. Key as Accept with value as application/json
                                                5. Key as Content-Type and value as application/json
                                                6. Key as charset and value as utf-8
                                                7. Key as If-Match and value as '*'  **]**

    **Tests_SRS_DEVICETWIN_25_019: [** The function shall send the created request and get the response **]**

    **Tests_SRS_DEVICETWIN_25_020: [** The function shall verify the response status and throw proper Exception **]**

    *Tests_SRS_DEVICETWIN_25_036: [** The function shall verify the response status and throw proper Exception **]**

     */
@Test
public void updateTwinSucceeds(@Mocked DeviceTwinDevice mockedDevice) throws Exception {
    // arrange
    final String connectionString = "testString";
    constructorExpectations(connectionString);
    DeviceTwin testTwin = DeviceTwin.createFromConnectionString(connectionString);
    TwinCollection testMap = new TwinCollection();
    testMap.putFinal("TestKey", "TestValue");
    new NonStrictExpectations() {

        {
            mockedDevice.getDeviceId();
            result = "SomeDevID";
            Deencapsulation.invoke(mockedDevice, "getDesiredMap");
            result = testMap;
            Deencapsulation.invoke(mockedDevice, "getTagsMap");
            result = testMap;
            new TwinState((TwinCollection) any, (TwinCollection) any, null);
            result = mockedTwinState;
            mockedTwinState.toJsonElement().toString();
            result = "SomeJsonString";
        }
    };
    // act
    testTwin.updateTwin(mockedDevice);
    // assert
    new Verifications() {

        {
            IotHubConnectionString.getUrlTwin(anyString, anyString);
            times = 1;
            mockedHttpRequest.setReadTimeoutMillis(anyInt);
            times = 1;
            mockedHttpRequest.setHeaderField(anyString, anyString);
            times = 6;
            mockedHttpRequest.send();
            times = 1;
        }
    };
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) TwinState(com.microsoft.azure.sdk.iot.deps.twin.TwinState) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) DeviceTwin(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin) 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