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");
}
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");
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
Aggregations