-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcase for AppGroup/Teams:3x (#301)
- Loading branch information
1 parent
7609cd4
commit fc25a76
Showing
24 changed files
with
908 additions
and
3 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
43 changes: 43 additions & 0 deletions
43
tests/Api/ApigeeX/Controller/AppGroupControllerAwareTestTrait.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,43 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Tests\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Controller\AppGroupController; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait; | ||
use Apigee\Edge\Tests\Test\Controller\DefaultTestOrganizationAwareTrait; | ||
use Apigee\Edge\Tests\Test\Controller\EntityControllerTester; | ||
|
||
trait AppGroupControllerAwareTestTrait | ||
{ | ||
use DefaultTestOrganizationAwareTrait; | ||
use DefaultAPIClientAwareTrait; | ||
|
||
/** | ||
* @param \Apigee\Edge\ClientInterface|null $client | ||
* | ||
* @return \Apigee\Edge\Tests\Test\Controller\EntityControllerTester|\Apigee\Edge\Api\ApigeeX\Controller\AppGroupControllerInterface | ||
*/ | ||
protected static function appGroupController(ClientInterface $client = null): EntityControllerTester | ||
{ | ||
$client = $client ?? static::defaultAPIClient(); | ||
|
||
return new EntityControllerTester(new AppGroupController(static::defaultTestOrganization($client), $client)); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
tests/Api/ApigeeX/Controller/AppGroupControllerTest.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,109 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Tests\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Entity\EntityInterface; | ||
use Apigee\Edge\Tests\Api\ApigeeX\Entity\AppGroupTestEntityProviderTrait; | ||
use Apigee\Edge\Tests\Api\Management\Controller\AttributesAwareEntityControllerTestTrait; | ||
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait; | ||
use Apigee\Edge\Tests\Test\Controller\EntityControllerTesterInterface; | ||
use Apigee\Edge\Tests\Test\Controller\EntityCreateOperationControllerTester; | ||
use Apigee\Edge\Tests\Test\Controller\EntityCreateOperationControllerTestTrait; | ||
use Apigee\Edge\Tests\Test\Controller\EntityCreateOperationTestControllerTesterInterface; | ||
use Apigee\Edge\Tests\Test\Controller\EntityDeleteOperationControllerTestTrait; | ||
use Apigee\Edge\Tests\Test\Controller\EntityUpdateOperationControllerTestTrait; | ||
use Apigee\Edge\Tests\Test\TestClientFactory; | ||
use Apigee\Edge\Tests\Test\Utility\MarkOnlineTestSkippedAwareTrait; | ||
|
||
/** | ||
* Class AppGroupControllerTest. | ||
* | ||
* @group controller | ||
* @group management | ||
*/ | ||
class AppGroupControllerTest extends EntityControllerTestBase | ||
{ | ||
use AppGroupControllerAwareTestTrait; | ||
use AppGroupTestEntityProviderTrait; | ||
use DefaultAPIClientAwareTrait; | ||
use MarkOnlineTestSkippedAwareTrait; | ||
// The order of these trait matters. Check @depends in test methods. | ||
use EntityCreateOperationControllerTestTrait; | ||
use EntityLoadOperationControllerTestTrait; | ||
use EntityUpdateOperationControllerTestTrait; | ||
use EntityDeleteOperationControllerTestTrait; | ||
use PaginatedEntityListingControllerTestTraitBase; | ||
use PaginatedEntityListingControllerTestTrait; | ||
use AttributesAwareEntityControllerTestTrait; | ||
|
||
/** | ||
* @group online | ||
*/ | ||
public function testStatusChange(): void | ||
{ | ||
static::markOnlineTestSkipped(__FUNCTION__); | ||
/** @var \Apigee\Edge\Api\ApigeeX\Controller\AppGroupControllerInterface $controller */ | ||
$controller = static::entityController(); | ||
|
||
/** @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface $entity */ | ||
$entity = static::getNewEntity(); | ||
$controller->create($entity); | ||
$controller->setStatus($entity->id(), AppGroupInterface::STATUS_INACTIVE); | ||
$entity = $controller->load($entity->id()); | ||
$this->assertEquals($entity->getStatus(), AppGroupInterface::STATUS_INACTIVE); | ||
$controller->setStatus($entity->id(), AppGroupInterface::STATUS_ACTIVE); | ||
$entity = $controller->load($entity->id()); | ||
$this->assertEquals($entity->getStatus(), AppGroupInterface::STATUS_ACTIVE); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function entityController(ClientInterface $client = null): EntityControllerTesterInterface | ||
{ | ||
return static::appGroupController($client); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function getNewEntity(): EntityInterface | ||
{ | ||
return static::getNewAppGroup(!TestClientFactory::isOfflineClient(static::defaultAPIClient())); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function entityForUpdateTest(EntityInterface $existing): EntityInterface | ||
{ | ||
/* @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface $existing */ | ||
return static::getUpdatedAppGroup($existing, !TestClientFactory::isOfflineClient(static::defaultAPIClient())); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function entityCreateOperationTestController(): EntityCreateOperationTestControllerTesterInterface | ||
{ | ||
return new EntityCreateOperationControllerTester(static::entityController()); | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
tests/Api/ApigeeX/Controller/AttributesAwareEntityControllerTestTrait.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,132 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Tests\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Exception\ApiResponseException; | ||
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait; | ||
use Apigee\Edge\Tests\Test\Controller\EntityControllerAwareTestTrait; | ||
use Apigee\Edge\Tests\Test\Controller\EntityCreateOperationTestControllerAwareTrait; | ||
use Apigee\Edge\Tests\Test\Entity\NewEntityProviderTrait; | ||
use Apigee\Edge\Tests\Test\Utility\MarkOnlineTestSkippedAwareTrait; | ||
use DMS\PHPUnitExtensions\ArraySubset\Assert; | ||
|
||
trait AttributesAwareEntityControllerTestTrait | ||
{ | ||
use DefaultAPIClientAwareTrait; | ||
use EntityCreateOperationTestControllerAwareTrait; | ||
use EntityControllerAwareTestTrait; | ||
use NewEntityProviderTrait; | ||
use MarkOnlineTestSkippedAwareTrait; | ||
|
||
public function testAddAttributesToEntity(): string | ||
{ | ||
/** @var \Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface $controller */ | ||
$controller = $this->entityController(); | ||
/** @var \Apigee\Edge\Entity\Property\AttributesPropertyInterface|\Apigee\Edge\Entity\EntityInterface $entity */ | ||
$entity = static::getNewEntity(); | ||
static::entityCreateOperationTestController()->create($entity); | ||
/** @var \Apigee\Edge\Structure\AttributesProperty $attributes */ | ||
$attributes = $entity->getAttributes(); | ||
$originalAttributes = $attributes->values(); | ||
$attributes->add('name1', 'value1'); | ||
$attributes->add('name2', 'value2'); | ||
/** @var \Apigee\Edge\Structure\AttributesProperty $attributesProperty */ | ||
$attributesProperty = $controller->updateAttributes($entity->id(), $attributes); | ||
/** @var array $newAttributes */ | ||
$newAttributes = $attributesProperty->values(); | ||
Assert::assertArraySubset($originalAttributes, $newAttributes); | ||
$this->assertArrayHasKey('name1', $newAttributes); | ||
$this->assertArrayHasKey('name2', $newAttributes); | ||
$this->assertEquals('value1', $newAttributes['name1']); | ||
$this->assertEquals('value2', $newAttributes['name2']); | ||
|
||
return $entity->id(); | ||
} | ||
|
||
/** | ||
* @depends testAddAttributesToEntity | ||
* | ||
* @param string $entityId | ||
*/ | ||
public function testGetAttributes(string $entityId): void | ||
{ | ||
/** @var \Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface $controller */ | ||
$controller = $this->entityController(); | ||
/** @var \Apigee\Edge\Structure\AttributesProperty $attributesProperty */ | ||
$attributesProperty = $controller->getAttributes($entityId); | ||
$attributes = $attributesProperty->values(); | ||
$this->assertNotEmpty($attributes); | ||
$this->assertArrayHasKey('name1', $attributes); | ||
$this->assertArrayHasKey('name2', $attributes); | ||
$this->assertEquals('value1', $attributes['name1']); | ||
$this->assertEquals('value2', $attributes['name2']); | ||
} | ||
|
||
/** | ||
* @depends testAddAttributesToEntity | ||
* | ||
* @param string $entityId | ||
*/ | ||
public function testGetAttribute(string $entityId): void | ||
{ | ||
/** @var \Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface $controller */ | ||
$controller = $this->entityController(); | ||
$value = $controller->getAttribute($entityId, 'name1'); | ||
$this->assertEquals('value1', $value); | ||
} | ||
|
||
/** | ||
* @depends testAddAttributesToEntity | ||
* | ||
* @param string $entityId | ||
* | ||
* @return string | ||
*/ | ||
public function testUpdateAttribute(string $entityId): string | ||
{ | ||
/** @var \Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface $controller */ | ||
$controller = $this->entityController(); | ||
$expected = 'value1-edited'; | ||
$value = $controller->updateAttribute($entityId, 'name1', $expected); | ||
$this->assertEquals($expected, $value); | ||
|
||
return $entityId; | ||
} | ||
|
||
/** | ||
* @depends testUpdateAttribute | ||
* | ||
* @group online | ||
* | ||
* @param string $entityId | ||
*/ | ||
public function testDeleteAttribute(string $entityId): void | ||
{ | ||
static::markOnlineTestSkipped(__FUNCTION__); | ||
/** @var \Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface $controller */ | ||
$controller = $this->entityController(); | ||
$attribute = 'name1'; | ||
$controller->deleteAttribute($entityId, $attribute); | ||
try { | ||
$controller->getAttribute($entityId, $attribute); | ||
} catch (ApiResponseException $e) { | ||
$this->assertEquals('organizations.keymanagement.AttributeDoesntExist', $e->getEdgeErrorCode()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.