Permalink
Browse files

Fix TODOs in scenario tests.

* Verify the tasks in a job
* Set task options

Remove spurious `println`s in tests
Make scenario tests that wait for jobs to complete to wait for 30 iterations (like the other tests), instead of 10 iterations.
Copy and refactor some parts of the encryption tests, to validate that `AssetFile`s can propertly store encryption information
  • Loading branch information...
1 parent c33b704 commit 97fe6534525502482b44584da267261ba28201c5 @jcookems jcookems committed Jan 9, 2013
@@ -130,7 +130,7 @@ private JobInfo decodeAsset(String name, String inputAssetId) throws ServiceExce
JobInfo currentJobInfo = jobInfo;
int retryCounter = 0;
- while (currentJobInfo.getState().getCode() < 3 && retryCounter < 10) {
+ while (currentJobInfo.getState().getCode() < 3 && retryCounter < 30) {
Thread.sleep(10000);
currentJobInfo = service.get(Job.get(jobInfo.getId()));
retryCounter++;
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
+import java.util.Random;
import java.util.UUID;
import org.junit.AfterClass;
@@ -89,6 +90,20 @@ public void uploadFiles() throws Exception {
}
@Test
+ public void uploadEncryptedFiles() throws Exception {
+ signalSetupStarting();
+ // Media Services requires 256-bit (32-byte) keys for AES encryption.
+ Random random = new Random();
+ byte[] aesKey = new byte[32];
+ random.nextBytes(aesKey);
+ AssetInfo asset = wrapper.createAsset(testAssetPrefix + "uploadEncryptedFiles", AssetOption.StorageEncrypted);
+ signalSetupFinished();
+
+ wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles(), aesKey);
+ validator.validateAssetFiles(asset, getTestAssetFiles());
+ }
+
+ @Test
public void downloadFiles() throws Exception {
signalSetupStarting();
AssetInfo asset = wrapper.createAsset(testAssetPrefix + "downloadFiles", AssetOption.None);
@@ -125,6 +140,34 @@ public void transformAsset() throws Exception {
validator.validateOutputAssets(outputAssets, getTestAssetFiles().keys());
}
+ @Test
+ public void transformEncryptedAsset() throws Exception {
+ signalSetupStarting();
+ // Media Services requires 256-bit (32-byte) keys for AES encryption.
+ Random random = new Random();
+ byte[] aesKey = new byte[32];
+ random.nextBytes(aesKey);
+ AssetInfo asset = wrapper
+ .createAsset(testAssetPrefix + "transformEncryptedAsset", AssetOption.StorageEncrypted);
+ wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles(), aesKey);
+ String jobName = "my job transformEncryptedAsset" + UUID.randomUUID().toString();
+ JobInfo job = wrapper.createJob(jobName, asset, wrapper.createTaskOptionsDecodeAsset("Decode", 0, 0));
+ signalSetupFinished();
+
+ waitForJobToFinish(job);
+ List<AssetInfo> outputAssets = wrapper.getJobOutputMediaAssets(job);
+ validator.validateOutputAssets(outputAssets, getTestAssetFiles().keys());
+
+ // Verify output asset files.
+ assertEquals("output assets count", 1, outputAssets.size());
+ AssetInfo outputAsset = outputAssets.get(0);
+ validator.validateAssetFiles(outputAsset, getTestAssetFiles());
+
+ // Verify assets were decoded.
+ List<URL> fileUrls = wrapper.createFileURLsFromAsset(outputAsset, 10);
+ validator.validateAssetFileUrls(fileUrls, getTestAssetFiles());
+ }
+
private void waitForJobToFinish(JobInfo job) throws InterruptedException, ServiceException {
for (int counter = 0; !wrapper.isJobFinished(job); counter++) {
if (counter > 30) {
@@ -35,6 +35,8 @@
import com.microsoft.windowsazure.services.media.models.AssetInfo;
import com.microsoft.windowsazure.services.media.models.AssetOption;
import com.microsoft.windowsazure.services.media.models.AssetState;
+import com.microsoft.windowsazure.services.media.models.ContentKey;
+import com.microsoft.windowsazure.services.media.models.ContentKeyInfo;
import com.microsoft.windowsazure.services.media.models.JobInfo;
import com.microsoft.windowsazure.services.media.models.ListResult;
import com.microsoft.windowsazure.services.media.models.Task;
@@ -96,15 +98,30 @@ public void validateAssetFiles(AssetInfo asset, Hashtable<String, InputStream> i
assertNotNull("assetFiles", assetFiles);
assertEquals("assetFiles.size", inputFiles.size(), assetFiles.size());
- // More general verifications:
- // * Verify that the asset count on the server increments for each asset added.
- // * Verify that the file count on the server increments for each file added.
- // * Verify that can query the server for assets matching
- // * The created asset ID, and get only that one item
- // * The created asset name, get only that one.
- // * If Encrypted, verify file and content key
- // * Get the asset encryption info and compare with the file's encryption info
- // * Compare these properties: IsEncrypted, InitializationVector, EncryptionKeyId, EncryptionScheme, EncryptionVersion
+ ContentKeyInfo contentKey = null;
+ if (asset.getOptions() == AssetOption.StorageEncrypted) {
+ ListResult<ContentKeyInfo> contentKeys = service.list(ContentKey.list(asset.getContentKeysLink()));
+ assertEquals("contentKeys size", 1, contentKeys.size());
+ contentKey = contentKeys.get(0);
+ }
+
+ // Compare encryption info for asset files
+ for (AssetFileInfo assetFile : assetFiles) {
+ if (asset.getOptions() == AssetOption.StorageEncrypted) {
+ assertEquals("assetFile.getIsEncrypted", true, assetFile.getIsEncrypted());
+ assertEquals("assetFile.getEncryptionKeyId", contentKey.getId(), assetFile.getEncryptionKeyId());
+ assertNotNullOrEmpty("assetFile.getEncryptionScheme", assetFile.getEncryptionScheme());
+ assertNotNullOrEmpty("assetFile.getEncryptionVersion", assetFile.getEncryptionVersion());
+ assertNotNullOrEmpty("assetFile.getInitializationVector", assetFile.getInitializationVector());
+ }
+ else {
+ assertEquals("assetFile.getIsEncrypted", false, assetFile.getIsEncrypted());
+ assertNullOrEmpty("assetFile.getEncryptionKeyId", assetFile.getEncryptionKeyId());
+ assertNullOrEmpty("assetFile.getEncryptionScheme", assetFile.getEncryptionScheme());
+ assertNullOrEmpty("assetFile.getEncryptionVersion", assetFile.getEncryptionVersion());
+ assertNullOrEmpty("assetFile.getInitializationVector", assetFile.getInitializationVector());
+ }
+ }
// Compare the asset files with all files
List<AssetFileInfo> allFiles = service.list(AssetFile.list());
@@ -132,26 +149,24 @@ public void validateAssetFileUrls(List<URL> fileUrls, Hashtable<String, InputStr
}
}
- public void validateJob(JobInfo job, String name, AssetInfo asset, List<Task.CreateBatchOperation> createTasks) {
+ public void validateJob(JobInfo job, String name, AssetInfo asset, List<Task.CreateBatchOperation> createTasks)
+ throws ServiceException {
assertDateApproxEquals("getEndTime", new Date(), job.getCreated());
assertEquals("job.getName", name, job.getName());
- // TODO: Uncomment when fixed:
- // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508
- // List<String> inputAssets = job.getInputMediaAssets();
- // assertNotNull("inputAssets", inputAssets);
- // assertEquals("inputAssets.size()", 1, inputAssets.size());
- // assertEquals("inputAssets.get(0)", asset.getId(), inputAssets.get(0));
- //
- // List<String> outputAssets = job.getOutputMediaAssets();
- // assertNotNull("outputAssets", outputAssets);
- // assertEquals("outputAssets.size()", createTasks.size(), outputAssets.size());
+ List<AssetInfo> inputAssets = service.list(Asset.list(job.getInputAssetsLink()));
+ assertNotNull("inputAssets", inputAssets);
+ assertEquals("inputAssets.size()", 1, inputAssets.size());
+ assertEquals("inputAssets.get(0)", asset.getId(), inputAssets.get(0).getId());
+
+ List<AssetInfo> outputAssets = service.list(Asset.list(job.getOutputAssetsLink()));
+ assertNotNull("outputAssets", outputAssets);
+ assertEquals("outputAssets.size()", createTasks.size(), outputAssets.size());
}
public void validateOutputAssets(List<AssetInfo> outputAssets, Enumeration<String> enumeration) {
assertNotNull("outputAssets", outputAssets);
for (AssetInfo asset : outputAssets) {
-
assertNotNull("asset", asset);
assertNotNull("asset.getId", asset.getId());
assertFalse("asset.getId != ''", "".equals(asset.getId()));
@@ -239,4 +254,23 @@ private void assertStreamsEqual(InputStream inputStream1, InputStream inputStrea
inputStream2.close();
}
}
+
+ private void assertNullOrEmpty(String message, String actual) {
+ if (actual == null) {
+ assertNull(message, actual);
+ }
+ else {
+ assertEquals(message, "", actual);
+ }
+ }
+
+ private void assertNotNullOrEmpty(String message, String actual) {
+ if (actual == null) {
+ assertNotNull(message, actual);
+ }
+ else {
+ assertTrue(message + ": expect " + actual + " to be null or empty", actual.length() > 0);
+ }
+ }
+
}
Oops, something went wrong.

0 comments on commit 97fe653

Please sign in to comment.