/** * Create a job. * * @param WindowsAzure\MediaServices\Models\JobTemplate $jobTemplate Job * template data * * @param array $taskTemplates Performed * tasks template array * * @return Models\JobTemplate */ public function createJobTemplate($jobTemplate, $taskTemplates) { Validate::isA($jobTemplate, 'WindowsAzure\\MediaServices\\Models\\JobTemplate', 'jobTemplate'); Validate::isArray($taskTemplates, 'taskTemplates'); $batch = new BatchRequest(); $batch->appendContext($this->_getCreateEmptyJobTemplateContext($jobTemplate)); if ($taskTemplates != null) { foreach ($taskTemplates as $taskTemplate) { $batch->appendContext($this->_getCreateTaskTemplateContext($taskTemplate)); } } $batch->encode(); $method = Resources::HTTP_POST; $headers = $batch->getHeaders(); $postParams = array(); $queryParams = array(); $path = '$batch'; $statusCode = Resources::STATUS_ACCEPTED; $body = $batch->getBody(); $response = $this->send($method, $headers, $postParams, $queryParams, $path, $statusCode, $body); $batchResponse = new BatchResponse($response->getBody(), $batch); $responses = $batchResponse->getContexts(); $jobTemplateResponse = $responses[0]; $entry = new Entry(); $entry->parseXml($jobTemplateResponse->getBody()); $properties = $this->getPropertiesFromAtomEntry($entry); return JobTemplate::createFromOptions($properties); }
/** * @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(); }