Exemple #1
0
 /**
  * Returns all properties and metadata on the blob.
  * 
  * @param string                        $container name of the container
  * @param string                        $blob      name of the blob
  * @param Models\GetBlobMetadataOptions $options   optional parameters
  * 
  * @return Models\GetBlobMetadataResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179350.aspx
  */
 public function getBlobMetadata($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $method = Resources::HTTP_HEAD;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::STATUS_OK;
     if (is_null($options)) {
         $options = new GetBlobMetadataOptions();
     }
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot());
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'metadata');
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $metadata = $this->getMetadataArray($response->getHeader());
     return GetBlobMetadataResult::create($response->getHeader(), $metadata);
 }
 /**
  * @covers WindowsAzure\Blob\Models\GetBlobMetadataOptions::getSnapshot
  */
 public function testGetSnapshot()
 {
     // Setup
     $blob = new GetBlobMetadataOptions();
     $expected = TestResources::QUEUE_URI;
     $blob->setSnapshot($expected);
     // Test
     $actual = $blob->getSnapshot();
     // Assert
     $this->assertEquals($expected, $actual);
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::deleteBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlobMetadata
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlobProperties
  * @covers WindowsAzure\Blob\BlobRestProxy::setBlobMetadata
  */
 private function getBlobMetadataWorker($container, $options)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName();
     // Make sure there is something to test
     $this->restProxy->createBlockBlob($container, $blob, "");
     $properties = BlobServiceFunctionalTestData::getNiceMetadata();
     $this->restProxy->setBlobMetadata($container, $blob, $properties);
     // TODO: Bug https://github->com/WindowsAzure/azure-sdk-for-java/issues/74
     // means that createBlockBlob does not return the etag. So just read it separately.
     $blobInfo = $this->restProxy->getBlobProperties($container, $blob);
     if (!is_null($options)) {
         BlobServiceFunctionalTestData::fixEtagAccessCondition($options->getAccessCondition(), $blobInfo->getProperties()->getEtag());
     }
     try {
         $res = is_null($options) ? $this->restProxy->getBlobMetadata($container, $blob) : $this->restProxy->getBlobMetadata($container, $blob, $options);
         if (is_null($options)) {
             $options = new GetBlobMetadataOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Failing temporal access condition should throw');
         }
         if (!BlobServiceFunctionalTestData::passEtagAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Failing etag access condition should throw');
         }
         $this->verifyGetBlobMetadataWorker($res, $properties);
     } catch (ServiceException $e) {
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertEquals(500, $e->getCode(), 'bad timeout: getCode');
         } else {
             if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
                 $this->assertEquals(412, $e->getCode(), 'bad temporal access condition: getCode');
             } else {
                 if (!BlobServiceFunctionalTestData::passEtagAccessCondition($options->getAccessCondition())) {
                     $this->assertEquals(412, $e->getCode(), 'bad etag access condition: getCode');
                 } else {
                 }
             }
         }
     }
     // Clean up.
     $this->restProxy->deleteBlob($container, $blob);
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::deleteBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlobMetadata
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlobProperties
  * @covers WindowsAzure\Blob\BlobRestProxy::setBlobMetadata
  */
 private function getBlobMetadataWorker($container, $options)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container);
     // Make sure there is something to test
     $createBlockBlobResult = $this->restProxy->createBlockBlob($container, $blob, "");
     $properties = BlobServiceFunctionalTestData::getNiceMetadata();
     $this->restProxy->setBlobMetadata($container, $blob, $properties);
     if (!is_null($options)) {
         BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $createBlockBlobResult->getETag());
     }
     try {
         $res = is_null($options) ? $this->restProxy->getBlobMetadata($container, $blob) : $this->restProxy->getBlobMetadata($container, $blob, $options);
         if (is_null($options)) {
             $options = new GetBlobMetadataOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Failing temporal access condition should throw');
         }
         if (!BlobServiceFunctionalTestData::passETagAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Failing etag access condition should throw');
         }
         $this->verifyGetBlobMetadataWorker($res, $properties);
     } catch (ServiceException $e) {
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'bad timeout: getCode');
         } else {
             if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
                 $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad temporal access condition: getCode');
             } else {
                 if (!BlobServiceFunctionalTestData::passETagAccessCondition($options->getAccessCondition())) {
                     $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad etag access condition: getCode');
                 } else {
                     throw $e;
                 }
             }
         }
     }
     // Clean up.
     $this->restProxy->deleteBlob($container, $blob);
 }