/** * @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 setBlobMetadataWorker($container, $options, $metadata) { $blob = BlobServiceFunctionalTestData::getInterestingBlobName(); // Make sure there is something to test $this->restProxy->createBlockBlob($container, $blob, ""); // 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()); } $firstkey = ''; if (!is_null($metadata) && count($metadata) > 0) { $firstkey = array_keys($metadata); $firstkey = $firstkey[0]; } try { 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 (\HTTP_Request2_LogicException $e) { $this->assertTrue(Utilities::startsWith($firstkey, '<'), 'Should get HTTP request error only if the metadata is invalid'); } } 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 { throw $e; } } } } // Clean up. $this->restProxy->deleteBlob($container, $blob); }
/** * 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($response->getHeader()); }
/** * @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 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 { 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 (\HTTP_Request2_LogicException $e) { $this->assertTrue(Utilities::startsWith($firstkey, '<'), 'Should get HTTP request error only if the metadata is invalid'); } } 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); }