refs #488. Testing

pull/7/head
Manuel Aranda Rosales 2024-07-04 11:07:55 +02:00
parent 04b3bb72c7
commit f9bf9b6190
24 changed files with 906 additions and 44 deletions

View File

@ -19,6 +19,7 @@ final class HardwareInput
#[ApiProperty(description: 'The description of the hardware', example: "Hardware 1 description")]
public ?string $description = null;
#[Assert\NotNull]
#[Groups(['hardware:write'])]
#[ApiProperty(description: 'The type of the hardware', example: "Server")]
public ?HardwareTypeOutput $type = null;

View File

@ -17,6 +17,7 @@ class HardwareProfile extends AbstractEntity
private ?string $comments = null;
#[ORM\ManyToOne(targetEntity: OrganizationalUnit::class)]
#[ORM\JoinColumn(nullable: false)]
private ?OrganizationalUnit $organizationalUnit = null;
/**

View File

@ -20,7 +20,6 @@ class SoftwareProfile extends AbstractEntity
#[ORM\JoinColumn(nullable: false)]
private ?OrganizationalUnit $organizationalUnit = null;
/**
* @var Collection<int, Software>
*/

View File

@ -21,11 +21,6 @@ final class ClientFactory extends ModelFactory
parent::__construct();
}
public static function class(): string
{
return Client::class;
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*

View File

@ -0,0 +1,61 @@
<?php
namespace App\Factory;
use App\Entity\Hardware;
use App\Repository\HardwareRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
/**
* @extends PersistentProxyObjectFactory<Hardware>
*/
final class HardwareFactory extends ModelFactory
{
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
*
* @todo inject services if required
*/
public function __construct()
{
parent::__construct();
}
public static function class(): string
{
return Hardware::class;
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*
* @todo add your default values here
*/
protected function getDefaults(): array
{
return [
'createdAt' => self::faker()->dateTime(),
'name' => self::faker()->text(255),
'updatedAt' => self::faker()->dateTime(),
'type' => HardwareTypeFactory::new()
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(Hardware $hardware): void {})
;
}
protected static function getClass(): string
{
return Hardware::class;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Factory;
use App\Entity\HardwareProfile;
use App\Model\OrganizationalUnitTypes;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
@ -37,6 +38,7 @@ final class HardwareProfileFactory extends ModelFactory
'createdAt' => self::faker()->dateTime(),
'updatedAt' => self::faker()->dateTime(),
'description' => self::faker()->text(255),
'organizationalUnit' => OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT])->_save(),
];
}

View File

