From ff3d149bc4d1c0a71b72cf14596338c9591e1c30 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 26 Feb 2013 13:11:12 -0800 Subject: [PATCH 1/3] fix the broken unit test due to nimbus server upgrade. --- .../services/media/AssetIntegrationTest.java | 2 +- .../media/ContentKeyIntegrationTest.java | 41 ++++++++++++++----- .../media/MediaProcessorIntegrationTest.java | 2 +- .../services/media/TaskIntegrationTest.java | 15 +++---- .../scenarios/MediaServiceWrapper.java | 2 +- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java index 2c012d168f51..f262d415b8ea 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java @@ -288,7 +288,7 @@ public void deleteAssetFailedWithInvalidId() throws ServiceException { @Test public void linkAssetContentKeySuccess() throws ServiceException, URISyntaxException { // Arrange - String originalTestName = testAssetPrefix + "linkAssetContentKeyInvalidIdFailed"; + String originalTestName = testAssetPrefix + "linkAssetContentKeySuccess"; AssetInfo assetInfo = service.create(Asset.create().setName(originalTestName) .setOptions(AssetOption.StorageEncrypted)); String contentKeyId = String.format("nb:kid:UUID:%s", UUID.randomUUID()); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java index 3f479a6ea8b7..d7c6f40b96d7 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java @@ -27,6 +27,7 @@ import com.microsoft.windowsazure.services.media.models.ContentKey; import com.microsoft.windowsazure.services.media.models.ContentKeyInfo; import com.microsoft.windowsazure.services.media.models.ContentKeyType; +import com.microsoft.windowsazure.services.media.models.ProtectionKey; import com.microsoft.windowsazure.services.media.models.ProtectionKeyType; public class ContentKeyIntegrationTest extends IntegrationTestBase { @@ -65,15 +66,17 @@ public void canCreateContentKey() throws Exception { // Arrange String testCanCreateContentKeyId = createRandomContentKeyId(); String testCanCreateContentKeyName = "testCanCreateContentKey"; + String protectionKeyId = service.action(ProtectionKey.getProtectionKeyId(testContentKeyType)); // Act - ContentKeyInfo contentKeyInfo = service.create(ContentKey.create(testCanCreateContentKeyId, testContentKeyType, - testEncryptedContentKey).setName(testCanCreateContentKeyName)); + ContentKeyInfo contentKeyInfo = service.create(ContentKey + .create(testCanCreateContentKeyId, testContentKeyType, testEncryptedContentKey) + .setName(testCanCreateContentKeyName).setProtectionKeyId(protectionKeyId)); // Assert verifyContentKeyProperties("ContentKey", testCanCreateContentKeyId, testContentKeyType, - testEncryptedContentKey, testCanCreateContentKeyName, "", ProtectionKeyType.fromCode(0), "", - contentKeyInfo); + testEncryptedContentKey, testCanCreateContentKeyName, protectionKeyId, ProtectionKeyType.fromCode(0), + "", contentKeyInfo); } @Test @@ -81,8 +84,10 @@ public void canGetSingleContentKeyById() throws Exception { // Arrange String expectedName = testContentKeyPrefix + "GetOne"; String testGetSingleContentKeyByIdId = createRandomContentKeyId(); - ContentKeyInfo ContentKeyToGet = service.create(ContentKey.create(testGetSingleContentKeyByIdId, - testContentKeyType, testEncryptedContentKey).setName(expectedName)); + String protectionKeyId = service.action(ProtectionKey.getProtectionKeyId(testContentKeyType)); + ContentKeyInfo ContentKeyToGet = service.create(ContentKey + .create(testGetSingleContentKeyByIdId, testContentKeyType, testEncryptedContentKey) + .setName(expectedName).setProtectionKeyId(protectionKeyId)); // Act ContentKeyInfo retrievedContentKeyInfo = service.get(ContentKey.get(ContentKeyToGet.getId())); @@ -90,7 +95,8 @@ public void canGetSingleContentKeyById() throws Exception { // Assert assertEquals(ContentKeyToGet.getId(), retrievedContentKeyInfo.getId()); verifyContentKeyProperties("ContentKey", testGetSingleContentKeyByIdId, testContentKeyType, - testEncryptedContentKey, expectedName, "", ProtectionKeyType.fromCode(0), "", retrievedContentKeyInfo); + testEncryptedContentKey, expectedName, protectionKeyId, ProtectionKeyType.fromCode(0), "", + retrievedContentKeyInfo); } @Test @@ -102,18 +108,22 @@ public void cannotGetSingleContentKeyByInvalidId() throws Exception { @Test public void canRetrieveListOfContentKeys() throws Exception { + // Arrange String[] ContentKeyNames = new String[] { testContentKeyPrefix + "ListOne", testContentKeyPrefix + "ListTwo" }; + String protectionKeyId = service.action(ProtectionKey.getProtectionKeyId(testContentKeyType)); List expectedContentKeys = new ArrayList(); for (int i = 0; i < ContentKeyNames.length; i++) { String testCanRetrieveListOfContentKeysId = createRandomContentKeyId(); ContentKeyInfo contentKey = service.create(ContentKey.create(testCanRetrieveListOfContentKeysId, - testContentKeyType, testEncryptedContentKey)); + testContentKeyType, testEncryptedContentKey).setProtectionKeyId(protectionKeyId)); expectedContentKeys.add(contentKey); } + // Act List actualContentKeys = service.list(ContentKey.list()); + // Assert verifyListResultContains("listContentKeyss", expectedContentKeys, actualContentKeys, new ComponentDelegate() { @Override public void verifyEquals(String message, Object expected, Object actual) { @@ -124,32 +134,41 @@ public void verifyEquals(String message, Object expected, Object actual) { @Test public void canUseQueryParametersWhenListingContentKeys() throws Exception { + // Arrange String[] ContentKeyNames = new String[] { testContentKeyPrefix + "ListThree", testContentKeyPrefix + "ListFour", testContentKeyPrefix + "ListFive", testContentKeyPrefix + "ListSix", testContentKeyPrefix + "ListSeven" }; + String protectionKeyId = service.action(ProtectionKey.getProtectionKeyId(testContentKeyType)); List expectedContentKeys = new ArrayList(); for (int i = 0; i < ContentKeyNames.length; i++) { ContentKeyInfo contentKeyInfo = service.create(ContentKey.create(createRandomContentKeyId(), - testContentKeyType, testEncryptedContentKey)); + testContentKeyType, testEncryptedContentKey).setProtectionKeyId(protectionKeyId)); expectedContentKeys.add(contentKeyInfo); } + // Act List actualContentKeys = service.list(ContentKey.list().setTop(2)); + // Assert assertEquals(2, actualContentKeys.size()); } @Test public void canDeleteContentKeyById() throws Exception { + // Arrange + String protectionKeyId = service.action(ProtectionKey.getProtectionKeyId(testContentKeyType)); String contentKeyName = testContentKeyPrefix + "ToDelete"; - ContentKeyInfo contentKeyToDelete = service.create(ContentKey.create(createRandomContentKeyId(), - testContentKeyType, testEncryptedContentKey).setName(contentKeyName)); + ContentKeyInfo contentKeyToDelete = service.create(ContentKey + .create(createRandomContentKeyId(), testContentKeyType, testEncryptedContentKey) + .setName(contentKeyName).setProtectionKeyId(protectionKeyId)); List listContentKeysResult = service.list(ContentKey.list()); int ContentKeyCountBaseline = listContentKeysResult.size(); + // Act service.delete(ContentKey.delete(contentKeyToDelete.getId())); + // Assert listContentKeysResult = service.list(ContentKey.list()); assertEquals("listPoliciesResult.size", ContentKeyCountBaseline - 1, listContentKeysResult.size()); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java index 052fdc0811ef..176220765c00 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaProcessorIntegrationTest.java @@ -73,6 +73,6 @@ public void listMediaProcessorWithOptionSuccess() throws ServiceException { assertEquals("listMediaProcessors size", 1, listMediaProcessorsResult.size()); MediaProcessorInfo mediaProcessorInfo = listMediaProcessorsResult.get(0); verifyMediaProcessorInfo("mediaProcessorInfo", "nb:mpid:UUID:aec03716-7c5e-4f68-b592-f4850eba9f10", - "Storage Decryption", "Storage Decryption", "", "Microsoft", "1.5.3", mediaProcessorInfo); + "Storage Decryption", "Storage Decryption", "", "Microsoft", "1.5.3.0", mediaProcessorInfo); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/TaskIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/TaskIntegrationTest.java index ad9ca21b6750..2c576c8c193b 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/TaskIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/TaskIntegrationTest.java @@ -71,7 +71,7 @@ public void createTaskSuccess() throws ServiceException, UnsupportedEncodingExce // Optional parameters String configuration = new String(Base64.encode(commonConfiguration), "UTF8"); String name = "My encoding Task " + UUID.randomUUID().toString(); - int priority = 0; + int jobPriority = 3; TaskOption options = TaskOption.ProtectedConfiguration; // Use a fake id, to simulate real use. String encryptionKeyId = "nb:kid:UUID:" + UUID.randomUUID().toString(); @@ -81,7 +81,7 @@ public void createTaskSuccess() throws ServiceException, UnsupportedEncodingExce String initializationVector = new String(Base64.encode(new byte[16]), "UTF8"); CreateBatchOperation taskCreator = Task.create(mediaProcessorId, taskBody).setConfiguration(configuration) - .setName(name).setPriority(priority).setOptions(options).setEncryptionKeyId(encryptionKeyId) + .setName(name).setPriority(jobPriority).setOptions(options).setEncryptionKeyId(encryptionKeyId) .setEncryptionScheme(encryptionScheme).setEncryptionVersion(encryptionVersion) .setInitializationVector(initializationVector); jobCreator.addTaskCreator(taskCreator); @@ -92,8 +92,9 @@ public void createTaskSuccess() throws ServiceException, UnsupportedEncodingExce // Assert assertEquals("taskInfos count", 1, taskInfos.size()); - verifyTaskPropertiesJustStarted("taskInfo", mediaProcessorId, options, taskBody, configuration, name, priority, - encryptionKeyId, encryptionScheme, encryptionVersion, initializationVector, taskInfos.get(0)); + verifyTaskPropertiesJustStarted("taskInfo", mediaProcessorId, options, taskBody, configuration, name, + jobPriority, encryptionKeyId, encryptionScheme, encryptionVersion, initializationVector, + taskInfos.get(0)); } @Test @@ -108,7 +109,7 @@ public void createTwoTasksSuccess() throws ServiceException { String configuration = commonConfiguration; String baseName = "My encoding Task " + UUID.randomUUID().toString(); String[] suffixes = new String[] { " 1", " 2" }; - int priority = 0; + int jobPriority = 3; TaskOption options = TaskOption.None; List taskCreators = new ArrayList(); @@ -128,7 +129,7 @@ public void createTwoTasksSuccess() throws ServiceException { assertEquals("taskInfos count", taskCreators.size(), taskInfos.size()); for (int i = 0; i < taskCreators.size(); i++) { verifyTaskPropertiesJustStartedNoEncryption("taskInfo", mediaProcessorId, options, taskBodies[i], - configuration, baseName + suffixes[i], priority, taskInfos.get(i)); + configuration, baseName + suffixes[i], jobPriority, taskInfos.get(i)); } } @@ -184,7 +185,7 @@ public void cancelTaskSuccess() throws ServiceException, InterruptedException { List taskInfos = service.list(Task.list(cancellingJobInfo.getTasksLink())); for (TaskInfo taskInfo : taskInfos) { verifyTaskPropertiesNoEncryption("canceled task", mediaProcessorId, TaskOption.None, taskBody, - configuration, name, 0, new Date(), null, 0.0, 0.0, null, TaskState.Canceled, taskInfo); + configuration, name, 3, new Date(), null, 0.0, 0.0, null, TaskState.Canceled, taskInfo); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java index 16ba0ddcdf92..19933421282f 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java @@ -278,7 +278,7 @@ public Task.CreateBatchOperation createTaskOptions(String taskName, int inputAss configuration = "VC1 Broadband SD 4x3"; break; case StorageDecryption: - processor = getMediaProcessorIdByName(MEDIA_PROCESSOR_STORAGE_DECRYPTION, "1.5.3"); + processor = getMediaProcessorIdByName(MEDIA_PROCESSOR_STORAGE_DECRYPTION, "1.5.3.0"); configuration = null; break; default: From 34d7de16c77148c8361074260ffbbb1818bcc61b Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Tue, 26 Feb 2013 13:24:32 -0800 Subject: [PATCH 2/3] fix another unit test due to nimbus server upgrade. --- .../windowsazure/services/media/AssetIntegrationTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java index f262d415b8ea..b9bcbb3bfeef 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java @@ -47,6 +47,7 @@ import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; import com.microsoft.windowsazure.services.media.models.LocatorType; +import com.microsoft.windowsazure.services.media.models.ProtectionKey; import com.microsoft.windowsazure.services.media.models.Task; import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; @@ -291,9 +292,12 @@ public void linkAssetContentKeySuccess() throws ServiceException, URISyntaxExcep String originalTestName = testAssetPrefix + "linkAssetContentKeySuccess"; AssetInfo assetInfo = service.create(Asset.create().setName(originalTestName) .setOptions(AssetOption.StorageEncrypted)); + + String protectionKeyId = service.action(ProtectionKey.getProtectionKeyId(ContentKeyType.StorageEncryption)); String contentKeyId = String.format("nb:kid:UUID:%s", UUID.randomUUID()); String encryptedContentKey = "dummyEncryptedContentKey"; - service.create(ContentKey.create(contentKeyId, ContentKeyType.StorageEncryption, encryptedContentKey)); + service.create(ContentKey.create(contentKeyId, ContentKeyType.StorageEncryption, encryptedContentKey) + .setProtectionKeyId(protectionKeyId)); // Act service.action(Asset.linkContentKey(assetInfo.getId(), contentKeyId)); From 39a498fc972c28ef15a12195f455e779ee745732 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 27 Feb 2013 15:49:12 -0800 Subject: [PATCH 3/3] fix a broken unit test --- .../windowsazure/services/media/JobIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index d93041f2c533..608aba0901e0 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -301,7 +301,6 @@ public void canGetTasksFromJob() throws Exception { @Test public void canGetErrorDetailsFromTask() throws Exception { - cleanupEnvironment(); String name = testJobPrefix + "canGetErrorDetailsFromTask"; JobInfo actualJob = service.create(Job.create().setName(name).addInputMediaAsset(assetInfo.getId())