Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-07-26 12:14:16 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-07-26 12:14:16 +0300
commit38c032cc41853715ec533f94dd4d164922070700 (patch)
tree9fabbb14f7f5f537646e9f57f78be1b152b8bc52 /lib
parent5e779d9876a9429d7abbf83f7d090ec9fe9a9329 (diff)
more tests
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Test.php207
-rw-r--r--lib/IFullTextSearchPlatform.php8
-rw-r--r--lib/Model/IndexDocument.php8
-rw-r--r--lib/Provider/TestProvider.php6
-rw-r--r--lib/Service/TestService.php78
5 files changed, 254 insertions, 53 deletions
diff --git a/lib/Command/Test.php b/lib/Command/Test.php
index bfea923..82687b0 100644
--- a/lib/Command/Test.php
+++ b/lib/Command/Test.php
@@ -27,10 +27,13 @@
namespace OCA\FullTextSearch\Command;
use Exception;
+use OCA\FullTextSearch\Exceptions\InterruptException;
use OCA\FullTextSearch\Exceptions\ProviderIsNotCompatibleException;
+use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException;
+use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
+use OCA\FullTextSearch\IFullTextSearchPlatform;
use OCA\FullTextSearch\IFullTextSearchProvider;
use OCA\FullTextSearch\Model\ExtendedBase;
-use OCA\FullTextSearch\Model\IndexDocument;
use OCA\FullTextSearch\Model\IndexOptions;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Provider\TestProvider;
@@ -38,6 +41,7 @@ use OCA\FullTextSearch\Service\IndexService;
use OCA\FullTextSearch\Service\MiscService;
use OCA\FullTextSearch\Service\PlatformService;
use OCA\FullTextSearch\Service\RunningService;
+use OCA\FullTextSearch\Service\TestService;
use OCP\AppFramework\QueryException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -55,6 +59,9 @@ class Test extends ExtendedBase {
/** @var PlatformService */
private $platformService;
+ /** @var TestService */
+ private $testService;
+
/** @var MiscService */
private $miscService;
@@ -72,17 +79,19 @@ class Test extends ExtendedBase {
* @param RunningService $runningService
* @param IndexService $indexService
* @param PlatformService $platformService
+ * @param TestService $testService
* @param MiscService $miscService
*/
public function __construct(
RunningService $runningService, IndexService $indexService,
- PlatformService $platformService, MiscService $miscService
+ PlatformService $platformService, TestService $testService, MiscService $miscService
) {
parent::__construct();
$this->indexService = $indexService;
$this->runningService = $runningService;
$this->platformService = $platformService;
+ $this->testService = $testService;
$this->miscService = $miscService;
}
@@ -111,57 +120,27 @@ class Test extends ExtendedBase {
$this->output($output, '.Testing your current setup:');
try {
- $this->output($output, 'Creating mocked content provider.');
- $testProvider = $this->generateMockProvider();
- $this->output($output, true);
-
- $this->output($output, 'Testing mocked provider: get indexable documents.');
- $indexableDocuments = $testProvider->generateIndexableDocuments('user');
- $this->output($output, '(' . sizeof($indexableDocuments) . ' items)', false);
- $this->output($output, true);
-
+ $testProvider = $this->testCreatingProvider($output);
+ $this->testMockedProvider($output, $testProvider);
+ $testPlatform = $this->testLoadingPlatform($output);
} catch (Exception $e) {
$this->output($output, false);
throw $e;
}
try {
- $this->output($output, 'Loading search platform.');
- $testPlatform = $this->platformService->getPlatform();
- $this->output($output, '(' . $testPlatform->getName() . ')', false);
- $this->output($output, true);
-
- $this->output($output, 'Testing search platform.');
- $testPlatform->testPlatform();
- $this->output($output, true);
-
- $this->output($output, 'Locking process');
- $this->runner = new Runner($this->runningService, 'test');
- $this->runner->start(true);
- $this->indexService->setRunner($this->runner);
- $testPlatform->setRunner($this->runner);
- $testProvider->setRunner($this->runner);
- $this->output($output, true);
-
- $this->output($output, 'Indexing search platform.');
- $options = new IndexOptions(
- [
- 'provider' => TestProvider::TEST_PROVIDER_ID
- ]
- );
- $this->indexService->indexProviderContentFromUser(
- $testPlatform, $testProvider, 'user', $options
- );
- $this->output($output, true);
+ $this->testLockingProcess($output, $testPlatform, $testProvider);
+ $this->testIndexingDocuments($output, $testPlatform, $testProvider);
+ $this->testContentLicense($output, $testPlatform);
+ $this->testUnlockingProcess($output);
+ } catch (Exception $e) {
- $this->output($output, 'Unlocking process');
+ $this->output($output, false);
+ $this->output($output, 'Error detected, unlocking process');
$this->runner->stop();
$this->output($output, true);
-
- } catch (Exception $e) {
- $this->output($output, false);
throw $e;
}
@@ -248,6 +227,150 @@ class Test extends ExtendedBase {
return '<info>ok</info>';
}
+
+ /**
+ * @param $output
+ *
+ * @return IFullTextSearchProvider
+ * @throws ProviderIsNotCompatibleException
+ * @throws QueryException
+ */
+ private function testCreatingProvider($output) {
+ $this->output($output, 'Creating mocked content provider.');
+ $testProvider = $this->generateMockProvider();
+ $this->output($output, true);
+
+ return $testProvider;
+ }
+
+
+ /**
+ * @param $output
+ * @param IFullTextSearchProvider $testProvider
+ */
+ private function testMockedProvider($output, IFullTextSearchProvider $testProvider) {
+ $this->output($output, 'Testing mocked provider: get indexable documents.');
+ $indexableDocuments = $testProvider->generateIndexableDocuments('user');
+ $this->output($output, '(' . sizeof($indexableDocuments) . ' items)', false);
+ $this->output($output, true);
+ }
+
+
+ /**
+ * @param $output
+ *
+ * @return IFullTextSearchPlatform
+ * @throws Exception
+ */
+ private function testLoadingPlatform($output) {
+ $this->output($output, 'Loading search platform.');
+ $testPlatform = $this->platformService->getPlatform();
+ $this->output($output, '(' . $testPlatform->getName() . ')', false);
+ $this->output($output, true);
+
+ $this->output($output, 'Testing search platform.');
+ $testPlatform->testPlatform();
+ $this->output($output, true);
+
+ return $testPlatform;
+ }
+
+
+ /**
+ * @param OutputInterface $output
+ * @param IFullTextSearchPlatform $testPlatform
+ * @param IFullTextSearchProvider $testProvider
+ *
+ * @throws RunnerAlreadyUpException
+ */
+ private function testLockingProcess(
+ OutputInterface $output, IFullTextSearchPlatform $testPlatform,
+ IFullTextSearchProvider $testProvider
+ ) {
+ $this->output($output, 'Locking process');
+ $this->runner = new Runner($this->runningService, 'test');
+ $this->runner->start(true);
+ $this->indexService->setRunner($this->runner);
+ $testPlatform->setRunner($this->runner);
+ $testProvider->setRunner($this->runner);
+ $this->output($output, true);
+ }
+
+
+ /**
+ * @param OutputInterface $output
+ * @param IFullTextSearchPlatform $testPlatform
+ * @param IFullTextSearchProvider $testProvider
+ *
+ * @throws InterruptException
+ * @throws TickDoesNotExistException
+ */
+ private function testIndexingDocuments(
+ OutputInterface $output, IFullTextSearchPlatform $testPlatform,
+ IFullTextSearchProvider $testProvider
+ ) {
+ $this->output($output, 'Indexing generated documents.');
+ $options = new IndexOptions(
+ [
+ 'provider' => TestProvider::TEST_PROVIDER_ID
+ ]
+ );
+ $this->indexService->indexProviderContentFromUser(
+ $testPlatform, $testProvider, 'user', $options
+ );
+ $this->output($output, true);
+ }
+
+
+ /**
+ * @param OutputInterface $output
+ * @param IFullTextSearchPlatform $testPlatform
+ *
+ * @throws Exception
+ */
+ private function testContentLicense(
+ OutputInterface $output, IFullTextSearchPlatform $testPlatform
+ ) {
+
+ try {
+ $this->output($output, 'Retreiving content from a big index (license).');
+ $indexDocument = $testPlatform->getDocument(
+ TestProvider::TEST_PROVIDER_ID, TestService::DOCUMENT_TEST_LICENSE
+ );
+
+ $this->output(
+ $output, '(size: ' . $indexDocument->getContentSize() . ')', false
+ );
+ $this->output($output, true);
+
+ } catch (Exception $e) {
+ throw new Exception(
+ "Issue while getting test document '" . TestService::DOCUMENT_TEST_LICENSE
+ . "' from search platform: " . $e->getMessage()
+ );
+ }
+
+ $this->output($output, 'Comparing document with source.');
+ $this->testService->compareIndexDocument(
+ $this->testService->generateIndexDocumentContentLicense(), $indexDocument
+ );
+ $this->output($output, true);
+ }
+
+
+ /**
+ * @param OutputInterface $output
+ *
+ * @throws TickDoesNotExistException
+ */
+ private function testUnlockingProcess(OutputInterface $output) {
+ $this->output($output, 'Unlocking process');
+ $this->runner->stop();
+ $this->output($output, true);
+ }
+
+
+
// /**
// * @param IFullTextSearchProvider $provider
// * @param IndexOptions $options
diff --git a/lib/IFullTextSearchPlatform.php b/lib/IFullTextSearchPlatform.php
index 9980a4b..3864ff2 100644
--- a/lib/IFullTextSearchPlatform.php
+++ b/lib/IFullTextSearchPlatform.php
@@ -132,4 +132,12 @@ interface IFullTextSearchPlatform {
IFullTextSearchProvider $provider, DocumentAccess $access, SearchRequest $request
);
+
+// /**
+// * @param string $providerId
+// * @param string $documentId
+// *
+// * @return IndexDocument
+// */
+// public function getDocument($providerId, $documentId);
} \ No newline at end of file
diff --git a/lib/Model/IndexDocument.php b/lib/Model/IndexDocument.php
index c3d4bb9..3fa45c9 100644
--- a/lib/Model/IndexDocument.php
+++ b/lib/Model/IndexDocument.php
@@ -277,6 +277,13 @@ class IndexDocument implements \JsonSerializable {
return $this->content;
}
+ /**
+ * @return int
+ */
+ public function getContentSize() {
+ return strlen($this->getContent());
+ }
+
/**
* @return $this
@@ -528,6 +535,7 @@ class IndexDocument implements \JsonSerializable {
'source' => $this->getSource(),
'info' => $this->getInfoAll(),
'hash' => $this->getHash(),
+ 'contentSize' => $this->getContentSize(),
'tags' => $this->getTags(),
'more' => $this->getMore(),
'excerpts' => $this->getExcerpts(),
diff --git a/lib/Provider/TestProvider.php b/lib/Provider/TestProvider.php
index 097b214..29808c8 100644
--- a/lib/Provider/TestProvider.php
+++ b/lib/Provider/TestProvider.php
@@ -160,9 +160,9 @@ class TestProvider implements IFullTextSearchProvider {
public function generateIndexableDocuments($userId) {
$result = [];
- $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX1);
- $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX2);
- $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX3);
+ $result[] = $this->testService->generateIndexDocumentContentLicense();
+ $result[] = $this->testService->generateIndexDocumentSimple();
+// $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX3);
return $result;
}
diff --git a/lib/Service/TestService.php b/lib/Service/TestService.php
index 9d93a1d..87a4b95 100644
--- a/lib/Service/TestService.php
+++ b/lib/Service/TestService.php
@@ -30,15 +30,20 @@ use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Exceptions\ProviderOptionsDoesNotExistException;
use OCA\FullTextSearch\Model\DocumentAccess;
use OCA\FullTextSearch\Model\IndexDocument;
+use OCA\FullTextSearch\Provider\TestProvider;
use OCP\IConfig;
use OCP\PreConditionNotMetException;
use OCP\Util;
class TestService {
- const DOCUMENT_TEST_INDEX1 = 1;
- const DOCUMENT_TEST_INDEX2 = 2;
- const DOCUMENT_TEST_INDEX3 = 3;
+ const DOCUMENT_USER = 'user';
+
+ const DOCUMENT_TEST_LICENSE = 'license';
+ const DOCUMENT_TEST_SIMPLE = 'simple';
+ const DOCUMENT_TEST_ACCESS = 'access';
+
+ const LICENSE_HASH = '108322602bb857915803a84e23a2cc2f';
/** @var MiscService */
private $miscService;
@@ -55,16 +60,73 @@ class TestService {
/**
- * @param int $documentType
+ * @return IndexDocument
+ */
+ public function generateIndexDocumentContentLicense() {
+ $indexDocument = $this->generateIndexDocument(self::DOCUMENT_TEST_LICENSE);
+
+ $content = file_get_contents(__DIR__ . '/../../LICENSE');
+ $indexDocument->setContent($content);
+
+ return $indexDocument;
+ }
+
+
+ /**
+ * @return IndexDocument
+ */
+ public function generateIndexDocumentSimple() {
+
+ $indexDocument = $this->generateIndexDocument(self::DOCUMENT_TEST_SIMPLE);
+ $indexDocument->setContent('This is a test');
+
+ return $indexDocument;
+ }
+
+
+ /**
+ * @param IndexDocument $origIndex
+ * @param IndexDocument $compareIndex
+ *
+ * @throws \Exception
+ */
+ public function compareIndexDocument(IndexDocument $origIndex, IndexDocument $compareIndex) {
+ if ($origIndex->getAccess()
+ ->getOwnerId() !== $compareIndex->getAccess()
+ ->getOwnerId()) {
+ throw new \Exception('issue with AccessDocument');
+ }
+
+ $methods = [
+ 'getId',
+ 'getProviderId',
+ 'getTitle',
+ 'getSource'
+ ];
+
+ foreach ($methods as $method) {
+ $orig = call_user_func([$origIndex, $method]);
+ $compare = call_user_func([$compareIndex, $method]);
+ if ($orig !== $compare) {
+ throw new \Exception($method . '() orig:' . $orig . ' compare:' . $compare);
+
+ };
+ }
+ }
+
+
+ /**
+ * @param string $documentType
*
* @return IndexDocument
*/
- public function generateIndexDocuments($documentType) {
- $indexDocument = new IndexDocument('test', 'test_' . $documentType);
- $indexDocument->setContent('This is the content');
+ private function generateIndexDocument($documentType) {
+ $indexDocument = new IndexDocument(TestProvider::TEST_PROVIDER_ID, $documentType);
- $access = new DocumentAccess('user');
+ $access = new DocumentAccess(self::DOCUMENT_USER);
$indexDocument->setAccess($access);
+
return $indexDocument;
}
+
}