Permalink
Browse files

self code review.

  • Loading branch information...
1 parent f7f032e commit 53b73c665f970efaba05d064d159149831576ee9 Albert Cheng committed Dec 17, 2012
@@ -21,44 +21,56 @@
/**
* This type maps the XML returned in the odata ATOM serialization
- * for Asset entities.
+ * for ErrorDetail entities.
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class ErrorDetailType implements MediaServiceDTO {
+ /** The code. */
@XmlElement(name = "Code", namespace = Constants.ODATA_DATA_NS)
protected String code;
+ /** The message. */
@XmlElement(name = "Message", namespace = Constants.ODATA_DATA_NS)
protected String message;
/**
+ * Gets the code.
+ *
* @return the code
*/
public String getCode() {
return code;
}
/**
+ * Sets the code.
+ *
* @param code
* the id to set
+ * @return the error detail type
*/
public ErrorDetailType setCode(String code) {
this.code = code;
return this;
}
/**
+ * Gets the message.
+ *
* @return the message
*/
public String getMessage() {
return message;
}
/**
+ * Sets the message.
+ *
* @param message
* the message to set
+ * @return the error detail type
*/
public ErrorDetailType setMessage(String message) {
this.message = message;
@@ -21,7 +21,6 @@
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
import com.microsoft.windowsazure.services.media.implementation.content.ContentKeyRestType;
-// TODO: Auto-generated Javadoc
/**
* The Class ContentKeyInfo.
*/
@@ -99,63 +99,6 @@ private String getProtectionKey(ContentKeyType contentKeyType) {
return protectionKey;
}
- @Test
- public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
- // Arrange
- Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
- InputStream smallWMVInputStream = getClass().getResourceAsStream("/media/SmallWMV.wmv");
- byte[] aesKey = EncryptionHelper.createRandomVector(256);
- byte[] initializationVector = EncryptionHelper.createRandomVector(128);
- int durationInMinutes = 10;
-
- // Act
-
- // creates asset
- AssetInfo assetInfo = service.create(Asset.create().setName("uploadAesProtectedAssetSuccess")
- .setOptions(AssetOption.StorageEncrypted));
-
- // creates writable access policy
- AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create("uploadAesPortectedAssetSuccess",
- durationInMinutes, EnumSet.of(AccessPolicyPermission.WRITE)));
-
- // creates locator for the input media asset
- LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
- LocatorType.SAS));
-
- // gets the public key for storage encryption.
-
- String protectionKeyId = getProtectionKeyId();
- String protectionKey = getProtectionKey(protectionKeyId);
-
- // creates the content key with encrypted
- ContentKeyInfo contentKeyInfo = createContentKey(aesKey, ContentKeyType.StorageEncryption, protectionKeyId,
- protectionKey);
-
- // link the content key with the asset.
- linkContentKey(assetInfo, contentKeyInfo);
-
- // encrypt the file.
- byte[] encryptedContent = EncryptionHelper.EncryptFile(smallWMVInputStream, aesKey, initializationVector);
-
- // upload the encrypted file to the server.
- AssetFileInfo assetFileInfo = uploadEncryptedAssetFile(assetInfo, locatorInfo, contentKeyInfo,
- "uploadAesProtectedAssetSuccess", encryptedContent);
-
- // submit and execute the decoding job.
- JobInfo jobInfo = decodeAsset("uploadAesProtectedAssetSuccess", assetInfo);
-
- // assert
- LinkInfo 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());
-
- }
-
private String getProtectionKeyId() throws ServiceException {
String protectionKeyId = (String) service.action(ProtectionKey
.getProtectionKeyId(ContentKeyType.StorageEncryption));
@@ -241,4 +184,61 @@ private ContentKeyInfo createContentKey(byte[] aesKey, ContentKeyType contentKey
return contentKeyInfo;
}
+ @Test
+ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception {
+ // Arrange
+ Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
+ InputStream smallWMVInputStream = getClass().getResourceAsStream("/media/SmallWMV.wmv");
+ byte[] aesKey = EncryptionHelper.createRandomVector(256);
+ byte[] initializationVector = EncryptionHelper.createRandomVector(128);
+ int durationInMinutes = 10;
+
+ // Act
+
+ // creates asset
+ AssetInfo assetInfo = service.create(Asset.create().setName("uploadAesProtectedAssetSuccess")
+ .setOptions(AssetOption.StorageEncrypted));
+
+ // creates writable access policy
+ AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create("uploadAesPortectedAssetSuccess",
+ durationInMinutes, EnumSet.of(AccessPolicyPermission.WRITE)));
+
+ // creates locator for the input media asset
+ LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
+ LocatorType.SAS));
+
+ // gets the public key for storage encryption.
+
+ String protectionKeyId = getProtectionKeyId();
+ String protectionKey = getProtectionKey(protectionKeyId);
+
+ // creates the content key with encrypted
+ ContentKeyInfo contentKeyInfo = createContentKey(aesKey, ContentKeyType.StorageEncryption, protectionKeyId,
+ protectionKey);
+
+ // link the content key with the asset.
+ linkContentKey(assetInfo, contentKeyInfo);
+
+ // encrypt the file.
+ byte[] encryptedContent = EncryptionHelper.EncryptFile(smallWMVInputStream, aesKey, initializationVector);
+
+ // upload the encrypted file to the server.
+ AssetFileInfo assetFileInfo = uploadEncryptedAssetFile(assetInfo, locatorInfo, contentKeyInfo,
+ "uploadAesProtectedAssetSuccess", encryptedContent);
+
+ // submit and execute the decoding job.
+ JobInfo jobInfo = decodeAsset("uploadAesProtectedAssetSuccess", assetInfo);
+
+ // assert
+ LinkInfo 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());
+
+ }
+
}

0 comments on commit 53b73c6

Please sign in to comment.