/** * @covers WindowsAzure\MediaServices\Internal\ContentPropertiesSerializer::serialize * @covers WindowsAzure\MediaServices\Internal\ContentPropertiesSerializer::_serializeRecursive */ public function testSerializeElement() { // Setup $name = 'NameName'; $nameKey = 'Name'; $statKey = 'Statistics'; $statPendingFilesKey = 'PendingFilesCount'; $statPendingFiles = 1; $statFinishedFilesKey = 'FinishedFilesCount'; $statFinishedFiles = 2; $stat = array($statPendingFilesKey => $statPendingFiles, $statFinishedFilesKey => $statFinishedFiles); $objArray = array($nameKey => $name, $statKey => $stat); $obj = IngestManifest::createFromOptions($objArray); $expected = ' <meta:properties xmlns:meta="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <data:' . $statKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices"> <data:' . $statFinishedFilesKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $statFinishedFiles . '</data:' . $statFinishedFilesKey . '> <data:' . $statPendingFilesKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $statPendingFiles . '</data:' . $statPendingFilesKey . '> </data:' . $statKey . '> <data:' . $nameKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $name . '</data:' . $nameKey . '> </meta:properties> '; // Test $result = ContentPropertiesSerializer::serialize($obj); // Assert $this->assertXmlStringEqualsXmlString($expected, $result); }
public function testBulkIngestEncryptedAsset() { // Setup $asset = new Asset(Asset::OPTIONS_STORAGE_ENCRYPTED); $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); $asset = $this->createAsset($asset); $aesKey = Utilities::generateCryptoKey(32); $protectionKeyId = $this->restProxy->getProtectionKeyId(ProtectionKeyTypes::X509_CERTIFICATE_THUMBPRINT); $protectionKey = $this->restProxy->getProtectionKey($protectionKeyId); $contentKey = new ContentKey(); $contentKey->setContentKey($aesKey, $protectionKey); $contentKey->setProtectionKeyId($protectionKeyId); $contentKey->setProtectionKeyType(ProtectionKeyTypes::X509_CERTIFICATE_THUMBPRINT); $contentKey->setContentKeyType(ContentKeyTypes::STORAGE_ENCRYPTION); $contentKey = $this->createContentKey($contentKey); $this->restProxy->linkContentKeyToAsset($asset, $contentKey); $fileName = TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME; $otherFileName = TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME_1; $manifest = new IngestManifest(); $manifest->setName('IngestManifest' . $this->createSuffix()); $manifest = $this->createIngestManifest($manifest); $manifestAsset = new IngestManifestAsset($manifest->getId()); $manifestAsset = $this->createIngestManifestAsset($manifestAsset, $asset); $manifestFile1 = new IngestManifestFile($fileName, $manifest->getId(), $manifestAsset->getId()); $manifestFile2 = new IngestManifestFile($otherFileName, $manifest->getId(), $manifestAsset->getId()); $initializationVector1 = base64_encode(Utilities::generateCryptoKey(8)); $initializationVector2 = base64_encode(Utilities::generateCryptoKey(8)); $manifestFile1->setIsEncrypted(true); $manifestFile1->setEncryptionKeyId($contentKey->getId()); $manifestFile1->setEncryptionScheme(EncryptionSchemes::STORAGE_ENCRYPTION); $manifestFile1->setEncryptionVersion(Resources::MEDIA_SERVICES_ENCRYPTION_VERSION); $manifestFile1->setInitializationVector($initializationVector1); $manifestFile2->setIsEncrypted(true); $manifestFile2->setEncryptionKeyId($contentKey->getId()); $manifestFile2->setEncryptionScheme(EncryptionSchemes::STORAGE_ENCRYPTION); $manifestFile2->setEncryptionVersion(Resources::MEDIA_SERVICES_ENCRYPTION_VERSION); $manifestFile2->setInitializationVector($initializationVector2); $manifestFile1 = $this->createIngestManifestFile($manifestFile1); $manifestFile2 = $this->createIngestManifestFile($manifestFile2); $initialStat = $this->restProxy->getIngestManifest($manifest); $blobUrl = $manifest->getBlobStorageUriForUpload(); $blobUrlParts = explode('/', $blobUrl); $blob = array_pop($blobUrlParts); $blobRestProxy = $this->builder->createBlobService($this->connectionString); $blobRestProxy->createBlockBlob($blob, $fileName, TestResources::MEDIA_SERVICES_DUMMY_FILE_CONTENT); $this->waitIngestManifestFinishedFiles($manifest, 1); $finishedFirstStat = $this->restProxy->getIngestManifest($manifest); $blobRestProxy->createBlockBlob($blob, $otherFileName, TestResources::MEDIA_SERVICES_DUMMY_FILE_CONTENT_1); $this->waitIngestManifestFinishedFiles($manifest, 2); $finishedSecondStat = $this->restProxy->getIngestManifest($manifest); // Test // Assert $contentKeysFromAsset = $this->restProxy->getAssetContentKeys($asset); $assetFiles = $this->restProxy->getAssetAssetFileList($asset); $this->assertEquals(0, $initialStat->getStatistics()->getFinishedFilesCount()); $this->assertEquals(1, $finishedFirstStat->getStatistics()->getFinishedFilesCount()); $this->assertEquals(2, $finishedSecondStat->getStatistics()->getFinishedFilesCount()); $this->assertEquals($contentKey->getId(), $contentKeysFromAsset[0]->getId()); $this->assertEquals($contentKey->getId(), $manifestFile1->getEncryptionKeyId()); $this->assertEquals('true', $manifestFile1->getIsEncrypted()); $this->assertEquals(EncryptionSchemes::STORAGE_ENCRYPTION, $manifestFile1->getEncryptionScheme()); $this->assertEquals($initializationVector1, $manifestFile1->getInitializationVector()); $this->assertEquals(Resources::MEDIA_SERVICES_ENCRYPTION_VERSION, $manifestFile1->getEncryptionVersion()); $this->assertEquals($contentKey->getId(), $manifestFile2->getEncryptionKeyId()); $this->assertEquals('true', $manifestFile2->getIsEncrypted()); $this->assertEquals(EncryptionSchemes::STORAGE_ENCRYPTION, $manifestFile2->getEncryptionScheme()); $this->assertEquals($initializationVector2, $manifestFile2->getInitializationVector()); $this->assertEquals(Resources::MEDIA_SERVICES_ENCRYPTION_VERSION, $manifestFile2->getEncryptionVersion()); // Files order is not static, so we don't know the index of each file and need to serve them as a set $resultFileNames = array($assetFiles[0]->getName(), $assetFiles[1]->getName()); $this->assertContains($otherFileName, $resultFileNames); $this->assertEquals($asset->getId(), $assetFiles[0]->getParentAssetId()); $this->assertContains($fileName, $resultFileNames); $this->assertEquals($asset->getId(), $assetFiles[1]->getParentAssetId()); }
/** * Get IngestManifest list * * @return array of Models\IngestManifest */ public function getIngestManifestList() { $propertyList = $this->_getEntityList("IngestManifests"); $result = array(); foreach ($propertyList as $properties) { $result[] = IngestManifest::createFromOptions($properties); } return $result; }
/** * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::getIngestManifestFileList */ public function testGetIngestManifestFileList() { // Setup $ingestManifest = new IngestManifest(); $name = TestResources::MEDIA_SERVICES_INGEST_MANIFEST . $this->createSuffix(); $ingestManifest->setName($name); $ingestManifest = $this->createIngestManifest($ingestManifest); $ingestAssetFileName = TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME . $this->createSuffix(); $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); $asset = $this->createAsset($asset); $ingestManifestAsset = new IngestManifestAsset($ingestManifest->getId()); $ingestManifestAsset = $this->createIngestManifestAsset($ingestManifestAsset, $asset); $ingestManifestFile = new IngestManifestFile($ingestAssetFileName, $ingestManifest->getId(), $ingestManifestAsset->getId()); $ingestManifestFile = $this->createIngestManifestFile($ingestManifestFile); // Test $result = $this->restProxy->getIngestManifestFileList(); // Assert $this->assertGreaterThanOrEqual(1, count($result)); $this->assertEquals($ingestManifestFile->getParentIngestManifestId(), $result[0]->getParentIngestManifestId()); $this->assertEquals($ingestManifestFile->getParentIngestManifestAssetId(), $result[0]->getParentIngestManifestAssetId()); $this->assertEquals($ingestManifestFile->getName(), $result[0]->getName()); }
/** * Create manifest from array * * @param array $options Array containing values for object properties * * @return WindowsAzure\MediaServices\Models\IngestManifest */ public static function createFromOptions($options) { $manifest = new IngestManifest(); $manifest->fromArray($options); return $manifest; }
/** * @covers WindowsAzure\MediaServices\Models\IngestManifest::getId */ public function testGetId() { // Setup $id = 'ingest-id-258'; $options = array('Id' => $id); $ingestManifest = IngestManifest::createFromOptions($options); // Test $result = $ingestManifest->getId(); // Assert $this->assertEquals($id, $result); }