@ -11,22 +11,6 @@ use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
/**
* @extends PersistentProxyObjectFactory<HardwareType>
*
* @method HardwareType|Proxy create(array|callable $attributes = [])
* @method static HardwareType|Proxy createOne(array $attributes = [])
* @method static HardwareType|Proxy find(object|array|mixed $criteria)
* @method static HardwareType|Proxy findOrCreate(array $attributes)
* @method static HardwareType|Proxy first(string $sortedField = 'id')
* @method static HardwareType|Proxy last(string $sortedField = 'id')
* @method static HardwareType|Proxy random(array $attributes = [])
* @method static HardwareType|Proxy randomOrCreate(array $attributes = [])
* @method static HardwareTypeRepository|ProxyRepositoryDecorator repository()
* @method static HardwareType[]|Proxy[] all()
* @method static HardwareType[]|Proxy[] createMany(int $number, array|callable $attributes = [])
* @method static HardwareType[]|Proxy[] createSequence(iterable|callable $sequence)
* @method static HardwareType[]|Proxy[] findBy(array $attributes)
* @method static HardwareType[]|Proxy[] randomRange(int $min, int $max, array $attributes = [])
* @method static HardwareType[]|Proxy[] randomSet(int $number, array $attributes = [])
*/
final class HardwareTypeFactory extends ModelFactory
{
@ -40,11 +24,6 @@ final class HardwareTypeFactory extends ModelFactory
parent::__construct();
}
public static function class(): string
{
return HardwareType::class;
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*

View File

@ -0,0 +1,60 @@
<?php
namespace App\Factory;
use App\Entity\Image;
use App\Repository\ImageRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
/**
* @extends PersistentProxyObjectFactory<Image>
*/
final class ImageFactory extends ModelFactory
{
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
*
* @todo inject services if required
*/
public function __construct()
{
parent::__construct();
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*
* @todo add your default values here
*/
protected function getDefaults(): array
{
return [
'client' => ClientFactory::new(),
'createdAt' => self::faker()->dateTime(),
'name' => self::faker()->text(255),
'path' => self::faker()->text(255),
'size' => self::faker()->randomNumber(),
'softwareProfile' => SoftwareProfileFactory::new(),
'type' => self::faker()->text(255),
'updatedAt' => self::faker()->dateTime(),
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(Image $image): void {})
;
}
protected static function getClass(): string
{
return Image::class;
}
}

View File

@ -24,11 +24,6 @@ final class MenuFactory extends ModelFactory
parent::__construct();
}
public static function class(): string
{
return Menu::class;
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*/

View File

@ -40,7 +40,9 @@ final class PartitionFactory extends ModelFactory
'createdAt' => self::faker()->dateTime(),
'memoryUsage' => self::faker()->randomNumber(),
'size' => self::faker()->randomNumber(),
'updatedAt' => self::faker()->dateTime()
'updatedAt' => self::faker()->dateTime(),
'operativeSystem' => OperativeSystemFactory::new(),
'client' => ClientFactory::new(),
];
}

View File

