/** * @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 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); }
/** * 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); $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); $metadata = $this->getMetadataArray($responseHeaders); return GetBlobMetadataResult::create($responseHeaders, $metadata); }