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