/**
  * @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']);
 }
 /**
  * Creates a rule. 
  *
  * @link http://msdn.microsoft.com/en-us/library/windowsazure/hh780774
  * 
  * @param string   $topicPath        The path of the topic.
  * @param string   $subscriptionName The name of the subscription. 
  * @param RuleInfo $ruleInfo         The information of the rule.
  *
  * @return RuleInfo
  */
 public function createRule($topicPath, $subscriptionName, $ruleInfo)
 {
     $httpCallContext = new HttpCallContext();
     $httpCallContext->setMethod(Resources::HTTP_PUT);
     $httpCallContext->addStatusCode(Resources::STATUS_CREATED);
     $httpCallContext->addHeader(Resources::CONTENT_TYPE, Resources::ATOM_ENTRY_CONTENT_TYPE);
     $rulePath = sprintf(Resources::RULE_PATH, $topicPath, $subscriptionName, $ruleInfo->getTitle());
     $ruleDescriptionXml = XmlSerializer::objectSerialize($ruleInfo->getRuleDescription(), 'RuleDescription');
     $entry = new Entry();
     $content = new Content($ruleDescriptionXml);
     $content->setType(Resources::XML_CONTENT_TYPE);
     $entry->setContent($content);
     $entry->setAttribute(Resources::XMLNS, Resources::SERVICE_BUS_NAMESPACE);
     $xmlWriter = new \XMLWriter();
     $xmlWriter->openMemory();
     $entry->writeXml($xmlWriter);
     $httpCallContext->setBody($xmlWriter->outputMemory());
     $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;
 }
 /**
  * Updates the label and/or the description for an affinity group for the 
  * specified subscription.
  * 
  * @param string                            $name    The affinity group name.
  * @param string                            $label   The affinity group label.
  * @param Models\CreateAffinityGroupOptions $options The optional parameters.
  * 
  * @return none
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/gg715316.aspx
  */
 public function updateAffinityGroup($name, $label, $options = null)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     Validate::isString($label, 'label');
     Validate::notNullOrEmpty($label, 'label');
     if (is_null($options)) {
         $options = new CreateAffinityGroupOptions();
     }
     $affinityGroup = new AffinityGroup();
     $affinityGroup->setLabel($label);
     $affinityGroup->setDescription($options->getDescription());
     $affinityGroup->addSerializationProperty(XmlSerializer::ROOT_NAME, 'UpdateAffinityGroup');
     $context = new HttpCallContext();
     $context->setMethod(Resources::HTTP_PUT);
     $context->setPath($this->_getAffinityGroupPath($name));
     $context->addStatusCode(Resources::STATUS_OK);
     $context->setBody($affinityGroup->serialize($this->dataSerializer));
     $context->addHeader(Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE);
     $this->sendContext($context);
 }
 /**
  * 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());
 }
 /**
  * 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);
 }
 /**
  * Constructs HTTP call context for insertEntity API.
  * 
  * @param string                     $table   The name of the table.
  * @param Models\Entity              $entity  The table entity.
  * @param Models\TableServiceOptions $options The optional parameters.
  * 
  * @return HttpCallContext
  */
 private function _constructInsertEntityContext($table, $entity, $options)
 {
     Validate::isString($table, 'table');
     Validate::notNullOrEmpty($table, 'table');
     Validate::notNullOrEmpty($entity, 'entity');
     Validate::isTrue($entity->isValid($msg), $msg);
     $method = Resources::HTTP_POST;
     $context = new HttpCallContext();
     $headers = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_CREATED;
     $path = $table;
     $body = $this->_atomSerializer->getEntity($entity);
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE);
     $context->setBody($body);
     $context->setHeaders($headers);
     $context->setMethod($method);
     $context->setPath($path);
     $context->setQueryParameters($queryParams);
     $context->addStatusCode($statusCode);
     $context->setUri($this->getUri());
     return $context;
 }