/**
  * @covers MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataOptions::setAccessCondition
  */
 public function testSetAccessCondition()
 {
     // Setup
     $expected = AccessCondition::none();
     $result = new SetBlobMetadataOptions();
     // Test
     $result->setAccessCondition($expected);
     // Assert
     $this->assertEquals($expected, $result->getAccessCondition());
 }
 /**
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlockBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobMetadata
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobProperties
  * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setBlobMetadata
  */
 private function setBlobMetadataWorker($container, $options, $metadata)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container);
     // Make sure there is something to test
     $createBlockBlobResult = $this->restProxy->createBlockBlob($container, $blob, "");
     if (!is_null($options)) {
         BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $createBlockBlobResult->getETag());
     }
     $firstkey = '';
     if (!is_null($metadata) && count($metadata) > 0) {
         $firstkey = array_keys($metadata);
         $firstkey = $firstkey[0];
     }
     try {
         // And put in some properties
         $res = is_null($options) ? $this->restProxy->setBlobMetadata($container, $blob, $metadata) : $this->restProxy->setBlobMetadata($container, $blob, $metadata, $options);
         if (is_null($options)) {
             $options = new SetBlobMetadataOptions();
         }
         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 access condition should throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Expect failing access condition to throw');
         }
         if (Utilities::startsWith($firstkey, '<')) {
             $this->assertTrue(false, 'Should get HTTP request error if the metadata is invalid');
         }
         $this->verifySetBlobMetadataWorker($res);
         $res2 = $this->restProxy->getBlobMetadata($container, $blob);
         $this->verifyGetBlobMetadataWorker($res2, $metadata);
     } catch (ServiceException $e) {
         if (Utilities::startsWith($firstkey, '<')) {
             $this->assertEquals(TestResources::STATUS_BAD_REQUEST, $e->getCode(), 'getCode');
         } else {
             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);
 }
 public static function getSetBlobMetadataOptions()
 {
     $ret = array();
     $options = new SetBlobMetadataOptions();
     array_push($ret, $options);
     $options = new SetBlobMetadataOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new SetBlobMetadataOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     foreach (self::getAllAccessConditions() as $ac) {
         $options = new SetBlobMetadataOptions();
         $options->setAccessCondition($ac);
         array_push($ret, $options);
     }
     // TODO: Make sure the lease id part is tested in the leasing part.
     //        $options = new SetBlobMetadataOptions();
     //        $options->setLeaseId(leaseId)
     //        array_push($ret, $options);
     return $ret;
 }
Ejemplo n.º 4
0
 /**
  * Sets metadata headers on the blob.
  * 
  * @param string                        $container name of the container
  * @param string                        $blob      name of the blob
  * @param array                         $metadata  key/value pair representation
  * @param Models\SetBlobMetadataOptions $options   optional parameters
  * 
  * @return Models\SetBlobMetadataResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179414.aspx
  */
 public function setBlobMetadata($container, $blob, $metadata, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $this->validateMetadata($metadata);
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::STATUS_OK;
     if (is_null($options)) {
         $options = new SetBlobMetadataOptions();
     }
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->addMetadataHeaders($headers, $metadata);
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'metadata');
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     return SetBlobMetadataResult::create(HttpFormatter::formatHeaders($response->getHeaders()));
 }