Skip to content

Commit

Permalink
Fix Invalid payload issue while editing/updating AppGroup/Teams in Ap…
Browse files Browse the repository at this point in the history
…igee X (#344)
  • Loading branch information
shishir-intelli authored Jan 10, 2024
1 parent 14b01a8 commit 88b3cc2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 43 deletions.
10 changes: 8 additions & 2 deletions src/Api/ApigeeX/Entity/AppGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@

namespace Apigee\Edge\Api\ApigeeX\Entity;

use Apigee\Edge\Api\Management\Entity\AppOwner;
use Apigee\Edge\Entity\CommonEntityPropertiesAwareTrait;
use Apigee\Edge\Entity\Entity;
use Apigee\Edge\Entity\Property\AttributesPropertyAwareTrait;
use Apigee\Edge\Entity\Property\DisplayNamePropertyAwareTrait;
use Apigee\Edge\Entity\Property\NamePropertyAwareTrait;
use Apigee\Edge\Entity\Property\StatusPropertyAwareTrait;
use Apigee\Edge\Structure\AttributesProperty;

/**
* Describes an AppGroup entity.
*/
class AppGroup extends AppOwner implements AppGroupInterface
class AppGroup extends Entity implements AppGroupInterface
{
use DisplayNamePropertyAwareTrait;
use NamePropertyAwareTrait;
use AttributesPropertyAwareTrait;
use CommonEntityPropertiesAwareTrait;
use StatusPropertyAwareTrait;

/** @var string|null */
protected $channelUri;
Expand Down
10 changes: 7 additions & 3 deletions src/Api/ApigeeX/Entity/AppGroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

namespace Apigee\Edge\Api\ApigeeX\Entity;

use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\Entity\CommonEntityPropertiesInterface;
use Apigee\Edge\Entity\Property\AttributesPropertyInterface;
use Apigee\Edge\Entity\Property\DisplayNamePropertyInterface;
use Apigee\Edge\Entity\Property\NamePropertyInterface;
use Apigee\Edge\Entity\Property\StatusPropertyInterface;

/**
* Interface AppGroupInterface.
*/
interface AppGroupInterface extends AppOwnerInterface,
interface AppGroupInterface extends AttributesPropertyInterface,
DisplayNamePropertyInterface,
NamePropertyInterface
NamePropertyInterface,
StatusPropertyInterface,
CommonEntityPropertiesInterface
{
/**
* @param string $channelUri
Expand Down
64 changes: 32 additions & 32 deletions tests/Api/ApigeeX/Controller/AppCredentialControllerTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

namespace Apigee\Edge\Tests\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Entity\AppGroup;
use Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface;
use Apigee\Edge\Api\Management\Entity\AppCredentialInterface;
use Apigee\Edge\Api\Management\Entity\AppInterface;
use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\Structure\CredentialProductInterface;
use Apigee\Edge\Tests\Api\Management\Entity\ApiProductTestEntityProviderTrait;
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait;
Expand All @@ -43,13 +43,13 @@ abstract class AppCredentialControllerTestBase extends EntityControllerTestBase
// The order of these trait matters. Check @depends in test methods.
use AttributesAwareEntityControllerTestTrait;

/** @var \Apigee\Edge\Api\ApigeeX\Entity\ApiProductInterface */
/** @var ApiProductInterface */
protected static $testApiProduct;

/** @var \Apigee\Edge\Api\Management\Entity\AppOwnerInterface */
/** @var AppOwnerInterface */
protected static $testAppOwner;

/** @var \Apigee\Edge\Api\Management\Entity\AppInterface */
/** @var AppInterface */
protected static $testApp;

/**
Expand All @@ -66,12 +66,12 @@ public static function setUpBeforeClass(): void

public function testCreatedAppHasAnEmptyCredential(): void
{
/** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $entity */
/** @var \Apigee\Edge\Api\Management\Controller\AppByOwnerControllerInterface $controller */
/** @var DeveloperAppInterface $entity */
/** @var AppByOwnerControllerInterface $controller */
$entity = static::appByOwnerController()->load(static::$testApp->id());
$credentials = $entity->getCredentials();
$this->assertCount(1, $credentials);
/** @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/** @var AppCredentialInterface $credential */
$credential = reset($credentials);
$this->assertCount(0, $credential->getApiProducts());
$this->assertNotEmpty($credential->getConsumerKey());
Expand All @@ -82,7 +82,7 @@ public function testCreatedAppHasAnEmptyCredential(): void
/**
* @depends testCreatedAppHasAnEmptyCredential
*
* @return \Apigee\Edge\Api\Management\Entity\AppCredentialInterface
* @return AppCredentialInterface
*/
public function testCreate(): AppCredentialInterface
{
Expand All @@ -102,13 +102,13 @@ public function testCreate(): AppCredentialInterface
/**
* @depends testCreate
*
* @param \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $created
* @param AppCredentialInterface $created
*
* @return string
*/
public function testLoad(AppCredentialInterface $created)
{
/** @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $loaded */
/** @var AppCredentialInterface $loaded */
$loaded = static::entityController()->load($created->id());
$this->assertCount(count($loaded->getApiProducts()), $created->getApiProducts());
$this->assertEquals($created->getConsumerKey(), $loaded->getConsumerKey());
Expand All @@ -126,7 +126,7 @@ public function testLoad(AppCredentialInterface $created)
*/
public function testAddProducts(string $entityId): void
{
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
/** @var AppCredentialControllerInterface $controller */
$controller = $this->entityController();
$credential = $controller->addProducts($entityId, [static::$testApiProduct->id()]);
$productNames = $this->getCredentialProducts($credential);
Expand All @@ -140,9 +140,9 @@ public function testAddProducts(string $entityId): void
*/
public function testOverrideScopes(string $entityId): void
{
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
/** @var AppCredentialControllerInterface $controller */
$controller = $this->entityController();
/** @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/** @var AppCredentialInterface $credential */
$credential = $controller->load($entityId);
$this->assertEmpty($credential->getScopes());
$credential = $controller->overrideScopes($entityId, ['scope 1']);
Expand All @@ -165,9 +165,9 @@ public function testOverrideScopes(string $entityId): void
public function testStatusChange(string $entityId): void
{
static::markOnlineTestSkipped(__FUNCTION__);
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
/** @var AppCredentialControllerInterface $controller */
$controller = static::entityController();
/* @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/* @var AppCredentialInterface $credential */
$controller->setStatus($entityId, AppCredentialControllerInterface::STATUS_REVOKE);
$credential = $controller->load($entityId);
$this->assertEquals($credential->getStatus(), AppCredentialInterface::STATUS_REVOKED);
Expand All @@ -186,16 +186,16 @@ public function testStatusChange(string $entityId): void
public function testApiProductStatusChange(string $entityId): void
{
static::markOnlineTestSkipped(__FUNCTION__);
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
/** @var AppCredentialControllerInterface $controller */
$controller = static::entityController();
/* @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/* @var AppCredentialInterface $credential */
$controller->setApiProductStatus(
$entityId,
static::$testApiProduct->id(),
AppCredentialControllerInterface::STATUS_REVOKE
);
$credential = $controller->load($entityId);
/** @var \Apigee\Edge\Structure\CredentialProduct $product */
/** @var CredentialProduct $product */
foreach ($credential->getApiProducts() as $product) {
if ($product->getApiproduct() === static::$testApiProduct->id()) {
$this->assertEquals($product->getStatus(), CredentialProductInterface::STATUS_REVOKED);
Expand Down Expand Up @@ -224,11 +224,11 @@ public function testApiProductStatusChange(string $entityId): void
public function testGenerate(): string
{
static::markOnlineTestSkipped(__FUNCTION__);
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
/** @var AppCredentialControllerInterface $controller */
$controller = $this->entityController();
/** @var \Apigee\Edge\Api\Management\Entity\AppInterface $app */
/** @var AppInterface $app */
$app = static::appByOwnerController()->load(static::$testApp->id());
/** @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/** @var AppCredentialInterface $credential */
$credential = $controller->generate(
[static::$testApiProduct->id()],
$app->getAttributes(),
Expand All @@ -243,7 +243,7 @@ public function testGenerate(): string
// Thanks for the offline tests, we can not expect a concrete value
// here.
$this->assertNotEquals('-1', $credential->getExpiresAt());
/** @var \Apigee\Edge\Api\Management\Entity\AppInterface $updatedApp */
/** @var AppInterface $updatedApp */
$updatedApp = static::appByOwnerController()->load(static::$testApp->id());
// Credential generation should not deleted any previously existing app
// credentials.
Expand All @@ -260,13 +260,13 @@ public function testGenerate(): string
public function testDeleteApiProduct(string $entityId): void
{
static::markOnlineTestSkipped(__FUNCTION__);
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
/** @var AppCredentialControllerInterface $controller */
$controller = static::entityController();
/** @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/** @var AppCredentialInterface $credential */
$credential = $controller->load($entityId);
$productNames = $this->getCredentialProducts($credential);
$this->assertContains(static::$testApiProduct->id(), $productNames);
/* @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/* @var AppCredentialInterface $credential */
$controller->deleteApiProduct(
$entityId,
static::$testApiProduct->id()
Expand All @@ -281,15 +281,15 @@ public function testDeleteApiProduct(string $entityId): void
*/
public function testAddAttributesToEntity(): string
{
/** @var \Apigee\Edge\Api\Management\Entity\AppCredentialInterface $credential */
/** @var AppCredentialInterface $credential */
$credentials = static::$testApp->getCredentials();
$credential = reset($credentials);
/** @var \Apigee\Edge\Structure\AttributesProperty $attributes */
/** @var AttributesProperty $attributes */
$attributes = $credential->getAttributes();
$originalAttributes = $attributes->values();
$attributes->add('name1', 'value1');
$attributes->add('name2', 'value2');
/** @var \Apigee\Edge\Structure\AttributesProperty $attributesProperty */
/** @var AttributesProperty $attributesProperty */
$attributesProperty = static::entityController()->updateAttributes($credential->id(), $attributes);
/** @var array $newAttributes */
$newAttributes = $attributesProperty->values();
Expand Down Expand Up @@ -329,19 +329,19 @@ public function testDelete(): void
$this->assertFalse($found, 'Credential credential has not been deleted.');
}

abstract protected static function setupTestApp(AppOwnerInterface $appOwner): AppInterface;
abstract protected static function setupTestApp(AppGroup $appOwner): AppInterface;

abstract protected static function setupTestAppOwner(): AppOwnerInterface;
abstract protected static function setupTestAppOwner(): AppGroup;

/**
* @return \Apigee\Edge\Tests\Test\Controller\EntityControllerTesterInterface|\Apigee\Edge\Api\Management\Controller\AppByOwnerControllerInterface
* @return EntityControllerTesterInterface|AppByOwnerControllerInterface
*/
abstract protected static function appByOwnerController(): EntityControllerTesterInterface;

private function getCredentialProducts(AppCredentialInterface $credential)
{
return array_map(function ($product) {
/* @var \Apigee\Edge\Structure\CredentialProduct $product */
/* @var CredentialProduct $product */
return $product->getApiproduct();
}, $credential->getApiProducts());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
namespace Apigee\Edge\Tests\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Controller\AppGroupAppCredentialController;
use Apigee\Edge\Api\ApigeeX\Entity\AppGroup;
use Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface;
use Apigee\Edge\Api\Management\Entity\AppInterface;
use Apigee\Edge\Api\Management\Entity\AppOwnerInterface;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Entity\EntityInterface;
use Apigee\Edge\Tests\Api\ApigeeX\Entity\AppGroupAppTestEntityProviderTrait;
Expand All @@ -47,22 +47,22 @@ class AppGroupAppCredentialControllerTest extends AppCredentialControllerTestBas
/**
* {@inheritdoc}
*/
protected static function entityController(ClientInterface $client = null): EntityControllerTesterInterface
protected static function entityController(?ClientInterface $client = null): EntityControllerTesterInterface
{
$client = $client ?? static::defaultAPIClient();

return new EntityControllerTester(new AppGroupAppCredentialController(static::defaultTestOrganization($client), static::$testAppOwner->id(), static::$testApp->id(), $client));
}

protected static function setupTestApp(AppOwnerInterface $appOwner): AppInterface
protected static function setupTestApp(AppGroup $appOwner): AppInterface
{
$app = static::getNewAppGroupApp();
static::appGroupAppController()->create($app);

return $app;
}

protected static function setupTestAppOwner(): AppOwnerInterface
protected static function setupTestAppOwner(): AppGroup
{
$appGroup = static::getNewAppGroup();
static::appGroupController()->create($appGroup);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"apps": [],
"channelUri": "http:\/\/example.com",
"channelId": "devportal",
"name": "phpunit",
"displayName": "A PHPUnit appgroup",
"status": "active",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"apps": [],
"channelUri": "http:\/\/example.com",
"channelId": "devportal",
"name": "phpunit",
"displayName": "(Edited) A PHPUnit appgroup",
"status": "active",
Expand Down

0 comments on commit 88b3cc2

Please sign in to comment.