Ejemplo n.º 1
0
 /**
  * Testing proper Jenkins API method - should return JSON parsed into array
  *
  * @dataProvider fetchStatusForBuildWidgetBuildingDataProvider
  */
 public function testFetchStatusForBuildWidgetBuilding($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)), \GuzzleHttp\Psr7\parse_response(file_get_contents(__DIR__ . '/../../Mock/Dao/Jenkins/fetchBuildStatusResponse.txt')));
     $response = $this->testedDao->fetchStatusForBuildWidget(['view' => 'VGTV', 'job' => 'VGTV_front-end']);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider fetchJobsWithWorkersForGearmanWidgetDataProvider
  */
 public function testFetchJobsWithWorkersForGearmanWidget($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $response = $this->testedDao->fetchJobsWithWorkersForGearmanWidget(['gearmanuiUrl' => 'http://gearmanui-url.com']);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
 /**
  * Get the HTTP response object.
  *
  * @return \Psr\Http\Message\ResponseInterface The response as object.
  */
 public function getResponse()
 {
     if ($this->response) {
         return $this->response;
     }
     return $this->response = \GuzzleHttp\Psr7\parse_response($this->getResponseStream());
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider fetchStatusForBuildWidgetDataProvider
  */
 public function testFetchStatusForBuildWidget($runningBuildsResponse, $fetchStatusForBuildWidgetResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($runningBuildsResponse)), \GuzzleHttp\Psr7\parse_response(file_get_contents($fetchStatusForBuildWidgetResponse)));
     $response = $this->testedDao->fetchStatusForBuildWidget(['project' => 'foobar', 'plan' => 'awesome']);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider fetchForSmogWidgetDataProvider
  */
 public function testFetchForSmogWidget($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $response = $this->testedDao->fetchForSmogWidget();
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
Ejemplo n.º 6
0
 /**
  * @dataProvider fetchListRecentMessagesForMessagesWidgetDataProvider
  */
 public function testFetchListRecentMessagesForMessagesWidget($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $this->testedDao->setDaoOptions(['params' => ['auth_token' => 'qwertyuiop']]);
     $response = $this->testedDao->fetchListRecentMessagesForMessagesWidget(['room' => 'foobar', 'limit' => 10]);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
Ejemplo n.º 7
0
 public function testWhoami_ReturnsResponse()
 {
     $this->mockHandler->append(GuzzleHttp\Psr7\parse_response(file_get_contents(__DIR__ . "/../fixtures/misc/whoami/success.http")));
     $data = $this->service->whoami();
     $this->assertInstanceOf("stdClass", $data);
     $this->assertObjectHasAttribute("user", $data);
     $this->assertObjectHasAttribute("account", $data);
 }
Ejemplo n.º 8
0
 /**
  * @dataProvider fetchQueuesForRabbitMQWidgetDataProvider
  */
 public function testFetchQueuesForRabbitMQWidget($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $response = $this->testedDao->fetchQueuesForRabbitMQWidget(['rabbitMQUrl' => 'http://rabbitmq-url.com', 'vhost' => 'integrator', 'ignoreQueues' => ['.*testing.*'], 'queueNameParser' => function ($queueName) {
         return $queueName;
     }]);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
Ejemplo n.º 9
0
 /**
  * @dataProvider fetchFivehundredsForAlertWidgetDataProvider
  */
 public function testFetchFivehundredsForAlertWidget($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->setDaoOptions(['params' => ['baseUrl' => 'https://splunk-01.int.vgnett.no:8089'], 'auth' => ['username' => 'foo', 'password' => 'bar']]);
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $response = $this->testedDao->fetchFivehundredsForAlertWidget(['config' => ['search' => 'search sourcetype=apache_access NOT(toolbox)' . ' host=godt-web-* OR host=red-web-* status=500' . ' | stats count latest(_time) as latestTime by url | sort -count | head 5', 'earliest_time' => '-1h', 'latest' => 'now', 'output_mode' => 'json']]);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }
Ejemplo n.º 10
0
 public function testGetUsersResponse()
 {
     $mockResponse = file_get_contents(__DIR__ . '/responses/getUsersResponse.txt');
     $mock = new MockHandler([\GuzzleHttp\Psr7\parse_response($mockResponse)]);
     $handler = HandlerStack::create($mock);
     $client = new Client(['handler' => $handler]);
     $db = new DeployBot('foo_api_key', 'bar_account_name', $client);
     $result = $db->getUsers();
     $this->assertEquals(3, count($result->entries));
 }
Ejemplo n.º 11
0
 /**
  * TODO Support strams
  * @param RequestInterface $request Reqeuest used to get the response
  * @param mixed            $body    Stream body
  * @param int              $status  Status code for the response, if any
  */
 public function __construct(RequestInterface $request = null, $body = null, $status = 200)
 {
     $this->request = $request;
     $this->raw = $body;
     $body = (string) $body;
     // Make the HTTP message complete
     if (substr($body, 0, 5) !== 'HTTP/') {
         $body = "HTTP/1.1 " . $status . " OK\r\n" . $body;
     }
     $this->response = \GuzzleHttp\Psr7\parse_response($body);
 }
Ejemplo n.º 12
0
 /**
  * @param  ServerRequestInterface $request
  */
 public function send(ServerRequestInterface $request)
 {
     $this->currentUri = $request->getUri();
     $this->setBase($this->currentUri);
     if (empty($this->currentUri->getHost())) {
         $this->currentUri = new Uri($this->getBase() . $this->currentUri);
     }
     $curl = curl_init();
     $options = [CURLOPT_URL => (string) $this->currentUri, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_USERAGENT => Loader::USER_AGENT, CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => $this->getConvertedHeaders($request->getHeaders())];
     if ($request->getBody()->getSize()) {
         $options[CURLOPT_POSTFIELDS] = (string) $request->getBody();
     }
     curl_setopt_array($curl, $options);
     $response = curl_exec($curl);
     $this->currentUri = new Uri(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
     return \GuzzleHttp\Psr7\parse_response($response);
 }
Ejemplo n.º 13
0
 static function createResponse($body = '', $status = 200)
 {
     // Make the HTTP message complete
     if (substr($body, 0, 5) !== 'HTTP/') {
         $body = "HTTP/1.1 " . $status . " Foo\r\n" . $body;
     }
     $response = \GuzzleHttp\Psr7\parse_response((string) $body);
     return $response->withStatus($status);
 }
Ejemplo n.º 14
0
 /**
  * @param $data
  */
 public function parseHead($data)
 {
     if (empty($data)) {
         $this->notifyError(new EmptyResponseException());
         $this->dispose();
         return;
     }
     if (false !== strpos($data, "\r\n\r\n")) {
         list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);
         // extract headers
         $response = \GuzzleHttp\Psr7\parse_response($headers);
         $this->response = $response;
         $encoding = Arrays::first($response->getHeader('Transfer-Encoding'));
         switch ($encoding) {
             case 'chunked':
                 $this->parserCallable = [$this, 'parseChunk'];
                 break;
                 // TODO multipart
             // TODO multipart
             default:
                 $this->parserCallable = [$this, 'parseContentLength'];
                 if ($length = $response->getHeader("Content-Length")) {
                     $this->contentLength = (int) Arrays::first($length);
                 }
         }
         // Parse rest of body
         call_user_func($this->parserCallable, $bodyBuffer);
     }
 }
Ejemplo n.º 15
0
 /**
  * @dataProvider fetchThresholdDataProvider
  */
 public function testFetchThreshold($apiResponse, $expectedDaoResponse)
 {
     $this->testedDao->getDataProvider()->getConfig('handler')->append(\GuzzleHttp\Psr7\parse_response(file_get_contents($apiResponse)));
     $response = $this->testedDao->fetchThreshold(['appId' => '1111111', 'metric' => 'Apdex']);
     $this->assertInternalType('array', $response);
     $this->assertEquals($expectedDaoResponse, $response);
 }