Search in sources :

Example 6 with DeviceMethod

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

the class DeviceMethodTest method invoke_IllegalParameters_failed.

/* Tests_SRS_DEVICEMETHOD_21_004: [The invoke shall throw IllegalArgumentException if the provided deviceId is null or empty.] */
@Test
public void invoke_IllegalParameters_failed() throws Exception {
    //arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    //act
    for (TestMethod testCase : illegalParameter) {
        try {
            testMethod.invoke(testCase.deviceId, testCase.methodName, testCase.responseTimeoutInSeconds, testCase.connectTimeoutInSeconds, testCase.payload);
            System.out.print("Negative case> DeviceId=" + testCase.deviceId + " MethodName=" + testCase.methodName + " responseTimeoutInSeconds=" + testCase.responseTimeoutInSeconds + " connectTimeoutInSeconds=" + testCase.connectTimeoutInSeconds + " payload=" + testCase.payload + "\r\n");
            assert true;
        } catch (IllegalArgumentException expected) {
        //Don't do anything. Expected throw.
        }
    }
}
Also used : DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) Test(org.junit.Test)

Example 7 with DeviceMethod

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

the class DeviceMethodTest method constructor_throwOnNullCS_failed.

/* Tests_SRS_DEVICEMETHOD_21_001: [The constructor shall throw IllegalArgumentException if the input string is null or empty.] */
@Test(expected = IllegalArgumentException.class)
public void constructor_throwOnNullCS_failed() throws Exception {
    //arrange
    final String connectionString = null;
    //act
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(connectionString);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) Test(org.junit.Test)

Example 8 with DeviceMethod

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

the class DeviceMethodTest method invoke_throwOnNullJson_failed.

/* Tests_SRS_DEVICEMETHOD_21_012: [If `MethodParser` return a null Json, the invoke shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnNullJson_failed(@Mocked final MethodParser methodParser) throws Exception {
    //arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            methodParser.toJson();
            result = null;
        }
    };
    //act
    testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Also used : DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) Test(org.junit.Test)

Example 9 with DeviceMethod

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

the class DeviceMethodTest method invoke_throwOnHttpRequester_failed.

/* Tests_SRS_DEVICEMETHOD_21_009: [The invoke shall send the created request and get the response using the HttpRequester.] */
/* Tests_SRS_DEVICEMETHOD_21_010: [The invoke shall create a new HttpRequest with http method as `POST`.] */
@Test(expected = IotHubException.class)
public void invoke_throwOnHttpRequester_failed(@Mocked final MethodParser methodParser, @Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
    //arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            methodParser.toJson();
            result = STANDARD_JSON;
            iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
            result = STANDARD_URL;
        }
    };
    new MockUp<DeviceOperations>() {

        @Mock
        HttpResponse request(IotHubConnectionString iotHubConnectionString, URL url, HttpMethod method, byte[] payload, String requestId, long timeoutInMs) throws IOException, IotHubException, IllegalArgumentException {
            throw new IotHubException();
        }
    };
    //act
    testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) URL(java.net.URL) HttpMethod(com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 10 with DeviceMethod

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

the class DeviceMethodTest method invoke_throwOnGetUrlMethod_failed.

/* Tests_SRS_DEVICEMETHOD_21_008: [The invoke shall build the Method URL `{iot hub}/twins/{device id}/methods/` by calling getUrlMethod.] */
@Test(expected = IllegalArgumentException.class)
public void invoke_throwOnGetUrlMethod_failed(@Mocked final MethodParser methodParser, @Mocked final IotHubConnectionStringBuilder mockedConnectionStringBuilder) throws Exception {
    //arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            methodParser.toJson();
            result = STANDARD_JSON;
            iotHubConnectionString.getUrlMethod(STANDARD_DEVICEID);
            result = new IllegalArgumentException();
        }
    };
    //act
    testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Also used : DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) Test(org.junit.Test)

Aggregations

DeviceMethod (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod)13 Test (org.junit.Test)12 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)5 MethodResult (com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)2 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)1 IOException (java.io.IOException)1 URL (java.net.URL)1