Search in sources :

Example 6 with FileUploadTask

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

the class FileUploadTaskTest method constructorStoreParametersSucceed.

/* Tests_SRS_FILEUPLOADTASK_21_006: [The constructor shall store all the provided parameters.] */
@Test
public void constructorStoreParametersSucceed() {
    // arrange
    // act
    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);
    // assert
    assertEquals(Deencapsulation.getField(fileUploadTask, "blobName"), VALID_BLOB_NAME);
    assertEquals(Deencapsulation.getField(fileUploadTask, "inputStream"), mockInputStream);
    assertEquals(Deencapsulation.getField(fileUploadTask, "streamLength"), VALID_STREAM_LENGTH);
    assertEquals(Deencapsulation.getField(fileUploadTask, "userCallback"), mockIotHubEventCallback);
    assertEquals(Deencapsulation.getField(fileUploadTask, "userCallbackContext"), VALID_CALLBACK_CONTEXT);
    assertEquals(Deencapsulation.getField(fileUploadTask, "httpsTransportManager"), mockHttpsTransportManager);
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Test(org.junit.Test)

Example 7 with FileUploadTask

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

the class FileUploadTaskTest method runCreateNotification.

/* Tests_SRS_FILEUPLOADTASK_21_023: [The run shall create a FileUpload status notification message, by using the FileUploadStatusParser.] */
@Test
public void runCreateNotification() 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 8 with FileUploadTask

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

the class FileUploadTaskTest method runSendNotificationToIothub.

/* Tests_SRS_FILEUPLOADTASK_21_027: [The run shall send the blob request message to the iothub, using the httpsTransportManager.] */
@Test
public void runSendNotificationToIothub() 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.sendFileUploadNotification(mockMessageNotification);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 9 with FileUploadTask

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

the class FileUploadTaskTest method runCreateNotificationMessageThrows.

/* 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 runCreateNotificationMessageThrows() 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 = 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");
}
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) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 10 with FileUploadTask

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

the class FileUploadTaskTest method getFileUploadSasUriChecksHttpStatusCode.

@Test
public void getFileUploadSasUriChecksHttpStatusCode() throws IOException, IllegalArgumentException {
    // arrange
    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);
    new Expectations() {

        {
            mockHttpsTransportManager.getFileUploadSasUri((IotHubTransportMessage) any);
            result = mockResponseMessage;
            mockResponseMessage.getStatus();
            result = IotHubStatusCode.UNAUTHORIZED;
        }
    };
    // act
    try {
        fileUploadTask.getFileUploadSasUri(mockFileUploadSasUriRequest);
        fail("Test should have thrown an IOException with a nested UnauthorizedException");
    } catch (IOException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof UnauthorizedException);
    }
}
Also used : Expectations(mockit.Expectations) NonStrictExpectations(mockit.NonStrictExpectations) FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) UnauthorizedException(com.microsoft.azure.sdk.iot.device.exceptions.UnauthorizedException) IOException(java.io.IOException) 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