@ -0,0 +1,60 @@
<?php
namespace App\Factory;
use App\Entity\Software;
use App\Repository\SoftwareRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
/**
* @extends PersistentProxyObjectFactory<Software>
*/
final class SoftwareFactory extends ModelFactory
{
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
*
* @todo inject services if required
*/
public function __construct()
{
parent::__construct();
}
public static function class(): string
{
return Software::class;
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*
* @todo add your default values here
*/
protected function getDefaults(): array
{
return [
'createdAt' => self::faker()->dateTime(),
'name' => self::faker()->text(255),
'updatedAt' => self::faker()->dateTime(),
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(Software $software): void {})
;
}
protected static function getClass(): string
{
return Software::class;
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace App\Factory;
use App\Entity\SoftwareProfile;
use App\Model\OrganizationalUnitTypes;
use App\Repository\SoftwareProfileRepository;
use Zenstruck\Foundry\ModelFactory;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
/**
* @extends PersistentProxyObjectFactory<SoftwareProfile>
*/
final class SoftwareProfileFactory extends ModelFactory
{
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
*
* @todo inject services if required
*/
public function __construct()
{
parent::__construct();
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
*
* @todo add your default values here
*/
protected function getDefaults(): array
{
return [
'createdAt' => self::faker()->dateTime(),
'description' => self::faker()->text(255),
'updatedAt' => self::faker()->dateTime(),
'organizationalUnit' => OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT])->_save(),
];
}
/**
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
*/
protected function initialize(): self
{
return $this
// ->afterInstantiate(function(SoftwareProfile $softwareProfile): void {})
;
}
protected static function getClass(): string
{
return SoftwareProfile::class;
}
}

View File

@ -26,7 +26,7 @@ class HardwareProcessor implements ProcessorInterface
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareOutput
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareOutput|null
{
switch ($operation){
case $operation instanceof Post:

View File

@ -26,7 +26,7 @@ readonly class HardwareProfileProcessor implements ProcessorInterface
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareProfileOutput
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareProfileOutput|null
{
switch ($operation){
case $operation instanceof Post:

View File

@ -25,7 +25,7 @@ readonly class ImageProcessor implements ProcessorInterface
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput|null
{
switch ($operation){
case $operation instanceof Post:

View File

@ -25,7 +25,7 @@ readonly class SoftwareProcessor implements ProcessorInterface
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareOutput
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareOutput|null
{
switch ($operation){
case $operation instanceof Post:

View File

@ -25,7 +25,7 @@ readonly class SoftwareProfileProcessor implements ProcessorInterface
/**
* @throws \Exception
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareProfileOutput
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareProfileOutput|null
{
switch ($operation){
case $operation instanceof Post:

View File

@ -4,11 +4,13 @@ namespace Functional;
use App\Entity\Client;
use App\Entity\HardwareProfile;
use App\Entity\HardwareType;
use App\Entity\OrganizationalUnit;
use App\Entity\User;
use App\Entity\UserGroup;
use App\Factory\ClientFactory;
use App\Factory\HardwareProfileFactory;
use App\Factory\HardwareTypeFactory;
use App\Factory\OrganizationalUnitFactory;
use App\Factory\UserFactory;
use App\Factory\UserGroupFactory;

View File

@ -0,0 +1,124 @@
<?php
namespace Functional;
use App\Entity\HardwareProfile;
use App\Entity\OrganizationalUnit;
use App\Factory\HardwareProfileFactory;
use App\Factory\OrganizationalUnitFactory;
use App\Factory\UserFactory;
use App\Model\OrganizationalUnitTypes;
use App\Model\UserGroupPermissions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class HardwareProfileTest extends AbstractTest
{
CONST string USER_ADMIN = 'ogadmin';
CONST string HW_PROFILE_CREATE = 'test-hw-profile-create';
CONST string HW_PROFILE_UPDATE = 'test-hw-profile-update';
CONST string HW_PROFILE_DELETE = 'test-hw-profile-delete';
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testGetCollectionHardwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareProfileFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/hardware-profiles');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/HardwareProfile',
'@id' => '/hardware-profiles',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 10,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreateHardwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$ouIri = $this->findIriBy(OrganizationalUnit::class, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$this->createClientWithCredentials()->request('POST', '/hardware-profiles',['json' => [
'description' => self::HW_PROFILE_CREATE,
'organizationalUnit' => $ouIri
]]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/HardwareProfileOutput',
'@type' => 'HardwareProfile',
'description' => self::HW_PROFILE_CREATE
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testUpdateHardwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareProfileFactory::createOne(['description' => self::HW_PROFILE_CREATE]);
$iri = $this->findIriBy(HardwareProfile::class, ['description' => self::HW_PROFILE_CREATE]);
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
'description' => self::HW_PROFILE_UPDATE,
]]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'description' => self::HW_PROFILE_UPDATE,
]);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
public function testDeleteHardwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareProfileFactory::createOne(['description' => self::HW_PROFILE_DELETE]);
$iri = $this->findIriBy(HardwareProfile::class, ['description' => self::HW_PROFILE_DELETE]);
$this->createClientWithCredentials()->request('DELETE', $iri);
$this->assertResponseStatusCodeSame(204);
$this->assertNull(
static::getContainer()->get('doctrine')->getRepository(HardwareProfile::class)->findOneBy(['description' => self::HW_PROFILE_DELETE])
);
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace Functional;
use App\Entity\Hardware;
use App\Entity\HardwareType;
use App\Factory\HardwareFactory;
use App\Factory\HardwareTypeFactory;
use App\Factory\UserFactory;
use App\Model\UserGroupPermissions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class HardwareTest extends AbstractTest
{
CONST string USER_ADMIN = 'ogadmin';
CONST string HW_CREATE = 'test-hw-create';
CONST string HW_UPDATE = 'test-hw-update';
CONST string HW_DELETE = 'test-hw-delete';
CONST string HW_TYPE = 'Server';
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testGetCollectionHardware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/hardware');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/Hardware',
'@id' => '/hardware',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 10,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreateHardware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareTypeFactory::createOne(['name' => self::HW_TYPE]);
$hwIri = $this->findIriBy(HardwareType::class, ['name' => self::HW_TYPE]);
$this->createClientWithCredentials()->request('POST', '/hardware',['json' => [
'name' => self::HW_CREATE,
'type' => $hwIri
]]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/HardwareOutput',
'@type' => 'Hardware',
'name' => self::HW_CREATE
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testUpdateHardware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareFactory::createOne(['name' => self::HW_CREATE]);
$iri = $this->findIriBy(Hardware::class, ['name' => self::HW_CREATE]);
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
'name' => self::HW_UPDATE,
]]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'name' => self::HW_UPDATE,
]);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
public function testDeleteHardware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
HardwareFactory::createOne(['name' => self::HW_DELETE]);
$iri = $this->findIriBy(Hardware::class, ['name' => self::HW_DELETE]);
$this->createClientWithCredentials()->request('DELETE', $iri);
$this->assertResponseStatusCodeSame(204);
$this->assertNull(
static::getContainer()->get('doctrine')->getRepository(Hardware::class)->findOneBy(['name' => self::HW_DELETE])
);
}
}

View File

@ -0,0 +1,136 @@
<?php
namespace Functional;
use App\Entity\Client;
use App\Entity\Image;
use App\Entity\OrganizationalUnit;
use App\Entity\SoftwareProfile;
use App\Factory\ClientFactory;
use App\Factory\ImageFactory;
use App\Factory\SoftwareProfileFactory;
use App\Factory\UserFactory;
use App\Model\UserGroupPermissions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class ImageTest extends AbstractTest
{
CONST string USER_ADMIN = 'ogadmin';
CONST string IMAGE_CREATE = 'test-image-create';
CONST string IMAGE_UPDATE = 'test-image-update';
CONST string IMAGE_DELETE = 'test-image-delete';
const string CLIENT = 'test-client';
const string SOFTWARE_PROFILE = 'test-software-profile';
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testGetCollectionImages(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
ImageFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/images');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/Image',
'@id' => '/images',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 10,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreateImage(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
ClientFactory::createOne(['name' => self::CLIENT]);
$clientIri = $this->findIriBy(Client::class, ['name' => self::CLIENT]);
SoftwareProfileFactory::createOne(['description' => self::SOFTWARE_PROFILE]);
$swPIri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SOFTWARE_PROFILE]);
$this->createClientWithCredentials()->request('POST', '/images',['json' => [
'name' => self::IMAGE_CREATE,
'size' => 123,
'path' => '/path/to/image',
'type' => 'type',
'client' => $clientIri,
'softwareProfile' => $swPIri
]]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/ImageOutput',
'@type' => 'Image',
'name' => self::IMAGE_CREATE,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testUpdateImage(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
ImageFactory::createOne(['name' => self::IMAGE_CREATE]);
$iri = $this->findIriBy(Image::class, ['name' => self::IMAGE_CREATE]);
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
'name' => self::IMAGE_UPDATE,
'size' => 123
]]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'name' => self::IMAGE_UPDATE,
'size' => 123
]);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
public function testDeleteImage(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
ImageFactory::createOne(['name' => self::IMAGE_DELETE]);
$iri = $this->findIriBy(Image::class, ['name' => self::IMAGE_DELETE]);
$this->createClientWithCredentials()->request('DELETE', $iri);
$this->assertResponseStatusCodeSame(204);
$this->assertNull(
static::getContainer()->get('doctrine')->getRepository(Client::class)->findOneBy(['name' => self::IMAGE_DELETE])
);
}
}

View File

@ -40,12 +40,7 @@ class PartitionTest extends AbstractTest
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
$ou = OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$hp = HardwareProfileFactory::createOne(['description' => self::HW_PROFILE]);
$client = ClientFactory::createOne(['name' => self::CLIENT_CREATE, 'serialNumber' => '123abc', 'organizationalUnit' => $ou, 'hardwareProfile' => $hp]);
PartitionFactory::createMany(10, ['client' => $client]);
PartitionFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/partitions');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
@ -95,4 +90,30 @@ class PartitionTest extends AbstractTest
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testUpdatePartition(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
PartitionFactory::createOne(['size' => 100, 'memoryUsage' => 100]);
$iri = $this->findIriBy(Partition::class, ['size' => 100, 'memoryUsage' => 100]);
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
'size' => 200,
'memoryUsage' => 300
]]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'size' => 200,
'memoryUsage' => 300
]);
}
}

View File

@ -0,0 +1,124 @@
<?php
namespace Functional;
use App\Entity\OrganizationalUnit;
use App\Entity\SoftwareProfile;
use App\Factory\OrganizationalUnitFactory;
use App\Factory\SoftwareProfileFactory;
use App\Factory\UserFactory;
use App\Model\OrganizationalUnitTypes;
use App\Model\UserGroupPermissions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class SoftwareProfileTest extends AbstractTest
{
CONST string USER_ADMIN = 'ogadmin';
CONST string SW_PROFILE_CREATE = 'test-sw-profile-create';
CONST string SW_PROFILE_UPDATE = 'test-sw-profile-update';
CONST string SW_PROFILE_DELETE = 'test-sw-profile-delete';
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testGetCollectionSoftwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
SoftwareProfileFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/software-profiles');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/SoftwareProfile',
'@id' => '/software-profiles',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 10,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreateSoftwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$ouIri = $this->findIriBy(OrganizationalUnit::class, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]);
$this->createClientWithCredentials()->request('POST', '/software-profiles',['json' => [
'description' => self::SW_PROFILE_CREATE,
'organizationalUnit' => $ouIri
]]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/SoftwareProfileOutput',
'@type' => 'SoftwareProfile',
'description' => self::SW_PROFILE_CREATE
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testUpdateSoftwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
SoftwareProfileFactory::createOne(['description' => self::SW_PROFILE_CREATE]);
$iri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SW_PROFILE_CREATE]);
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
'description' => self::SW_PROFILE_UPDATE,
]]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'description' => self::SW_PROFILE_UPDATE,
]);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
public function testDeleteSoftwareProfile(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
SoftwareProfileFactory::createOne(['description' => self::SW_PROFILE_DELETE]);
$iri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SW_PROFILE_DELETE]);
$this->createClientWithCredentials()->request('DELETE', $iri);
$this->assertResponseStatusCodeSame(204);
$this->assertNull(
static::getContainer()->get('doctrine')->getRepository(SoftwareProfile::class)->findOneBy(['description' => self::SW_PROFILE_DELETE])
);
}
}

View File

@ -0,0 +1,118 @@
<?php
namespace Functional;
use App\Entity\Software;
use App\Factory\OrganizationalUnitFactory;
use App\Factory\SoftwareFactory;
use App\Factory\UserFactory;
use App\Model\UserGroupPermissions;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class SoftwareTest extends AbstractTest
{
CONST string USER_ADMIN = 'ogadmin';
CONST string SW_CREATE = 'test-sw-create';
CONST string SW_UPDATE = 'test-sw-update';
CONST string SW_DELETE = 'test-sw-delete';
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testGetCollectionSoftware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
SoftwareFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/software');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/Software',
'@id' => '/software',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 10,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreateSoftware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
$this->createClientWithCredentials()->request('POST', '/software',['json' => [
'name' => self::SW_CREATE,
]]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/SoftwareOutput',
'@type' => 'Software',
'name' => self::SW_CREATE
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testUpdateSoftware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
SoftwareFactory::createOne(['name' => self::SW_CREATE]);
$iri = $this->findIriBy(Software::class, ['name' => self::SW_CREATE]);
$this->createClientWithCredentials()->request('PUT', $iri, ['json' => [
'name' => self::SW_UPDATE,
]]);
$this->assertResponseIsSuccessful();
$this->assertJsonContains([
'@id' => $iri,
'name' => self::SW_UPDATE,
]);
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
public function testDeleteSoftware(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
SoftwareFactory::createOne(['name' => self::SW_DELETE]);
$iri = $this->findIriBy(Software::class, ['name' => self::SW_DELETE]);
$this->createClientWithCredentials()->request('DELETE', $iri);
$this->assertResponseStatusCodeSame(204);
$this->assertNull(
static::getContainer()->get('doctrine')->getRepository(Software::class)->findOneBy(['name' => self::SW_DELETE])
);
}
}