Search in sources :

Example 16 with FileUploadTask

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

the class FileUploadTaskTest method runCreateNotificationSucceed.

/* Tests_SRS_FILEUPLOADTASK_21_021: [If the upload to blob succeed, the run shall create a notification the IoT Hub with `isSuccess` equals true, `statusCode` equals 0.] */
@Test
public void runCreateNotificationSucceed() 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 17 with FileUploadTask

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

the class FileUploadTaskTest method runFileUploadResponseParserThrows.

/* Tests_SRS_FILEUPLOADTASK_21_016: [If the `responseMessage` is null, empty, do not contains a valid json, or if the information in json is not correct, the run shall call the `userCallback` reporting the error, and abort the upload.] */
@Test
public void runFileUploadResponseParserThrows() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    requestExpectations(VALID_BLOB_NAME, VALID_REQUEST_JSON);
    new NonStrictExpectations() {

        {
            mockResponseMessage.getStatus();
            result = IotHubStatusCode.OK;
            mockResponseMessage.getBytes();
            result = VALID_RESPONSE_JSON.getBytes(StandardCharsets.UTF_8);
            new FileUploadSasUriResponse(VALID_RESPONSE_JSON);
            result = new IllegalArgumentException();
        }
    };
    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) FileUploadSasUriResponse(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriResponse) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 18 with FileUploadTask

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

the class FileUploadTaskTest method runOpenConnectionToIothubForRequestAndNotification.

/* Tests_SRS_FILEUPLOADTASK_21_010: [The run shall open the connection with the iothub, using the httpsTransportManager.] */
/* Tests_SRS_FILEUPLOADTASK_21_026: [The run shall open the connection with the iothub, using the httpsTransportManager.] */
@Test
public void runOpenConnectionToIothubForRequestAndNotification() 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(mockHttpsTransportManager, "open");
            times = 2;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 19 with FileUploadTask

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

the class FileUploadTaskTest method runFileUploadStatusParserThrows.

/* Tests_SRS_FILEUPLOADTASK_21_033: [If run failed to send the notification, it shall call the userCallback with the stratus `ERROR`, and abort the upload.] */
@Test
public void runFileUploadStatusParserThrows() 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 = new IllegalArgumentException();
        }
    };
    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() {

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

Example 20 with FileUploadTask

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

the class FileUploadTaskTest method runSendRequestToIothub.

/* Tests_SRS_FILEUPLOADTASK_21_011: [The run shall send the blob request message to the iothub, using the httpsTransportManager.] */
@Test
public void runSendRequestToIothub() 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() {

        {
            mockHttpsTransportManager.getFileUploadSasUri(mockMessageRequest);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Verifications(mockit.Verifications) 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