/** * @covers WindowsAzure\Common\Internal\Http\BatchRequest::getHeaders */ public function testGetHeaders() { // Setup $batchReq = new BatchRequest(); $context = new HttpCallContext(); $body = 'test body'; $uri = 'http://www.someurl.com'; $context->setBody($body); $context->setUri($uri); // Test $batchReq->appendContext($context); $batchReq->encode(); $resultHeader = $batchReq->getHeaders(); // Assert $this->assertEquals(1, count($resultHeader)); $this->assertContains('multipart/mixed', $resultHeader['Content-Type']); }
/** * @covers WindowsAzure\Common\Internal\Http\HttpCallContext::__construct */ public function test__construct() { // Test $context = new HttpCallContext(); // Assert $this->assertNull($context->getBody()); $this->assertNull($context->getMethod()); $this->assertNull($context->getPath()); $this->assertNull($context->getUri()); $this->assertTrue(is_array($context->getHeaders())); $this->assertTrue(is_array($context->getQueryParameters())); $this->assertTrue(is_array($context->getStatusCodes())); return $context; }
/** * Gets a rule. * * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780772 * * @param string $topicPath The path of the topic. * @param string $subscriptionName The name of the subscription. * @param string $ruleName The name of the rule. * * @return RuleInfo */ public function getRule($topicPath, $subscriptionName, $ruleName) { $httpCallContext = new HttpCallContext(); $httpCallContext->setMethod(Resources::HTTP_GET); $httpCallContext->addStatusCode(Resources::STATUS_OK); $rulePath = sprintf(Resources::RULE_PATH, $topicPath, $subscriptionName, $ruleName); $httpCallContext->setPath($rulePath); $response = $this->sendContext($httpCallContext); $ruleInfo = new RuleInfo(); $ruleInfo->parseXml($response->getBody()); return $ruleInfo; }
/** * Create task template HTTP call context * * @param WindowsAzure\MediaServices\Models\TaskTemplate $taskTemplate Task * template object to be created * * @return WindowsAzure\Common\Internal\Http\HttpCallContext */ private function _getCreateTaskTemplateContext($taskTemplate) { Validate::isA($taskTemplate, 'WindowsAzure\\MediaServices\\Models\\TaskTemplate', 'taskTemplate'); $result = new HttpCallContext(); $result->setMethod(Resources::HTTP_POST); $result->setHeaders($this->_batchHeaders); $result->setUri($this->getUri()); $result->setPath('/$1/TaskTemplates'); $result->setBody($this->wrapAtomEntry($taskTemplate)); $result->addStatusCode(Resources::STATUS_CREATED); return $result; }
/** * Returns the status of the specified operation. After calling an asynchronous * operation, you can call Get Operation Status to determine whether the * operation has succeeded, failed, or is still in progress. * * @param string $requestId The request ID for the request you wish to track. * * @return Models\GetOperationStatusResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx */ public function getOperationStatus($requestId) { $context = new HttpCallContext(); $context->setMethod(Resources::HTTP_GET); $context->setPath($this->_getOperationPath($requestId)); $context->addStatusCode(Resources::STATUS_OK); $response = $this->sendContext($context); $serialized = $this->dataSerializer->unserialize($response->getBody()); return GetOperationStatusResult::create($serialized); }
/** * Cancels an in progress configuration change (update) or upgrade and returns * the deployment to its state before the upgrade or configuration change was * started. * * Note that you can rollback update or upgrade either by specifying the * deployment environment (staging or production), or by specifying the * deployment's unique name. * * @param string $name The hosted service name. * @param string $mode Specifies whether the rollback * should proceed automatically or not. Auto, The rollback proceeds without * further user input. Manual, You must call the walkUpgradeDomain API to apply * the rollback to each upgrade domain. * @param boolean $force Specifies whether the rollback * should proceed even when it will cause local data to be lost from some role * instances. True if the rollback should proceed; otherwise false if the * rollback should fail. * @param GetDeploymentOptions $options The optional parameters. * * @return none * * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh403977.aspx */ public function rollbackUpdateOrUpgrade($name, $mode, $force, $options) { Validate::isString($name, 'name'); Validate::notNullOrEmpty($name, 'name'); Validate::isString($mode, 'mode'); Validate::isTrue(Mode::isValid($mode), Resources::INVALID_CHANGE_MODE_MSG); Validate::isBoolean($force, 'force'); Validate::notNullOrEmpty($force, 'force'); Validate::notNullOrEmpty($options, 'options'); $xmlElements = array(Resources::XTAG_MODE => $mode, Resources::XTAG_FORCE => Utilities::booleanToString($force)); $body = $this->_createRequestXml($xmlElements, Resources::XTAG_ROLLBACK_UPDATE_OR_UPGRADE); $context = new HttpCallContext(); $context->setMethod(Resources::HTTP_POST); $context->setPath($this->_getDeploymentPath($name, $options) . '/'); $context->addStatusCode(Resources::STATUS_ACCEPTED); $context->addQueryParameter(Resources::QP_COMP, Resources::QPV_ROLLBACK); $context->setBody($body); $context->addHeader(Resources::CONTENT_TYPE, Resources::XML_CONTENT_TYPE); assert(Utilities::endsWith($context->getPath(), '/')); $response = $this->sendContext($context); return AsynchronousOperationResult::create($response->getHeader()); }
/** * @covers WindowsAzure\Common\Internal\Http\BatchResponse::__construct * @covers WindowsAzure\Common\Internal\Http\BatchResponse::getContexts */ public function test__constructWithRequestException() { // Setup $statusCode = '200'; $expectedCode = '201'; $body = 'test response body'; $httpCallContext = new HttpCallContext(); $httpCallContext->addStatusCode($expectedCode); $batchReq = new BatchRequest(); $batchReq->appendContext($httpCallContext); $encodedBody = "--batch_956c339e-1ef0-4443-9276-68c12888a3f7\r\n" . "Content-Type: multipart/mixed; boundary=changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n" . "\r\n" . "--changeset_4a3f1712-c034-416e-9772-905d28c0b122\r\n" . "Content-Transfer-Encoding: binary\r\n" . "Content-Type: application/http\r\n" . "\r\n" . "HTTP/1.1 {$statusCode} OK\r\n" . "content-id: 1\r\n" . "\r\n" . $body . "--changeset_4a3f1712-c034-416e-9772-905d28c0b122--\r\n" . '--batch_956c339e-1ef0-4443-9276-68c12888a3f7--'; $this->setExpectedException('WindowsAzure\\Common\\ServiceException'); // Test $batchResp = new BatchResponse($encodedBody, $batchReq); $result = $batchResp->getContexts(); }
/** * Sends HTTP request with the specified parameters. * * @param string $method HTTP method used in the request * @param array $headers HTTP headers. * @param array $queryParams URL query parameters. * @param array $postParameters The HTTP POST parameters. * @param string $path URL path * @param int $statusCode Expected status code received in the response * @param string $body Request body * * @return \HTTP_Request2_Response */ protected function send($method, $headers, $queryParams, $postParameters, $path, $statusCode, $body = Resources::EMPTY_STRING) { $context = new HttpCallContext(); $context->setBody($body); $context->setHeaders($headers); $context->setMethod($method); $context->setPath($path); $context->setQueryParameters($queryParams); $context->setPostParameters($postParameters); if (is_array($statusCode)) { $context->setStatusCodes($statusCode); } else { $context->addStatusCode($statusCode); } return $this->sendContext($context); }
/** * Sends HTTP request with the specified HTTP call context. * * @param WindowsAzure\Common\Internal\Http\HttpCallContext $context The HTTP * call context. * * @return \HTTP_Request2_Response */ protected function sendContext($context) { $context->setUri($this->getUri()); return parent::sendContext($context); }
/** * Gets table entity. * * @param string $table The name of the table. * @param string $partitionKey The entity partition key. * @param string $rowKey The entity row key. * @param Models\TableServiceOptions $options The optional parameters. * * @return Models\GetEntityResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179421.aspx */ public function getEntity($table, $partitionKey, $rowKey, $options = null) { Validate::isString($table, 'table'); Validate::notNullOrEmpty($table, 'table'); Validate::isTrue(!is_null($partitionKey), Resources::NULL_TABLE_KEY_MSG); Validate::isTrue(!is_null($rowKey), Resources::NULL_TABLE_KEY_MSG); $method = Resources::HTTP_GET; $headers = array(); $queryParams = array(); $statusCode = Resources::STATUS_OK; $path = $this->_getEntityPath($table, $partitionKey, $rowKey); if (is_null($options)) { $options = new TableServiceOptions(); } $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $context = new HttpCallContext(); $context->setHeaders($headers); $context->setMethod($method); $context->setPath($path); $context->setQueryParameters($queryParams); $context->addStatusCode($statusCode); $response = $this->sendContext($context); $entity = $this->_atomSerializer->parseEntity($response->getBody()); $result = new GetEntityResult(); $result->setEntity($entity); return $result; }