Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a93e7e5
Fix current existing Unit tests or the code being tested
WilcoLouwerse Aug 21, 2025
69b49a8
Added Unit tests for MappingService, ObjectService and RuleService
WilcoLouwerse Aug 21, 2025
af63b0a
Added unit tests for all mapping cast types and for all rule types
WilcoLouwerse Aug 21, 2025
722b49c
Added unit tests for all Services
WilcoLouwerse Aug 22, 2025
b1d3b3b
Replace skipped tests with actual working tests for the ImportService
WilcoLouwerse Aug 22, 2025
da19daa
Replace skipped tests with working tests for Job, Search & StorageSer…
WilcoLouwerse Aug 22, 2025
5375f8b
Fix some bugs, reduce the amount of skipped Service unit tests further
WilcoLouwerse Aug 26, 2025
9a263c6
Added unit tests for all controllers
WilcoLouwerse Aug 26, 2025
8aee6cc
Put back SourceMapper->findByRef function for importing sources
WilcoLouwerse Aug 28, 2025
4f3acc0
Merge branch 'development' into feature/CONNECTOR-371/unit-tests
WilcoLouwerse Aug 28, 2025
a8d5a58
Some small fixes related to versions php 8.3 and NextCloud 31
WilcoLouwerse Sep 2, 2025
e685484
Small fix/change in dashboard functions naming and docblocks
WilcoLouwerse Sep 16, 2025
6e4d234
Add unit tests for skipped tests in SourcesControllerTest
WilcoLouwerse Sep 16, 2025
d538038
Fixes in MappingsController & replaces skipped tests with actual tests
WilcoLouwerse Sep 16, 2025
9690133
Some finishing touches for unit test (improved coverage and quality)
WilcoLouwerse Sep 18, 2025
c53469e
Merge branch 'development' into feature/CONNECTOR-371/unit-tests
WilcoLouwerse Sep 18, 2025
3903d54
Add / update unit tests with new changes from Development branch
WilcoLouwerse Sep 18, 2025
0276cc8
Added unit tests for all mappers
WilcoLouwerse Sep 18, 2025
fc417bb
Do fixes for all mapping tests so that they all pass
WilcoLouwerse Sep 19, 2025
5b874f7
Improved unit test coverage and quality + changes for new code from dev
WilcoLouwerse Sep 19, 2025
1792fbb
Replace some skipped tests with actual correct assertions
WilcoLouwerse Sep 19, 2025
d9243f5
small fixes and started adding documentation
WilcoLouwerse Sep 19, 2025
71aac87
Added documentation for complex unit test files
WilcoLouwerse Sep 20, 2025
d38152a
Small update/fixes for SOAPServiceTest & SoftwareCatalogusServiceTest
WilcoLouwerse Sep 22, 2025
9db9138
Small fixes in SoftwareCatalogueServiceTest
WilcoLouwerse Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[submodule "3rdparty"]
shallow = true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

