ogcore/tests/Functional/PartitionTest.php

125 lines
4.5 KiB
PHP

<?php
namespace Functional;
use App\Entity\Client;
use App\Entity\Image;
use App\Entity\Menu;
use App\Entity\OperativeSystem;
use App\Entity\Partition;
use App\Factory\ClientFactory;
use App\Factory\HardwareProfileFactory;
use App\Factory\ImageFactory;
use App\Factory\MenuFactory;
use App\Factory\OperativeSystemFactory;
use App\Factory\OrganizationalUnitFactory;
use App\Factory\PartitionFactory;
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 PartitionTest extends AbstractTest
{
CONST string USER_ADMIN = 'ogadmin';
CONST string CLIENT_CREATE = 'test-client-create';
const string HW_PROFILE = 'HW Test';
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testGetCollectionPartitions(): void
{
UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]);
PartitionFactory::createMany(10);
$this->createClientWithCredentials()->request('GET', '/partitions');
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/Partition',
'@id' => '/partitions',
'@type' => 'hydra:Collection',
'hydra:totalItems' => 10,
]);
}
/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function testCreatePartition(): void
{
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]);
ClientFactory::createOne(['name' => self::CLIENT_CREATE, 'serialNumber' => '123abc', 'organizationalUnit' => $ou, 'hardwareProfile' => $hp]);
$iri = $this->findIriBy(Client::class, ['name' => self::CLIENT_CREATE]);
OperativeSystemFactory::createOne(['name' => 'Ubuntu']);
$osIri = $this->findIriBy(OperativeSystem::class, ['name' => 'Ubuntu']);
ImageFactory::createOne(['name' => 'Image 1']);
$imageIri = $this->findIriBy(Image::class, ['name' => 'Image 1']);
$this->createClientWithCredentials()->request('POST', '/partitions',['json' => [
'size' => 100,
'operativeSystem' => $osIri,
'image' => $imageIri,
'client' => $iri,
'memoryUsage' => 100
]]);
$this->assertResponseStatusCodeSame(201);
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/contexts/PartitionOutput',
'@type' => 'Partition',
'size' => 100,
'memoryUsage' => 100
]);
}
/**
* @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
]);
}
}