InputStream encryptedContent = EncryptionHelper.encryptFile(
mpeg4H264InputStream, aesKey, iv);
int durationInMinutes = 10;
// Act
AssetInfo assetInfo = service.create(Asset.create()
.setName(testAssetPrefix + "uploadAesProtectedAssetSuccess")
.setOptions(AssetOption.StorageEncrypted));
WritableBlobContainerContract blobWriter = getBlobWriter(
assetInfo.getId(), durationInMinutes);
// gets the public key for storage encryption.
String contentKeyId = createContentKey(aesKey);
// link the content key with the asset.
service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyId));
// upload the encrypted file to the server.
uploadEncryptedAssetFile(assetInfo, blobWriter, "MPEG4-H264.mp4",
encryptedContent, contentKeyId, iv);
// submit and execute the decoding job.
JobInfo jobInfo = decodeAsset(testJobPrefix
+ "uploadAesProtectedAssetSuccess", assetInfo.getId());
// assert
LinkInfo<TaskInfo> taskLinkInfo = jobInfo.getTasksLink();
List<TaskInfo> taskInfos = service.list(Task.list(taskLinkInfo));
for (TaskInfo taskInfo : taskInfos) {
assertEquals(TaskState.Completed, taskInfo.getState());
ListResult<AssetInfo> outputs = service.list(Asset.list(taskInfo
.getOutputAssetsLink()));
assertEquals(1, outputs.size());
}
assertEquals(JobState.Finished, jobInfo.getState());
// Verify that the contents match
InputStream expected = getClass().getResourceAsStream(
"/media/MPEG4-H264.mp4");
ListResult<AssetInfo> outputAssets = service.list(Asset.list(jobInfo
.getOutputAssetsLink()));
assertEquals(1, outputAssets.size());
AssetInfo outputAsset = outputAssets.get(0);
ListResult<AssetFileInfo> assetFiles = service.list(AssetFile
.list(assetInfo.getAssetFilesLink()));
assertEquals(1, assetFiles.size());
AssetFileInfo outputFile = assetFiles.get(0);
InputStream actual = getFileContents(outputAsset.getId(),
outputFile.getName(), durationInMinutes);
assertStreamsEqual(expected, actual);
}