Search in sources :

Example 1 with FileUploadTask

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

the class FileUploadTaskTest method runSendRequestThrows.

/* 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 runSendRequestThrows() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    new NonStrictExpectations() {

        {
            new FileUploadSasUriRequest(VALID_BLOB_NAME);
            result = mockFileUploadSasUriRequest;
            mockFileUploadSasUriRequest.toJson();
            result = VALID_REQUEST_JSON;
            new IotHubTransportMessage(VALID_REQUEST_JSON);
            result = mockMessageRequest;
            mockHttpsTransportManager.getFileUploadSasUri(mockMessageRequest);
            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.getFileUploadSasUri(mockMessageRequest);
            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) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) FileUploadSasUriRequest(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriRequest) Test(org.junit.Test)

Example 2 with FileUploadTask

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

the class FileUploadTaskTest method sendNotificationChecksHttpStatusCode.

@Test
public void sendNotificationChecksHttpStatusCode() throws IOException, IllegalArgumentException, URISyntaxException {
    // 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.sendFileUploadNotification((IotHubTransportMessage) any);
            result = mockResponseMessage;
            mockResponseMessage.getStatus();
            result = IotHubStatusCode.BAD_FORMAT;
        }
    };
    // act
    try {
        fileUploadTask.sendNotification(mockFileUploadNotification);
        fail("Test should have thrown an IOException with a nested BadFormatException");
    } catch (IOException e) {
        assertNotNull(e.getCause());
        assertTrue(e.getCause() instanceof BadFormatException);
    }
}
Also used : Expectations(mockit.Expectations) NonStrictExpectations(mockit.NonStrictExpectations) FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) BadFormatException(com.microsoft.azure.sdk.iot.device.exceptions.BadFormatException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with FileUploadTask

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

the class FileUploadTaskTest method runFileUploadRequestParserThrows.

/* 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 runFileUploadRequestParserThrows() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    new NonStrictExpectations() {

        {
            new FileUploadSasUriRequest(VALID_BLOB_NAME);
            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) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) FileUploadSasUriRequest(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriRequest) Test(org.junit.Test)

Example 4 with FileUploadTask

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

the class FileUploadTaskTest method runSetPOSTForRequest.

/* Tests_SRS_FILEUPLOADTASK_21_008: [The run shall set the message method as `POST`.] */
@Test
public void runSetPOSTForRequest() 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(mockMessageRequest, "setIotHubMethod", IotHubMethod.POST);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 5 with FileUploadTask

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

the class FileUploadTaskTest method runCreateRequestMessageThrows.

/* 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 runCreateRequestMessageThrows() throws IOException, IllegalArgumentException, URISyntaxException {
    // arrange
    new NonStrictExpectations() {

        {
            new FileUploadSasUriRequest(VALID_BLOB_NAME);
            result = mockFileUploadSasUriRequest;
            mockFileUploadSasUriRequest.toJson();
            result = VALID_REQUEST_JSON;
            new IotHubTransportMessage(VALID_REQUEST_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");
    // assert
    new Verifications() {

        {
            mockIotHubEventCallback.execute(IotHubStatusCode.ERROR, VALID_CALLBACK_CONTEXT);
            times = 1;
        }
    };
}
Also used : FileUploadTask(com.microsoft.azure.sdk.iot.device.fileupload.FileUploadTask) IotHubTransportMessage(com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) FileUploadSasUriRequest(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadSasUriRequest) 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