Search in sources :

Example 1 with HttpsTransportManager

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.

the class FileUploadTest method constructorSuccess.

/* Tests_SRS_FILEUPLOAD_21_002: [The constructor shall create a new instance of `HttpsTransportManager` with the provided `config`.] */
/* Tests_SRS_FILEUPLOAD_21_012: [The constructor shall create an pool of 10 threads to execute the uploads in parallel.] */
/* Tests_SRS_FILEUPLOAD_21_013: [The constructor shall create a list `fileUploadInProgressesSet` to control the pending uploads.] */
@Test
public void constructorSuccess(@Mocked final LinkedBlockingDeque<?> mockFileUploadInProgressQueue) throws IOException {
    // arrange
    new Expectations() {

        {
            new HttpsTransportManager(mockConfig);
            result = mockHttpsTransportManager;
            Executors.newScheduledThreadPool(10);
            result = mockScheduler;
        }
    };
    // act
    final FileUpload fileUpload = new FileUpload(mockConfig);
    // assert
    new Verifications() {

        {
            new LinkedBlockingDeque<>();
            times = 1;
        }
    };
    assertNotNull(fileUpload);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 2 with HttpsTransportManager

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.

the class ModuleClientTest method invokeMethodOnModuleWrapsExceptions.

// Tests_SRS_MODULECLIENT_34_036: [If this function encounters an exception, it shall throw a moduleClientException with that exception nested.]
@Test(expected = ModuleClientException.class)
public void invokeMethodOnModuleWrapsExceptions() throws URISyntaxException, ModuleClientException, IOException, TransportException {
    // arrange
    baseExpectations();
    ModuleClient client = new ModuleClient("connection string", IotHubClientProtocol.AMQPS);
    final String expectedDeviceId = "someDevice";
    final String expectedModuleId = "someModule";
    new NonStrictExpectations() {

        {
            new HttpsTransportManager((DeviceClientConfig) any);
            result = mockedHttpsTransportManager;
            mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
            result = new IOException();
        }
    };
    // act
    client.invokeMethod(expectedDeviceId, expectedModuleId, mockedMethodRequest);
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with HttpsTransportManager

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.

the class ModuleClientTest method invokeMethodOnDeviceSuccess.

// Tests_SRS_MODULECLIENT_34_033: [This function shall create an HttpsTransportManager and use it to invoke the method on the device.]
@Test
public void invokeMethodOnDeviceSuccess() throws URISyntaxException, ModuleClientException, IOException, TransportException {
    // arrange
    baseExpectations();
    ModuleClient client = new ModuleClient("connection string", IotHubClientProtocol.AMQPS);
    final String expectedDeviceId = "someDevice";
    new NonStrictExpectations() {

        {
            new HttpsTransportManager((DeviceClientConfig) any);
            result = mockedHttpsTransportManager;
            mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, "");
            result = mockedMethodResult;
        }
    };
    // act
    MethodResult actualResult = client.invokeMethod(expectedDeviceId, mockedMethodRequest);
    // assert
    assertEquals(mockedMethodResult, actualResult);
    new Verifications() {

        {
            mockedHttpsTransportManager.open();
            times = 1;
            mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, "");
            times = 1;
        }
    };
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) MethodResult(com.microsoft.azure.sdk.iot.device.edge.MethodResult) Test(org.junit.Test)

Example 4 with HttpsTransportManager

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.

the class ModuleClientTest method invokeMethodOnModuleSuccess.

// Tests_SRS_MODULECLIENT_34_035: [This function shall create an HttpsTransportManager and use it to invoke the method on the module.]
@Test
public void invokeMethodOnModuleSuccess() throws URISyntaxException, ModuleClientException, IOException, TransportException {
    // arrange
    baseExpectations();
    ModuleClient client = new ModuleClient("connection string", IotHubClientProtocol.AMQPS);
    final String expectedDeviceId = "someDevice";
    final String expectedModuleId = "someModule";
    new NonStrictExpectations() {

        {
            new HttpsTransportManager((DeviceClientConfig) any);
            result = mockedHttpsTransportManager;
            mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
            result = mockedMethodResult;
        }
    };
    // act
    MethodResult actualResult = client.invokeMethod(expectedDeviceId, expectedModuleId, mockedMethodRequest);
    // assert
    assertEquals(mockedMethodResult, actualResult);
    new Verifications() {

        {
            mockedHttpsTransportManager.open();
            times = 1;
            mockedHttpsTransportManager.invokeMethod(mockedMethodRequest, expectedDeviceId, expectedModuleId);
            times = 1;
        }
    };
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) MethodResult(com.microsoft.azure.sdk.iot.device.edge.MethodResult) Test(org.junit.Test)

Example 5 with HttpsTransportManager

use of com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager in project azure-iot-sdk-java by Azure.

the class ModuleClient method invokeMethod.

/**
 * Invoke a method on a device
 * @param deviceId the device to invoke a method on
 * @param methodRequest the request containing the method to invoke on the device
 * @return the result of the method call
 * @throws ModuleClientException if the method cannot be invoked
 * @throws IllegalArgumentException if deviceid is null or empty
 */
public MethodResult invokeMethod(String deviceId, MethodRequest methodRequest) throws ModuleClientException, IllegalArgumentException {
    if (deviceId == null || deviceId.isEmpty()) {
        // Codes_SRS_MODULECLIENT_34_039: [If the provided deviceId is null or empty, this function shall throw an IllegalArgumentException.]
        throw new IllegalArgumentException("DeviceId cannot be null or empty");
    }
    try {
        // Codes_SRS_MODULECLIENT_34_033: [This function shall create an HttpsTransportManager and use it to invoke the method on the device.]
        HttpsTransportManager httpsTransportManager = new HttpsTransportManager(this.config);
        httpsTransportManager.open();
        return httpsTransportManager.invokeMethod(methodRequest, deviceId, "");
    } catch (URISyntaxException | IOException | TransportException e) {
        // Codes_SRS_MODULECLIENT_34_034: [If this function encounters an exception, it shall throw a moduleClientException with that exception nested.]
        throw new ModuleClientException("Could not invoke method", e);
    }
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) ModuleClientException(com.microsoft.azure.sdk.iot.device.exceptions.ModuleClientException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) TransportException(com.microsoft.azure.sdk.iot.device.exceptions.TransportException)

Aggregations

HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)32 Test (org.junit.Test)31 HttpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsIotHubConnection)12 FileUpload (com.microsoft.azure.sdk.iot.device.fileupload.FileUpload)5 IOException (java.io.IOException)5 MethodResult (com.microsoft.azure.sdk.iot.device.edge.MethodResult)4 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)3 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)3 HashMap (java.util.HashMap)2 IotHubEventCallback (com.microsoft.azure.sdk.iot.device.IotHubEventCallback)1 ModuleClientException (com.microsoft.azure.sdk.iot.device.exceptions.ModuleClientException)1 TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)1 FileUploadInProgress (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress)1 FileUploadStatusCallBack (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadStatusCallBack)1 URISyntaxException (java.net.URISyntaxException)1