/**
  * @covers WindowsAzure\Blob\Models\CreateBlobSnapshotOptions::setLeaseId
  * @covers WindowsAzure\Blob\Models\CreateBlobSnapshotOptions::getLeaseId
  */
 public function testSetLeaseId()
 {
     $createBlobSnapshotOptions = new CreateBlobSnapshotOptions();
     $expected = "123456789";
     $createBlobSnapshotOptions->setLeaseId($expected);
     $this->assertEquals($expected, $createBlobSnapshotOptions->getLeaseId());
 }
Ejemplo n.º 2
0
 /**
  * Creates a snapshot of a blob.
  * 
  * @param string                           $container The name of the container.
  * @param string                           $blob      The name of the blob.
  * @param Models\CreateBlobSnapshotOptions $options   The optional parameters.
  * 
  * @return Models\CreateBlobSnapshotResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx
  */
 public function createBlobSnapshot($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $expectedStatusCode = Resources::STATUS_CREATED;
     if (is_null($options)) {
         $options = new CreateBlobSnapshotOptions();
     }
     $queryParams[Resources::QP_COMP] = 'snapshot';
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->addMetadataHeaders($headers, $options->getMetadata());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $expectedStatusCode);
     return CreateBlobSnapshotResult::create($response->getHeader());
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlobSnapshot
  * @covers WindowsAzure\Blob\BlobRestProxy::createPageBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::deleteBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs
  */
 private function createBlobSnapshotWorker($options, $container)
 {
     $blob = BlobServiceFunctionalTestData::getInterestingBlobName();
     // Make sure there is something to test
     $dataSize = 512;
     $this->restProxy->createPageBlob($container, $blob, $dataSize);
     $snapshot1 = $this->restProxy->createBlobSnapshot($container, $blob);
     if (!is_null($options)) {
         BlobServiceFunctionalTestData::fixEtagAccessCondition($options->getAccessCondition(), $snapshot1->getEtag());
     }
     try {
         $res = is_null($options) ? $this->restProxy->createBlobSnapshot($container, $blob) : $this->restProxy->createBlobSnapshot($container, $blob, $options);
         if (is_null($options)) {
             $options = new CreateBlobSnapshotOptions();
         }
         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, 'Expect failing temporal access condition should throw');
         }
         if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
             $this->assertTrue(false, 'Expect failing etag access condition to throw');
         }
         $listOptions = new ListBlobsOptions();
         $listOptions->setIncludeSnapshots(true);
         $listOptions->setPrefix($blob);
         $listBlobsResult = $this->restProxy->listBlobs($container == '' ? '$root' : $container, $listOptions);
         $blobs = $listBlobsResult->getBlobs();
         $getBlobOptions = new GetBlobOptions();
         $getBlobOptions->setSnapshot($res->getSnapshot());
         $getBlobResult = $this->restProxy->getBlob($container, $blob, $getBlobOptions);
         $this->verifyCreateBlobSnapshotWorker($res, $options, $blobs, $getBlobResult);
     } catch (ServiceException $e) {
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertEquals(500, $e->getCode(), 'bad timeout: deleteHttpStatusCode');
         } else {
             if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) {
                 $this->assertEquals(412, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: deleteHttpStatusCode');
             } else {
                 if (!BlobServiceFunctionalTestData::passEtagAccessCondition($options->getAccessCondition())) {
                     $this->assertEquals(412, $e->getCode(), 'bad etag access condition: deleteHttpStatusCode');
                 } else {
                 }
             }
         }
     }
     // Clean up.
     $this->restProxy->deleteBlob($container, $blob);
 }
 public static function getCreateBlobSnapshotOptions()
 {
     $ret = array();
     $options = new CreateBlobSnapshotOptions();
     array_push($ret, $options);
     $options = new CreateBlobSnapshotOptions();
     $options->setTimeout(10);
     array_push($ret, $options);
     $options = new CreateBlobSnapshotOptions();
     $options->setTimeout(-10);
     array_push($ret, $options);
     foreach (self::getAllAccessConditions() as $ac) {
         $options = new CreateBlobSnapshotOptions();
         $options->setAccessCondition($ac);
         array_push($ret, $options);
     }
     $options = new CreateBlobSnapshotOptions();
     $options->setMetadata(self::getNiceMetadata());
     array_push($ret, $options);
     // TODO: Handle Lease ID
     //        $options = new CreateBlobSnapshotOptions();
     //        $options->setLeaseId('setLeaseId');
     //        array_push($ret, $options);
     return $ret;
 }
 /**
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlobSnapshot
  * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob
  * @covers WindowsAzure\Blob\BlobRestProxy::getBlobProperties
  */
 public function testCreateBlobSnapshotWithOptionsWorks()
 {
     // Act
     $container = self::$_test_container_for_blobs;
     $blob = 'test3';
     $this->restProxy->createBlockBlob($container, $blob, 'some content');
     $opts = new CreateBlobSnapshotOptions();
     $metadata = array('test' => 'bar', 'blah' => 'bleah');
     $opts->setMetadata($metadata);
     $snapshot = $this->restProxy->createBlobSnapshot($container, $blob, $opts);
     $opts = new GetBlobPropertiesOptions();
     $opts->setSnapshot($snapshot->getSnapshot());
     $result = $this->restProxy->getBlobProperties($container, $blob, $opts);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals($snapshot->getETag(), $result->getProperties()->getETag(), '$result->getProperties()->getETag()');
     $this->assertEquals($snapshot->getLastModified(), $result->getProperties()->getLastModified(), '$result->getProperties()->getLastModified()');
     // The capitalizaion gets changed.
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $result->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $result->getMetadata())');
     $this->assertTrue(!(array_search('bar', $result->getMetadata()) === FALSE), '!(array_search(\'bar\', $result->getMetadata()) === FALSE)');
     $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $result->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $result->getMetadata())');
     $this->assertTrue(!(array_search('bleah', $result->getMetadata()) === FALSE), '!(array_search(\'bleah\', $result->getMetadata()) === FALSE)');
 }