Search in sources :

Example 11 with FileUploadTask

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

the class FileUploadTaskTest method runUploadStreamToCloudBlockBlob.

/* Tests_SRS_FILEUPLOADTASK_21_020: [The run shall upload the `inputStream` with the `streamLength` to the created `CloudBlockBlob`.] */
@Test
public void runUploadStreamToCloudBlockBlob() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    expectSuccess(VALID_BLOB_NAME, VALID_CORRELATION_ID, VALID_HOST_NAME, VALID_CONTAINER_NAME, VALID_SAS_TOKEN, VALID_REQUEST_JSON, VALID_RESPONSE_JSON, VALID_NOTIFICATION_JSON);
    FileUploadTask fileUploadTask = Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, VALID_BLOB_NAME, mockInputStream, VALID_STREAM_LENGTH, mockHttpsTransportManager, mockIotHubEventCallback, VALID_CALLBACK_CONTEXT);
    // act
    Deencapsulation.invoke(fileUploadTask, "run");
    // assert
    new Verifications() {

        {
            mockCloudBlockBlob.upload(mockInputStream, VALID_STREAM_LENGTH);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 12 with FileUploadTask

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

the class FileUploadTaskTest method runSendNotificationThrows.

/* Tests_SRS_FILEUPLOADTASK_21_031: [If run failed to send the request, it shall call the userCallback with the status `ERROR`, and abort the upload.] */
@Test
public void runSendNotificationThrows() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    requestExpectations(VALID_BLOB_NAME, VALID_REQUEST_JSON);
    responseExpectations(VALID_RESPONSE_JSON);
    responseParserExpectations(VALID_BLOB_NAME, VALID_CORRELATION_ID, VALID_HOST_NAME, VALID_CONTAINER_NAME, VALID_SAS_TOKEN);
    blobClientBuilderExpectations();
    new NonStrictExpectations() {

        {
            new FileUploadCompletionNotification(VALID_CORRELATION_ID, true, 0, (String) any);
            result = mockFileUploadStatusParser;
            mockFileUploadStatusParser.toJson();
            result = VALID_NOTIFICATION_JSON;
            new IotHubTransportMessage(VALID_NOTIFICATION_JSON);
            result = mockMessageNotification;
            mockHttpsTransportManager.sendFileUploadNotification(mockMessageNotification);
            result = new IOException();
        }
    };
    FileUploadTask fileUploadTask = Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, VALID_BLOB_NAME, mockInputStream, VALID_STREAM_LENGTH, mockHttpsTransportManager, mockIotHubEventCallback, VALID_CALLBACK_CONTEXT);
    // act
    Deencapsulation.invoke(fileUploadTask, "run");
    // assert
    new Verifications() {

        {
            mockHttpsTransportManager.sendFileUploadNotification(mockMessageNotification);
            times = 1;
            mockIotHubEventCallback.execute(IotHubStatusCode.ERROR, VALID_CALLBACK_CONTEXT);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) IOException(java.io.IOException) FileUploadCompletionNotification(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadCompletionNotification) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 13 with FileUploadTask

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

the class FileUploadTaskTest method runCreateRequest.

/* Tests_SRS_FILEUPLOADTASK_21_007: [The run shall create a FileUpload request message, by using the FileUploadSasUriRequest.] */
@Test
public void runCreateRequest() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    expectSuccess(VALID_BLOB_NAME, VALID_CORRELATION_ID, VALID_HOST_NAME, VALID_CONTAINER_NAME, VALID_SAS_TOKEN, VALID_REQUEST_JSON, VALID_RESPONSE_JSON, VALID_NOTIFICATION_JSON);
    FileUploadTask fileUploadTask = Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, VALID_BLOB_NAME, mockInputStream, VALID_STREAM_LENGTH, mockHttpsTransportManager, mockIotHubEventCallback, VALID_CALLBACK_CONTEXT);
    // act
    Deencapsulation.invoke(fileUploadTask, "run");
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Test(org.junit.Test)

Example 14 with FileUploadTask

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

the class FileUploadTaskTest method runSetPOSTForNotification.

/* Tests_SRS_FILEUPLOADTASK_21_024: [The run shall set the message method as `POST`.] */
@Test
public void runSetPOSTForNotification() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    expectSuccess(VALID_BLOB_NAME, VALID_CORRELATION_ID, VALID_HOST_NAME, VALID_CONTAINER_NAME, VALID_SAS_TOKEN, VALID_REQUEST_JSON, VALID_RESPONSE_JSON, VALID_NOTIFICATION_JSON);
    FileUploadTask fileUploadTask = Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, VALID_BLOB_NAME, mockInputStream, VALID_STREAM_LENGTH, mockHttpsTransportManager, mockIotHubEventCallback, VALID_CALLBACK_CONTEXT);
    // act
    Deencapsulation.invoke(fileUploadTask, "run");
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockMessageNotification, "setIotHubMethod", IotHubMethod.POST);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 15 with FileUploadTask

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

the class FileUploadTaskTest method runCreateCloudBlockBlob.

/* Tests_SRS_FILEUPLOADTASK_21_019: [The run shall create a `CloudBlockBlob` using the `blobUri`.] */
@Test
public void runCreateCloudBlockBlob() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    expectSuccess(VALID_BLOB_NAME, VALID_CORRELATION_ID, VALID_HOST_NAME, VALID_CONTAINER_NAME, VALID_SAS_TOKEN, VALID_REQUEST_JSON, VALID_RESPONSE_JSON, VALID_NOTIFICATION_JSON);
    FileUploadTask fileUploadTask = Deencapsulation.newInstance(FileUploadTask.class, new Class[] { String.class, InputStream.class, long.class, HttpsTransportManager.class, IotHubEventCallback.class, Object.class }, VALID_BLOB_NAME, mockInputStream, VALID_STREAM_LENGTH, mockHttpsTransportManager, mockIotHubEventCallback, VALID_CALLBACK_CONTEXT);
    // act
    Deencapsulation.invoke(fileUploadTask, "run");
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Test(org.junit.Test)

Aggregations

FileUploadTask (com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask)21 Test (org.junit.Test)21 Verifications (mockit.Verifications)12 NonStrictExpectations (mockit.NonStrictExpectations)9 IOException (java.io.IOException)5 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)4 FileUploadCompletionNotification (com.microsoft.azure.sdk.iot.deps.serializer.FileUploadCompletionNotification)3 FileUploadSasUriRequest (com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriRequest)3 Expectations (mockit.Expectations)2 FileUploadSasUriResponse (com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriResponse)1 BadFormatException (com.microsoft.azure.sdk.iot.device.exceptions.BadFormatException)1 UnauthorizedException (com.microsoft.azure.sdk.iot.device.exceptions.UnauthorizedException)1