Search in sources :

Example 6 with FileUpload

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

the class FileUploadTest method callbackDeleteFileUploadInProgressThrows.

@Test
public void callbackDeleteFileUploadInProgressThrows(@Mocked final LinkedBlockingDeque<?> mockFileUploadInProgressQueue) throws IOException {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    constructorExpectations();
    new NonStrictExpectations() {

        {
            new LinkedBlockingDeque<>();
            result = mockFileUploadInProgressQueue;
            mockFileUploadInProgressQueue.remove(mockFileUploadInProgress);
            result = new UnsupportedOperationException();
        }
    };
    FileUpload fileUpload = new FileUpload(mockConfig);
    IotHubEventCallback testFileUploadStatusCallBack = new FileUploadStatusCallBack();
    // act
    testFileUploadStatusCallBack.execute(IotHubStatusCode.OK_EMPTY, mockFileUploadInProgress);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockFileUploadInProgress, "triggerCallback", new Class[] { IotHubStatusCode.class }, IotHubStatusCode.OK_EMPTY);
            times = 1;
        }
    };
}
Also used : IotHubEventCallback(com.microsoft.azure.sdk.iot.device.IotHubEventCallback) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) FileUploadStatusCallBack(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadStatusCallBack) Test(org.junit.Test)

Example 7 with FileUpload

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

the class FileUploadTest method uploadToBlobAsyncNegativeStreamLenghtThrows.

/* Tests_SRS_FILEUPLOAD_21_007: [If the `streamLength` is negative, the uploadToBlobAsync shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void uploadToBlobAsyncNegativeStreamLenghtThrows() 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, mockIotHubEventCallback, context);
}
Also used : HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) Test(org.junit.Test)

Example 8 with FileUpload

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

the class FileUploadTest method callbackBypassStatus.

/* Tests_SRS_FILEUPLOAD_21_014: [The constructor shall create an Event callback `fileUploadStatusCallBack` to receive the upload status.] */
/* Tests_SRS_FILEUPLOAD_21_019: [The FileUploadStatusCallBack shall implements the `IotHubEventCallback` as result of the FileUploadTask.] */
/* Tests_SRS_FILEUPLOAD_21_020: [The FileUploadStatusCallBack shall call the `statusCallback` reporting the received status.] */
@Test
public void callbackBypassStatus() throws IOException {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    constructorExpectations();
    FileUpload fileUpload = new FileUpload(mockConfig);
    IotHubEventCallback testFileUploadStatusCallBack = new FileUploadStatusCallBack();
    // act
    testFileUploadStatusCallBack.execute(IotHubStatusCode.OK_EMPTY, mockFileUploadInProgress);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockFileUploadInProgress, "triggerCallback", new Class[] { IotHubStatusCode.class }, IotHubStatusCode.OK_EMPTY);
            times = 1;
        }
    };
}
Also used : IotHubEventCallback(com.microsoft.azure.sdk.iot.device.IotHubEventCallback) HashMap(java.util.HashMap) FileUpload(com.microsoft.azure.sdk.iot.device.fileupload.FileUpload) FileUploadStatusCallBack(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadStatusCallBack) Test(org.junit.Test)

Example 9 with FileUpload

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

the class FileUploadTest method uploadToBlobAsyncSuccess.

/* Tests_SRS_FILEUPLOAD_21_004: [The uploadToBlobAsync shall asynchronously upload the InputStream `inputStream` to the blob in `blobName`.] */
/* Tests_SRS_FILEUPLOAD_21_009: [The uploadToBlobAsync shall create a `FileUploadTask` to control this file upload.] */
/* Tests_SRS_FILEUPLOAD_21_010: [The uploadToBlobAsync shall schedule the task `FileUploadTask` to immediately start.] */
/* Tests_SRS_FILEUPLOAD_21_016: [The uploadToBlobAsync shall create a `FileUploadInProgress` to store the fileUpload context.] */
@Test
public void uploadToBlobAsyncSuccess() throws IOException {
    // arrange
    final String blobName = "validBlobName";
    final long streamLength = 100;
    final Map<String, Object> context = new HashMap<>();
    constructorExpectations();
    FileUpload fileUpload = new FileUpload(mockConfig);
    // assert
    new NonStrictExpectations() {

        {
            mockInputStream.available();
            result = streamLength;
            Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
            result = mockFileUploadInProgress;
            times = 1;
            Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, blobName, mockInputStream, streamLength, mockHttpsTransportManager, (IotHubEventCallback) any, mockFileUploadInProgress);
            result = mockFileUploadTask;
            times = 1;
            mockScheduler.submit(mockFileUploadTask);
            times = 1;
        }
    };
    // 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 10 with FileUpload

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

the class FileUploadTest method closeNowWithPendingUploadSuccess.

/* Tests_SRS_FILEUPLOAD_21_018: [If there is pending file uploads, the closeNow shall cancel the upload, and call the `statusCallback` reporting ERROR.] */
@Test
public void closeNowWithPendingUploadSuccess(@Mocked final Future mockFuture) throws IOException {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    final Queue<FileUploadInProgress> fileUploadInProgressSet = new LinkedBlockingDeque<FileUploadInProgress>() {

        {
            add(mockFileUploadInProgress);
        }
    };
    new NonStrictExpectations() {

        {
            new HttpsTransportManager(mockConfig);
            result = mockHttpsTransportManager;
            Executors.newScheduledThreadPool(10);
            result = mockScheduler;
            Deencapsulation.invoke(mockFileUploadInProgress, "isCancelled");
            result = true;
        }
    };
    FileUpload fileUpload = new FileUpload(mockConfig);
    Deencapsulation.setField(fileUpload, "fileUploadInProgressesSet", fileUploadInProgressSet);
    // act
    fileUpload.closeNow();
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockFileUploadInProgress, "triggerCallback", new Class[] { IotHubStatusCode.class }, IotHubStatusCode.ERROR);
            times = 1;
        }
    };
}
Also used : HttpsTransportManager(com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager) FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HashMap(java.util.HashMap) 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