Search in sources :

Example 6 with FileUploadInProgress

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

the class FileUploadInProgressTest method isCancelledThrows.

@Test
public void isCancelledThrows() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    // act
    assertFalse((boolean) Deencapsulation.invoke(fileUploadInProgress, "isCancelled"));
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with FileUploadInProgress

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

the class FileUploadInProgressTest method setTaskSuccess.

/* Codes_SRS_FILEUPLOADINPROGRESS_21_003: [The setTask shall sore the content of the `task`.] */
@Test
public void setTaskSuccess() {
    // arrange
    final Map<String, Object> context = new HashMap<>();
    FileUploadInProgress fileUploadInProgress = Deencapsulation.newInstance(FileUploadInProgress.class, new Class[] { IotHubEventCallback.class, Object.class }, mockIotHubEventCallback, context);
    // act
    Deencapsulation.invoke(fileUploadInProgress, "setTask", new Class[] { Future.class }, mockFuture);
    // assert
    assertEquals(mockFuture, Deencapsulation.getField(fileUploadInProgress, "task"));
}
Also used : FileUploadInProgress(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with FileUploadInProgress

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

FileUploadInProgress (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadInProgress)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 NonStrictExpectations (mockit.NonStrictExpectations)2 FileUpload (com.microsoft.azure.sdk.iot.device.fileupload.FileUpload)1 HttpsTransportManager (com.microsoft.azure.sdk.iot.device.transport.https.HttpsTransportManager)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 Verifications (mockit.Verifications)1