Search in sources :

Example 6 with FileUploadNotificationParser

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);
}
Also used : FileUploadNotificationParser(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser) Test(org.junit.Test)

Example 7 with FileUploadNotificationParser

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.");
    }
}
Also used : FileUploadNotification(com.microsoft.azure.sdk.iot.service.FileUploadNotification) FileUploadNotificationParser(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser) IOException(java.io.IOException)

Example 8 with FileUploadNotificationParser

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);
}
Also used : FileUploadNotificationParser(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser) Test(org.junit.Test)

Example 9 with FileUploadNotificationParser

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);
}
Also used : FileUploadNotificationParser(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser) Test(org.junit.Test)

Example 10 with FileUploadNotificationParser

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);
}
Also used : FileUploadNotificationParser(com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser) Test(org.junit.Test)

Aggregations

FileUploadNotificationParser (com.microsoft.azure.sdk.iot.deps.serializer.FileUploadNotificationParser)10 Test (org.junit.Test)9 Date (java.util.Date)2 FileUploadNotification (com.microsoft.azure.sdk.iot.service.FileUploadNotification)1 IOException (java.io.IOException)1