-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
libs/azure-api-client/tests/EventGrid/EventGridApiClientFunctionalTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\AzureApiClient\Tests\EventGrid; | ||
|
||
use DateTimeImmutable; | ||
use Keboola\AzureApiClient\ApiClientConfiguration; | ||
use Keboola\AzureApiClient\Authentication\Authenticator\CustomHeaderAuth; | ||
use Keboola\AzureApiClient\Authentication\Authenticator\SASTokenAuthenticatorFactory; | ||
use Keboola\AzureApiClient\EventGrid\EventGridApiClient; | ||
use Keboola\AzureApiClient\EventGrid\Model\EventGridEvent; | ||
use Keboola\AzureApiClient\Json; | ||
use Keboola\AzureApiClient\ServiceBus\ServiceBusApiClient; | ||
use Keboola\AzureApiClient\Tests\ReflectionPropertyAccessTestCase; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class EventGridApiClientFunctionalTest extends TestCase | ||
{ | ||
use ReflectionPropertyAccessTestCase; | ||
|
||
private function getClient(): EventGridApiClient | ||
{ | ||
return new EventGridApiClient( | ||
getenv('AZURE_API_CLIENT_CI__EVENT_GRID__TOPIC_HOSTNAME'), | ||
new ApiClientConfiguration( | ||
authenticator: new CustomHeaderAuth( | ||
header: 'aeg-sas-key', | ||
value: getenv('AZURE_API_CLIENT_CI__EVENT_GRID__ACCESS_KEY'), | ||
), | ||
) | ||
); | ||
} | ||
|
||
private function getServiceBusClient(): ServiceBusApiClient | ||
{ | ||
$endpoint = getenv('AZURE_API_CLIENT_CI__SERVICE_BUS__ENDPOINT'); | ||
return new ServiceBusApiClient( | ||
serviceBusEndpoint: $endpoint, | ||
configuration: new ApiClientConfiguration( | ||
authenticator: new SASTokenAuthenticatorFactory( | ||
url: $endpoint, | ||
sharedAccessKeyName: 'RootManageSharedAccessKey', | ||
sharedAccessKey: getenv('AZURE_API_CLIENT_CI__SERVICE_BUS__SHARED_ACCESS_KEY'), | ||
), | ||
) | ||
); | ||
} | ||
|
||
public function testPublishEvent(): void | ||
{ | ||
$client = $this->getClient(); | ||
$client->publishEvents([ | ||
new EventGridEvent( | ||
'3e9825ed-b7db-44ea-a5c9-a1601fa43e23', | ||
'TestSubject', | ||
[ | ||
'Property1' => 'Value1', | ||
'Property2' => 'Value2', | ||
], | ||
'Keboola.EventGridClient.TestEvent' | ||
), | ||
]); | ||
|
||
$serviceBusClient = $this->getServiceBusClient(); | ||
$message = $serviceBusClient->peakMessage('queue-tests'); | ||
$this->assertNotNull($message); | ||
// returned message has id assigned by service bus | ||
self::assertNotSame('3e9825ed-b7db-44ea-a5c9-a1601fa43e23', $message->id); | ||
$messageBody = Json::decodeArray($message->body); | ||
self::assertSame('3e9825ed-b7db-44ea-a5c9-a1601fa43e23', $messageBody['id']); | ||
self::assertSame('TestSubject', $messageBody['subject']); | ||
self::assertSame([ | ||
'Property1' => 'Value1', | ||
'Property2' => 'Value2', | ||
], $messageBody['data']); | ||
self::assertSame('Keboola.EventGridClient.TestEvent', $messageBody['eventType']); | ||
self::assertSame('1.0', $messageBody['dataVersion']); | ||
self::assertSame('1', $messageBody['metadataVersion']); | ||
self::assertEqualsWithDelta( | ||
(new DateTimeImmutable('now'))->getTimestamp(), | ||
(new DateTimeImmutable($messageBody['eventTime']))->getTimestamp(), | ||
10 // peak has timeout 10s | ||
); | ||
self::assertStringEndsWith('Microsoft.EventGrid/topics/' . getenv('AZURE_API_CLIENT_CI__EVENT_GRID__TOPIC_NAME'), $messageBody['topic']); | ||
$serviceBusClient->deleteMessage($message->lockLocation); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
libs/azure-api-client/tests/ServiceBus/ServiceBusApiClientFunctionalTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Keboola\AzureApiClient\Tests\EventGrid; | ||
|
||
use Keboola\AzureApiClient\ApiClientConfiguration; | ||
use Keboola\AzureApiClient\Authentication\Authenticator\SASTokenAuthenticatorFactory; | ||
use Keboola\AzureApiClient\Json; | ||
use Keboola\AzureApiClient\ServiceBus\Model\ServiceBusBrokerMessageRequest; | ||
use Keboola\AzureApiClient\ServiceBus\ServiceBusApiClient; | ||
use Keboola\AzureApiClient\Tests\ReflectionPropertyAccessTestCase; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class ServiceBusApiClientFunctionalTest extends TestCase | ||
{ | ||
use ReflectionPropertyAccessTestCase; | ||
|
||
private function getClient(): ServiceBusApiClient | ||
{ | ||
$endpoint = getenv('AZURE_API_CLIENT_CI__SERVICE_BUS__ENDPOINT'); | ||
return new ServiceBusApiClient( | ||
serviceBusEndpoint: $endpoint, | ||
configuration: new ApiClientConfiguration( | ||
authenticator: new SASTokenAuthenticatorFactory( | ||
url: $endpoint, | ||
sharedAccessKeyName: 'RootManageSharedAccessKey', | ||
sharedAccessKey: getenv('AZURE_API_CLIENT_CI__SERVICE_BUS__SHARED_ACCESS_KEY'), | ||
), | ||
) | ||
); | ||
} | ||
|
||
public function testEvent(): void | ||
{ | ||
$client = $this->getClient(); | ||
$messageSend = ServiceBusBrokerMessageRequest::createJson( | ||
'123', | ||
['testdata' => 'value'] | ||
); | ||
$client->sendMessage( | ||
'queue-tests', | ||
$messageSend | ||
); | ||
$messageReceived = $client->peakMessage( | ||
'queue-tests' | ||
); | ||
$this->assertNotNull($messageReceived); | ||
self::assertSame($messageSend->id, $messageReceived->id); | ||
$messageBody = Json::decodeArray($messageReceived->body); | ||
self::assertSame([ | ||
'testdata' => 'value', | ||
], $messageBody); | ||
$client->deleteMessage($messageReceived->lockLocation); | ||
} | ||
} |