10 changes: 5 additions & 5 deletions lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public function index(): JSONResponse
{
try {
$results = [
"sources" => $this->sourceMapper->getTotalCallCount(),
"mappings" => $this->mappingMapper->getTotalCallCount(),
"synchronizations" => $this->synchronizationMapper->getTotalCallCount(),
"synchronizationContracts" => $this->synchronizationContractMapper->getTotalCallCount(),
"sources" => $this->sourceMapper->getTotalCount(),
"mappings" => $this->mappingMapper->getTotalCount(),
"synchronizations" => $this->synchronizationMapper->getTotalCount(),
"synchronizationContracts" => $this->synchronizationContractMapper->getTotalCount(),
"jobs" => $this->jobMapper->getTotalCount(),
"endpoints" => $this->endpointMapper->getTotalCallCount()
"endpoints" => $this->endpointMapper->getTotalCount()
];
return new JSONResponse($results);
} catch (\Exception $e) {
Expand Down
27 changes: 18 additions & 9 deletions lib/Controller/EndpointsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ public function handlePath(string $_path): Response
method: $this->request->getMethod()
);

// If no matching endpoint found, return 404
if ($endpoint === null) {
return new JSONResponse(
data: ['error' => 'No matching endpoint found for path and method: ' . $_path . ' ' . $this->request->getMethod()],
statusCode: 404
);
}
// If no matching endpoint found, return 404
if ($endpoint === null) {
$response = new JSONResponse(
data: ['error' => 'No matching endpoint found for path and method: ' . $_path . ' ' . $this->request->getMethod()],
statusCode: 404
);
return $this->authorizationService->corsAfterController($this->request, $response);
}
} catch (\Exception $e) {
// Multiple endpoints found (handled by cache service)
return new JSONResponse(
Expand Down Expand Up @@ -495,8 +496,16 @@ private function handleSimpleSchemaRequest(Endpoint $endpoint, string $path): JS
return new JSONResponse($object->jsonSerialize());
}

// Handle collection request (list objects)
$result = $mapper->findAllPaginated(requestParams: $parameters);
// Handle collection request (list objects)
$result = $mapper->findAll(
$parameters['limit'] ?? null,
$parameters['offset'] ?? null,
$parameters['filters'] ?? [],
$parameters['searchConditions'] ?? [],
$parameters['searchParams'] ?? [],
$parameters['sort'] ?? [],
$parameters['search'] ?? null
);

// Debug: log the register and schema we're querying
$this->logger->info('Simple endpoint query', [
Expand Down
5 changes: 2 additions & 3 deletions lib/Controller/LogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,13 @@ public function export(
$logs = $this->synchronizationLogMapper->findAll(null, null, $filters);

// Create CSV content
$csvData = "ID,UUID,Level,Message,Synchronization ID,User ID,Session ID,Created,Expires\n";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synchronizations don't have a property called level

$csvData = "ID,UUID,Message,Synchronization ID,User ID,Session ID,Created,Expires\n";

foreach ($logs as $log) {
$csvData .= sprintf(
"%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
"%s,%s,%s,%s,%s,%s,%s,%s\n",
$log->getId() ?? '',
$log->getUuid() ?? '',
$log->getLevel() ?? '',
'"' . str_replace('"', '""', $log->getMessage() ?? '') . '"',
$log->getSynchronizationId() ?? '',
$log->getUserId() ?? '',
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/MappingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ public function test(ObjectService $objectService, IURLGenerator $urlGenerator):
}

// Decode the input object from JSON
$inputObject = $data['inputObject'];
$inputObject = json_decode($data['inputObject'], true);

// Decode the mapping from JSON
$mapping = $data['mapping'];
$mapping = json_decode($data['mapping'], true);

// Initialize schema and validation flags
$schema = false;
Expand Down Expand Up @@ -283,7 +283,7 @@ public function test(ObjectService $objectService, IURLGenerator $urlGenerator):

// Perform schema validation if both schema and validation are provided
if ($schema !== false && $validation !== false && $openRegisters !== null) {
$result = $openRegisters->validateObject(object: $resultObject, schemaObject: $schema->getSchemaObject($urlGenerator));
$result = $openRegisters->getValidateHandler()->validateObject(object: $resultObject, schemaObject: $schema->getSchemaObject($urlGenerator));

$isValid = $result->isValid();

Expand Down Expand Up @@ -319,7 +319,7 @@ public function saveObject(): ?JSONResponse
$openRegisters = $this->objectService->getOpenRegisters();
if ($openRegisters !== null) {
$data = $this->request->getParams();
return new JSONResponse($openRegisters->saveObject($data['register'], $data['schema'], $data['object']));
return new JSONResponse($openRegisters->saveObject($data['object'], [], $data['register'], $data['schema']));
}

return null;
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/SourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IAppConfig;
use OCP\IRequest;

Expand Down
20 changes: 10 additions & 10 deletions lib/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,46 @@ class UserController extends Controller
* @param IUserManager $userManager The user manager for user operations
* @param IUserSession $userSession The user session manager
* @param AuthorizationService $authorizationService The authorization service
* @param ICacheFactory $cacheFactory The cache factory for rate limiting
* @param LoggerInterface $logger The logger for security events
* @param SecurityService $securityService The security service for rate limiting and XSS protection
* @param UserService $userService The user service for user-related operations
* @param OrganisationBridgeService $organisationBridgeService The organization bridge service
* @param LoggerInterface $logger The logger for security events
*
* @psalm-param string $appName
* @psalm-param IRequest $request
* @psalm-param IUserManager $userManager
* @psalm-param IUserSession $userSession
* @psalm-param AuthorizationService $authorizationService
* @psalm-param ICacheFactory $cacheFactory
* @psalm-param LoggerInterface $logger
* @psalm-param SecurityService $securityService
* @psalm-param UserService $userService
* @psalm-param OrganisationBridgeService $organisationBridgeService
* @psalm-param LoggerInterface $logger
* @phpstan-param string $appName
* @phpstan-param IRequest $request
* @phpstan-param IUserManager $userManager
* @phpstan-param IUserSession $userSession
* @phpstan-param AuthorizationService $authorizationService
* @phpstan-param ICacheFactory $cacheFactory
* @phpstan-param LoggerInterface $logger
* @phpstan-param SecurityService $securityService
* @phpstan-param UserService $userService
* @phpstan-param OrganisationBridgeService $organisationBridgeService
* @phpstan-param LoggerInterface $logger
*/
public function __construct(
string $appName,
IRequest $request,
IUserManager $userManager,
IUserSession $userSession,
AuthorizationService $authorizationService,
ICacheFactory $cacheFactory,
LoggerInterface $logger,
SecurityService $securityService,
UserService $userService,
OrganisationBridgeService $organisationBridgeService
OrganisationBridgeService $organisationBridgeService,
LoggerInterface $logger
) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->authorizationService = $authorizationService;
$this->securityService = new SecurityService($cacheFactory, $logger);
$this->securityService = $securityService;
$this->userService = $userService;
$this->organisationBridgeService = $organisationBridgeService;
$this->logger = $logger;
Expand Down
21 changes: 16 additions & 5 deletions lib/Db/EndpointMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,33 @@ public function updateFromArray(int $id, array $object): Endpoint
}

/**
* Get the total count of all call logs.
* Get the total count of all endpoints.
*
* @return int The total number of call logs in the database.
* @param array $filters Optional filters to apply
* @return int The total number of endpoints in the database.
*/
public function getTotalCallCount(): int
public function getTotalCount(array $filters = []): int
{
$qb = $this->db->getQueryBuilder();

// Select count of all logs
// Select count of all endpoints
$qb->select($qb->createFunction('COUNT(*) as count'))
->from('openconnector_endpoints');

// Apply filters if provided
foreach ($filters as $filter => $value) {
if ($value === 'IS NOT NULL') {
$qb->andWhere($qb->expr()->isNotNull($filter));
} elseif ($value === 'IS NULL') {
$qb->andWhere($qb->expr()->isNull($filter));
} else {
$qb->andWhere($qb->expr()->eq($filter, $qb->createNamedParameter($value)));
}
}

$result = $qb->execute();
$row = $result->fetch();

// Return the total count
return (int)$row['count'];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getData(): array
}

/**
* Constructor to set up data types for properties
* Constructor to set up data types for propertiesimage.png
*/
public function __construct() {
$this->addType('uuid', 'string');
Expand Down
22 changes: 9 additions & 13 deletions lib/Db/EventMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public function createFromArray(array $object): Event
$obj->setUuid(Uuid::v4());
}

// Set version
if (empty($obj->getVersion()) === true) {
$obj->setVersion('0.0.1');
// Set specversion
if (empty($obj->getSpecversion()) === true) {
$obj->setSpecversion('1.0');
}

return $this->insert(entity: $obj);
Expand All @@ -119,16 +119,12 @@ public function updateFromArray(int $id, array $object): Event
{
$obj = $this->find($id);

// Set version
if (empty($obj->getVersion()) === true) {
$object['version'] = '0.0.1';
} else if (empty($object['version']) === true) {
// Update version
$version = explode('.', $obj->getVersion());
if (isset($version[2]) === true) {
$version[2] = (int) $version[2] + 1;
$object['version'] = implode('.', $version);
}
// Set specversion
if (empty($obj->getSpecversion()) === true) {
$object['specversion'] = '1.0';
} else if (empty($object['specversion']) === true) {
// Keep existing specversion
$object['specversion'] = $obj->getSpecversion();
}

$obj->hydrate($object);
Expand Down
21 changes: 16 additions & 5 deletions lib/Db/MappingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,33 @@ public function updateFromArray(int $id, array $object): Mapping
}

/**
* Get the total count of all call logs.
* Get the total count of all mappings.
*
* @return int The total number of call logs in the database.
* @param array $filters Optional filters to apply
* @return int The total number of mappings in the database.
*/
public function getTotalCallCount(): int
public function getTotalCount(array $filters = []): int
{
$qb = $this->db->getQueryBuilder();

// Select count of all logs
// Select count of all mappings
$qb->select($qb->createFunction('COUNT(*) as count'))
->from('openconnector_mappings');

// Apply filters if provided
foreach ($filters as $filter => $value) {
if ($value === 'IS NOT NULL') {
$qb->andWhere($qb->expr()->isNotNull($filter));
} elseif ($value === 'IS NULL') {
$qb->andWhere($qb->expr()->isNull($filter));
} else {
$qb->andWhere($qb->expr()->eq($filter, $qb->createNamedParameter($value)));
}
}

$result = $qb->execute();
$row = $result->fetch();

// Return the total count
return (int)$row['count'];
}

Expand Down
40 changes: 35 additions & 5 deletions lib/Db/SourceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ public function find(int|string $id): Source
return $this->findEntity(query: $qb);
}

/**
* Find all sources that belong to a specific reference.
*
* @param string $reference The reference to find sources for
* @return array<Source> Array of Source entities
*/
public function findByRef(string $reference): array
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubenvdlinde ik kan op OpenConnector geen Sources meer importeren omdat de findByRef function op de SourceMapper niet meer bestaat
Is dit intentional? Of mag ik deze functie terug zetten?

image image

{
$qb = $this->db->getQueryBuilder();

$qb->select('*')
->from('openconnector_sources')
->where(
$qb->expr()->eq('reference', $qb->createNamedParameter($reference))
);

return $this->findEntities(query: $qb);
}

/**
* Find all sources matching the given criteria
*
Expand Down Expand Up @@ -159,22 +178,33 @@ public function updateFromArray(int $id, array $object): Source
}

/**
* Get the total count of all call logs.
* Get the total count of all sources.
*
* @return int The total number of call logs in the database.
* @param array $filters Optional filters to apply
* @return int The total number of sources in the database.
*/
public function getTotalCallCount(): int
public function getTotalCount(array $filters = []): int
{
$qb = $this->db->getQueryBuilder();

// Select count of all logs
// Select count of all sources
$qb->select($qb->createFunction('COUNT(*) as count'))
->from('openconnector_sources');

// Apply filters if provided
foreach ($filters as $filter => $value) {
if ($value === 'IS NOT NULL') {
$qb->andWhere($qb->expr()->isNotNull($filter));
} elseif ($value === 'IS NULL') {
$qb->andWhere($qb->expr()->isNull($filter));
} else {
$qb->andWhere($qb->expr()->eq($filter, $qb->createNamedParameter($value)));
}
}

$result = $qb->execute();
$row = $result->fetch();

// Return the total count
return (int)$row['count'];
}

Expand Down
8 changes: 4 additions & 4 deletions lib/EventListener/SoftwareCatalogEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function handleObjectCreated(ObjectCreatedEvent $event): void
}

// Handle organization creation
if ($object->getSchema() === self::ORGANIZATION_SCHEMA_ID) {
if ((string)$object->getSchema() === (string)self::ORGANIZATION_SCHEMA_ID) {
try {
$this->softwareCatalogueService->handleNewOrganization($object);
} catch (\Exception $e) {
Expand All @@ -102,7 +102,7 @@ private function handleObjectCreated(ObjectCreatedEvent $event): void
}

// Handle contact creation
if ($object->getSchema() === self::CONTACT_SCHEMA_ID) {
if ((string)$object->getSchema() === (string)self::CONTACT_SCHEMA_ID) {
try {
$this->softwareCatalogueService->handleNewContact($object);
} catch (\Exception $e) {
Expand All @@ -128,7 +128,7 @@ private function handleObjectUpdated(ObjectUpdatedEvent $event): void
}

// Handle contact updates
if ($object->getSchema() === self::CONTACT_SCHEMA_ID) {
if ((string)$object->getSchema() === (string)self::CONTACT_SCHEMA_ID) {
try {
$this->softwareCatalogueService->handleContactUpdate($object);
} catch (\Exception $e) {
Expand All @@ -154,7 +154,7 @@ private function handleObjectDeleted(ObjectDeletedEvent $event): void
}

// Handle contact deletion
if ($object->getSchema() === self::CONTACT_SCHEMA_ID) {
if ((string)$object->getSchema() === (string)self::CONTACT_SCHEMA_ID) {
try {
$this->softwareCatalogueService->handleContactDeletion($object);
} catch (\Exception $e) {
Expand Down
Loading
Loading