use of com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser in project azure-iot-sdk-java by Azure.
the class FileUploadNotificationParserTest method constructor_json_succeed.
/* Tests_SRS_FILE_UPLOAD_NOTIFICATION_21_001: [The constructor shall create an instance of the FileUploadNotification.] */
/* Tests_SRS_FILE_UPLOAD_NOTIFICATION_21_002: [The constructor shall parse the provided json and initialize `correlationId`, `hostName`, `containerName`, `blobName`, and `sasToken` using the information in the json.] */
@Test
public void constructor_json_succeed() {
// arrange
String validJson = createJson(VALID_DEVICEID, VALID_BLOB_UTI, VALID_BLOB_NAME, VALID_LAST_UPDATE_TIME, VALID_ENQUEUED_TIME_UTC, VALID_BLOB_SIZE_IN_BYTES);
// act
FileUploadNotificationParser fileUploadNotificationParser = new FileUploadNotificationParser(validJson);
// assert
assertFileUploadNotification(fileUploadNotificationParser, VALID_DEVICEID, VALID_BLOB_UTI, VALID_BLOB_NAME, VALID_LAST_UPDATE_TIME, VALID_ENQUEUED_TIME_UTC, VALID_BLOB_SIZE_IN_BYTES);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser in project azure-iot-sdk-java by Azure.
the class AmqpFileUploadNotificationReceive method onFeedbackReceived.
/**
* Handle on feedback received Proton event
* Parse received json and save result to a member variable
* Release semaphore for wait function
* @param feedbackJson Received Json string to process
*/
public synchronized void onFeedbackReceived(String feedbackJson) {
try {
FileUploadNotificationParser notificationParser = new FileUploadNotificationParser(feedbackJson);
fileUploadNotification = new FileUploadNotification(notificationParser.getDeviceId(), notificationParser.getBlobUri(), notificationParser.getBlobName(), notificationParser.getLastUpdatedTime(), notificationParser.getBlobSizeInBytesTag(), notificationParser.getEnqueuedTimeUtc());
} catch (Exception e) {
// this should never happen. However if it does, proton can't handle it. So guard against throwing it at proton.
log.warn("Service gave feedback message with poorly formed json, message abandoned.");
}
}
use of com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser in project azure-iot-sdk-java by Azure.
the class FileUploadNotificationParserTest method constructor_specialCase_blobSizeInBytes_notExists_succeed.
/* Codes_SRS_FILE_UPLOAD_NOTIFICATION_21_012: [If the provided json do not the keys `blobSizeInBytes`, the constructor shall assume the default value 0 for the blob size.] */
@Test
public void constructor_specialCase_blobSizeInBytes_notExists_succeed() {
// arrange
String validJson = "{\n" + " \"deviceId\": \"null\",\n" + " \"blobUri\": \"" + VALID_BLOB_UTI + "\",\n" + " \"blobName\": \"" + VALID_BLOB_NAME + "\",\n" + " \"lastUpdatedTime\": \"" + VALID_LAST_UPDATE_TIME + "\",\n" + " \"enqueuedTimeUtc\": \"" + VALID_ENQUEUED_TIME_UTC + "\"\n" + "}";
// act
FileUploadNotificationParser fileUploadNotificationParser = new FileUploadNotificationParser(validJson);
// assert
assertFileUploadNotification(fileUploadNotificationParser, "null", VALID_BLOB_UTI, VALID_BLOB_NAME, VALID_LAST_UPDATE_TIME, VALID_ENQUEUED_TIME_UTC, 0L);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser in project azure-iot-sdk-java by Azure.
the class FileUploadNotificationParserTest method constructor_json_realCase_succeed.
/* Tests_SRS_FILE_UPLOAD_NOTIFICATION_21_001: [The constructor shall create an instance of the FileUploadNotification.] */
/* Tests_SRS_FILE_UPLOAD_NOTIFICATION_21_002: [The constructor shall parse the provided json and initialize `correlationId`, `hostName`, `containerName`, `blobName`, and `sasToken` using the information in the json.] */
@Test
public void constructor_json_realCase_succeed() {
// arrange
String validJson = "{" + "\"deviceId\":\"test-device1\"," + "\"blobUri\":\"https://storageaccount.blob.core.windows.net/storage-accout-storageaccount/storageaccount-test/hello_world.txt\"," + "\"blobName\":\"storageaccount-test/hello_world.txt\"," + "\"lastUpdatedTime\":\"2017-05-01T23:29:11+00:00\"," + "\"blobSizeInBytes\":45," + "\"enqueuedTimeUtc\":\"2017-05-01T23:29:13.5700695Z\"}";
// act
FileUploadNotificationParser fileUploadNotificationParser = new FileUploadNotificationParser(validJson);
// assert
assertFileUploadNotification(fileUploadNotificationParser, "test-device1", "https://storageaccount.blob.core.windows.net/storage-accout-storageaccount/storageaccount-test/hello_world.txt", "storageaccount-test/hello_world.txt", "2017-05-01T23:29:11+00:00", "2017-05-01T23:29:13.5700695Z", 45);
}
use of com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser in project azure-iot-sdk-java by Azure.
the class FileUploadNotificationParserTest method constructor_specialCase_string_null_succeed.
/* Tests_SRS_FILE_UPLOAD_NOTIFICATION_21_002: [The constructor shall parse the provided json and initialize `correlationId`, `hostName`, `containerName`, `blobName`, and `sasToken` using the information in the json.] */
@Test
public void constructor_specialCase_string_null_succeed() {
// arrange
String validJson = "{\n" + " \"deviceId\": \"null\",\n" + " \"blobUri\": \"" + VALID_BLOB_UTI + "\",\n" + " \"blobName\": \"" + VALID_BLOB_NAME + "\",\n" + " \"lastUpdatedTime\": \"" + VALID_LAST_UPDATE_TIME + "\",\n" + " \"blobSizeInBytes\": " + VALID_BLOB_SIZE_IN_BYTES + ",\n" + " \"enqueuedTimeUtc\": \"" + VALID_ENQUEUED_TIME_UTC + "\"\n" + "}";
// act
FileUploadNotificationParser fileUploadNotificationParser = new FileUploadNotificationParser(validJson);
// assert
assertFileUploadNotification(fileUploadNotificationParser, "null", VALID_BLOB_UTI, VALID_BLOB_NAME, VALID_LAST_UPDATE_TIME, VALID_ENQUEUED_TIME_UTC, VALID_BLOB_SIZE_IN_BYTES);
}
Aggregations