Search in sources :

Example 1 with FileUpload

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUpload in project azure-iot-sdk-java by Azure.

the class FileUploadTest method uploadToBlobAsyncNullUserCallbackThrows.

/* Tests_SRS_FILEUPLOAD_21_008: [If the `userCallback` is null, the uploadToBlobAsync shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void uploadToBlobAsyncNullUserCallbackThrows() throws IOException {
    // arrange
    final String blobName = "validBlobName";
    final long streamLength = 100;
    final Map<String, Object> context = new HashMap<>();
    constructorExpectations();
    new NonStrictExpectations() {

        {
            mockInputStream.available();
            result = streamLength;
        }
    };
    FileUpload fileUpload = new FileUpload(mockConfig);
    // act
    fileUpload.uploadToBlobAsync(blobName, mockInputStream, streamLength, null, context);
}
Also used : HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 2 with FileUpload

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUpload in project azure-iot-sdk-java by Azure.

the class FileUploadTest method closeNowSuccess.

/* Tests_SRS_FILEUPLOAD_21_017: [The closeNow shall shutdown the thread pool by calling `shutdownNow`.] */
@Test
public void closeNowSuccess() throws IOException {
    // arrange
    constructorExpectations();
    FileUpload fileUpload = new FileUpload(mockConfig);
    // act
    fileUpload.closeNow();
    // assert
    new Verifications() {

        {
            mockScheduler.shutdownNow();
            times = 1;
        }
    };
}
Also used : FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 3 with FileUpload

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUpload in project azure-iot-sdk-java by Azure.

the class FileUploadTest method uploadToBlobAsyncNullBlobNameThrows.

/* Tests_SRS_FILEUPLOAD_21_005: [If the `blobName` is null or empty, the uploadToBlobAsync shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void uploadToBlobAsyncNullBlobNameThrows() throws IOException {
    // arrange
    final String blobName = null;
    final long streamLength = 100;
    final Map<String, Object> context = new HashMap<>();
    constructorExpectations();
    FileUpload fileUpload = new FileUpload(mockConfig);
    // act
    fileUpload.uploadToBlobAsync(blobName, mockInputStream, streamLength, mockIotHubEventCallback, context);
}
Also used : HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 4 with FileUpload

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUpload in project azure-iot-sdk-java by Azure.

the class FileUploadTest method uploadToBlobAsyncNullInputStreamThrows.

/* Tests_SRS_FILEUPLOAD_21_006: [If the `inputStream` is null or not available, the uploadToBlobAsync shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void uploadToBlobAsyncNullInputStreamThrows() throws IOException {
    // arrange
    final String blobName = "validBlobName";
    final long streamLength = 100;
    final Map<String, Object> context = new HashMap<>();
    constructorExpectations();
    new NonStrictExpectations() {

        {
            mockInputStream.available();
            result = streamLength;
        }
    };
    FileUpload fileUpload = new FileUpload(mockConfig);
    // act
    fileUpload.uploadToBlobAsync(blobName, null, streamLength, mockIotHubEventCallback, context);
}
Also used : HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 5 with FileUpload

use of com.microsoft.azure.sdk.iot.device.fileupload.FileUpload 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)

Aggregations

FileUpload (com.microsoft.azure.sdk.iot.device.fileupload.FileUpload)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)10 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)5 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)4 IotHubEventCallback (com.microsoft.azure.sdk.iot.device.IotHubEventCallback)3 FileUploadStatusCallBack (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadStatusCallBack)3 FileUploadInProgress (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress)1