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