From b0f057f0d71784d273ff8272302be778785d1c29 Mon Sep 17 00:00:00 2001 From: Andrei Rebegea Date: Tue, 31 Oct 2017 14:18:00 +0200 Subject: [PATCH] REPO-2028: Remove lucene dependency Refactor test to avoid using search service or mock it. Mark some of the tests as redundant, this will be processed in REPO-3019. --- l10n.properties | 2 +- pom.xml | 3 - .../email/server/EmailServiceImpl.java | 46 +- .../org/alfresco/repo/model/Repository.java | 96 +- .../executer/AbstractRenderingEngine.java | 58 +- .../executer/BaseTemplateRenderingEngine.java | 71 +- .../service/ServiceDescriptorRegistry.java | 64 +- .../DefaultManifestProcessorFactoryImpl.java | 110 +- .../transfer/RepoTransferReceiverImpl.java | 106 +- .../transfer/TransferSummaryReportImpl.java | 79 +- .../resources/alfresco/bootstrap-context.xml | 1 + .../webscripts/blogsearch.get.html.400.ftl | 2 +- .../categorysearch.get.html.404.ftl | 2 +- .../webscripts/categorysearch.get.html.ftl | 2 +- .../alfresco/core-services-context.xml | 17 - .../alfresco/rendition-services-context.xml | 49 +- .../Search/buildonly/bootstrap-context.xml | 45 - .../common-search-scheduler-context.xml | 47 - .../Search/buildonly/common-search.properties | 11 - .../buildonly/index-recovery-context.xml | 184 - .../buildonly/index-recovery.properties | 10 - .../buildonly/lucene-search-context.xml | 414 - .../Search/buildonly/lucene-search.properties | 57 - .../Search/buildonly/opencmis-context.xml | 72 - .../buildonly/scheduled-jobs-context.xml | 65 - .../buildonly/scheduled-jobs.properties | 1 - .../alfresco/transfer-service-context.xml | 18 +- .../java/org/alfresco/AllUnitTestsSuite.java | 4 +- .../org/alfresco/AppContext04TestSuite.java | 5 - .../org/alfresco/AppContext06TestSuite.java | 2 - .../alfresco/AppContextExtraTestSuite.java | 2 +- .../email/server/EmailServiceImplTest.java | 2 +- .../org/alfresco/opencmis/BaseCMISTest.java | 5 +- .../java/org/alfresco/opencmis/CMISTest.java | 4 +- .../opencmis/search/OpenCmisQueryTest.java | 40 +- ...ontentMetadataExtracterTagMappingTest.java | 3 +- ...ueryBasedTemplateActionDefinitionTest.java | 3 +- .../repo/blog/BlogServiceImplTest.java | 8 +- .../calendar/CalendarServiceImplTest.java | 35 +- .../discussion/DiscussionServiceImplTest.java | 196 +- .../repo/exporter/ExporterComponentTest.java | 3 + .../alfresco/repo/imap/ImapMessageTest.java | 4 +- .../org/alfresco/repo/jscript/PeopleTest.java | 295 +- .../repo/links/LinksServiceImplTest.java | 31 +- .../repo/lock/LockServiceImplTest.java | 5 +- .../FileFolderServicePropagationTest.java | 17 +- .../model/filefolder/HiddenAspectTest.java | 77 +- .../alfresco/repo/module/ComponentsTest.java | 3 +- .../node/ConcurrentNodeServiceSearchTest.java | 11 +- .../index/FullIndexRecoveryComponentTest.java | 181 - .../index/IndexTransactionTrackerTest.java | 159 - .../MissingContentReindexComponentTest.java | 198 - .../RenditionServiceIntegrationTest.java | 2 +- .../rendition/executer/XSLTFunctionsTest.java | 12 +- .../repo/search/SearchServiceTest.java | 5 +- .../alfresco/repo/search/SearchTestSuite.java | 62 +- .../repo/search/SearcherComponentTest.java | 11 +- .../impl/lucene/ADMLuceneCategoryTest.java | 1151 --- .../search/impl/lucene/ADMLuceneTest.java | 7927 ----------------- .../repo/search/impl/lucene/ALF947Test.java | 423 - .../LuceneIndexBackupComponentTest.java | 99 - .../search/impl/lucene/MultiReaderTest.java | 113 - ...ullTextSearchIndexerBootstrapBeanTest.java | 94 - .../impl/lucene/index/IndexInfoTest.java | 912 -- .../impl/querymodel/impl/db/DBQueryTest.java | 6 +- .../authority/AuthorityServiceTest.java | 5 +- .../permissions/impl/ReadPermissionTest.java | 3 +- .../repo/security/person/PersonTest.java | 84 +- .../security/person/TestGroupManager.java | 83 +- .../repo/site/SiteServiceImplTest.java | 4 + .../SubscriptionServiceImplTest.java | 29 +- .../repo/tagging/TaggingServiceImplTest.java | 214 +- .../UpdateTagScopesActionExecuterTest.java | 5 +- .../repo/template/XSLTProcessorTest.java | 18 +- .../alfresco/repo/tenant/MultiTDemoTest.java | 9 +- .../repo/transfer/NodeCrawlerTest.java | 12 +- .../RepoTransferReceiverImplTest.java | 52 +- .../transfer/TransferServiceImplTest.java | 121 +- .../TransferServiceToBeRefactoredTest.java | 93 +- .../VirtualizationIntegrationTest.java | 129 +- .../bundle/FileInfoPropsComparatorTest.java | 32 +- ...alCheckOutCheckInServiceExtensionTest.java | 13 +- ...VirtualFileFolderServiceExtensionTest.java | 76 +- ...ockableAspectInterceptorExtensionTest.java | 9 +- .../VirtualNodeServiceExtensionTest.java | 60 +- ...VirtualPermissionServiceExtensionTest.java | 22 +- ...VirtualPreferenceServiceExtensionTest.java | 25 +- .../VirtualRatingServiceExtensionTest.java | 18 +- .../VirtualVersionServiceExtensionTest.java | 7 +- .../config/NodeRefPathExpressionTest.java | 9 +- ...SystemTemplateLocationsConstraintTest.java | 12 +- .../store/SystemVirtualizationMethodTest.java | 7 +- ...peVirtualizationMethodIntegrationTest.java | 241 + .../store/TypeVirtualizationMethodTest.java | 381 - .../TypeVirtualizationMethodUnitTest.java | 107 + .../virtual/store/VirtualStoreImplTest.java | 8 +- .../template/ApplyTemplateMethodTest.java | 16 +- .../template/TemplateFilingRuleTest.java | 2 + .../TemplateResourceProcessorTest.java | 7 +- ...bstractWorkflowServiceIntegrationTest.java | 4 +- ...ctivitiWorkflowServiceIntegrationTest.java | 4 +- .../search/impl/lucene/LuceneTest_model.xml | 385 - .../impl/lucene/test_categoryService.js | 69 - .../repo/site/script/test_siteService.js | 81 +- 104 files changed, 1820 insertions(+), 14378 deletions(-) delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/bootstrap-context.xml delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/common-search-scheduler-context.xml delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/common-search.properties delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery-context.xml delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery.properties delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search-context.xml delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search.properties delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/opencmis-context.xml delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs-context.xml delete mode 100644 src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs.properties delete mode 100644 src/test/java/org/alfresco/repo/node/index/FullIndexRecoveryComponentTest.java delete mode 100644 src/test/java/org/alfresco/repo/node/index/IndexTransactionTrackerTest.java delete mode 100644 src/test/java/org/alfresco/repo/node/index/MissingContentReindexComponentTest.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneCategoryTest.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/ALF947Test.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/LuceneIndexBackupComponentTest.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/MultiReaderTest.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/fts/FullTextSearchIndexerBootstrapBeanTest.java delete mode 100644 src/test/java/org/alfresco/repo/search/impl/lucene/index/IndexInfoTest.java create mode 100644 src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodIntegrationTest.java delete mode 100644 src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodTest.java create mode 100644 src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodUnitTest.java delete mode 100644 src/test/resources/org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml delete mode 100644 src/test/resources/org/alfresco/repo/search/impl/lucene/test_categoryService.js diff --git a/l10n.properties b/l10n.properties index 22141e822e..26efac3f76 100644 --- a/l10n.properties +++ b/l10n.properties @@ -3,5 +3,5 @@ MESSAGE_SEARCH_PATH="src/main/resources/alfresco/messages/action-config*.properties src/main/resources/alfresco/messages/action-service*.properties src/main/resources/alfresco/messages/activiti-engine-messages*.properties src/main/resources/alfresco/messages/activities-service*.properties src/main/resources/alfresco/messages/activity-list*.properties src/main/resources/alfresco/messages/application-model*.properties src/main/resources/alfresco/messages/authentication*.properties src/main/resources/alfresco/messages/bootstrap-content-template-examples*.properties src/main/resources/alfresco/messages/bootstrap-example-javascripts*.properties src/main/resources/alfresco/messages/bootstrap-example-smartfoldertemplates*.properties src/main/resources/alfresco/messages/bootstrap-imapScripts*.properties src/main/resources/alfresco/messages/bootstrap-javascripts*.properties src/main/resources/alfresco/messages/bootstrap-messages*.properties src/main/resources/alfresco/messages/bootstrap-readme-template*.properties src/main/resources/alfresco/messages/bootstrap-spaces*.properties src/main/resources/alfresco/messages/bootstrap-templates*.properties src/main/resources/alfresco/messages/bootstrap-tutorial*.properties src/main/resources/alfresco/messages/bootstrap-webScripts*.properties src/main/resources/alfresco/messages/bootstrap-webScriptsExtensions*.properties src/main/resources/alfresco/messages/bpm-messages*.properties src/main/resources/alfresco/messages/categories*.properties src/main/resources/alfresco/messages/coci-service*.properties src/main/resources/alfresco/messages/content-filter-languages*.properties src/main/resources/alfresco/messages/content-model*.properties src/main/resources/alfresco/messages/copy-service*.properties src/main/resources/alfresco/messages/custommodel-service*.properties src/main/resources/alfresco/messages/discussion-messages*.properties src/main/resources/alfresco/messages/distributionpolicies-model*.properties src/main/resources/alfresco/messages/doclink-service*.properties src/main/resources/alfresco/messages/download-model*.properties src/main/resources/alfresco/messages/email-server-model*.properties src/main/resources/alfresco/messages/email-service*.properties src/main/resources/alfresco/messages/file-folder-service*.properties src/main/resources/alfresco/messages/form-service*.properties src/main/resources/alfresco/messages/forum-model*.properties src/main/resources/alfresco/messages/imap-service*.properties src/main/resources/alfresco/messages/initiate-inplace*.properties src/main/resources/alfresco/messages/invitation-service*.properties src/main/resources/alfresco/messages/lock-service*.properties src/main/resources/alfresco/messages/notification-service*.properties src/main/resources/alfresco/messages/period-provider*.properties src/main/resources/alfresco/messages/permissions-service*.properties src/main/resources/alfresco/messages/publishing-model*.properties src/main/resources/alfresco/messages/publishing-service*.properties src/main/resources/alfresco/messages/quickshare-service*.properties src/main/resources/alfresco/messages/rendition-config*.properties src/main/resources/alfresco/messages/replication*.properties src/main/resources/alfresco/messages/repoadmin-service*.properties src/main/resources/alfresco/messages/reset-password-messages*.properties src/main/resources/alfresco/messages/rule-config*.properties src/main/resources/alfresco/messages/site-model*.properties src/main/resources/alfresco/messages/site-service*.properties src/main/resources/alfresco/messages/slingshot*.properties src/main/resources/alfresco/messages/smartfolder-model*.properties src/main/resources/alfresco/messages/subscription-service*.properties src/main/resources/alfresco/messages/system-messages*.properties src/main/resources/alfresco/messages/system-model*.properties src/main/resources/alfresco/messages/template-service*.properties src/main/resources/alfresco/messages/templates-messages*.properties src/main/resources/alfresco/messages/transfer-model*.properties src/main/resources/alfresco/messages/transfer-service*.properties src/main/resources/alfresco/messages/ui-inplace*.properties src/main/resources/alfresco/messages/webdav-messages*.properties src/main/resources/alfresco/messages/workflow-package-messages*.properties src/main/resources/alfresco/workflow/invitation-moderated-workflow-messages*.properties src/main/resources/alfresco/workflow/invitation-nominated-workflow-messages*.properties src/main/resources/alfresco/workflow/workflow-messages*.properties" -EXCLUDED_FILES="src/main/resources/alfresco/messages/content-service.properties src/main/resources/alfresco/messages/module-messages.properties src/main/resources/alfresco/messages/patch-service.properties src/main/resources/alfresco/messages/repoadmin-interpreter-help.properties src/main/resources/alfresco/messages/schema-update.properties src/main/resources/alfresco/messages/tenant-interpreter-help.properties src/main/resources/alfresco/messages/version-service.properties src/main/resources/alfresco/messages/workflow-interpreter-help.properties src/main/resources/alfresco/alfresco-shared.properties src/main/resources/alfresco/caches.properties src/main/resources/alfresco/repository.properties src/main/resources/alfresco/client/config/repo-clients-apps.properties src/main/resources/alfresco/domain/cache-strategies.properties src/main/resources/alfresco/domain/hibernate-cfg.properties src/main/resources/alfresco/domain/quartz.properties src/main/resources/alfresco/domain/transaction.properties src/main/resources/alfresco/keystore/keystore-passwords.properties src/main/resources/alfresco/keystore/ssl-keystore-passwords.properties src/main/resources/alfresco/keystore/ssl-truststore-passwords.properties src/main/resources/alfresco/metadata/DWGMetadataExtracter.properties src/main/resources/alfresco/metadata/HtmlMetadataExtracter.properties src/main/resources/alfresco/metadata/MailMetadataExtracter.properties src/main/resources/alfresco/metadata/MP3MetadataExtracter.properties src/main/resources/alfresco/metadata/OfficeMetadataExtracter.properties src/main/resources/alfresco/metadata/OpenDocumentMetadataExtracter.properties src/main/resources/alfresco/metadata/OpenOfficeMetadataExtracter.properties src/main/resources/alfresco/metadata/PdfBoxMetadataExtracter.properties src/main/resources/alfresco/metadata/PoiMetadataExtracter.properties src/main/resources/alfresco/metadata/RFC822MetadataExtracter.properties src/main/resources/alfresco/metadata/TikaAudioMetadataExtracter.properties src/main/resources/alfresco/metadata/TikaAutoMetadataExtracter.properties src/main/resources/alfresco/metadata/TikaSpringConfiguredMetadataExtracter.properties src/main/resources/alfresco/subsystems/ActivitiesFeed/default/activities-jobs.properties src/main/resources/alfresco/subsystems/Authentication/alfrescoNtlm/alfresco-authentication.properties src/main/resources/alfresco/subsystems/Authentication/external/external-authentication.properties src/main/resources/alfresco/subsystems/Authentication/kerberos/kerberos-authentication.properties src/main/resources/alfresco/subsystems/Authentication/ldap/ldap-authentication.properties src/main/resources/alfresco/subsystems/Authentication/ldap-ad/ldap-ad-authentication.properties src/main/resources/alfresco/subsystems/Authentication/passthru/passthru-authentication-context.properties src/main/resources/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties src/main/resources/alfresco/subsystems/email/OutboundSMTP/outboundSMTP.properties src/main/resources/alfresco/subsystems/fileServers/default/file-servers.properties src/main/resources/alfresco/subsystems/imap/default/imap-server.properties src/main/resources/alfresco/subsystems/OOoDirect/default/openoffice-transform.properties src/main/resources/alfresco/subsystems/Replication/default/replication.properties src/main/resources/alfresco/subsystems/Search/buildonly/common-search.properties src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery.properties src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search.properties src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs.properties src/main/resources/alfresco/subsystems/Search/noindex/common-search.properties src/main/resources/alfresco/subsystems/Search/noindex/noindex-search.properties src/main/resources/alfresco/subsystems/Search/solr/common-search.properties src/main/resources/alfresco/subsystems/Search/solr/solr-backup.properties src/main/resources/alfresco/subsystems/Search/solr/solr-search.properties src/main/resources/alfresco/subsystems/Search/solr/facet/solr-facets-config.properties src/main/resources/alfresco/subsystems/Search/solr4/common-search.properties src/main/resources/alfresco/subsystems/Search/solr4/solr-backup.properties src/main/resources/alfresco/subsystems/Search/solr4/solr-search.properties src/main/resources/alfresco/subsystems/Search/solr6/common-search.properties src/main/resources/alfresco/subsystems/Search/solr6/solr-backup.properties src/main/resources/alfresco/subsystems/Search/solr6/solr-search.properties src/main/resources/alfresco/subsystems/Subscriptions/default/subscription-service.properties src/main/resources/alfresco/subsystems/Synchronization/default/default-synchronization.properties src/main/resources/alfresco/subsystems/sysAdmin/default/sysadmin-parameter.properties src/main/resources/alfresco/subsystems/thirdparty/default/alfresco-pdf-renderer-transform.properties src/main/resources/alfresco/subsystems/thirdparty/default/imagemagick-transform.properties src/main/resources/alfresco/subsystems/Transformers/default/transformers.properties src/main/resources/org/alfresco/encryption/keystore-parameters.properties src/main/resources/org/alfresco/repo/i18n/testMessages.properties src/main/resources/org/alfresco/repo/module/tool/default-file-mapping.properties src/main/resources/org/alfresco/repo/publishing/facebook/facebook-publishing.properties src/main/resources/org/alfresco/repo/publishing/flickr/flickr-publishing.properties src/main/resources/org/alfresco/repo/publishing/linkedin/linkedin-publishing.properties src/main/resources/org/alfresco/repo/publishing/slideshare/slideshare-publishing.properties src/main/resources/org/alfresco/repo/publishing/twitter/twitter-publishing.properties src/main/resources/org/alfresco/repo/publishing/youtube/youtube-publishing.properties" +EXCLUDED_FILES="src/main/resources/alfresco/messages/content-service.properties src/main/resources/alfresco/messages/module-messages.properties src/main/resources/alfresco/messages/patch-service.properties src/main/resources/alfresco/messages/repoadmin-interpreter-help.properties src/main/resources/alfresco/messages/schema-update.properties src/main/resources/alfresco/messages/tenant-interpreter-help.properties src/main/resources/alfresco/messages/version-service.properties src/main/resources/alfresco/messages/workflow-interpreter-help.properties src/main/resources/alfresco/alfresco-shared.properties src/main/resources/alfresco/caches.properties src/main/resources/alfresco/repository.properties src/main/resources/alfresco/client/config/repo-clients-apps.properties src/main/resources/alfresco/domain/cache-strategies.properties src/main/resources/alfresco/domain/hibernate-cfg.properties src/main/resources/alfresco/domain/quartz.properties src/main/resources/alfresco/domain/transaction.properties src/main/resources/alfresco/keystore/keystore-passwords.properties src/main/resources/alfresco/keystore/ssl-keystore-passwords.properties src/main/resources/alfresco/keystore/ssl-truststore-passwords.properties src/main/resources/alfresco/metadata/DWGMetadataExtracter.properties src/main/resources/alfresco/metadata/HtmlMetadataExtracter.properties src/main/resources/alfresco/metadata/MailMetadataExtracter.properties src/main/resources/alfresco/metadata/MP3MetadataExtracter.properties src/main/resources/alfresco/metadata/OfficeMetadataExtracter.properties src/main/resources/alfresco/metadata/OpenDocumentMetadataExtracter.properties src/main/resources/alfresco/metadata/OpenOfficeMetadataExtracter.properties src/main/resources/alfresco/metadata/PdfBoxMetadataExtracter.properties src/main/resources/alfresco/metadata/PoiMetadataExtracter.properties src/main/resources/alfresco/metadata/RFC822MetadataExtracter.properties src/main/resources/alfresco/metadata/TikaAudioMetadataExtracter.properties src/main/resources/alfresco/metadata/TikaAutoMetadataExtracter.properties src/main/resources/alfresco/metadata/TikaSpringConfiguredMetadataExtracter.properties src/main/resources/alfresco/subsystems/ActivitiesFeed/default/activities-jobs.properties src/main/resources/alfresco/subsystems/Authentication/alfrescoNtlm/alfresco-authentication.properties src/main/resources/alfresco/subsystems/Authentication/external/external-authentication.properties src/main/resources/alfresco/subsystems/Authentication/kerberos/kerberos-authentication.properties src/main/resources/alfresco/subsystems/Authentication/ldap/ldap-authentication.properties src/main/resources/alfresco/subsystems/Authentication/ldap-ad/ldap-ad-authentication.properties src/main/resources/alfresco/subsystems/Authentication/passthru/passthru-authentication-context.properties src/main/resources/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties src/main/resources/alfresco/subsystems/email/OutboundSMTP/outboundSMTP.properties src/main/resources/alfresco/subsystems/fileServers/default/file-servers.properties src/main/resources/alfresco/subsystems/imap/default/imap-server.properties src/main/resources/alfresco/subsystems/OOoDirect/default/openoffice-transform.properties src/main/resources/alfresco/subsystems/Replication/default/replication.properties src/main/resources/alfresco/subsystems/Search/noindex/common-search.properties src/main/resources/alfresco/subsystems/Search/noindex/noindex-search.properties src/main/resources/alfresco/subsystems/Search/solr/common-search.properties src/main/resources/alfresco/subsystems/Search/solr/solr-backup.properties src/main/resources/alfresco/subsystems/Search/solr/solr-search.properties src/main/resources/alfresco/subsystems/Search/solr/facet/solr-facets-config.properties src/main/resources/alfresco/subsystems/Search/solr4/common-search.properties src/main/resources/alfresco/subsystems/Search/solr4/solr-backup.properties src/main/resources/alfresco/subsystems/Search/solr4/solr-search.properties src/main/resources/alfresco/subsystems/Search/solr6/common-search.properties src/main/resources/alfresco/subsystems/Search/solr6/solr-backup.properties src/main/resources/alfresco/subsystems/Search/solr6/solr-search.properties src/main/resources/alfresco/subsystems/Subscriptions/default/subscription-service.properties src/main/resources/alfresco/subsystems/Synchronization/default/default-synchronization.properties src/main/resources/alfresco/subsystems/sysAdmin/default/sysadmin-parameter.properties src/main/resources/alfresco/subsystems/thirdparty/default/alfresco-pdf-renderer-transform.properties src/main/resources/alfresco/subsystems/thirdparty/default/imagemagick-transform.properties src/main/resources/alfresco/subsystems/Transformers/default/transformers.properties src/main/resources/org/alfresco/encryption/keystore-parameters.properties src/main/resources/org/alfresco/repo/i18n/testMessages.properties src/main/resources/org/alfresco/repo/module/tool/default-file-mapping.properties src/main/resources/org/alfresco/repo/publishing/facebook/facebook-publishing.properties src/main/resources/org/alfresco/repo/publishing/flickr/flickr-publishing.properties src/main/resources/org/alfresco/repo/publishing/linkedin/linkedin-publishing.properties src/main/resources/org/alfresco/repo/publishing/slideshare/slideshare-publishing.properties src/main/resources/org/alfresco/repo/publishing/twitter/twitter-publishing.properties src/main/resources/org/alfresco/repo/publishing/youtube/youtube-publishing.properties" diff --git a/pom.xml b/pom.xml index 98373258f6..062b493433 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,6 @@ community - buildonly ${project.build.directory}/alf_data convert @@ -1026,8 +1025,6 @@ 30 2000 - - ${index.subsystem.name} true diff --git a/src/main/java/org/alfresco/email/server/EmailServiceImpl.java b/src/main/java/org/alfresco/email/server/EmailServiceImpl.java index a209b29289..f2f0a13dc4 100644 --- a/src/main/java/org/alfresco/email/server/EmailServiceImpl.java +++ b/src/main/java/org/alfresco/email/server/EmailServiceImpl.java @@ -437,50 +437,26 @@ public class EmailServiceImpl implements EmailService return ref; } - StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); - -// // Ok, alias wasn't found, let's try to interpret recipient address as 'node-bdid' value -// try -// { -// Long nodeId = Long.parseLong(parts[0]); -// -// NodeRef byNodeId = nodeService.getNodeRef(nodeId); -// -// if(byNodeId != null) -// { -// if(logger.isDebugEnabled()) -// { -// logger.debug("found email alias via node service =" + alias); -// } -// return byNodeId; -// } -// } -// catch (NumberFormatException ne) -// { -// } - // Ok, alias wasn't found, let's try to interpret recipient address as 'node-bdid' value - ResultSet resultSet = null; try { Long nodeId = Long.parseLong(parts[0]); - String query = "@sys\\:node-dbid:" + nodeId; - resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, query); - if (resultSet.length() > 0) + + // Get recipient by system account + NodeRef byNodeId = AuthenticationUtil.runAsSystem(() -> nodeService.getNodeRef(nodeId)); + + if(byNodeId != null) { - return resultSet.getNodeRef(0); + if(logger.isDebugEnabled()) + { + logger.debug("found email alias via node service =" + alias); + } + return byNodeId; } } - catch (NumberFormatException e) + catch (NumberFormatException ne) { } - finally - { - if(resultSet != null) - { - resultSet.close(); - } - } throw new EmailMessageException(ERR_INVALID_NODE_ADDRESS, recipient); } diff --git a/src/main/java/org/alfresco/repo/model/Repository.java b/src/main/java/org/alfresco/repo/model/Repository.java index e56ee66dce..25de5ccf5a 100644 --- a/src/main/java/org/alfresco/repo/model/Repository.java +++ b/src/main/java/org/alfresco/repo/model/Repository.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.model; import java.util.ArrayList; @@ -72,10 +72,13 @@ public class Repository implements ApplicationContextAware private StoreRef companyHomeStore; // ie. workspace://SpaceStore private String companyHomePath; // ie. /app:company_home private String sharedHomePath; // ie. /app:shared + + private String guestHomePath; // /app:company_home/app:guest_home // note: cache is tenant-aware (if using EhCacheAdapter shared cache) private SimpleCache singletonCache; // eg. for companyHomeNodeRef private final String KEY_COMPANYHOME_NODEREF = "key.companyhome.noderef"; + private final String KEY_GUESTHOME_NODEREF = "key.guesthome.noderef"; private final String KEY_SHAREDHOME_NODEREF = "key.sharedhome.noderef"; @@ -113,7 +116,12 @@ public class Repository implements ApplicationContextAware { this.singletonCache = singletonCache; } - + + public void setGuestHomePath(String guestHomePath) + { + this.guestHomePath = guestHomePath; + } + /** * Sets helper that provides transaction callbacks */ @@ -242,7 +250,41 @@ public class Repository implements ApplicationContextAware } return companyHomeRef; } - + + /** + * Gets the Guest Home. Note this is tenant-aware if the correct Cache is supplied. + * + * @return guest home node ref + */ + public NodeRef getGuestHome() + { + NodeRef guestHomeRef = singletonCache.get(KEY_GUESTHOME_NODEREF); + if (guestHomeRef == null) + { + guestHomeRef = AuthenticationUtil.runAs(new RunAsWork() + { + public NodeRef doWork() throws Exception + { + return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Exception + { + List refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), guestHomePath, null, namespaceService, false); + if (refs.size() != 1) + { + throw new IllegalStateException("Invalid guest home path: " + guestHomePath + " - found: " + refs.size()); + } + return refs.get(0); + } + }, true); + } + }, AuthenticationUtil.getSystemUserName()); + + singletonCache.put(KEY_COMPANYHOME_NODEREF, guestHomeRef); + } + return guestHomeRef; + } + /** * Gets the Shared Home. Note this is tenant-aware if the correct Cache is supplied. * diff --git a/src/main/java/org/alfresco/repo/rendition/executer/AbstractRenderingEngine.java b/src/main/java/org/alfresco/repo/rendition/executer/AbstractRenderingEngine.java index 0bbbc2071c..c83ecaa2cb 100644 --- a/src/main/java/org/alfresco/repo/rendition/executer/AbstractRenderingEngine.java +++ b/src/main/java/org/alfresco/repo/rendition/executer/AbstractRenderingEngine.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.rendition.executer; import static org.alfresco.service.cmr.rendition.RenditionService.PARAM_DESTINATION_PATH_TEMPLATE; @@ -145,6 +145,7 @@ public abstract class AbstractRenderingEngine extends ActionExecuterAbstractBase protected ContentService contentService; protected MimetypeMap mimetypeMap; protected ActionTrackingService actionTrackingService; + protected NamespaceService namespaceService; /* Parameter names common to all Rendering Actions */ /** @@ -249,7 +250,12 @@ public abstract class AbstractRenderingEngine extends ActionExecuterAbstractBase { this.renditionLocationResolver = renditionLocationResolver; } - + + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + } + public AbstractRenderingEngine(NodeLocator temporaryParentNodeLocator, QName temporaryRenditionLinkType) { this.publicAction = false; diff --git a/src/main/java/org/alfresco/repo/rendition/executer/BaseTemplateRenderingEngine.java b/src/main/java/org/alfresco/repo/rendition/executer/BaseTemplateRenderingEngine.java index 933f84ffa9..d98e021cf6 100644 --- a/src/main/java/org/alfresco/repo/rendition/executer/BaseTemplateRenderingEngine.java +++ b/src/main/java/org/alfresco/repo/rendition/executer/BaseTemplateRenderingEngine.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.rendition.executer; @@ -31,6 +31,7 @@ import java.io.OutputStreamWriter; import java.io.Serializable; import java.io.Writer; import java.util.Collection; +import java.util.List; import java.util.Map; import org.alfresco.repo.action.ParameterDefinitionImpl; @@ -41,7 +42,6 @@ import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.TemplateService; -import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -180,21 +180,14 @@ public abstract class BaseTemplateRenderingEngine extends AbstractRenderingEngin if (path != null && path.length() > 0) { StoreRef storeRef = context.getDestinationNode().getStoreRef(); - ResultSet result = null; - - try + + List refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), + path, null, namespaceService, false); + if (refs.size() != 1) { - result = searchService.query(storeRef, SearchService.LANGUAGE_XPATH, path); - if (result.length() != 1) - { - throw new RenditionServiceException("Could not find template node for path: " + path); - } - node = result.getNodeRef(0); - } - finally - { - if (result != null) {result.close();} + throw new RenditionServiceException("Could not find template node for path: " + path); } + node = refs.get(0); } } return node; diff --git a/src/main/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java b/src/main/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java index 42ab59ebf9..6f0b0d971d 100644 --- a/src/main/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java +++ b/src/main/java/org/alfresco/repo/service/ServiceDescriptorRegistry.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.service; import java.util.Collection; @@ -102,7 +102,7 @@ public class ServiceDescriptorRegistry { // Bean Factory within which the registry lives private BeanFactory beanFactory = null; - + private SearchService mockSearchService; @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException @@ -192,7 +192,17 @@ public class ServiceDescriptorRegistry @Override public SearchService getSearchService() { - return (SearchService)getService(SEARCH_SERVICE); + return mockSearchService == null ? (SearchService)getService(SEARCH_SERVICE) : mockSearchService; + } + + /** + * For use in test classes only that need to mock the searchServices. + * @param mockSearchService to be set. If {@code null} the next call to {@link #getSearchService()} will return + * the real search service from the context. + */ + public void setMockSearchService(SearchService mockSearchService) + { + this.mockSearchService = mockSearchService; } @Override diff --git a/src/main/java/org/alfresco/repo/transfer/DefaultManifestProcessorFactoryImpl.java b/src/main/java/org/alfresco/repo/transfer/DefaultManifestProcessorFactoryImpl.java index 912b932390..2595578cea 100644 --- a/src/main/java/org/alfresco/repo/transfer/DefaultManifestProcessorFactoryImpl.java +++ b/src/main/java/org/alfresco/repo/transfer/DefaultManifestProcessorFactoryImpl.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.transfer; @@ -36,11 +36,12 @@ import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.search.CategoryService; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.search.CategoryService; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.cmr.transfer.TransferReceiver; +import org.alfresco.service.namespace.NamespaceService; /** * @author brian @@ -53,12 +54,13 @@ public class DefaultManifestProcessorFactoryImpl implements ManifestProcessorFac private PermissionService permissionService; private CorrespondingNodeResolverFactory nodeResolverFactory; private AlienProcessor alienProcessor; - private CategoryService categoryService; - private TaggingService taggingService; - private SearchService searchService; - private String transferSummaryReportLocation; - private Properties properties; - private FileFolderService fileFolderService; + private CategoryService categoryService; + private TaggingService taggingService; + private SearchService searchService; + private String transferSummaryReportLocation; + private Properties properties; + private FileFolderService fileFolderService; + private NamespaceService namespaceService; /* * (non-Javadoc) @@ -76,6 +78,7 @@ public class DefaultManifestProcessorFactoryImpl implements ManifestProcessorFac summaryReport.setSearchService(searchService); summaryReport.setFileFolderService(fileFolderService); summaryReport.setTransferSummaryReportLocation(transferSummaryReportLocation); + summaryReport.setNamespaceService(namespaceService); transferSummaryReport = summaryReport; } @@ -89,9 +92,9 @@ public class DefaultManifestProcessorFactoryImpl implements ManifestProcessorFac primaryProcessor.setDictionaryService(dictionaryService); primaryProcessor.setPermissionService(getPermissionService()); primaryProcessor.setAlienProcessor(getAlienProcessor()); - primaryProcessor.setCategoryService(categoryService); - primaryProcessor.setTaggingService(getTaggingService()); - primaryProcessor.setTransferSummaryReport(transferSummaryReport); + primaryProcessor.setCategoryService(categoryService); + primaryProcessor.setTaggingService(getTaggingService()); + primaryProcessor.setTransferSummaryReport(transferSummaryReport); processors.add(primaryProcessor); RepoSecondaryManifestProcessorImpl secondaryProcessor = new RepoSecondaryManifestProcessorImpl(receiver, transferId); @@ -198,24 +201,29 @@ public class DefaultManifestProcessorFactoryImpl implements ManifestProcessorFac this.searchService = searchService; } - public CategoryService getCategoryService() - { - return categoryService; - } - - public void setCategoryService(CategoryService categoryService) - { - this.categoryService = categoryService; + public CategoryService getCategoryService() + { + return categoryService; } - public TaggingService getTaggingService() - { - return taggingService; + public void setCategoryService(CategoryService categoryService) + { + this.categoryService = categoryService; } - public void setTaggingService(TaggingService taggingService) - { - this.taggingService = taggingService; + public TaggingService getTaggingService() + { + return taggingService; + } + + public void setTaggingService(TaggingService taggingService) + { + this.taggingService = taggingService; + } + + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; } /** diff --git a/src/main/java/org/alfresco/repo/transfer/RepoTransferReceiverImpl.java b/src/main/java/org/alfresco/repo/transfer/RepoTransferReceiverImpl.java index 56a72594e8..cdf6de7e8d 100644 --- a/src/main/java/org/alfresco/repo/transfer/RepoTransferReceiverImpl.java +++ b/src/main/java/org/alfresco/repo/transfer/RepoTransferReceiverImpl.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.transfer; @@ -78,7 +78,6 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.rule.RuleService; -import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.transfer.TransferException; import org.alfresco.service.cmr.transfer.TransferProgress; @@ -199,6 +198,7 @@ public class RepoTransferReceiverImpl implements TransferReceiver, private AlienProcessor alienProcessor; private JobLockService jobLockService; private TransferVersionChecker transferVersionChecker; + private NamespaceService namespaceService; // note: cache is tenant-aware (if using TransctionalCache impl) private SimpleCache singletonCache; // eg. for transfer temp folder nodeRef @@ -254,6 +254,7 @@ public class RepoTransferReceiverImpl implements TransferReceiver, PropertyCheck.mandatory(this, "alienProcessor", alienProcessor); PropertyCheck.mandatory(this, "jobLockService", getJobLockService()); PropertyCheck.mandatory(this, "transferVersionChecker", getTransferVersionChecker()); + PropertyCheck.mandatory(this, "namespaceService", namespaceService); beforeStartInboundTransferDelegate = policyComponent.registerClassPolicy(TransferServicePolicies.BeforeStartInboundTransferPolicy.class); onStartInboundTransferDelegate = policyComponent.registerClassPolicy(TransferServicePolicies.OnStartInboundTransferPolicy.class); @@ -361,26 +362,17 @@ public class RepoTransferReceiverImpl implements TransferReceiver, // If not then do so. if (transferTempFolder == null) { - ResultSet rs = null; - - try + List refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), + transferTempFolderPath, null, namespaceService, false); + if (refs.size() > 0) { - rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, - transferTempFolderPath); - if (rs.length() > 0) - { - transferTempFolder = rs.getNodeRef(0); + transferTempFolder = refs.get(0); singletonCache.put(KEY_TRANSFER_TEMP_NODEREF, transferTempFolder); - } - else - { - throw new TransferException(MSG_TRANSFER_TEMP_FOLDER_NOT_FOUND, new Object[] { transferId, - transferTempFolderPath }); - } } - finally + else { - if (rs != null) {rs.close();} + throw new TransferException(MSG_TRANSFER_TEMP_FOLDER_NOT_FOUND, new Object[] { transferId, + transferTempFolderPath }); } } @@ -516,27 +508,18 @@ public class RepoTransferReceiverImpl implements TransferReceiver, if (inboundTransferRecordsFolder == null) { log.debug("Trying to find transfer records folder: " + inboundTransferRecordsPath); - ResultSet rs = null; - - try + List refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), + inboundTransferRecordsPath, null, namespaceService, false); + if (refs.size() > 0) { - rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, - inboundTransferRecordsPath); - if (rs.length() > 0) - { - inboundTransferRecordsFolder = rs.getNodeRef(0); + inboundTransferRecordsFolder = refs.get(0); singletonCache.put(KEY_INBOUND_TRANSFER_RECORDS_NODEREF, inboundTransferRecordsFolder); - log.debug("Found inbound transfer records folder: " + inboundTransferRecordsFolder); - } - else - { - throw new TransferException(MSG_INBOUND_TRANSFER_FOLDER_NOT_FOUND, - new Object[] { inboundTransferRecordsPath }); - } + log.debug("Found inbound transfer records folder: " + inboundTransferRecordsFolder); } - finally + else { - if (rs != null) {rs.close();} + throw new TransferException(MSG_INBOUND_TRANSFER_FOLDER_NOT_FOUND, + new Object[] { inboundTransferRecordsPath }); } } @@ -1155,6 +1138,11 @@ public class RepoTransferReceiverImpl implements TransferReceiver, return this.ruleService; } + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + } + /** * Generate the requsite */ diff --git a/src/main/java/org/alfresco/repo/transfer/TransferSummaryReportImpl.java b/src/main/java/org/alfresco/repo/transfer/TransferSummaryReportImpl.java index bbff4b85a3..265ed81764 100644 --- a/src/main/java/org/alfresco/repo/transfer/TransferSummaryReportImpl.java +++ b/src/main/java/org/alfresco/repo/transfer/TransferSummaryReportImpl.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.transfer; import java.io.Serializable; @@ -69,6 +69,7 @@ public class TransferSummaryReportImpl implements TransferSummaryReport private FileFolderService fileFolderService; private NodeRef reportFile; private TransferDestinationReportWriter destinationWriter; + private NamespaceService namespaceService; // where the summary report will be stored private String transferSummaryReportLocation; @@ -243,28 +244,18 @@ public class TransferSummaryReportImpl implements TransferSummaryReport { NodeRef reportParentFolder = null; log.debug("Trying to find transfer summary report records folder: " + transferSummaryReportLocation); - ResultSet rs = null; - try + List refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), + transferSummaryReportLocation, null, namespaceService, false); + if (refs.size() > 0) { - rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, transferSummaryReportLocation); - if (rs.length() > 0) - { - reportParentFolder = rs.getNodeRef(0); + reportParentFolder = refs.get(0); - log.debug("Found transfer summary report records folder: " + reportParentFolder); - } - else - { - throw new TransferException(MSG_INBOUND_TRANSFER_FOLDER_NOT_FOUND, new Object[] { transferSummaryReportLocation }); - } + log.debug("Found transfer summary report records folder: " + reportParentFolder); } - finally + else { - if (rs != null) - { - rs.close(); - } + throw new TransferException(MSG_INBOUND_TRANSFER_FOLDER_NOT_FOUND, new Object[] { transferSummaryReportLocation }); } return reportParentFolder; } @@ -294,4 +285,8 @@ public class TransferSummaryReportImpl implements TransferSummaryReport this.searchService = searchService; } + public void setNamespaceService(NamespaceService namespaceService) + { + this.namespaceService = namespaceService; + } } diff --git a/src/main/resources/alfresco/bootstrap-context.xml b/src/main/resources/alfresco/bootstrap-context.xml index 4ef5367571..3fae856eb3 100644 --- a/src/main/resources/alfresco/bootstrap-context.xml +++ b/src/main/resources/alfresco/bootstrap-context.xml @@ -701,6 +701,7 @@ ${spaces.store} /${spaces.company_home.childname} /${spaces.company_home.childname}/${spaces.shared.childname} + /${spaces.company_home.childname}/${spaces.guest_home.childname} diff --git a/src/main/resources/alfresco/bootstrap/webscripts/blogsearch.get.html.400.ftl b/src/main/resources/alfresco/bootstrap/webscripts/blogsearch.get.html.400.ftl index 8ad403b295..b7c9fbdc94 100644 --- a/src/main/resources/alfresco/bootstrap/webscripts/blogsearch.get.html.400.ftl +++ b/src/main/resources/alfresco/bootstrap/webscripts/blogsearch.get.html.400.ftl @@ -1,5 +1,5 @@ - ${status.message} + ${status.message?html} \ No newline at end of file diff --git a/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.404.ftl b/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.404.ftl index 8ad403b295..b7c9fbdc94 100644 --- a/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.404.ftl +++ b/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.404.ftl @@ -1,5 +1,5 @@ - ${status.message} + ${status.message?html} \ No newline at end of file diff --git a/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.ftl b/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.ftl index a6bc79561d..ff38816fc5 100644 --- a/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.ftl +++ b/src/main/resources/alfresco/bootstrap/webscripts/categorysearch.get.html.ftl @@ -1,7 +1,7 @@ Alfresco - Category search: ${url.extension} + Category search: ${url.extension?html}
<#list resultset as node> diff --git a/src/main/resources/alfresco/core-services-context.xml b/src/main/resources/alfresco/core-services-context.xml index 0b4b07f01e..054362d0f3 100644 --- a/src/main/resources/alfresco/core-services-context.xml +++ b/src/main/resources/alfresco/core-services-context.xml @@ -1106,23 +1106,6 @@ - - - - false - - - Search - - - buildonly - - - - hidden - - - diff --git a/src/main/resources/alfresco/rendition-services-context.xml b/src/main/resources/alfresco/rendition-services-context.xml index df4f880012..1d82c15a41 100644 --- a/src/main/resources/alfresco/rendition-services-context.xml +++ b/src/main/resources/alfresco/rendition-services-context.xml @@ -132,14 +132,15 @@ + + + + + + - - - - - - + @@ -188,21 +189,21 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/bootstrap-context.xml b/src/main/resources/alfresco/subsystems/Search/buildonly/bootstrap-context.xml deleted file mode 100644 index bb9ff54a7a..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/bootstrap-context.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - ${system.bootstrap.config_check.strict} - - - ${dir.root} - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/common-search-scheduler-context.xml b/src/main/resources/alfresco/subsystems/Search/buildonly/common-search-scheduler-context.xml deleted file mode 100644 index f97bfe0e1b..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/common-search-scheduler-context.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - classpath:alfresco/domain/quartz.properties - classpath*:alfresco/enterprise/*-quartz.properties - classpath*:alfresco/extension/*-quartz.properties - - - - - - - - - - - - - - - - true - - - org.alfresco.repo.scheduler.AlfrescoSchedulerFactory - - - - - - - - - SearchScheduler - - - - false - - - diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/common-search.properties b/src/main/resources/alfresco/subsystems/Search/buildonly/common-search.properties deleted file mode 100644 index 2cd4fdfd14..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/common-search.properties +++ /dev/null @@ -1,11 +0,0 @@ -search.solrTrackingSupport.enabled=true -search.solrTrackingSupport.ignorePathsForSpecificTypes=false -search.solrTrackingSupport.ignorePathsForSpecificAspects=false - -solr.query.fts.queryConsistency=TRANSACTIONAL_IF_POSSIBLE -solr.query.cmis.queryConsistency=TRANSACTIONAL_IF_POSSIBLE -solr.query.hybrid.enabled=false - -search.solrShardRegistry.purgeOnInit=true -search.solrShardRegistry.shardInstanceTimeoutInSeconds=300 -search.solrShardRegistry.maxAllowedReplicaTxCountDifference=1000 \ No newline at end of file diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery-context.xml b/src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery-context.xml deleted file mode 100644 index 81564db88b..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery-context.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - - indexTrackerThread - - - ${index.recovery.maximumPoolSize} - - - ${index.recovery.maximumPoolSize} - - - 100 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - deleted - - - - - ${version.store.version2Store} - ${version.store.deprecated.lightWeightVersionStore} - - - - - - - - ${index.recovery.mode} - - - ${index.recovery.stopOnError} - - - ${index.tracking.maxTransactionsPerLuceneCommit} - - - - - - - - - - - - - - ${index.tracking.maxTxnDurationMinutes} - - - ${index.tracking.reindexLagMs} - - - ${index.tracking.maxRecordSetSize} - - - ${index.tracking.maxTransactionsPerLuceneCommit} - - - ${index.tracking.disableInTransactionIndexing} - - - - - - org.alfresco.repo.node.index.NoOpIndexRecoveryJob - - - - - - - - - - - - - - - - - - - ${index.tracking.adm.cronExpression} - - - ${system.cronJob.startDelayMinutes} - - - - - - - - - - - - org.alfresco.repo.node.index.NoOpIndexRecoveryJob - - - - - - - - - - - - - - - - - - - ${index.reindexMissingContent.cronExpression} - - - ${system.cronJob.startDelayMinutes} - - - - - - diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery.properties b/src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery.properties deleted file mode 100644 index e95bd83a93..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/index-recovery.properties +++ /dev/null @@ -1,10 +0,0 @@ -index.recovery.maximumPoolSize=5 -index.recovery.mode=VALIDATE -index.recovery.stopOnError=false -index.tracking.maxTransactionsPerLuceneCommit=100 -index.tracking.maxTxnDurationMinutes=10 -index.tracking.reindexLagMs=1000 -index.tracking.maxRecordSetSize=1000 -index.tracking.disableInTransactionIndexing=false -index.tracking.adm.cronExpression=0/5 * * * * ? -index.reindexMissingContent.cronExpression=* * * * * ? 2099 \ No newline at end of file diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search-context.xml b/src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search-context.xml deleted file mode 100644 index bc9fd1629d..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search-context.xml +++ /dev/null @@ -1,414 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.alfresco.repo.search.impl.lucene.LuceneIndexerAndSearcher - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.alfresco.service.cmr.search.CategoryService - - - - - - - - - - - - - - - - - - - indexThread - - - 10 - - - 20 - - - 5 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${dir.indexes} - - - ${dir.indexes.lock} - - - ${lucene.maxAtomicTransformationTime} - - - ${lucene.query.maxClauses} - - - ${lucene.indexer.batchSize} - - - - ${lucene.indexer.cacheEnabled} - - - ${lucene.indexer.maxDocIdCacheSize} - - - ${lucene.indexer.maxDocumentCacheSize} - - - ${lucene.indexer.maxIsCategoryCacheSize} - - - ${lucene.indexer.maxLinkAspectCacheSize} - - - ${lucene.indexer.maxParentCacheSize} - - - ${lucene.indexer.maxPathCacheSize} - - - ${lucene.indexer.maxTypeCacheSize} - - - - ${lucene.indexer.mergerMaxMergeDocs} - - - ${lucene.indexer.mergerMergeFactor} - - - ${lucene.indexer.mergerMaxBufferedDocs} - - - ${lucene.indexer.mergerRamBufferSizeMb} - - - - ${lucene.indexer.writerMaxMergeDocs} - - - ${lucene.indexer.writerMergeFactor} - - - ${lucene.indexer.writerMaxBufferedDocs} - - - ${lucene.indexer.writerRamBufferSizeMb} - - - - ${lucene.indexer.mergerTargetIndexCount} - - - ${lucene.indexer.mergerTargetOverlayCount} - - - ${lucene.indexer.mergerTargetOverlaysBlockingFactor} - - - ${lucene.indexer.maxDocsForInMemoryMerge} - - - ${lucene.indexer.maxRamInMbForInMemoryMerge} - - - ${lucene.indexer.maxDocsForInMemoryIndex} - - - ${lucene.indexer.maxRamInMbForInMemoryIndex} - - - - ${lucene.indexer.termIndexInterval} - - - ${lucene.indexer.useNioMemoryMapping} - - - ${lucene.indexer.postSortDateTime} - - - ${lucene.indexer.defaultMLIndexAnalysisMode} - - - ${lucene.indexer.defaultMLSearchAnalysisMode} - - - ${lucene.indexer.maxFieldLength} - - - ${lucene.indexer.fairLocking} - - - ${lucene.write.lock.timeout} - - - ${lucene.commit.lock.timeout} - - - ${lucene.lock.poll.interval} - - - ${lucene.indexer.contentIndexingEnabled} - - - ${lucene.indexer.useInMemorySort} - - - ${lucene.indexer.maxRawResultSetSizeForInMemorySort} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${lucene.indexer.useInMemorySort} - - - ${lucene.indexer.maxRawResultSetSizeForInMemorySort} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${category.queryFetchSize} - - - - - - - - - - - - - - ${fts.indexer.batchSize} - - - - - - - - - - - - - - - - - - ${dir.indexes.backup} - - - true - - - - - - ${index.recovery.mode} - - - - - - - - - - - - - diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search.properties b/src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search.properties deleted file mode 100644 index 923e078547..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/lucene-search.properties +++ /dev/null @@ -1,57 +0,0 @@ -dir.indexes=${dir.root}/lucene-indexes -dir.indexes.lock=${dir.indexes}/locks - -lucene.maxAtomicTransformationTime=20 -lucene.query.maxClauses=10000 -lucene.indexer.batchSize=1000000 - -lucene.indexer.cacheEnabled=true -lucene.indexer.maxDocIdCacheSize=10000 -lucene.indexer.maxDocumentCacheSize=100 -lucene.indexer.maxIsCategoryCacheSize=-1 -lucene.indexer.maxLinkAspectCacheSize=10000 -lucene.indexer.maxParentCacheSize=10000 -lucene.indexer.maxPathCacheSize=10000 -lucene.indexer.maxTypeCacheSize=10000 - -lucene.indexer.mergerMaxMergeDocs=1000000 -lucene.indexer.mergerMergeFactor=5 -lucene.indexer.mergerMaxBufferedDocs=-1 -lucene.indexer.mergerRamBufferSizeMb=16 - -lucene.indexer.writerMaxMergeDocs=1000000 -lucene.indexer.writerMergeFactor=5 -lucene.indexer.writerMaxBufferedDocs=-1 -lucene.indexer.writerRamBufferSizeMb=16 - -lucene.indexer.mergerTargetIndexCount=5 -lucene.indexer.mergerTargetOverlayCount=5 -lucene.indexer.mergerTargetOverlaysBlockingFactor=2 -lucene.indexer.maxDocsForInMemoryMerge=10000 -lucene.indexer.maxRamInMbForInMemoryMerge=16 -lucene.indexer.maxDocsForInMemoryIndex=10000 -lucene.indexer.maxRamInMbForInMemoryIndex=16 - -lucene.indexer.termIndexInterval=128 -lucene.indexer.useNioMemoryMapping=true - -lucene.indexer.postSortDateTime=true -lucene.indexer.defaultMLIndexAnalysisMode=EXACT_LANGUAGE_AND_ALL -lucene.indexer.defaultMLSearchAnalysisMode=EXACT_LANGUAGE_AND_ALL - -lucene.indexer.maxFieldLength=10000 - -lucene.indexer.fairLocking=true - -lucene.write.lock.timeout=10000 -lucene.commit.lock.timeout=100000 -lucene.lock.poll.interval=100 - -lucene.indexer.useInMemorySort=true -lucene.indexer.maxRawResultSetSizeForInMemorySort=1000 - -lucene.indexer.contentIndexingEnabled=true - -fts.indexer.batchSize=1000 - -dir.indexes.backup=${dir.root}/backup-lucene-indexes \ No newline at end of file diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/opencmis-context.xml b/src/main/resources/alfresco/subsystems/Search/buildonly/opencmis-context.xml deleted file mode 100644 index 91c3cb6102..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/opencmis-context.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.alfresco.repo.search.impl.querymodel.QueryEngine - - - - - - - - - - - - - - - - - - org.alfresco.repo.search.impl.querymodel.QueryEngine.executeQuery=ACL_ALLOW,AFTER_ACL_NODE.sys:base.Read - org.alfresco.repo.search.impl.querymodel.QueryEngine.getQueryModelFactory=ACL_ALLOW - - - - \ No newline at end of file diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs-context.xml b/src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs-context.xml deleted file mode 100644 index 7c54e616e9..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs-context.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - org.alfresco.repo.search.impl.lucene.fts.FTSIndexerJob - - - - - - - - - - - - - - - 1 - - - 1 - - - - - - - - - org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory$LuceneIndexBackupJob - - - - - - - - - - - - - - - - - - - - ${index.backup.cronExpression} - - - ${system.cronJob.startDelayMinutes} - - - - - diff --git a/src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs.properties b/src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs.properties deleted file mode 100644 index 341cf60ceb..0000000000 --- a/src/main/resources/alfresco/subsystems/Search/buildonly/scheduled-jobs.properties +++ /dev/null @@ -1 +0,0 @@ -index.backup.cronExpression=0 0 3 * * ? \ No newline at end of file diff --git a/src/main/resources/alfresco/transfer-service-context.xml b/src/main/resources/alfresco/transfer-service-context.xml index ef9b57de84..85191901c6 100644 --- a/src/main/resources/alfresco/transfer-service-context.xml +++ b/src/main/resources/alfresco/transfer-service-context.xml @@ -127,6 +127,7 @@ + - - - ${spaces.transfer_summary_report.location} - - - - - + + + ${spaces.transfer_summary_report.location} + + + + + + tags = Arrays.asList(new String[]{"hello", "goodbye"}); @@ -823,7 +826,8 @@ public class BlogServiceImplTest /** * Test that correct paging info is returned when searching for tagged blog posts. */ - @Test + @Test + @Category(RedundantTests.class) public void testGetBlogPostsByTagPaging() throws Exception{ final String tagToSearchBy = "testtag"; final int numberOfBlogPostsTagged = 2; diff --git a/src/test/java/org/alfresco/repo/calendar/CalendarServiceImplTest.java b/src/test/java/org/alfresco/repo/calendar/CalendarServiceImplTest.java index ed8adac56f..fd7cec3597 100644 --- a/src/test/java/org/alfresco/repo/calendar/CalendarServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/calendar/CalendarServiceImplTest.java @@ -30,12 +30,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.TimeZone; +import java.util.*; import org.alfresco.model.ContentModel; import org.alfresco.query.CannedQueryFactory; @@ -74,6 +71,10 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; import org.springframework.context.ApplicationContext; /** @@ -83,6 +84,7 @@ import org.springframework.context.ApplicationContext; * @since 4.0 */ @Category(LuceneTests.class) +@RunWith(MockitoJUnitRunner.class) public class CalendarServiceImplTest { private static final String TEST_SITE_PREFIX = "CalendarSiteTest"; @@ -102,6 +104,7 @@ public class CalendarServiceImplTest private static RetryingTransactionHelper TRANSACTION_HELPER; private static PermissionService PERMISSION_SERVICE; private static SiteService SITE_SERVICE; + @Mock private static TaggingService TAGGING_SERVICE; private static GetCalendarEntriesCannedQueryFactory CALENDAR_CQ_FACTORY; @@ -132,8 +135,6 @@ public class CalendarServiceImplTest TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper"); PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService"); SITE_SERVICE = (SiteService)testContext.getBean("SiteService"); - TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService"); - // Get the canned query registry, and from that the factory @SuppressWarnings("unchecked") NamedObjectRegistry> calendarCannedQueryRegistry = @@ -149,7 +150,15 @@ public class CalendarServiceImplTest AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER); createTestSites(); } - + + @Before + public void before() + { + // Inject a mock to a real calendar service instead of tagging service + ((CalendarServiceImpl) testContext.getBean("calendarService")).setTaggingService(TAGGING_SERVICE); + when(TAGGING_SERVICE.isTagScope(Matchers.any(NodeRef.class))).thenReturn(true); + } + @Test public void createNewEntry() throws Exception { CalendarEntry entry; @@ -384,7 +393,8 @@ public class CalendarServiceImplTest CALENDAR_SERVICE.updateCalendarEntry(entry); // Check - entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); + when(TAGGING_SERVICE.getTags(entry.getNodeRef())).thenReturn(Arrays.asList(TAG_1, TAG_2)); + entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); assertEquals(2, entry.getTags().size()); assertEquals(true, entry.getTags().contains(TAG_1)); assertEquals(true, entry.getTags().contains(TAG_2)); @@ -404,6 +414,7 @@ public class CalendarServiceImplTest assertEquals(true, entry.getTags().contains(TAG_3)); // Now load and re-check + when(TAGGING_SERVICE.getTags(entry.getNodeRef())).thenReturn(Arrays.asList(TAG_1, TAG_3)); entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); assertEquals(2, entry.getTags().size()); // Duplicate now gone assertEquals(true, entry.getTags().contains(TAG_1)); @@ -416,6 +427,7 @@ public class CalendarServiceImplTest CALENDAR_SERVICE.updateCalendarEntry(entry); // Check + when(TAGGING_SERVICE.getTags(entry.getNodeRef())).thenReturn(Collections.EMPTY_LIST); entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); assertEquals(0, entry.getTags().size()); @@ -427,6 +439,7 @@ public class CalendarServiceImplTest CALENDAR_SERVICE.updateCalendarEntry(entry); // Check + when(TAGGING_SERVICE.getTags(entry.getNodeRef())).thenReturn(Arrays.asList(TAG_1, TAG_2, TAG_3)); entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); assertEquals(3, entry.getTags().size()); assertEquals(true, entry.getTags().contains(TAG_1)); @@ -447,6 +460,7 @@ public class CalendarServiceImplTest testNodesToTidy.add(entry.getNodeRef()); // Check + when(TAGGING_SERVICE.getTags(entry.getNodeRef())).thenReturn(Arrays.asList(TAG_1, TAG_2)); entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); assertEquals(2, entry.getTags().size()); assertEquals(true, entry.getTags().contains(TAG_1)); @@ -460,7 +474,8 @@ public class CalendarServiceImplTest entry.getTags().add(TAG_1); CALENDAR_SERVICE.updateCalendarEntry(entry); - // Check + // Check + when(TAGGING_SERVICE.getTags(entry.getNodeRef())).thenReturn(Arrays.asList(TAG_1, TAG_3)); entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName()); assertEquals(2, entry.getTags().size()); assertEquals(true, entry.getTags().contains(TAG_1)); diff --git a/src/test/java/org/alfresco/repo/discussion/DiscussionServiceImplTest.java b/src/test/java/org/alfresco/repo/discussion/DiscussionServiceImplTest.java index bda3fec406..5b3cdcd9d5 100644 --- a/src/test/java/org/alfresco/repo/discussion/DiscussionServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/discussion/DiscussionServiceImplTest.java @@ -30,8 +30,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -65,12 +67,17 @@ import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.Pair; import org.alfresco.util.PropertyMap; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; import org.springframework.context.ApplicationContext; /** @@ -80,6 +87,7 @@ import org.springframework.context.ApplicationContext; * @since 4.0 */ @Category(LuceneTests.class) +@RunWith(MockitoJUnitRunner.class) public class DiscussionServiceImplTest { private static final String TEST_SITE_PREFIX = "DiscussionsSiteTest"; @@ -97,13 +105,14 @@ public class DiscussionServiceImplTest private static RetryingTransactionHelper TRANSACTION_HELPER; private static PermissionService PERMISSION_SERVICE; private static SiteService SITE_SERVICE; + @Mock private static TaggingService TAGGING_SERVICE; private static TenantAdminService TENANT_ADMIN_SERVICE; private static final String TENANT_DOMAIN = (DiscussionServiceImplTest.class.getSimpleName() + "Tenant").toLowerCase(); private static final String TEST_USER = DiscussionServiceImplTest.class.getSimpleName() + "_testuser@" + TENANT_DOMAIN; - private static final String ADMIN_USER = AuthenticationUtil.getAdminUserName() + "@" + TENANT_DOMAIN; + private static String ADMIN_USER; private static SiteInfo DISCUSSION_SITE; private static SiteInfo ALTERNATE_DISCUSSION_SITE; @@ -130,9 +139,10 @@ public class DiscussionServiceImplTest TRANSACTION_HELPER = (RetryingTransactionHelper)testContext.getBean("retryingTransactionHelper"); PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService"); SITE_SERVICE = (SiteService)testContext.getBean("SiteService"); - TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService"); TENANT_ADMIN_SERVICE = testContext.getBean("tenantAdminService", TenantAdminService.class); + ADMIN_USER = AuthenticationUtil.getAdminUserName() + "@" + TENANT_DOMAIN; + createTenant(); // Do the setup as admin @@ -145,7 +155,15 @@ public class DiscussionServiceImplTest TenantContextHolder.setTenantDomain(TENANT_DOMAIN); createTestSites(); } - + + @Before + public void before() + { + // Inject a mock to a real service instead of tagging service + ((DiscussionServiceImpl) testContext.getBean("discussionService")).setTaggingService(TAGGING_SERVICE); + when(TAGGING_SERVICE.isTagScope(Matchers.any(NodeRef.class))).thenReturn(true); + } + @Test public void createNewTopic() throws Exception { TopicInfo siteTopic; @@ -711,83 +729,83 @@ public class DiscussionServiceImplTest DISCUSSION_SERVICE.updateTopic(nodeT2); DISCUSSION_SERVICE.updateTopic(nodeT3); - - // Find without tags - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, null, true, new PagingRequest(10)); - assertEquals(2, topics.getPage().size()); - assertEquals("ST1", topics.getPage().get(0).getTitle()); - assertEquals("ST2", topics.getPage().get(1).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, null, true, new PagingRequest(10)); - assertEquals(3, topics.getPage().size()); - assertEquals("NT1", topics.getPage().get(0).getTitle()); - assertEquals("NT2", topics.getPage().get(1).getTitle()); - assertEquals("NT3", topics.getPage().get(2).getTitle()); - - - // Find with tags - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_1, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("ST2", topics.getPage().get(0).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_1, true, new PagingRequest(10)); - assertEquals(2, topics.getPage().size()); - assertEquals("NT2", topics.getPage().get(0).getTitle()); - assertEquals("NT3", topics.getPage().get(1).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_2, true, new PagingRequest(10)); - assertEquals(0, topics.getPage().size()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_2, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("NT2", topics.getPage().get(0).getTitle()); - - - // Find by user but not by tag - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, null, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("ST1", topics.getPage().get(0).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, true, new PagingRequest(10)); - assertEquals(2, topics.getPage().size()); - assertEquals("NT2", topics.getPage().get(0).getTitle()); - assertEquals("NT3", topics.getPage().get(1).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, null, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("ST2", topics.getPage().get(0).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, null, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("NT1", topics.getPage().get(0).getTitle()); - - - // Find by user and tag together - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, TAG_1, true, new PagingRequest(10)); - assertEquals(0, topics.getPage().size()); - - topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, TAG_1, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("ST2", topics.getPage().get(0).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, TAG_2, true, new PagingRequest(10)); - assertEquals(1, topics.getPage().size()); - assertEquals("NT2", topics.getPage().get(0).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, TAG_2, true, new PagingRequest(10)); - assertEquals(0, topics.getPage().size()); - - - // Do a find to check the ordering alters as requested - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, true, new PagingRequest(10)); - assertEquals(2, topics.getPage().size()); - assertEquals("NT2", topics.getPage().get(0).getTitle()); - assertEquals("NT3", topics.getPage().get(1).getTitle()); - - topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, false, new PagingRequest(10)); - assertEquals(2, topics.getPage().size()); - assertEquals("NT3", topics.getPage().get(0).getTitle()); - assertEquals("NT2", topics.getPage().get(1).getTitle()); +// @Category(RedundantTests.class) +// // Find without tags +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, null, true, new PagingRequest(10)); +// assertEquals(2, topics.getPage().size()); +// assertEquals("ST1", topics.getPage().get(0).getTitle()); +// assertEquals("ST2", topics.getPage().get(1).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, null, true, new PagingRequest(10)); +// assertEquals(3, topics.getPage().size()); +// assertEquals("NT1", topics.getPage().get(0).getTitle()); +// assertEquals("NT2", topics.getPage().get(1).getTitle()); +// assertEquals("NT3", topics.getPage().get(2).getTitle()); +// +// +// // Find with tags +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_1, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("ST2", topics.getPage().get(0).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_1, true, new PagingRequest(10)); +// assertEquals(2, topics.getPage().size()); +// assertEquals("NT2", topics.getPage().get(0).getTitle()); +// assertEquals("NT3", topics.getPage().get(1).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_2, true, new PagingRequest(10)); +// assertEquals(0, topics.getPage().size()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_2, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("NT2", topics.getPage().get(0).getTitle()); +// +// +// // Find by user but not by tag +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, null, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("ST1", topics.getPage().get(0).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, true, new PagingRequest(10)); +// assertEquals(2, topics.getPage().size()); +// assertEquals("NT2", topics.getPage().get(0).getTitle()); +// assertEquals("NT3", topics.getPage().get(1).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, null, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("ST2", topics.getPage().get(0).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, null, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("NT1", topics.getPage().get(0).getTitle()); +// +// +// // Find by user and tag together +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, TAG_1, true, new PagingRequest(10)); +// assertEquals(0, topics.getPage().size()); +// +// topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, TAG_1, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("ST2", topics.getPage().get(0).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, TAG_2, true, new PagingRequest(10)); +// assertEquals(1, topics.getPage().size()); +// assertEquals("NT2", topics.getPage().get(0).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, TAG_2, true, new PagingRequest(10)); +// assertEquals(0, topics.getPage().size()); +// +// +// // Do a find to check the ordering alters as requested +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, true, new PagingRequest(10)); +// assertEquals(2, topics.getPage().size()); +// assertEquals("NT2", topics.getPage().get(0).getTitle()); +// assertEquals("NT3", topics.getPage().get(1).getTitle()); +// +// topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, false, new PagingRequest(10)); +// assertEquals(2, topics.getPage().size()); +// assertEquals("NT3", topics.getPage().get(0).getTitle()); +// assertEquals("NT2", topics.getPage().get(1).getTitle()); // Alter the creation date on a couple, see the ordering change @@ -1173,9 +1191,11 @@ public class DiscussionServiceImplTest testNodesToTidy.add(topic.getNodeRef()); // Check + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(10)); assertEquals(0, topic.getTags().size()); - topic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), topic.getSystemName()); + topic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), topic.getSystemName()); + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(10)); assertEquals(0, topic.getTags().size()); @@ -1187,6 +1207,7 @@ public class DiscussionServiceImplTest DISCUSSION_SERVICE.updateTopic(topic); // Check + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_2))); topic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), topic.getSystemName()); assertEquals(2, topic.getTags().size()); assertEquals(true, topic.getTags().contains(TAG_1)); @@ -1201,12 +1222,14 @@ public class DiscussionServiceImplTest DISCUSSION_SERVICE.updateTopic(topic); // Check it as-is + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_3))); assertEquals(3, topic.getTags().size()); // Includes duplicate tag until re-loaded assertEquals(true, topic.getTags().contains(TAG_1)); assertEquals(false, topic.getTags().contains(TAG_2)); assertEquals(true, topic.getTags().contains(TAG_3)); // Now load and re-check + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_3))); topic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), topic.getSystemName()); assertEquals(2, topic.getTags().size()); // Duplicate now gone assertEquals(true, topic.getTags().contains(TAG_1)); @@ -1219,6 +1242,8 @@ public class DiscussionServiceImplTest DISCUSSION_SERVICE.updateTopic(topic); // Check + + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(10)); topic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), topic.getSystemName()); assertEquals(0, topic.getTags().size()); @@ -1230,6 +1255,7 @@ public class DiscussionServiceImplTest DISCUSSION_SERVICE.updateTopic(topic); // Check + when(TAGGING_SERVICE.getTags(topic.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_2, TAG_3))); topic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), topic.getSystemName()); assertEquals(3, topic.getTags().size()); assertEquals(true, topic.getTags().contains(TAG_1)); @@ -1903,10 +1929,10 @@ public class DiscussionServiceImplTest { performDeletionOfNodes(CLASS_TEST_NODES_TO_TIDY); deleteUser(TEST_USER); - deleteTenant(); - - TenantContextHolder.setTenantDomain(""); - AuthenticationUtil.setMtEnabled(false); + deleteTenant(); + + TenantContextHolder.setTenantDomain(""); + AuthenticationUtil.setMtEnabled(false); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); } diff --git a/src/test/java/org/alfresco/repo/exporter/ExporterComponentTest.java b/src/test/java/org/alfresco/repo/exporter/ExporterComponentTest.java index c5e6c1a162..a4278b3945 100644 --- a/src/test/java/org/alfresco/repo/exporter/ExporterComponentTest.java +++ b/src/test/java/org/alfresco/repo/exporter/ExporterComponentTest.java @@ -76,6 +76,7 @@ import org.alfresco.util.GUID; import org.alfresco.util.TempFileProvider; import org.alfresco.util.debug.NodeStoreInspector; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; import org.springframework.extensions.surf.util.I18NUtil; @@ -175,6 +176,7 @@ public class ExporterComponentTest extends BaseSpringTest * assigned to it as for the exported content -- provided the source and destination stores are the same. */ @SuppressWarnings("unchecked") + @Category(RedundantTests.class) public void testRoundTripKeepsCategoriesWhenWithinSameStore() throws Exception { // Use a store ref that has the bootstrapped categories @@ -204,6 +206,7 @@ public class ExporterComponentTest extends BaseSpringTest * on the exported content. */ @SuppressWarnings("unchecked") + @Category(RedundantTests.class) public void testRoundTripLosesCategoriesImportingToDifferentStore() throws Exception { // Use a store ref that has the bootstrapped categories diff --git a/src/test/java/org/alfresco/repo/imap/ImapMessageTest.java b/src/test/java/org/alfresco/repo/imap/ImapMessageTest.java index c9a05ee9a6..15d3e9c563 100644 --- a/src/test/java/org/alfresco/repo/imap/ImapMessageTest.java +++ b/src/test/java/org/alfresco/repo/imap/ImapMessageTest.java @@ -81,6 +81,7 @@ import org.alfresco.util.GUID; import org.alfresco.util.PropertyMap; import org.alfresco.util.config.RepositoryFolderConfigBean; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.experimental.categories.Category; @@ -486,7 +487,8 @@ public class ImapMessageTest extends TestCase assertNotNull(imapMessageCc); assertEquals(decodedAddress, imapMessageCc); } - + + @Category(RedundantTests.class) public void testEightBitMessage() throws Exception { diff --git a/src/test/java/org/alfresco/repo/jscript/PeopleTest.java b/src/test/java/org/alfresco/repo/jscript/PeopleTest.java index e91246069e..b7f586d73b 100644 --- a/src/test/java/org/alfresco/repo/jscript/PeopleTest.java +++ b/src/test/java/org/alfresco/repo/jscript/PeopleTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Repository * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2017 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -25,18 +25,14 @@ */ package org.alfresco.repo.jscript; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.transaction.UserTransaction; - import junit.framework.TestCase; - import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.SearchParameters; +import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService.PersonInfo; import org.alfresco.service.transaction.TransactionService; @@ -44,37 +40,59 @@ import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.PropertyMap; import org.alfresco.util.ScriptPagingDetails; -import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.springframework.context.ApplicationContext; +import javax.transaction.HeuristicMixedException; +import javax.transaction.HeuristicRollbackException; +import javax.transaction.NotSupportedException; +import javax.transaction.RollbackException; +import javax.transaction.SystemException; +import javax.transaction.UserTransaction; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + /** * Unit tests for {@link org.alfresco.repo.jscript.People} - *

- * Note that this class currently works with Lucene only. In other words, it - * won't work with Solr. - * + * * @author Jamal Kaabi-Mofrad * @since 4.2 */ -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) +@Category({OwnJVMTestsCategory.class}) public class PeopleTest extends TestCase { private static final String SIMPLE_FILTER = "a"; private static final String CQ_SIMPLE_FILTER = SIMPLE_FILTER + " [hint:useCQ]"; - private static final String DEFAULT_SORT_BY_FIELD = "username"; + private static final String DEFAULT_SORT_BY_FIELD = "PeopleTestUsername"; - - private static final UserInfo USER_1 = new UserInfo("user1", "john junior", "lewis second"); - private static final UserInfo USER_2 = new UserInfo("user2", "john senior", "lewis second"); - private static final UserInfo USER_3 = new UserInfo("user3", "john junior", "lewis third"); - private static final UserInfo USER_4 = new UserInfo("user4", "john", "lewis third"); - private static final UserInfo USER_5 = new UserInfo("user5", "mike", "doe first"); - private static final UserInfo USER_6 = new UserInfo("user6", "sam", "doe first"); - private static final UserInfo USER_7 = new UserInfo("user7", "sara jones", "doe"); - private static final UserInfo USER_8 = new UserInfo("user8", "sara", "doe"); + // These tests users are only created once, even if the test is rerun. + private static final List userNodeRefs = new ArrayList<>(); + private static final UserInfo[] userInfos = + { + new UserInfo("PeopleTestUser0", "john junior", "lewis second"), + new UserInfo("PeopleTestUser1", "john senior", "lewis second"), + new UserInfo("PeopleTestUser2", "john junior", "lewis third"), + new UserInfo("PeopleTestUser3", "john", "lewis third"), + new UserInfo("PeopleTestUser4", "mike", "doe first"), + new UserInfo("PeopleTestUser5", "sam", "doe first"), + new UserInfo("PeopleTestUser6", "sara jones", "doe"), + new UserInfo("PeopleTestUser7", "sara", "doe"), + }; private ApplicationContext ctx; @@ -84,24 +102,38 @@ public class PeopleTest extends TestCase private People people; private PersonService personService; + @Mock + private SearchService mockSearchService; + @Mock + private ResultSet mockResultSet; + private List mockResultSetNodeRefs = new ArrayList<>(); + private int callCount = 0; + /* * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + ctx = ApplicationContextHelper.getApplicationContext(); people = (People) ctx.getBean("peopleScript"); serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry"); transactionService = serviceRegistry.getTransactionService(); personService = serviceRegistry.getPersonService(); + ServiceRegistry mockServiceRegistry = spy(serviceRegistry); + people.setServiceRegistry(mockServiceRegistry); + doReturn(mockSearchService).when(mockServiceRegistry).getSearchService(); + when(mockSearchService.query(any())).thenReturn(mockResultSet); + when(mockResultSet.getNodeRefs()).thenReturn(mockResultSetNodeRefs); + AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); + createUsers(); + // Start a transaction txn = transactionService.getUserTransaction(); txn.begin(); - - // Create users - createUser(USER_1, USER_2, USER_3, USER_4, USER_5, USER_6, USER_7, USER_8); } @Override @@ -115,78 +147,125 @@ public class PeopleTest extends TestCase { e.printStackTrace(); } + AuthenticationUtil.clearCurrentSecurityContext(); + + people.setServiceRegistry(serviceRegistry); } public void testGetPeople() { + // 1 Get people with multi-part firstNames. Users 0 & 2 both have 'john junior' as their firstName, but the query shouldn't select user 3 + assertPeopleImpl( + "john junior", + "There are two users who have \"john junior\" as their first name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*john*\" \"*junior*\" OR lastName:\"*john*\" \"*junior*\")", + 0, 2); + + // 2 Get user with multi-part firstNames and lastNames + assertPeopleImpl( + "john junior lewis sec*", + "There is one user with the name: \"john junior lewis second\".", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*john*\" \"*junior*\"\"*lewis*\"\"*sec*\" OR lastName:\"*john*\" \"*junior*\"\"*lewis*\"\"*sec*\")", + 0); + + // 3 Only USER_2's first name is "john senior" + assertPeopleImpl( + "john senior", + "There is one user who has \"john senior\" as his first name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*john*\" \"*senior*\" OR lastName:\"*john*\" \"*senior*\")", + 1); + + // 4* + assertPeopleImpl( + "john*", + "There are four users with \"john\" as their first name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (\"*john**\")", + 0, 1, 2, 3); + + // 5 Get people with multi-part lastNames. Users 2 & 3 both have 'lewis third' as their lastName + assertPeopleImpl( + "lewis third", + "There are two users who have \"lewis third\" as their last name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*lewis*\" \"*third*\" OR lastName:\"*lewis*\" \"*third*\")", + 2, 3); + + // 6 Only user 4 & 5 have last name "doe first". The query shouldn't select user 6 + assertPeopleImpl( + "doe fi*", + "There are two users who have \"doe first\" as their last name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*doe*\" \"*fi*\" OR lastName:\"*doe*\" \"*fi*\")", + 4, 5); + + // 7* + assertPeopleImpl( + "lewi*", + "There are four users with \"lewis\" as their last name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (\"*lewi**\")", + 0, 1, 2, 3); + + // 8* + assertPeopleImpl( + "thir*", + "There are two users with \"lewis third\" as their last name.", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (\"*thir**\")", + 2, 3); + + // 9 Get people with single firstName and multi-part lastNames + assertPeopleImpl( + "sam doe first", + "There is one user with the name: \"sam doe first\".", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*sam*\" \"*doe*\"\"*first*\" OR lastName:\"*sam*\" \"*doe*\"\"*first*\")", + 5); + + // 10 Get people with multi-part firstNames and single lastName + assertPeopleImpl( + "sara jones doe", + "There is one user with the name: \"sara jones doe\".", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*sara*\" \"*jones*\"\"*doe*\" OR lastName:\"*sara*\" \"*jones*\"\"*doe*\")", + 6); + + // 11 Get people with single firstName and single lastName + assertPeopleImpl( + "sara doe", + "There are two users with the name: \"sara doe\".", + "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\" AND (firstName:\"*sara*\" \"*doe*\" OR lastName:\"*sara*\" \"*doe*\")", + 6, 7); + } + + private void assertPeopleImpl(String filter, String sizeMessage, String expectedQuery, int... userIds) + { + String expectedSort = "[]"; + int expectedMaxItems = -1; + int expectedSkipCount = 0; + + mockResultSetNodeRefs.clear(); + for (int i: userIds) + { + NodeRef nodeRef = userNodeRefs.get(i); + mockResultSetNodeRefs.add(nodeRef); + } + + ArgumentCaptor searchParametersCaptor = ArgumentCaptor.forClass(SearchParameters.class); ScriptPagingDetails paging = new ScriptPagingDetails(0, 0); - // Get people with multi-part firstNames - // USER_1 and USER_3 both have 'john junior' as their firstName - // The query shouldn't select USER_4 - List persons = people.getPeopleImpl("john junior", paging, null, null); - assertEquals("There are two users who have \"john junior\" as their first name.", 2, - persons.size()); - assertEquals(USER_1.getFirstName(), persons.get(0).getFirstName()); - assertEquals(USER_3.getFirstName(), persons.get(1).getFirstName()); + List persons = people.getPeopleImpl(filter, paging, null, null); + verify(mockSearchService, times(++callCount)).query(searchParametersCaptor.capture()); - // Get user with multi-part firstNames and lastNames - persons = people.getPeopleImpl("john junior lewis sec*", paging, null, null); - assertEquals("There is one user with the name: \"john junior lewis second\".", 1, - persons.size()); - assertEquals(USER_1.getFirstName(), persons.get(0).getFirstName()); - assertEquals(USER_1.getLastName(), persons.get(0).getLastName()); - - // Only USER_2's first name is "john senior" - persons = people.getPeopleImpl("john senior", paging, null, null); - assertEquals("There is one user who has \"john senior\" as his first name.", 1, - persons.size()); - assertEquals(USER_2.getFirstName(), persons.get(0).getFirstName()); - assertEquals(USER_2.getLastName(), persons.get(0).getLastName()); - - persons = people.getPeopleImpl("john*", paging, null, null); - assertEquals("There are four users with \"john\" as their first name.", 4, persons.size()); - - // Get people with multi-part lastNames - // USER_3 and USER_4 both have 'lewis third' as their lastName - persons = people.getPeopleImpl("lewis third", paging, null, null); - assertEquals("There are two users who have \"lewis third\" as their last name.", 2, - persons.size()); - assertEquals(USER_3.getLastName(), persons.get(0).getLastName()); - assertEquals(USER_4.getLastName(), persons.get(1).getLastName()); - - // Only USER_5 and USER_6 have last name "doe first" - // The query shouldn't select USER_7 - persons = people.getPeopleImpl("doe fi*", paging, null, null); - assertEquals("There are two users who have \"doe first\" as their last name.", 2, - persons.size()); - assertEquals(USER_5.getLastName(), persons.get(0).getLastName()); - assertEquals(USER_6.getLastName(), persons.get(1).getLastName()); - - persons = people.getPeopleImpl("lewi*", paging, null, null); - assertEquals("There are four users with \"lewis\" as their last name.", 4, persons.size()); - - persons = people.getPeopleImpl("thir*", paging, null, null); - assertEquals("There are two users with \"lewis third\" as their last name.", 2, persons.size()); - - // Get people with single firstName and multi-part lastNames - persons = people.getPeopleImpl("sam doe first", paging, null, null); - assertEquals("There is one user with the name: \"sam doe first\".", 1, persons.size()); - assertEquals(USER_6.getFirstName(), persons.get(0).getFirstName()); - assertEquals(USER_6.getLastName(), persons.get(0).getLastName()); - - // Get people with multi-part firstNames and single lastName - persons = people.getPeopleImpl("sara jones doe", paging, null, null); - assertEquals("There is one user with the name: \"sara jones doe\".", 1, persons.size()); - assertEquals(USER_7.getFirstName(), persons.get(0).getFirstName()); - assertEquals(USER_7.getLastName(), persons.get(0).getLastName()); - - // Get people with single firstName and single lastName - persons = people.getPeopleImpl("sara doe", paging, null, null); - assertEquals("There are two users with the name: \"sara doe\".", 2, persons.size()); - assertEquals(USER_7.getLastName(), persons.get(0).getLastName()); - assertEquals(USER_8.getLastName(), persons.get(0).getLastName()); + SearchParameters parameters = searchParametersCaptor.getValue(); + assertEquals("Query", expectedQuery, parameters.getQuery().toString()); + assertEquals("Sort", expectedSort, parameters.getSortDefinitions().toString()); + assertEquals("maxItems", expectedMaxItems, parameters.getMaxItems()); + assertEquals("SkipCount", expectedSkipCount, parameters.getSkipCount()); + assertEquals(sizeMessage, userIds.length, persons.size()); + int n = 0; + for (int i : userIds) + { + UserInfo userInfo = userInfos[i]; + assertEquals("PeopleTestUser " + i + " firstName ", userInfo.getFirstName(), persons.get(n).getFirstName()); + assertEquals("PeopleTestUser " + i + " lastName ", userInfo.getLastName(), persons.get(n).getLastName()); + n++; + } } /** @@ -194,11 +273,12 @@ public class PeopleTest extends TestCase *
* This test is also valid for SOLR1 and SOLR4! */ + @Category(RedundantTests.class) // This test is checking that canned queries and Solr searches return the same. We no longer test SOLR. public void testGetPeopleByPatternIndexedAndCQ() throws Exception { ScriptPagingDetails paging = new ScriptPagingDetails(0, 0); List unsortedPeople = people.getPeopleImpl(CQ_SIMPLE_FILTER, paging, null, null); - assertNotNull("No one person is found!", unsortedPeople); + assertNotNull("Not one person was found!", unsortedPeople); Set expectedUsers = new HashSet(); for (PersonInfo person : unsortedPeople) @@ -216,19 +296,30 @@ public class PeopleTest extends TestCase } } - private void createUser(UserInfo... userInfo) + private void createUsers() throws HeuristicRollbackException, RollbackException, HeuristicMixedException, SystemException, NotSupportedException { - for (UserInfo user : userInfo) + txn = transactionService.getUserTransaction(); + txn.begin(); + for (UserInfo user : userInfos) { - PropertyMap testUser = new PropertyMap(); - testUser.put(ContentModel.PROP_USERNAME, user.getUserName()); - testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName()); - testUser.put(ContentModel.PROP_LASTNAME, user.getLastName()); - testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test"); - testUser.put(ContentModel.PROP_PASSWORD, "password"); + String username = user.getUserName(); + NodeRef nodeRef = personService.getPersonOrNull(username); + boolean create = nodeRef == null; + if (create) + { + PropertyMap testUser = new PropertyMap(); + testUser.put(ContentModel.PROP_USERNAME, username); + testUser.put(ContentModel.PROP_FIRSTNAME, user.getFirstName()); + testUser.put(ContentModel.PROP_LASTNAME, user.getLastName()); + testUser.put(ContentModel.PROP_EMAIL, user.getUserName() + "@acme.test"); + testUser.put(ContentModel.PROP_PASSWORD, "password"); - personService.createPerson(testUser); + nodeRef = personService.createPerson(testUser); + } + userNodeRefs.add(nodeRef); +// System.out.println((create ? "create" : "existing")+" user " + username + " nodeRef=" + nodeRef); } + txn.commit(); } static class UserInfo @@ -262,7 +353,7 @@ public class PeopleTest extends TestCase @Override public String toString() { - return "UserInfo [userName=" + this.userName + ", firstName=" + this.firstName + return "PeopleTestUserInfo [userName=" + this.userName + ", firstName=" + this.firstName + ", lastName=" + this.lastName + "]"; } } diff --git a/src/test/java/org/alfresco/repo/links/LinksServiceImplTest.java b/src/test/java/org/alfresco/repo/links/LinksServiceImplTest.java index 6500ad7f0f..c62cc9c7e1 100644 --- a/src/test/java/org/alfresco/repo/links/LinksServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/links/LinksServiceImplTest.java @@ -29,10 +29,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import org.alfresco.model.ContentModel; import org.alfresco.query.PagingRequest; @@ -57,12 +56,17 @@ import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.PropertyMap; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; import org.springframework.context.ApplicationContext; /** @@ -71,6 +75,7 @@ import org.springframework.context.ApplicationContext; * @author Nick Burch * @since 4.0 */ +@RunWith(MockitoJUnitRunner.class) @Category(LuceneTests.class) public class LinksServiceImplTest { @@ -90,6 +95,7 @@ public class LinksServiceImplTest private static PermissionService PERMISSION_SERVICE; private static SiteService SITE_SERVICE; private static ContentService CONTENT_SERVICE; + @Mock private static TaggingService TAGGING_SERVICE; private static final String TEST_USER = LinksServiceImplTest.class.getSimpleName() + "_testuser"; @@ -119,7 +125,6 @@ public class LinksServiceImplTest PERMISSION_SERVICE = (PermissionService)testContext.getBean("permissionService"); SITE_SERVICE = (SiteService)testContext.getBean("siteService"); CONTENT_SERVICE = (ContentService)testContext.getBean("ContentService"); - TAGGING_SERVICE = (TaggingService)testContext.getBean("TaggingService"); // Do the setup as admin AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER); @@ -129,7 +134,15 @@ public class LinksServiceImplTest AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER); createTestSites(); } - + + @Before + public void before() + { + // Inject a mock to a real service instead of tagging service + ((LinksServiceImpl) testContext.getBean("linksService")).setTaggingService(TAGGING_SERVICE); + when(TAGGING_SERVICE.isTagScope(Matchers.any(NodeRef.class))).thenReturn(true); + } + @Test public void createNewEntry() throws Exception { LinkInfo link; @@ -307,7 +320,7 @@ public class LinksServiceImplTest // Check assertEquals(0, link.getTags().size()); - + when(TAGGING_SERVICE.getTags(link.getNodeRef())).thenReturn(new ArrayList<>(10)); link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName()); assertEquals(0, link.getTags().size()); @@ -320,6 +333,7 @@ public class LinksServiceImplTest LINKS_SERVICE.updateLink(link); // Check + when(TAGGING_SERVICE.getTags(link.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_2))); link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName()); assertEquals(2, link.getTags().size()); assertEquals(true, link.getTags().contains(TAG_1)); @@ -334,12 +348,14 @@ public class LinksServiceImplTest LINKS_SERVICE.updateLink(link); // Check it as-is + when(TAGGING_SERVICE.getTags(link.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_3))); assertEquals(3, link.getTags().size()); // Includes duplicate tag until re-loaded assertEquals(true, link.getTags().contains(TAG_1)); assertEquals(false, link.getTags().contains(TAG_2)); assertEquals(true, link.getTags().contains(TAG_3)); // Now load and re-check + when(TAGGING_SERVICE.getTags(link.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_3))); link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName()); assertEquals(2, link.getTags().size()); // Duplicate now gone assertEquals(true, link.getTags().contains(TAG_1)); @@ -352,6 +368,7 @@ public class LinksServiceImplTest LINKS_SERVICE.updateLink(link); // Check + when(TAGGING_SERVICE.getTags(link.getNodeRef())).thenReturn(new ArrayList<>()); link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName()); assertEquals(0, link.getTags().size()); @@ -363,6 +380,7 @@ public class LinksServiceImplTest LINKS_SERVICE.updateLink(link); // Check + when(TAGGING_SERVICE.getTags(link.getNodeRef())).thenReturn(new ArrayList<>(Arrays.asList(TAG_1, TAG_2, TAG_3))); link = LINKS_SERVICE.getLink(LINKS_SITE.getShortName(), link.getSystemName()); assertEquals(3, link.getTags().size()); assertEquals(true, link.getTags().contains(TAG_1)); @@ -617,6 +635,7 @@ public class LinksServiceImplTest /** * The lucene based searching */ + @Category(RedundantTests.class) @Test public void linksSearching() throws Exception { AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER); diff --git a/src/test/java/org/alfresco/repo/lock/LockServiceImplTest.java b/src/test/java/org/alfresco/repo/lock/LockServiceImplTest.java index 0ca8335a77..c32cf44edd 100644 --- a/src/test/java/org/alfresco/repo/lock/LockServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/lock/LockServiceImplTest.java @@ -63,6 +63,7 @@ import org.alfresco.test_category.BaseSpringTestsCategory; import org.alfresco.util.BaseSpringTest; import org.alfresco.util.TestWithUserUtils; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -375,6 +376,7 @@ public class LockServiceImplTest extends BaseSpringTest } @Test + @Category(RedundantTests.class) public void testEphemeralLockIndexing() { TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, authenticationService); @@ -730,7 +732,8 @@ public class LockServiceImplTest extends BaseSpringTest LockStatus lockStatus4 = this.lockService.getLockStatus(this.parentNode); assertEquals(LockStatus.LOCK_OWNER, lockStatus4); } - + + @Category(RedundantTests.class) public void testGetLocks() { TestWithUserUtils.authenticateUser(GOOD_USER_NAME, PWD, rootNodeRef, this.authenticationService); diff --git a/src/test/java/org/alfresco/repo/model/filefolder/FileFolderServicePropagationTest.java b/src/test/java/org/alfresco/repo/model/filefolder/FileFolderServicePropagationTest.java index 8dc6cfffc0..9ca3f511f0 100644 --- a/src/test/java/org/alfresco/repo/model/filefolder/FileFolderServicePropagationTest.java +++ b/src/test/java/org/alfresco/repo/model/filefolder/FileFolderServicePropagationTest.java @@ -25,15 +25,12 @@ */ package org.alfresco.repo.model.filefolder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import java.util.List; import junit.framework.TestCase; import org.alfresco.model.ContentModel; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; @@ -45,9 +42,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.transaction.TransactionService; @@ -86,10 +80,9 @@ public class FileFolderServicePropagationTest extends TestCase private PermissionService permissionService; - private SearchService searchService; - private NodeService nodeService; + private Repository repositoryHelper; private FileInfo testFile; @@ -115,8 +108,8 @@ public class FileFolderServicePropagationTest extends TestCase authenticationService = serviceRegistry.getAuthenticationService(); transactionService = serviceRegistry.getTransactionService(); permissionService = serviceRegistry.getPermissionService(); - searchService = serviceRegistry.getSearchService(); nodeService = serviceRegistry.getNodeService(); + repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper"); testFile = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() { @@ -128,9 +121,7 @@ public class FileFolderServicePropagationTest extends TestCase @Override public FileInfo doWork() throws Exception { - ResultSet resultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\""); - NodeRef companyHome = resultSet.getNodeRef(0); - resultSet.close(); + NodeRef companyHome = repositoryHelper.getCompanyHome(); StringBuilder name = new StringBuilder("TestRootFolder-").append(System.currentTimeMillis()); testRootFolder = fileFolderService.create(companyHome, name.toString(), ContentModel.TYPE_FOLDER); diff --git a/src/test/java/org/alfresco/repo/model/filefolder/HiddenAspectTest.java b/src/test/java/org/alfresco/repo/model/filefolder/HiddenAspectTest.java index 29f08c58a5..c44897c08c 100644 --- a/src/test/java/org/alfresco/repo/model/filefolder/HiddenAspectTest.java +++ b/src/test/java/org/alfresco/repo/model/filefolder/HiddenAspectTest.java @@ -93,7 +93,6 @@ import org.junit.experimental.categories.Category; import org.junit.rules.TestName; import org.springframework.context.ApplicationContext; -@Category(LuceneTests.class) public class HiddenAspectTest { @Rule public TestName name = new TestName(); @@ -110,7 +109,6 @@ public class HiddenAspectTest private CheckOutCheckInService cociService; private UserTransaction txn; - private SearchService searchService; private DictionaryNamespaceComponent namespacePrefixResolver; private ImapService imapService; private PersonService personService; @@ -143,7 +141,6 @@ public class HiddenAspectTest cociService = (CheckOutCheckInService) ctx.getBean("checkOutCheckInService"); imapService = serviceRegistry.getImapService(); personService = serviceRegistry.getPersonService(); - searchService = serviceRegistry.getSearchService(); permissionService = serviceRegistry.getPermissionService(); imapEnabled = serviceRegistry.getImapService().getImapServerEnabled(); @@ -237,8 +234,6 @@ public class HiddenAspectTest assertTrue(nodeService.hasAspect(child1, ContentModel.ASPECT_TEMPORARY)); assertTrue(nodeService.hasAspect(child1, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(child1, ContentModel.ASPECT_INDEX_CONTROL)); - ResultSet results = searchForName(".TemporaryItems"); - assertEquals("", 0, results.length()); children = fileFolderService.list(parent); assertEquals(1, children.size()); @@ -259,8 +254,6 @@ public class HiddenAspectTest assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY)); assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("Thumbs.db"); - assertEquals("", 0, results.length()); children = fileFolderService.list(parent); assertEquals(1, children.size()); // set hidden attribute for cifs, webdav. ftp, nfs should be able to see, other clients not @@ -275,8 +268,6 @@ public class HiddenAspectTest NodeRef node = fileFolderService.create(topNodeRef, "surf-config", ContentModel.TYPE_FOLDER).getNodeRef(); assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("surf-config"); - assertEquals("", 0, results.length()); for(Client client : hiddenAspect.getClients()) { if(!client.equals(Client.admin)) @@ -289,8 +280,6 @@ public class HiddenAspectTest node = fileFolderService.create(topNodeRef, ".DS_Store", ContentModel.TYPE_CONTENT).getNodeRef(); assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName(".DS_Store"); - assertEquals("", 0, results.length()); for(Client client : hiddenAspect.getClients()) { if(client == Client.cifs) @@ -311,8 +300,6 @@ public class HiddenAspectTest node = fileFolderService.create(topNodeRef, "._resourceFork", ContentModel.TYPE_FOLDER).getNodeRef(); assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("._resourceFork"); - assertEquals("", 0, results.length()); for(Client client : hiddenAspect.getClients()) { if(client != Client.admin) @@ -536,10 +523,7 @@ public class HiddenAspectTest assertTrue(nodeService.hasAspect(node31, ContentModel.ASPECT_INDEX_CONTROL)); assertTrue(nodeService.hasAspect(node41, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(node41, ContentModel.ASPECT_INDEX_CONTROL)); - - ResultSet results = searchForName(nodeName); - assertEquals("", 1, results.length()); - + try { fileFolderService.rename(node, "." + nodeName); @@ -568,12 +552,6 @@ public class HiddenAspectTest assertTrue(nodeService.hasAspect(node41, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(node41, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName(nodeName); - assertEquals("", 0, results.length()); - - results = searchForName("." + nodeName); - assertEquals("", 0, results.length()); - try { fileFolderService.rename(node, nodeName); @@ -601,9 +579,6 @@ public class HiddenAspectTest assertTrue(nodeService.hasAspect(node31, ContentModel.ASPECT_INDEX_CONTROL)); assertTrue(nodeService.hasAspect(node41, ContentModel.ASPECT_HIDDEN)); assertTrue(nodeService.hasAspect(node41, ContentModel.ASPECT_INDEX_CONTROL)); - - results = searchForName(nodeName); - assertEquals("", 1, results.length()); } finally { @@ -625,9 +600,6 @@ public class HiddenAspectTest NodeRef node = fileFolderService.create(topNodeRef, nodeName, ContentModel.TYPE_FOLDER).getNodeRef(); NodeRef checkedOutNode = fileFolderService.create(node, guid + ".lockedchild", ContentModel.TYPE_CONTENT).getNodeRef(); - ResultSet results = searchForName(nodeName); - assertEquals("", 1, results.length()); - workingCopyNodeRef = cociService.checkout(checkedOutNode); assertNotNull(workingCopyNodeRef); assertTrue(nodeService.hasAspect(checkedOutNode, ContentModel.ASPECT_CHECKED_OUT)); @@ -649,12 +621,6 @@ public class HiddenAspectTest { fail(); } - - results = searchForName(nodeName); - assertEquals("File with old name should not be found", 0, results.length()); - - results = searchForName(newName); - assertEquals("File with new name should be found", 1, results.length()); } finally { @@ -678,8 +644,6 @@ public class HiddenAspectTest assertTrue(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY)); assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_INDEX_CONTROL)); - ResultSet results = searchForName("file.tmp"); - assertEquals("", 1, results.length()); List children = fileFolderService.list(parent); assertEquals(1, children.size()); @@ -692,8 +656,6 @@ public class HiddenAspectTest assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY)); assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName(".TemporaryItems"); - assertEquals("", 1, results.length()); children = fileFolderService.list(parent); assertEquals(1, children.size()); @@ -702,22 +664,16 @@ public class HiddenAspectTest assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_TEMPORARY)); assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(child, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("Thumbs.db"); - assertEquals("", 1, results.length()); children = fileFolderService.list(parent); assertEquals(1, children.size()); NodeRef node = fileFolderService.create(topNodeRef, "surf-config", ContentModel.TYPE_FOLDER).getNodeRef(); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("surf-config"); - assertEquals("", 1, results.length()); - + node = fileFolderService.create(topNodeRef, ".DS_Store", ContentModel.TYPE_CONTENT).getNodeRef(); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName(".DS_Store"); - assertEquals("", 1, results.length()); for(Client client : hiddenAspect.getClients()) { assertEquals("Should be visible for client " + client, Visibility.Visible, hiddenAspect.getVisibility(client, node)); @@ -726,9 +682,7 @@ public class HiddenAspectTest node = fileFolderService.create(topNodeRef, "._resourceFork", ContentModel.TYPE_FOLDER).getNodeRef(); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("._resourceFork"); - assertEquals("", 1, results.length()); - + children = fileFolderService.list(parent); assertEquals(1, children.size()); @@ -737,8 +691,6 @@ public class HiddenAspectTest node = fileFolderService.create(topNodeRef, nodeName, ContentModel.TYPE_CONTENT).getNodeRef(); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName(nodeName); - assertEquals("", 1, results.length()); try { fileFolderService.rename(node, "." + nodeName); @@ -754,12 +706,6 @@ public class HiddenAspectTest assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName(nodeName); - assertEquals("", 1, results.length()); - - results = searchForName("." + nodeName); - assertEquals("", 1, results.length()); - try { fileFolderService.rename(node, nodeName); @@ -775,9 +721,6 @@ public class HiddenAspectTest assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_HIDDEN)); assertFalse(nodeService.hasAspect(node, ContentModel.ASPECT_INDEX_CONTROL)); - results = searchForName("." + nodeName); - assertEquals("", 1, results.length()); - imapService.getOrCreateMailbox(user, MAILBOX_NAME_A, false, true); imapService.renameMailbox(user, MAILBOX_NAME_A, MAILBOX_NAME_B); assertFalse("Can't rename mailbox", checkMailbox(user, MAILBOX_NAME_A)); @@ -811,10 +754,6 @@ public class HiddenAspectTest NodeRef node31 = fileFolderService.create(node21, ".31", ContentModel.TYPE_FOLDER).getNodeRef(); NodeRef node41 = fileFolderService.create(node31, nodeName + ".41", ContentModel.TYPE_CONTENT).getNodeRef(); - assertEquals(1, searchForName(".12").length()); - assertEquals(1, searchForName(".31").length()); - assertEquals(1, searchForName(nodeName + ".41").length()); - txn.commit(); } finally @@ -933,14 +872,4 @@ public class HiddenAspectTest } return true; } - - private ResultSet searchForName(String name) - { - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_NAME.toString()) + ":\"" + name + "\""); - sp.addLocale(new Locale("en")); - return searchService.query(sp); - } } diff --git a/src/test/java/org/alfresco/repo/module/ComponentsTest.java b/src/test/java/org/alfresco/repo/module/ComponentsTest.java index abefe10021..82aafff3c3 100644 --- a/src/test/java/org/alfresco/repo/module/ComponentsTest.java +++ b/src/test/java/org/alfresco/repo/module/ComponentsTest.java @@ -41,6 +41,7 @@ import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.search.CategoryService; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -53,7 +54,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * * @author Derek Hulley */ -@Category(LuceneTests.class) +@Category({LuceneTests.class, RedundantTests.class}) public class ComponentsTest extends TestCase { private static ApplicationContext ctx = new ClassPathXmlApplicationContext("module/module-component-test-beans.xml"); diff --git a/src/test/java/org/alfresco/repo/node/ConcurrentNodeServiceSearchTest.java b/src/test/java/org/alfresco/repo/node/ConcurrentNodeServiceSearchTest.java index a8a2466496..1810c9556c 100644 --- a/src/test/java/org/alfresco/repo/node/ConcurrentNodeServiceSearchTest.java +++ b/src/test/java/org/alfresco/repo/node/ConcurrentNodeServiceSearchTest.java @@ -34,7 +34,6 @@ import junit.framework.TestCase; import org.alfresco.repo.dictionary.DictionaryDAO; import org.alfresco.repo.dictionary.M2Model; -import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.ChildAssociationRef; @@ -50,11 +49,11 @@ import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.DBTests; import org.junit.experimental.categories.Category; import org.springframework.context.ApplicationContext; -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) +@Category({OwnJVMTestsCategory.class, DBTests.class}) public class ConcurrentNodeServiceSearchTest extends TestCase { @@ -78,8 +77,6 @@ public class ConcurrentNodeServiceSearchTest extends TestCase private NodeRef rootNodeRef; - private FullTextSearchIndexer luceneFTS; - private AuthenticationComponent authenticationComponent; public ConcurrentNodeServiceSearchTest() @@ -105,7 +102,6 @@ public class ConcurrentNodeServiceSearchTest extends TestCase nodeService = (NodeService) ctx.getBean("dbNodeService"); transactionService = (TransactionService) ctx.getBean("transactionComponent"); - luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); this.authenticationComponent.setSystemUserAsCurrentUser(); @@ -142,9 +138,6 @@ public class ConcurrentNodeServiceSearchTest extends TestCase public void testConcurrent() throws Exception { - luceneFTS.pause(); - // TODO: LUCENE UPDATE ISSUE fix commit lock timeout here - // IndexWriter.COMMIT_LOCK_TIMEOUT = 100000; int count = 10; int repeats = 10; diff --git a/src/test/java/org/alfresco/repo/node/index/FullIndexRecoveryComponentTest.java b/src/test/java/org/alfresco/repo/node/index/FullIndexRecoveryComponentTest.java deleted file mode 100644 index 1ff05567b5..0000000000 --- a/src/test/java/org/alfresco/repo/node/index/FullIndexRecoveryComponentTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.node.index; - -import java.util.List; - -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.domain.node.NodeDAO; -import org.alfresco.repo.domain.node.Transaction; -import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; -import org.alfresco.repo.node.index.AbstractReindexComponent.InIndex; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; - -/** - * Checks that full index recovery is possible - * - * @author Derek Hulley - */ -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class FullIndexRecoveryComponentTest extends TestCase -{ - private ApplicationContext ctx; - - private FullIndexRecoveryComponent indexRecoverer; - private NodeService nodeService; - private NodeRef rootNodeRef; - private TransactionService transactionService; - private AuthenticationComponent authenticationComponent; - private UserTransaction testTX; - private NodeDAO nodeDAO; - - public void setUp() throws Exception - { - ctx = ApplicationContextHelper.getApplicationContext(); - ChildApplicationContextFactory luceneSubSystem = (ChildApplicationContextFactory) ctx.getBean("buildonly"); - indexRecoverer = (FullIndexRecoveryComponent) luceneSubSystem.getApplicationContext().getBean("search.indexRecoveryComponent"); - nodeService = (NodeService) ctx.getBean("nodeService"); - transactionService = (TransactionService) ctx.getBean("transactionComponent"); - authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); - nodeDAO = (NodeDAO) ctx.getBean("nodeDAO"); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - } - - public void testSetup() throws Exception - { - - } - - public void XtestDeletionReporting() throws Exception - { - StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - NodeRef folder = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}folder"), ContentModel.TYPE_FOLDER).getChildRef(); - - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - NodeRef[] refs = new NodeRef[20]; - for(int i = 0; i < refs.length; i++) - { - refs[i] = nodeService.createNode(folder, ContentModel.ASSOC_CONTAINS, QName.createQName("{namespace}file"+i), ContentModel.TYPE_CONTENT).getChildRef(); - } - - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - for(int i = 0; i < refs.length; i++) - { - nodeService.deleteNode(refs[i]); - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - } - - // The following test are important but take too long .... - -// List startTxns = nodeDaoService.getTxnsByCommitTimeAscending( -// Long.MIN_VALUE, Long.MAX_VALUE, 1, null, false); -// InIndex startAllPresent = indexRecoverer.areTxnsInStartSample(startTxns); -// assertEquals(InIndex.YES, startAllPresent); -// Long maxId = nodeDaoService.getMaxTxnIdByCommitTime(Long.MAX_VALUE); -// startTxns = nodeDaoService.getTxnsByCommitTimeAscending( -// Long.MIN_VALUE, Long.MAX_VALUE, maxId.intValue(), null, false); -// startAllPresent = indexRecoverer.areTxnsInStartSample(startTxns); -// assertEquals(InIndex.INDETERMINATE, startAllPresent); - -// for(int i = 0; i <= maxId.intValue(); i++) -// { -// System.out.println("TX "+i+" is "+indexRecoverer.isTxnPresentInIndex(nodeDaoService.getTxnById(i))); -// } - -// startTxns = nodeDaoService.getTxnsByCommitTimeAscending( -// Long.MIN_VALUE, Long.MAX_VALUE, startTxns.size() - 20, null, false); -// startAllPresent = indexRecoverer.areTxnsInStartSample(startTxns); -// assertEquals(InIndex.YES, startAllPresent); -// - - - List endTxns = nodeDAO.getTxnsByCommitTimeDescending( - Long.MIN_VALUE, Long.MAX_VALUE, 20, null, false); - InIndex endAllPresent = indexRecoverer.areAllTxnsInEndSample(endTxns); - assertEquals(InIndex.INDETERMINATE, endAllPresent); - - endTxns = nodeDAO.getTxnsByCommitTimeDescending( - Long.MIN_VALUE, Long.MAX_VALUE, 21, null, false); - endAllPresent = indexRecoverer.areAllTxnsInEndSample(endTxns); - assertEquals(InIndex.INDETERMINATE, endAllPresent); - - endTxns = nodeDAO.getTxnsByCommitTimeDescending( - Long.MIN_VALUE, Long.MAX_VALUE, 22, null, false); - endAllPresent = indexRecoverer.areAllTxnsInEndSample(endTxns); - assertEquals(InIndex.YES, endAllPresent); - } - - public synchronized void testReindexing() throws Exception - { - indexRecoverer.setRecoveryMode(FullIndexRecoveryComponent.RecoveryMode.FULL.name()); - // reindex - Thread reindexThread = new Thread() - { - public void run() - { - indexRecoverer.reindex(); - } - }; - //reindexThread.setDaemon(true); - reindexThread.start(); - - // must allow the rebuild to complete or the test after this one will fail to validate their indexes - // - as they now will be deleted. - reindexThread.join(); - - // wait a bit and then terminate - wait(20000); - indexRecoverer.setShutdown(true); - wait(20000); - } -} diff --git a/src/test/java/org/alfresco/repo/node/index/IndexTransactionTrackerTest.java b/src/test/java/org/alfresco/repo/node/index/IndexTransactionTrackerTest.java deleted file mode 100644 index 9010df6d78..0000000000 --- a/src/test/java/org/alfresco/repo/node/index/IndexTransactionTrackerTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.node.index; - -import java.util.concurrent.ThreadPoolExecutor; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.content.ContentStore; -import org.alfresco.repo.domain.node.NodeDAO; -import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; -import org.alfresco.repo.search.Indexer; -import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.tenant.TenantService; -import org.alfresco.repo.transaction.TransactionServiceImpl; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; - -/** - * @see org.alfresco.repo.node.index.IndexRemoteTransactionTracker - * - * @author Derek Hulley - */ -@SuppressWarnings("unused") -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class IndexTransactionTrackerTest extends TestCase -{ - private ApplicationContext ctx; - - private AuthenticationComponent authenticationComponent; - private SearchService searchService; - private NodeService nodeService; - private ThreadPoolExecutor threadPoolExecutor; - private FileFolderService fileFolderService; - private ContentStore contentStore; - private FullTextSearchIndexer ftsIndexer; - private Indexer indexer; - private NodeRef rootNodeRef; - - private IndexTransactionTracker indexTracker; - - public void setUp() throws Exception - { - ctx = ApplicationContextHelper.getApplicationContext(); - ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); - searchService = (SearchService) ctx.getBean("searchService"); - nodeService = (NodeService) ctx.getBean("nodeService"); - ChildApplicationContextFactory luceneSubSystem = (ChildApplicationContextFactory) ctx.getBean("buildonly"); - threadPoolExecutor = (ThreadPoolExecutor) luceneSubSystem.getApplicationContext().getBean("search.indexTrackerThreadPoolExecutor"); - fileFolderService = serviceRegistry.getFileFolderService(); - authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); - contentStore = (ContentStore) ctx.getBean("fileContentStore"); - ftsIndexer = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); - - indexer = (Indexer) ctx.getBean("indexerComponent"); - NodeDAO nodeDAO = (NodeDAO) ctx.getBean("nodeDAO"); - TransactionService transactionService = serviceRegistry.getTransactionService(); - indexTracker = new IndexTransactionTracker(); - indexTracker.setAuthenticationComponent(authenticationComponent); - indexTracker.setFtsIndexer(ftsIndexer); - indexTracker.setIndexer(indexer); - indexTracker.setNodeDAO(nodeDAO); - indexTracker.setNodeService(nodeService); - indexTracker.setThreadPoolExecutor(threadPoolExecutor); - indexTracker.setSearcher(searchService); - indexTracker.setTransactionService((TransactionServiceImpl)transactionService); - indexTracker.setTenantService((TenantService) ctx.getBean("tenantService")); - - // authenticate - authenticationComponent.setSystemUserAsCurrentUser(); - - // disable indexing - RetryingTransactionCallback createNodeWork = new RetryingTransactionCallback() - { - public ChildAssociationRef execute() throws Exception - { - StoreRef storeRef = new StoreRef("test", getName() + "-" + System.currentTimeMillis()); - NodeRef rootNodeRef = null; - if (!nodeService.exists(storeRef)) - { - nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier()); - } - rootNodeRef = nodeService.getRootNode(storeRef); - // create another node - ChildAssociationRef childAssocRef = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - QName.createQName(NamespaceService.ALFRESCO_URI, "xyz"), - ContentModel.TYPE_FOLDER); - // remove the node from the index - indexer.deleteNode(childAssocRef); - return childAssocRef; - } - }; - ChildAssociationRef childAssocRef = transactionService.getRetryingTransactionHelper().doInTransaction(createNodeWork, false); - } - - public void testSetup() throws Exception - { - - } - - public synchronized void testStartup() throws Exception - { - Thread reindexThread = new Thread() - { - public void run() - { - indexTracker.reindex(); - indexTracker.reindex(); - } - }; - reindexThread.setDaemon(true); - reindexThread.start(); - // wait a bit and then terminate - wait(20000); - indexTracker.setShutdown(true); - wait(20000); - } -} diff --git a/src/test/java/org/alfresco/repo/node/index/MissingContentReindexComponentTest.java b/src/test/java/org/alfresco/repo/node/index/MissingContentReindexComponentTest.java deleted file mode 100644 index d5f8184b92..0000000000 --- a/src/test/java/org/alfresco/repo/node/index/MissingContentReindexComponentTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.node.index; - -import java.util.concurrent.ThreadPoolExecutor; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.content.ContentContext; -import org.alfresco.repo.content.ContentStore; -import org.alfresco.repo.content.filestore.FileContentStore; -import org.alfresco.repo.domain.node.NodeDAO; -import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; -import org.alfresco.repo.search.Indexer; -import org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl; -import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.transaction.TransactionServiceImpl; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.repository.ContentData; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.SearchParameters; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.GUID; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; - -/** - * @see org.alfresco.repo.node.index.MissingContentReindexComponent - * - * @author Derek Hulley - */ -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class MissingContentReindexComponentTest extends TestCase -{ - private ApplicationContext ctx; - - private AuthenticationComponent authenticationComponent; - private SearchService searchService; - private NodeService nodeService; - private ThreadPoolExecutor threadPoolExecutor; - private FileFolderService fileFolderService; - private ContentStore contentStore; - private FullTextSearchIndexer ftsIndexer; - private NodeRef rootNodeRef; - private MissingContentReindexComponent reindexer; - - @Override - protected void setUp() throws Exception - { - ctx = ApplicationContextHelper.getApplicationContext(); - ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); - searchService = serviceRegistry.getSearchService(); - nodeService = serviceRegistry.getNodeService(); - - ChildApplicationContextFactory luceneSubSystem = (ChildApplicationContextFactory) ctx.getBean("buildonly"); - threadPoolExecutor = (ThreadPoolExecutor) luceneSubSystem.getApplicationContext().getBean("search.indexTrackerThreadPoolExecutor"); - fileFolderService = serviceRegistry.getFileFolderService(); - authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); - contentStore = (ContentStore) ctx.getBean("fileContentStore"); - ftsIndexer = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); - - Indexer indexer = (Indexer) ctx.getBean("indexerComponent"); - NodeDAO nodeDAO = (NodeDAO) ctx.getBean("nodeDAO"); - TransactionService transactionService = serviceRegistry.getTransactionService(); - reindexer = new MissingContentReindexComponent(); - reindexer.setAuthenticationComponent(authenticationComponent); - reindexer.setFtsIndexer(ftsIndexer); - reindexer.setIndexer(indexer); - reindexer.setNodeDAO(nodeDAO); - reindexer.setNodeService(nodeService); - reindexer.setThreadPoolExecutor(threadPoolExecutor); - reindexer.setSearcher(searchService); - reindexer.setTransactionService((TransactionServiceImpl)transactionService); - - // authenticate - authenticationComponent.setSystemUserAsCurrentUser(); - - // create a root node for the test - StoreRef storeRef = nodeService.createStore("test", getName() + "-" + System.nanoTime()); - rootNodeRef = nodeService.getRootNode(storeRef); - rootNodeRef = nodeService.createNode( - rootNodeRef, - ContentModel.ASSOC_CHILDREN, - QName.createQName("cm:x"), - ContentModel.TYPE_FOLDER).getChildRef(); - } - - @Override - protected void tearDown() throws Exception - { - authenticationComponent.clearCurrentSecurityContext(); - } - - /** - * Create a node with a content URL that points to missing content. It then - * checks that the indexing flagged it, prompts a reindex of missing content - * and checks that the text was properly indexed. - */ - public synchronized void testReindex() throws Exception - { - // create a node with missing content - String contentUrl = FileContentStore.STORE_PROTOCOL + FileContentStore.PROTOCOL_DELIMITER + - "x/y/" + GUID.generate() + ".bin"; - ContentData contentData = new ContentData(contentUrl, "text/plain", 0L, "UTF8"); - - // create the file node - NodeRef nodeRef = fileFolderService.create(rootNodeRef, "myfile", ContentModel.TYPE_CONTENT).getNodeRef(); - // add the content - nodeService.setProperty(nodeRef, ContentModel.PROP_CONTENT, contentData); - - // wait a bit for the indexing - ftsIndexer.index(); - wait(1000); - - // check that the content was but that the content was M.I.A. - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("TEXT:" + AbstractLuceneIndexerImpl.NOT_INDEXED_CONTENT_MISSING); - sp.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING); - ResultSet results = null; - try - { - results = searchService.query(sp); - assertTrue("Content missing NICM not found", results.length() == 1); - } - finally - { - if (results != null) { results.close(); } - } - - // now put some content in the store - ContentContext ctx = new ContentContext(null, contentUrl); - ContentWriter writer = contentStore.getWriter(ctx); - writer.setMimetype("text/plain"); - writer.setEncoding("UTF8"); - writer.putContent("123abc456def"); - - // prompt for reindex - reindexer.reindex(); - - // wait for it to have been indexed again - ftsIndexer.index(); - wait(1000); - - // search for the text - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("TEXT:" + "123abc456def"); - sp.addSort("@" + ContentModel.PROP_CREATED, false); - results = null; - try - { - results = searchService.query(sp); - assertTrue("Indexed content node found", results.length() == 1); - } - finally - { - if (results != null) { results.close(); } - } - } -} diff --git a/src/test/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java index f90c3aa2a5..3df4480bb8 100644 --- a/src/test/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java +++ b/src/test/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java @@ -102,7 +102,7 @@ import org.springframework.context.ConfigurableApplicationContext; * @since 3.3 */ @SuppressWarnings("deprecation") -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) +@Category({OwnJVMTestsCategory.class}) public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest { private static final String WHITE = "ffffff"; diff --git a/src/test/java/org/alfresco/repo/rendition/executer/XSLTFunctionsTest.java b/src/test/java/org/alfresco/repo/rendition/executer/XSLTFunctionsTest.java index 04f68e259e..39afa61848 100644 --- a/src/test/java/org/alfresco/repo/rendition/executer/XSLTFunctionsTest.java +++ b/src/test/java/org/alfresco/repo/rendition/executer/XSLTFunctionsTest.java @@ -33,6 +33,7 @@ import java.util.Set; import java.util.TreeSet; import org.alfresco.model.ContentModel; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.model.filefolder.FileFolderServiceImpl; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; @@ -40,8 +41,6 @@ import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.test_category.BaseSpringTestsCategory; import org.alfresco.util.BaseAlfrescoSpringTest; @@ -57,14 +56,14 @@ import org.w3c.dom.NodeList; * @author Brian * */ -@Category({BaseSpringTestsCategory.class, LuceneTests.class}) +@Category({BaseSpringTestsCategory.class}) public class XSLTFunctionsTest extends BaseAlfrescoSpringTest { private final static Log log = LogFactory.getLog(XSLTFunctionsTest.class); private XSLTFunctions xsltFunctions; - private SearchService searchService; private NodeRef companyHome; private FileFolderService fileFolderService; + private Repository repositoryHelper; /* (non-Javadoc) * @see org.alfresco.util.BaseAlfrescoSpringTest#onSetUpInTransaction() @@ -74,13 +73,12 @@ public class XSLTFunctionsTest extends BaseAlfrescoSpringTest protected void onSetUpInTransaction() throws Exception { super.onSetUpInTransaction(); - this.searchService = (SearchService) this.applicationContext.getBean("SearchService"); this.xsltFunctions = (XSLTFunctions) this.applicationContext.getBean("xsltFunctions"); this.nodeService = (NodeService) this.applicationContext.getBean("NodeService"); this.contentService = (ContentService) this.applicationContext.getBean("ContentService"); this.fileFolderService = (FileFolderService) this.applicationContext.getBean("FileFolderService"); - ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, "/app:company_home"); - this.companyHome = rs.getNodeRef(0); + this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper"); + this.companyHome = repositoryHelper.getCompanyHome(); } public void testSimplestParseXMLDocument() diff --git a/src/test/java/org/alfresco/repo/search/SearchServiceTest.java b/src/test/java/org/alfresco/repo/search/SearchServiceTest.java index 6c6d14951c..c51df91780 100644 --- a/src/test/java/org/alfresco/repo/search/SearchServiceTest.java +++ b/src/test/java/org/alfresco/repo/search/SearchServiceTest.java @@ -46,6 +46,7 @@ import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; import org.springframework.context.ApplicationContext; @@ -97,7 +98,7 @@ public class SearchServiceTest extends TestCase } public void setUp() throws Exception - { + { ctx = ApplicationContextHelper.getApplicationContext(); nodeService = (NodeService) ctx.getBean("dbNodeService"); authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); @@ -188,6 +189,7 @@ public class SearchServiceTest extends TestCase } } + @Category(RedundantTests.class) public void testAdmim() { authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); @@ -239,6 +241,7 @@ public class SearchServiceTest extends TestCase results.close(); } + @Category(RedundantTests.class) public void testAndy() { authenticationComponent.setCurrentUser("andy"); diff --git a/src/test/java/org/alfresco/repo/search/SearchTestSuite.java b/src/test/java/org/alfresco/repo/search/SearchTestSuite.java index 2a975e2285..a72e744a50 100644 --- a/src/test/java/org/alfresco/repo/search/SearchTestSuite.java +++ b/src/test/java/org/alfresco/repo/search/SearchTestSuite.java @@ -1,39 +1,33 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.search; import junit.framework.Test; import junit.framework.TestSuite; -import org.alfresco.repo.search.impl.lucene.ADMLuceneCategoryTest; -import org.alfresco.repo.search.impl.lucene.ADMLuceneTest; -import org.alfresco.repo.search.impl.lucene.ALF947Test; -import org.alfresco.repo.search.impl.lucene.LuceneIndexBackupComponentTest; -import org.alfresco.repo.search.impl.lucene.MultiReaderTest; -import org.alfresco.repo.search.impl.lucene.index.IndexInfoTest; import org.alfresco.repo.search.impl.parsers.CMISTest; import org.alfresco.repo.search.impl.parsers.CMIS_FTSTest; import org.alfresco.repo.search.impl.parsers.FTSTest; @@ -59,13 +53,7 @@ public class SearchTestSuite extends TestSuite suite.addTestSuite(SearcherComponentTest.class); suite.addTestSuite(SearchServiceTest.class); suite.addTestSuite(DocumentNavigatorTest.class); - suite.addTestSuite(ADMLuceneCategoryTest.class); - suite.addTestSuite(ADMLuceneTest.class); - suite.addTestSuite(ALF947Test.class); - suite.addTestSuite(LuceneIndexBackupComponentTest.class); - suite.addTestSuite(MultiReaderTest.class); suite.addTestSuite(NumericEncodingTest.class); - suite.addTestSuite(IndexInfoTest.class); suite.addTestSuite(CMIS_FTSTest.class); suite.addTestSuite(CMISTest.class); suite.addTestSuite(FTSTest.class); diff --git a/src/test/java/org/alfresco/repo/search/SearcherComponentTest.java b/src/test/java/org/alfresco/repo/search/SearcherComponentTest.java index 15763caaf4..1acb2e6fc8 100644 --- a/src/test/java/org/alfresco/repo/search/SearcherComponentTest.java +++ b/src/test/java/org/alfresco/repo/search/SearcherComponentTest.java @@ -63,7 +63,7 @@ import org.springframework.context.ApplicationContext; * * @author Derek Hulley */ -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) +@Category({OwnJVMTestsCategory.class}) public class SearcherComponentTest extends TestCase { private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); @@ -350,10 +350,11 @@ public class SearcherComponentTest extends TestCase answer = searcher.selectNodes(rootNodeRef, "*//.[@test:animal='monkey']", null, namespacePrefixResolver, false); assertEquals(1, answer.size()); assertTrue(answer.contains(n3)); - - answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:animal, 'monk*')]", null, namespacePrefixResolver, false); - assertEquals(1, answer.size()); - assertTrue(answer.contains(n3)); + + // "like" query is not translated to DB query +// answer = searcher.selectNodes(rootNodeRef, "//*[like(@test:animal, 'monk*')]", null, namespacePrefixResolver, false); +// assertEquals(1, answer.size()); +// assertTrue(answer.contains(n3)); answer = searcher.selectNodes(rootNodeRef, "//@*", null, namespacePrefixResolver, false); assertEquals(9, answer.size()); diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneCategoryTest.java b/src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneCategoryTest.java deleted file mode 100644 index ca015af880..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneCategoryTest.java +++ /dev/null @@ -1,1151 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.query.PagingRequest; -import org.alfresco.repo.dictionary.DictionaryDAO; -import org.alfresco.repo.dictionary.IndexTokenisationMode; -import org.alfresco.repo.dictionary.M2Aspect; -import org.alfresco.repo.dictionary.M2Model; -import org.alfresco.repo.dictionary.M2Property; -import org.alfresco.repo.jscript.CategoryNode; -import org.alfresco.repo.jscript.ClasspathScriptLocation; -import org.alfresco.repo.search.IndexerAndSearcher; -import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.tenant.TenantService; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.ScriptLocation; -import org.alfresco.service.cmr.repository.ScriptService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.CategoryService; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.ResultSetRow; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.DynamicNamespacePrefixResolver; -import org.alfresco.service.namespace.NamespacePrefixResolver; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.Pair; -import org.alfresco.util.SearchLanguageConversion; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; - -/** - * Category tests - * @author andyh - * - */ -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class ADMLuceneCategoryTest extends TestCase -{ - private ServiceRegistry serviceRegistry; - - static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); - NodeService nodeService; - NodeService publicNodeService; - DictionaryService dictionaryService; - ScriptService scriptService; - private NodeRef rootNodeRef; - private NodeRef n1; - private NodeRef n2; - private NodeRef n3; - private NodeRef n4; - private NodeRef n6; - private NodeRef n5; - private NodeRef n7; - private NodeRef n8; - private NodeRef n9; - private NodeRef n10; - private NodeRef n11; - private NodeRef n12; - private NodeRef n13; - private NodeRef n14; - - private NodeRef catContainer; - private NodeRef catRoot; - private NodeRef catACBase; - private NodeRef catACOne; - private NodeRef catACTwo; - private NodeRef catACThree; - private FullTextSearchIndexer luceneFTS; - private DictionaryDAO dictionaryDAO; - private String TEST_NAMESPACE = "http://www.alfresco.org/test/lucenecategorytest"; - private QName regionCategorisationQName; - private QName assetClassCategorisationQName; - private QName investmentRegionCategorisationQName; - private QName marketingRegionCategorisationQName; - private NodeRef catRBase; - private NodeRef catROne; - private NodeRef catRTwo; - private NodeRef catRThree; - private SearchService searcher; - private IndexerAndSearcher indexerAndSearcher; - private TenantService tenantService; - - private CategoryService categoryService; - - private LuceneConfig luceneConfig; - - /** - * Simple test constructor - * - */ - public ADMLuceneCategoryTest() - { - super(); - } - - /** - * Named test constructor - * @param arg0 String - */ - public ADMLuceneCategoryTest(String arg0) - { - super(arg0); - } - - public void setUp() throws Exception - { - nodeService = (NodeService)ctx.getBean("dbNodeService"); - publicNodeService = (NodeService)ctx.getBean("NodeService"); - dictionaryService = (DictionaryService)ctx.getBean("dictionaryService"); - luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); - dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO"); - searcher = (SearchService) ctx.getBean("searchService"); - indexerAndSearcher = (IndexerAndSearcher) ctx.getBean("admLuceneIndexerAndSearcherFactory"); - luceneConfig = (LuceneConfig) ctx.getBean("admLuceneIndexerAndSearcherFactory"); - categoryService = (CategoryService) ctx.getBean("categoryService"); - serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); - tenantService = (TenantService) ctx.getBean("tenantService"); - scriptService = (ScriptService) ctx.getBean("scriptService"); - - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); - - createTestTypes(); - - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - - StoreRef storeRef = nodeService.createStore( - StoreRef.PROTOCOL_WORKSPACE, - "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), ContentModel.TYPE_CONTAINER).getChildRef(); - nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "value-1"); - n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), ContentModel.TYPE_CONTAINER).getChildRef(); - nodeService.setProperty(n2, QName.createQName("{namespace}property-1"), "value-1"); - nodeService.setProperty(n2, QName.createQName("{namespace}property-2"), "value-2"); - n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), ContentModel.TYPE_CONTAINER).getChildRef(); - n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}four"), ContentModel.TYPE_CONTAINER).getChildRef(); - n5 = nodeService.createNode(n1, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}five"), ContentModel.TYPE_CONTAINER).getChildRef(); - n6 = nodeService.createNode(n1, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}six"), ContentModel.TYPE_CONTAINER).getChildRef(); - n7 = nodeService.createNode(n2, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}seven"), ContentModel.TYPE_CONTAINER).getChildRef(); - n8 = nodeService.createNode(n2, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-2"), ContentModel.TYPE_CONTAINER).getChildRef(); - n9 = nodeService.createNode(n5, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}nine"), ContentModel.TYPE_CONTAINER).getChildRef(); - n10 = nodeService.createNode(n5, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}ten"), ContentModel.TYPE_CONTAINER).getChildRef(); - n11 = nodeService.createNode(n5, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eleven"), ContentModel.TYPE_CONTAINER).getChildRef(); - n12 = nodeService.createNode(n5, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}twelve"), ContentModel.TYPE_CONTAINER).getChildRef(); - n13 = nodeService.createNode(n12, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}thirteen"), ContentModel.TYPE_CONTAINER).getChildRef(); - n14 = nodeService.createNode(n13, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}fourteen"), ContentModel.TYPE_CONTAINER).getChildRef(); - - nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0")); - nodeService.addChild(n1, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-1")); - nodeService.addChild(n2, n13, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}link")); - - nodeService.addChild(n1, n14, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}common")); - nodeService.addChild(n2, n14, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}common")); - nodeService.addChild(n5, n14, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}common")); - nodeService.addChild(n6, n14, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}common")); - nodeService.addChild(n12, n14, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}common")); - nodeService.addChild(n13, n14, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}common")); - - // Categories - - catContainer = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "categoryContainer"), ContentModel.TYPE_CONTAINER).getChildRef(); - catRoot = nodeService.createNode(catContainer, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "categoryRoot"), ContentModel.TYPE_CATEGORYROOT).getChildRef(); - - - - catRBase = nodeService.createNode(catRoot, ContentModel.ASSOC_CATEGORIES, QName.createQName(TEST_NAMESPACE, "region"), ContentModel.TYPE_CATEGORY).getChildRef(); - catROne = nodeService.createNode(catRBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "Europe"), ContentModel.TYPE_CATEGORY).getChildRef(); - catRTwo = nodeService.createNode(catRBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "RestOfWorld"), ContentModel.TYPE_CATEGORY).getChildRef(); - catRThree = nodeService.createNode(catRTwo, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "US"), ContentModel.TYPE_CATEGORY).getChildRef(); - - nodeService.addChild(catRoot, catRBase, ContentModel.ASSOC_CATEGORIES, QName.createQName(TEST_NAMESPACE, "investmentRegion")); - nodeService.addChild(catRoot, catRBase, ContentModel.ASSOC_CATEGORIES, QName.createQName(TEST_NAMESPACE, "marketingRegion")); - - - catACBase = nodeService.createNode(catRoot, ContentModel.ASSOC_CATEGORIES, QName.createQName(TEST_NAMESPACE, "assetClass"), ContentModel.TYPE_CATEGORY).getChildRef(); - catACOne = nodeService.createNode(catACBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "Fixed"), ContentModel.TYPE_CATEGORY).getChildRef(); - catACTwo = nodeService.createNode(catACBase, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "Equity"), ContentModel.TYPE_CATEGORY).getChildRef(); - catACThree = nodeService.createNode(catACTwo, ContentModel.ASSOC_SUBCATEGORIES, QName.createQName(TEST_NAMESPACE, "SpecialEquity"), ContentModel.TYPE_CATEGORY).getChildRef(); - - - - nodeService.addAspect(n1, assetClassCategorisationQName, createMap("assetClass", catACBase)); - nodeService.addAspect(n1, regionCategorisationQName, createMap("region", catRBase)); - - nodeService.addAspect(n2, assetClassCategorisationQName, createMap("assetClass", catACOne)); - nodeService.addAspect(n3, assetClassCategorisationQName, createMap("assetClass", catACOne)); - nodeService.addAspect(n4, assetClassCategorisationQName, createMap("assetClass", catACOne)); - nodeService.addAspect(n5, assetClassCategorisationQName, createMap("assetClass", catACOne)); - nodeService.addAspect(n6, assetClassCategorisationQName, createMap("assetClass", catACOne)); - - nodeService.addAspect(n7, assetClassCategorisationQName, createMap("assetClass", catACTwo)); - nodeService.addAspect(n8, assetClassCategorisationQName, createMap("assetClass", catACTwo)); - nodeService.addAspect(n9, assetClassCategorisationQName, createMap("assetClass", catACTwo)); - nodeService.addAspect(n10, assetClassCategorisationQName, createMap("assetClass", catACTwo)); - nodeService.addAspect(n11, assetClassCategorisationQName, createMap("assetClass", catACTwo)); - - nodeService.addAspect(n12, assetClassCategorisationQName, createMap("assetClass", catACOne, catACTwo)); - nodeService.addAspect(n13, assetClassCategorisationQName, createMap("assetClass", catACOne, catACTwo, catACThree)); - nodeService.addAspect(n14, assetClassCategorisationQName, createMap("assetClass", catACOne, catACTwo)); - - nodeService.addAspect(n2, regionCategorisationQName, createMap("region", catROne)); - nodeService.addAspect(n3, regionCategorisationQName, createMap("region", catROne)); - nodeService.addAspect(n4, regionCategorisationQName, createMap("region", catRTwo)); - nodeService.addAspect(n5, regionCategorisationQName, createMap("region", catRTwo)); - - nodeService.addAspect(n5, investmentRegionCategorisationQName, createMap("investmentRegion", catRBase)); - nodeService.addAspect(n5, marketingRegionCategorisationQName, createMap("marketingRegion", catRBase)); - nodeService.addAspect(n6, investmentRegionCategorisationQName, createMap("investmentRegion", catRBase)); - nodeService.addAspect(n7, investmentRegionCategorisationQName, createMap("investmentRegion", catRBase)); - nodeService.addAspect(n8, investmentRegionCategorisationQName, createMap("investmentRegion", catRBase)); - nodeService.addAspect(n9, investmentRegionCategorisationQName, createMap("investmentRegion", catRBase)); - nodeService.addAspect(n10, marketingRegionCategorisationQName, createMap("marketingRegion", catRBase)); - nodeService.addAspect(n11, marketingRegionCategorisationQName, createMap("marketingRegion", catRBase)); - nodeService.addAspect(n12, marketingRegionCategorisationQName, createMap("marketingRegion", catRBase)); - nodeService.addAspect(n13, marketingRegionCategorisationQName, createMap("marketingRegion", catRBase)); - nodeService.addAspect(n14, marketingRegionCategorisationQName, createMap("marketingRegion", catRBase)); - - tx.commit(); - } - - @Override - protected void tearDown() throws Exception - { - // TODO Auto-generated method stub - AuthenticationUtil.clearCurrentSecurityContext(); - super.tearDown(); - } - - private HashMap createMap(String name, NodeRef[] nodeRefs) - { - HashMap map = new HashMap(); - Serializable value = (Serializable) Arrays.asList(nodeRefs); - map.put(QName.createQName(TEST_NAMESPACE, name), value); - return map; - } - - private HashMap createMap(String name, NodeRef nodeRef) - { - return createMap(name, new NodeRef[]{nodeRef}); - } - - private HashMap createMap(String name, NodeRef nodeRef1, NodeRef nodeRef2) - { - return createMap(name, new NodeRef[]{nodeRef1, nodeRef2}); - } - - private HashMap createMap(String name, NodeRef nodeRef1, NodeRef nodeRef2, NodeRef nodeRef3) - { - return createMap(name, new NodeRef[]{nodeRef1, nodeRef2, nodeRef3}); - } - - private void createTestTypes() - { - M2Model model = M2Model.createModel("adm-cat-test:lucenecategory"); - model.createNamespace(TEST_NAMESPACE, "adm-cat-test"); - model.createImport(NamespaceService.DICTIONARY_MODEL_1_0_URI, NamespaceService.DICTIONARY_MODEL_PREFIX); - model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX); - - regionCategorisationQName = QName.createQName(TEST_NAMESPACE, "region"); - M2Aspect generalCategorisation = model.createAspect("adm-cat-test:" + regionCategorisationQName.getLocalName()); - generalCategorisation.setParentName("cm:" + ContentModel.ASPECT_CLASSIFIABLE.getLocalName()); - M2Property genCatProp = generalCategorisation.createProperty("adm-cat-test:region"); - genCatProp.setIndexed(true); - genCatProp.setIndexedAtomically(true); - genCatProp.setMandatory(true); - genCatProp.setMultiValued(true); - genCatProp.setStoredInIndex(true); - genCatProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE); - genCatProp.setType("d:" + DataTypeDefinition.CATEGORY.getLocalName()); - - assetClassCategorisationQName = QName.createQName(TEST_NAMESPACE, "assetClass"); - M2Aspect assetClassCategorisation = model.createAspect("adm-cat-test:" + assetClassCategorisationQName.getLocalName()); - assetClassCategorisation.setParentName("cm:" + ContentModel.ASPECT_CLASSIFIABLE.getLocalName()); - M2Property acProp = assetClassCategorisation.createProperty("adm-cat-test:assetClass"); - acProp.setIndexed(true); - acProp.setIndexedAtomically(true); - acProp.setMandatory(true); - acProp.setMultiValued(true); - acProp.setStoredInIndex(true); - acProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE); - acProp.setType("d:" + DataTypeDefinition.CATEGORY.getLocalName()); - - investmentRegionCategorisationQName = QName.createQName(TEST_NAMESPACE, "investmentRegion"); - M2Aspect investmentRegionCategorisation = model.createAspect("adm-cat-test:" + investmentRegionCategorisationQName.getLocalName()); - investmentRegionCategorisation.setParentName("cm:" + ContentModel.ASPECT_CLASSIFIABLE.getLocalName()); - M2Property irProp = investmentRegionCategorisation.createProperty("adm-cat-test:investmentRegion"); - irProp.setIndexed(true); - irProp.setIndexedAtomically(true); - irProp.setMandatory(true); - irProp.setMultiValued(true); - irProp.setStoredInIndex(true); - irProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE); - irProp.setType("d:" + DataTypeDefinition.CATEGORY.getLocalName()); - - marketingRegionCategorisationQName = QName.createQName(TEST_NAMESPACE, "marketingRegion"); - M2Aspect marketingRegionCategorisation = model.createAspect("adm-cat-test:" + marketingRegionCategorisationQName.getLocalName()); - marketingRegionCategorisation.setParentName("cm:" + ContentModel.ASPECT_CLASSIFIABLE.getLocalName()); - M2Property mrProp = marketingRegionCategorisation.createProperty("adm-cat-test:marketingRegion"); - mrProp.setIndexed(true); - mrProp.setIndexedAtomically(true); - mrProp.setMandatory(true); - mrProp.setMultiValued(true); - mrProp.setStoredInIndex(true); - mrProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE); - mrProp.setType("d:" + DataTypeDefinition.CATEGORY.getLocalName()); - - dictionaryDAO.putModel(model); - } - - private void buildBaseIndex() - { - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_" + (new Random().nextInt()), luceneConfig); - indexer.setNodeService(nodeService); - //indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.deleteIndex(rootNodeRef.getStoreRef()); - indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}one"), n1)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}two"), n2)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}three"), n3)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}four"), n4)); - - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}categoryContainer"), catContainer)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, catContainer, QName.createQName("{cat}categoryRoot"), catRoot)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, catRoot, QName.createQName(TEST_NAMESPACE, "AssetClass"), catACBase)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_SUBCATEGORIES, catACBase, QName.createQName(TEST_NAMESPACE, "Fixed"), catACOne)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_SUBCATEGORIES, catACBase, QName.createQName(TEST_NAMESPACE, "Equity"), catACTwo)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_SUBCATEGORIES, catACTwo, QName.createQName(TEST_NAMESPACE, "SpecialEquity"), catACThree)); - - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, catRoot, QName.createQName(TEST_NAMESPACE, "Region"), catRBase)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_SUBCATEGORIES, catRBase, QName.createQName(TEST_NAMESPACE, "Europe"), catROne)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_SUBCATEGORIES, catRBase, QName.createQName(TEST_NAMESPACE, "RestOfWorld"), catRTwo)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_SUBCATEGORIES, catRTwo, QName.createQName(TEST_NAMESPACE, "US"), catRThree)); - - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n1, QName.createQName("{namespace}five"), n5)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n1, QName.createQName("{namespace}six"), n6)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n2, QName.createQName("{namespace}seven"), n7)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n2, QName.createQName("{namespace}eight"), n8)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n5, QName.createQName("{namespace}nine"), n9)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n5, QName.createQName("{namespace}ten"), n10)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n5, QName.createQName("{namespace}eleven"), n11)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n5, QName.createQName("{namespace}twelve"), n12)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n12, QName.createQName("{namespace}thirteen"), n13)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CATEGORIES, n13, QName.createQName("{namespace}fourteen"), n14)); - indexer.prepare(); - indexer.commit(); - } - - private ADMLuceneSearcherImpl buildSearcher() - { - ADMLuceneSearcherImpl searcher = ADMLuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), luceneConfig); - searcher.setNodeService(nodeService); - searcher.setDictionaryService(dictionaryService); - searcher.setTenantService(tenantService); - searcher.setNamespacePrefixResolver(getNamespacePrefixResolver("")); - searcher.setQueryLanguages(indexerAndSearcher.getQueryLanguages()); - return searcher; - } - - /** - * Test multiple categories - * @throws Exception - */ - public void testMulti() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results; - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\" AND (PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/member\" PATH:\"/adm-cat-test:marketingRegion/member\")", null); - //printPaths(results); - assertEquals(9, results.length()); - results.close(); - tx.rollback(); - } - - /** - * Test basic categories. - * - * @throws Exception - */ - public void testBasic() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results; - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:marketingRegion\"", null); - //printPaths(results); - assertEquals(1, results.length()); - results.close(); - - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:marketingRegion//member\"", null); - //printPaths(results); - assertEquals(6, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass/member\" ", null); - assertEquals(1, results.length()); - results.close(); - - - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass/adm-cat-test:Fixed\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass/adm-cat-test:Equity\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Fixed\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:*\"", null); - assertEquals(2, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass//adm-cat-test:*\"", null); - assertEquals(3, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Fixed/member\"", null); - //printPaths(results); - assertEquals(8, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/member\"", null); - //printPaths(results); - assertEquals(8, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/adm-cat-test:SpecialEquity/member//.\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/adm-cat-test:SpecialEquity/member//*\"", null); - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/adm-cat-test:SpecialEquity/member\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/member\" AND +PATH:\"/adm-cat-test:assetClass/adm-cat-test:Fixed/member\"", null); - //printPaths(results); - assertEquals(3, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/member\" PATH:\"/adm-cat-test:assetClass/adm-cat-test:Fixed/member\"", null); - //printPaths(results); - assertEquals(13, results.length()); - results.close(); - - // Region - - assertEquals(4, nodeService.getChildAssocs(catRoot).size()); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:region\"", null); - //printPaths(results); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:region/member\"", null); - //printPaths(results); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:region/adm-cat-test:Europe/member\"", null); - //printPaths(results); - assertEquals(2, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:region/adm-cat-test:RestOfWorld/member\"", null); - //printPaths(results); - assertEquals(2, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:region//member\"", null); - //printPaths(results); - assertEquals(5, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:investmentRegion//member\"", null); - //printPaths(results); - assertEquals(5, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:marketingRegion//member\"", null); - //printPaths(results); - assertEquals(6, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+PATH:\"/adm-cat-test:assetClass/adm-cat-test:Fixed/member\" AND +PATH:\"/adm-cat-test:region/adm-cat-test:Europe/member\"", null); - //printPaths(results); - assertEquals(2, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass/adm-cat-test:Fixed/member\" AND +PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:region/adm-cat-test:Europe/member\"", null); - //printPaths(results); - assertEquals(2, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/adm-cat-test:assetClass/adm-cat-test:Equity/member\" PATH:\"/adm-cat-test:marketingRegion/member\"", null); - //printPaths(results); - assertEquals(9, results.length()); - results.close(); - tx.rollback(); - } - - /** - * Test the catgeory service. - * - * @throws Exception - */ - public void testCategoryServiceImpl() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass/*\" ", null); - assertEquals(3, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/cm:categoryContainer/cm:categoryRoot/adm-cat-test:assetClass/member\" ", null); - assertEquals(1, results.length()); - results.close(); - - LuceneCategoryServiceImpl impl = new LuceneCategoryServiceImpl(); - impl.setNodeService(nodeService); - impl.setPublicNodeService(publicNodeService); - impl.setNamespacePrefixResolver(getNamespacePrefixResolver("")); - impl.setIndexerAndSearcher(indexerAndSearcher); - impl.setTenantService(tenantService); - impl.setDictionaryService(dictionaryService); - - Collection - result = impl.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.IMMEDIATE); - assertEquals(1, result.size()); - - - result = impl.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.IMMEDIATE); - assertEquals(3, result.size()); - - - result = impl.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE); - assertEquals(2, result.size()); - - - result = impl.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.ANY); - assertEquals(14, result.size()); - - - result = impl.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.ANY); - assertEquals(17, result.size()); - - - result = impl.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY); - assertEquals(3, result.size()); - - - result = impl.getClassifications(rootNodeRef.getStoreRef()); - assertEquals(2, result.size()); - - - result = impl.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE); - assertEquals(2, result.size()); - - - Collection aspects = impl.getClassificationAspects(); - assertEquals(7, aspects.size()); - - - // Add an additional subcategory, and check it shows up - result = impl.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY); - assertEquals(3, result.size()); - - String newName = "TestSub"; - impl.createCategory(catACBase, newName); - - result = impl.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY); - assertEquals(4, result.size()); - - - // Tidy up - tx.rollback(); - } - - /** - * JavaScript tests for the Category Service. - * Note that this test lives here because that's where the Java - * CategeoryService tests are, and this also has all the required - * SetUp and TearDown to make it easier. - */ - public void testJavascriptAPI() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - buildBaseIndex(); - - ServiceRegistry services = (ServiceRegistry)ctx.getBean("ServiceRegistry"); - - // Call the test - Map model = new HashMap(); - model.put("catRoot", new CategoryNode(catRoot, services)); - model.put("catACBase", new CategoryNode(catACBase, services)); - model.put("catACOne", new CategoryNode(catACOne, services)); - model.put("catACTwo", new CategoryNode(catACTwo, services)); - model.put("catACThree", new CategoryNode(catACThree, services)); - model.put("catRBase", new CategoryNode(catRBase, services)); - model.put("catROne", new CategoryNode(catROne, services)); - model.put("catRTwo", new CategoryNode(catRTwo, services)); - model.put("catRThree", new CategoryNode(catRThree, services)); - - ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/search/impl/lucene/test_categoryService.js"); - this.scriptService.executeScript(location, model); - - // Tidy up - tx.rollback(); - } - - private NamespacePrefixResolver getNamespacePrefixResolver(String defaultURI) - { - DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null); - nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI); - nspr.registerNamespace("namespace", "namespace"); - nspr.registerNamespace("adm-cat-test", TEST_NAMESPACE); - nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI); - return nspr; - } - - /** - * - * @throws Exception - */ - public void testCategoryService() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - buildBaseIndex(); - assertEquals(1, categoryService.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.IMMEDIATE).size()); - assertEquals(2, categoryService.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE).size()); - assertEquals(3, categoryService.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.IMMEDIATE).size()); - assertEquals(14, categoryService.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.ANY).size()); - assertEquals(3, categoryService.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY).size()); - assertEquals(17, categoryService.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.ANY).size()); - assertEquals(2, categoryService.getClassifications(rootNodeRef.getStoreRef()).size()); - assertEquals(2, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE).size()); - assertEquals(3, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.ANY).size()); - assertEquals(7, categoryService.getClassificationAspects().size()); - assertEquals(2, categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass")).size()); - - NodeRef newRoot = categoryService.createRootCategory(rootNodeRef.getStoreRef(),QName.createQName(TEST_NAMESPACE, "assetClass"), "Fruit"); - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - assertEquals(3, categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass")).size()); - Collection fruitCategories = categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), "Fruit"); - assertEquals(1, fruitCategories.size()); - assertTrue(fruitCategories.iterator().next().getQName().toString().contains("Fruit")); - fruitCategories = categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), "Fru"); - assertEquals(1, fruitCategories.size()); - assertTrue(fruitCategories.iterator().next().getQName().toString().contains("Fruit")); - fruitCategories = categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), "rui"); - assertEquals(1, fruitCategories.size()); - assertTrue(fruitCategories.iterator().next().getQName().toString().contains("Fruit")); - fruitCategories = categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), "uit"); - assertEquals(1, fruitCategories.size()); - assertTrue(fruitCategories.iterator().next().getQName().toString().contains("Fruit")); - assertEquals(3, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE).size()); - assertEquals(4, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.ANY).size()); - - NodeRef newCat = categoryService.createCategory(newRoot, "Banana"); - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - assertEquals(3, categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass")).size()); - assertEquals(3, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE).size()); - assertEquals(5, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.ANY).size()); - - categoryService.deleteCategory(newCat); - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - assertEquals(3, categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass")).size()); - assertEquals(3, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE).size()); - assertEquals(4, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.ANY).size()); - - categoryService.deleteCategory(newRoot); - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - assertEquals(2, categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass")).size()); - assertEquals(2, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE).size()); - assertEquals(3, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.ANY).size()); - - - tx.rollback(); - - tx = transactionService.getUserTransaction(); - tx.begin(); - for ( int i=0; i<=5; i++) - { - categoryService.createRootCategory(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), "FirstTestCategory" + i); - categoryService.createRootCategory(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), "SecondTestCategory" + i); - } - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - PagingRequest pagingRequest = new PagingRequest(10); - assertEquals(10,categoryService.getRootCategories(rootNodeRef.getStoreRef(),QName.createQName(TEST_NAMESPACE, "assetClass"), pagingRequest, true, null).getPage().size()); - assertEquals(6,categoryService.getRootCategories(rootNodeRef.getStoreRef(),QName.createQName(TEST_NAMESPACE, "assetClass"), pagingRequest, true, "FirstTestCategory").getPage().size()); - assertEquals(6,categoryService.getRootCategories(rootNodeRef.getStoreRef(),QName.createQName(TEST_NAMESPACE, "assetClass"), pagingRequest, true, "SecondTestCategory").getPage().size()); - tx.commit(); - } - - /** - * - * @throws Exception - */ - public void xtestManyCategories() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - - tx.begin(); - long start = System.nanoTime(); - int startCount = categoryService.getRootCategories(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(), - ContentModel.ASPECT_GEN_CLASSIFIABLE).size(); - System.out.println("1 Query complete in "+(System.nanoTime()-start)/1e9f); - tx.commit(); - - tx = transactionService.getUserTransaction(); - - tx.begin(); - start = System.nanoTime(); - startCount = categoryService.getRootCategories(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(), - ContentModel.ASPECT_GEN_CLASSIFIABLE).size(); - System.out.println("2 Query complete in "+(System.nanoTime()-start)/1e9f); - tx.commit(); - - for (int i = 0; i < 0; i++) - { - tx = transactionService.getUserTransaction(); - tx.begin(); - categoryService.createRootCategory(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, "first" + i); - tx.commit(); - } - - for (int j = 0; j < 10; j++) - { - tx = transactionService.getUserTransaction(); - tx.begin(); - for (int i = 0; i < 1; i++) - { - NodeRef topref = categoryService.createRootCategory(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(),ContentModel.ASPECT_GEN_CLASSIFIABLE, "third" + (j*100)+ i); - for(int k = 0; k < 5; k++) - { - NodeRef oneRef = categoryService.createCategory(topref, "child_"+i+"_"+j+"_"+k); - for(int l = 0; l < 5; l++) - { - NodeRef twoRef = categoryService.createCategory(oneRef, "child_"+i+"_"+j+"_"+k+"_"+l); - for(int m = 0; m < 5; m++) - { - NodeRef threeRef = categoryService.createCategory(twoRef, "child_"+i+"_"+j+"_"+k+"_"+l+"_"+m); - for(int n = 0; n < 5; n++) - { - NodeRef fourRef = categoryService.createCategory(threeRef, "child_"+i+"_"+j+"_"+k+"_"+l+"_"+m+"_"+n); - for(int o = 0; o < 5; o++) - { - NodeRef fiveRef = categoryService.createCategory(fourRef, "child_"+i+"_"+j+"_"+k+"_"+l+"_"+m+"_"+n+"_"+o); - for(int p = 0; p < 5; p++) - { - @SuppressWarnings("unused") - NodeRef sixRef = categoryService.createCategory(fiveRef, "child_"+i+"_"+j+"_"+k+"_"+l+"_"+m+"_"+n+"_"+o+"_"+p); - } - } - } - } - } - } - } - tx.commit(); - } - - tx = transactionService.getUserTransaction(); - tx.begin(); - start = System.nanoTime(); - assertEquals(startCount + 10, categoryService.getRootCategories(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(), - ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - System.out.println("3 Query complete in "+(System.nanoTime()-start)/1e9f); - tx.commit(); - - tx = transactionService.getUserTransaction(); - tx.begin(); - start = System.nanoTime(); - assertEquals(startCount + 10, categoryService.getRootCategories(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(), - ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - System.out.println("4 Query complete in "+(System.nanoTime()-start)/1e9f); - tx.commit(); - - tx = transactionService.getUserTransaction(); - tx.begin(); - start = System.nanoTime(); - ResultSet set = searcher.query(serviceRegistry.getPersonService().getPeopleContainer().getStoreRef(), "lucene", "@"+SearchLanguageConversion.escapeLuceneQuery(ContentModel.ASPECT_GEN_CLASSIFIABLE.toString())+":second*"); - System.out.println("Query complete in "+(System.nanoTime()-start)/1e9f); - set.close(); - tx.commit(); - - } - - public void testCatCount() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - - - assertEquals(1, categoryService.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.IMMEDIATE).size()); - assertEquals(2, categoryService.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE).size()); - assertEquals(3, categoryService.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.IMMEDIATE).size()); - assertEquals(14, categoryService.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.ANY).size()); - assertEquals(3, categoryService.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY).size()); - assertEquals(17, categoryService.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.ANY).size()); - assertEquals(2, categoryService.getClassifications(rootNodeRef.getStoreRef()).size()); - assertEquals(2, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.IMMEDIATE).size()); - assertEquals(3, categoryService.getCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), CategoryService.Depth.ANY).size()); - assertEquals(7, categoryService.getClassificationAspects().size()); - assertEquals(2, categoryService.getRootCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass")).size()); - - List> top = categoryService.getTopCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "assetClass"), 10); - for(Pair current : top) - { - System.out.println(""+nodeService.getPaths(current.getFirst(), true) + " "+current.getSecond()); - } - - top = categoryService.getTopCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "investmentRegion"), 10); - for(Pair current : top) - { - System.out.println(""+nodeService.getPaths(current.getFirst(), true) + " "+current.getSecond()); - } - - top = categoryService.getTopCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "marketingRegion"), 10); - for(Pair current : top) - { - System.out.println(""+nodeService.getPaths(current.getFirst(), true) + " "+current.getSecond()); - } - - top = categoryService.getTopCategories(rootNodeRef.getStoreRef(), QName.createQName(TEST_NAMESPACE, "region"), 10); - for(Pair current : top) - { - System.out.println(""+nodeService.getPaths(current.getFirst(), true) + " "+current.getSecond()); - } - - tx.commit(); - } - - /** - * See ALF-5594 for details. - */ - public void testCreateMultiLingualCategoryRoots() throws Exception - { - TransactionService transactionService = serviceRegistry.getTransactionService(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - - StoreRef storeRef = catRoot.getStoreRef(); - - // Should initially not have any roots - assertEquals(0, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - // Setup to mimic how CreateCategoryDialogue works - // Create the node to use - nodeService.createNode( - catRoot, ContentModel.ASSOC_CATEGORIES, - ContentModel.ASPECT_GEN_CLASSIFIABLE, - ContentModel.TYPE_CATEGORY - ); - - // Commit this, as it's all search based and otherwise lucene won't see it - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - - - // Should initially not have any roots - assertEquals(0, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - - // First up, try a few in English - String eng1 = "This Is A Name!"; - NodeRef catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, eng1 - ); - - // Commit this, as it's all search based and otherwise lucene won't see it - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - - assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - // Now add a 2nd English one - String eng2 = "This Is Also A Name"; - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, eng2 - ); - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - assertEquals(2, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - // Not allowed to add a duplicate one though - try { - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, eng1 - ); - fail("Shouldn't be allowed to create a duplicate named root category"); - } catch(Exception e) { - tx.rollback(); - tx = transactionService.getUserTransaction(); - tx.begin(); - } - assertEquals(2, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - - // Do a check that the categories exist - assertEquals(0, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, "Does Not Exist", false).size()); - assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, eng1, false).size()); - assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, eng2, false).size()); - - - // Now in French and Spanish - String fr1 = "C'est une tr\u00e8s petite cat\u00e9gorie"; - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, fr1 - ); - String fr2 = "Une autre cat\u00e9gorie"; - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, fr2 - ); - - String es1 = "Una categor\u00eda"; - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, es1 - ); - - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - - assertEquals(5, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - - // Check that they have the accents in them - int also = 0; - int exclamation = 0; - int e_acute = 0; - int e_grave = 0; - int i_acute = 0; - for(ChildAssociationRef cref : categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE)) - { - String name = (String)nodeService.getProperty(cref.getChildRef(), ContentModel.PROP_NAME); - if(name.indexOf('!') != -1) exclamation++; - if(name.indexOf("Also") != -1) also++; - if(name.indexOf('\u00e8') != -1) e_grave++; - if(name.indexOf('\u00e9') != -1) e_acute++; - if(name.indexOf('\u00ed') != -1) i_acute++; - } - assertEquals(1, exclamation); // This Is A Name! - assertEquals(1, also); // This Is Also A Name - assertEquals(1, e_grave); // très, from 1st French one - assertEquals(2, e_acute); // catégorie, in both French ones - assertEquals(1, i_acute); // categoría, in Spanish one - - - // Now try to find them by name - assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, fr1, false).size()); - assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, fr2, false).size()); - assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, es1, false).size()); - - - // Ensure we can't add a duplicate French one - try { - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, fr1 - ); - fail("Shouldn't be allowed to create a duplicate named French root category"); - } catch(Exception e) { - tx.rollback(); - tx = transactionService.getUserTransaction(); - tx.begin(); - } - assertEquals(5, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - - // Finally add some Japanese ones - - // オペレーション中ににシステム - // Shortened to 14 Japanese characters for default DB2 install: ALF-6545 - String jp1 = "\u30aa\u30da\u30ec\u30fc\u30b7\u30e7\u30f3\u4e2d\u306b\u306b\u30b7\u30b9\u30c6\u30e0"; - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, jp1 - ); - // をクリックしてください。 - String jp2 = "\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\u3002"; - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, jp2 - ); - - tx.commit(); - tx = transactionService.getUserTransaction(); - tx.begin(); - -// Testing... What is there in the repo after all? -//for(ChildAssociationRef cref : categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE)) -//{ -// String name = (String)nodeService.getProperty(cref.getChildRef(), ContentModel.PROP_NAME); -// System.err.println(name); -//} - - // Check they're there - assertEquals(7, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - // TODO Fix me so we can find these by name! -// assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, jp1, false).size()); -// assertEquals(1, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, jp2, false).size()); - assertEquals(0, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, jp1.substring(0,5), false).size()); - - // Check we can't add a duplicate Japenese one - try { - catRef = categoryService.createRootCategory( - storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, jp1 - ); - fail("Shouldn't be allowed to create a duplicate named French root category"); - } catch(Exception e) { - tx.rollback(); - tx = transactionService.getUserTransaction(); - tx.begin(); - } - assertEquals(7, categoryService.getRootCategories(storeRef, ContentModel.ASPECT_GEN_CLASSIFIABLE).size()); - - // Finish - tx.commit(); - } - - @SuppressWarnings("unused") - private int getTotalScore(ResultSet results) - { - int totalScore = 0; - for(ResultSetRow row: results) - { - totalScore += row.getScore(); - } - return totalScore; - } -} diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java b/src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java deleted file mode 100644 index c572eab34b..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java +++ /dev/null @@ -1,7927 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Random; - -import javax.transaction.Status; -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.content.transform.TransformerDebug; -import org.alfresco.repo.dictionary.DictionaryDAO; -import org.alfresco.repo.dictionary.DictionaryListener; -import org.alfresco.repo.dictionary.DictionaryNamespaceComponent; -import org.alfresco.repo.dictionary.M2Model; -import org.alfresco.repo.dictionary.NamespaceDAO; -import org.alfresco.repo.node.BaseNodeServiceTest; -import org.alfresco.repo.node.NodeBulkLoader; -import org.alfresco.repo.search.IndexerAndSearcher; -import org.alfresco.repo.search.MLAnalysisMode; -import org.alfresco.repo.search.QueryParameterDefImpl; -import org.alfresco.repo.search.QueryRegisterComponent; -import org.alfresco.repo.search.impl.lucene.analysis.DateTimeAnalyser; -import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; -import org.alfresco.repo.search.impl.querymodel.QueryEngine; -import org.alfresco.repo.search.results.ChildAssocRefResultSet; -import org.alfresco.repo.search.results.DetachedResultSet; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.tenant.TenantService; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; -import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.dictionary.PropertyDefinition; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentData; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.MLText; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.Path; -import org.alfresco.service.cmr.repository.Period; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; -import org.alfresco.service.cmr.repository.datatype.Duration; -import org.alfresco.service.cmr.search.QueryParameter; -import org.alfresco.service.cmr.search.QueryParameterDefinition; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.ResultSetMetaData; -import org.alfresco.service.cmr.search.ResultSetRow; -import org.alfresco.service.cmr.search.SearchParameters; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.DynamicNamespacePrefixResolver; -import org.alfresco.service.namespace.NamespacePrefixResolver; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.CachingDateFormat; -import org.alfresco.util.CachingDateFormat.SimpleDateFormatAndResolution; -import org.alfresco.util.GUID; -import org.alfresco.util.ISO9075; -import org.alfresco.util.SearchLanguageConversion; -import org.alfresco.util.testing.category.LuceneTests; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermDocs; -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.PostgreSQLDialect; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; -import org.springframework.extensions.surf.util.I18NUtil; - -/** - * @author andyh - */ -@SuppressWarnings("unused") -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class ADMLuceneTest extends TestCase implements DictionaryListener -{ - - private static final String TEST_NAMESPACE = "http://www.alfresco.org/test/lucenetest"; - - private static final QName ASSOC_TYPE_QNAME = QName.createQName(TEST_NAMESPACE, "assoc"); - - private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); - - private static Log logger = LogFactory.getLog(ADMLuceneTest.class); - - QName createdDate = QName.createQName(TEST_NAMESPACE, "createdDate"); - - QName orderDouble = QName.createQName(TEST_NAMESPACE, "orderDouble"); - - QName orderFloat = QName.createQName(TEST_NAMESPACE, "orderFloat"); - - QName orderLong = QName.createQName(TEST_NAMESPACE, "orderLong"); - - QName orderInt = QName.createQName(TEST_NAMESPACE, "orderInt"); - - QName orderText = QName.createQName(TEST_NAMESPACE, "orderText"); - - QName orderMLText = QName.createQName(TEST_NAMESPACE, "orderMLText"); - - QName aspectWithChildren = QName.createQName(TEST_NAMESPACE, "aspectWithChildren"); - - TransactionService transactionService; - - RetryingTransactionHelper retryingTransactionHelper; - - NodeService nodeService; - - DictionaryService dictionaryService; - - TenantService tenantService; - - TransformerDebug transformerDebug; - - private NodeRef rootNodeRef; - - private NodeRef n1; - - private NodeRef n2; - - private NodeRef n3; - - private NodeRef n4; - - private NodeRef n5; - - private NodeRef n6; - - private NodeRef n7; - - private NodeRef n8; - - private NodeRef n9; - - private NodeRef n10; - - private NodeRef n11; - - private NodeRef n12; - - private NodeRef n13; - - private NodeRef n14; - - private DictionaryDAO dictionaryDAO; - - private FullTextSearchIndexer luceneFTS; - - private QName testType = QName.createQName(TEST_NAMESPACE, "testType"); - - private QName testSuperType = QName.createQName(TEST_NAMESPACE, "testSuperType"); - - private QName testAspect = QName.createQName(TEST_NAMESPACE, "testAspect"); - - private QName testSuperAspect = QName.createQName(TEST_NAMESPACE, "testSuperAspect"); - - private ContentService contentService; - - private QueryRegisterComponent queryRegisterComponent; - - private DictionaryNamespaceComponent namespacePrefixResolver; - - private IndexerAndSearcher indexerAndSearcher; - - private ServiceRegistry serviceRegistry; - - private UserTransaction testTX; - - private AuthenticationComponent authenticationComponent; - - private NodeRef[] documentOrder; - - private NamespaceDAO namespaceDao; - - private Date testDate; - - private NodeBulkLoader nodeBulkLoader; - - private QueryEngine queryEngine; - - private NodeRef n15; - - private M2Model model; - - // TODO: pending replacement - private Dialect dialect; - - private LuceneConfig luceneConfig; - - /** - * - */ - public ADMLuceneTest() - { - super(); - } - /** - * @param arg0 String - */ - public ADMLuceneTest(String arg0) - { - super(arg0); - } - - public void afterDictionaryDestroy() - { - } - - public void afterDictionaryInit() - { - } - - public void onDictionaryInit() - { - // Register the test model - dictionaryDAO.putModel(model); - } - - public void setUp() throws Exception - { - dialect = (Dialect) ctx.getBean("dialect"); - - nodeService = (NodeService) ctx.getBean("dbNodeService"); - dictionaryService = (DictionaryService) ctx.getBean("dictionaryService"); - dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO"); - luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); - contentService = (ContentService) ctx.getBean("contentService"); - queryRegisterComponent = (QueryRegisterComponent) ctx.getBean("queryRegisterComponent"); - namespacePrefixResolver = (DictionaryNamespaceComponent) ctx.getBean("namespaceService"); - transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug"); - indexerAndSearcher = (IndexerAndSearcher) ctx.getBean("admLuceneIndexerAndSearcherFactory"); - luceneConfig = (LuceneConfig)ctx.getBean("admLuceneIndexerAndSearcherFactory"); - ((LuceneConfig) indexerAndSearcher).setMaxAtomicTransformationTime(1000000); - transactionService = (TransactionService) ctx.getBean("transactionComponent"); - retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper"); - tenantService = (TenantService) ctx.getBean("tenantService"); - queryEngine = (QueryEngine) ctx.getBean("adm.luceneQueryEngineImpl"); - - nodeBulkLoader = (NodeBulkLoader) ctx.getBean("nodeDAO"); - - serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); - - namespaceDao = (NamespaceDAO) ctx.getBean("namespaceDAO"); - - I18NUtil.setLocale(Locale.UK); - - this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); - - queryRegisterComponent.loadQueryCollection("testQueryRegister.xml"); - - assertEquals(true, ctx.isSingleton("LuceneFullTextSearchIndexer")); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - // load in the test model - ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); - InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml"); - assertNotNull(modelStream); - model = M2Model.createModel(modelStream); - dictionaryDAO.registerListener(this); - dictionaryDAO.reset(); - assertNotNull(dictionaryDAO.getClass(testSuperType)); - - StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), testSuperType, getOrderProperties()).getChildRef(); - nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "ValueOne"); - - n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), testSuperType, getOrderProperties()).getChildRef(); - nodeService.setProperty(n2, QName.createQName("{namespace}property-1"), "valueone"); - nodeService.setProperty(n2, QName.createQName("{namespace}property-2"), "valuetwo"); - - n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), testSuperType, getOrderProperties()).getChildRef(); - - ObjectOutputStream oos; - try - { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - oos = new ObjectOutputStream(baos); - oos.writeObject(n3); - oos.close(); - - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - Object o = ois.readObject(); - ois.close(); - } - catch (IOException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - catch (ClassNotFoundException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Map testProperties = new HashMap(); - testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYONE"); - testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYUNSTORED"); - testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED BUT NOT ATOMICALLY KEYTWO"); - testProperties.put(QName.createQName(TEST_NAMESPACE, "int-ista"), Integer.valueOf(1)); - testProperties.put(QName.createQName(TEST_NAMESPACE, "long-ista"), Long.valueOf(2)); - testProperties.put(QName.createQName(TEST_NAMESPACE, "float-ista"), Float.valueOf(3.4f)); - testProperties.put(QName.createQName(TEST_NAMESPACE, "double-ista"), Double.valueOf(5.6)); - //testDate = new Date(((new Date().getTime() - 10000))); - Calendar c = new GregorianCalendar(); - c.setTime(new Date(((new Date().getTime() - 10000)))); - //c.add(Calendar.MINUTE, -1); - //c.set(Calendar.MINUTE, 0); - //c.set(Calendar.MILLISECOND, 999); - //c.set(Calendar.SECOND, 1); - //c.set(Calendar.MILLISECOND, 0); - //c.set(Calendar.SECOND, 0); - //c.set(Calendar.MINUTE, 0); - //c.set(Calendar.HOUR_OF_DAY, 0); -// c.set(Calendar.YEAR, 2000); -// c.set(Calendar.MONTH, 12); -// c.set(Calendar.DAY_OF_MONTH, 31); -// c.set(Calendar.HOUR_OF_DAY, 23); -// c.set(Calendar.MINUTE, 59); -// c.set(Calendar.SECOND, 59); -// c.set(Calendar.MILLISECOND, 999); - testDate = c.getTime(); - testProperties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), testDate); - testProperties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), testDate); - testProperties.put(QName.createQName(TEST_NAMESPACE, "boolean-ista"), Boolean.valueOf(true)); - testProperties.put(QName.createQName(TEST_NAMESPACE, "qname-ista"), QName.createQName("{wibble}wobble")); - testProperties.put(QName.createQName(TEST_NAMESPACE, "category-ista"), new NodeRef(storeRef, "CategoryId")); - testProperties.put(QName.createQName(TEST_NAMESPACE, "noderef-ista"), n1); - testProperties.put(QName.createQName(TEST_NAMESPACE, "path-ista"), nodeService.getPath(n3)); - testProperties.put(QName.createQName(TEST_NAMESPACE, "locale-ista"), Locale.UK); - testProperties.put(QName.createQName(TEST_NAMESPACE, "period-ista"), new Period("period|12")); - testProperties.put(QName.createQName(TEST_NAMESPACE, "null"), null); - testProperties.put(QName.createQName(TEST_NAMESPACE, "list"), new ArrayList()); - MLText mlText = new MLText(); - mlText.addValue(Locale.ENGLISH, "banana"); - mlText.addValue(Locale.FRENCH, "banane"); - mlText.addValue(Locale.CHINESE, "香蕉"); - mlText.addValue(new Locale("nl"), "banaan"); - mlText.addValue(Locale.GERMAN, "banane"); - mlText.addValue(new Locale("el"), "μπανάνα"); - mlText.addValue(Locale.ITALIAN, "banana"); - mlText.addValue(new Locale("ja"), "バナナ"); - mlText.addValue(new Locale("ko"), "바나나"); - mlText.addValue(new Locale("pt"), "banana"); - mlText.addValue(new Locale("ru"), "банан"); - mlText.addValue(new Locale("es"), "plátano"); - testProperties.put(QName.createQName(TEST_NAMESPACE, "ml"), mlText); - // Any multivalued - ArrayList anyValues = new ArrayList(); - anyValues.add(Integer.valueOf(100)); - anyValues.add("anyValueAsString"); - anyValues.add(new UnknownDataType()); - testProperties.put(QName.createQName(TEST_NAMESPACE, "any-many-ista"), anyValues); - // Content multivalued - // - note only one the first value is used from the collection - // - andit has to go in type d:any as d:content is not allowed to be multivalued - - ArrayList contentValues = new ArrayList(); - contentValues.add(new ContentData(null, "text/plain", 0L, "UTF-16", Locale.UK)); - testProperties.put(QName.createQName(TEST_NAMESPACE, "content-many-ista"), contentValues); - - // MLText multivalued - - MLText mlText1 = new MLText(); - mlText1.addValue(Locale.ENGLISH, "cabbage"); - mlText1.addValue(Locale.FRENCH, "chou"); - - MLText mlText2 = new MLText(); - mlText2.addValue(Locale.ENGLISH, "lemur"); - mlText2.addValue(new Locale("ru"), "лемур"); - - ArrayList mlValues = new ArrayList(); - mlValues.add(mlText1); - mlValues.add(mlText2); - - testProperties.put(QName.createQName(TEST_NAMESPACE, "mltext-many-ista"), mlValues); - - // null in multi valued - - ArrayList testList = new ArrayList(); - testList.add(null); - testProperties.put(QName.createQName(TEST_NAMESPACE, "nullist"), testList); - ArrayList testList2 = new ArrayList(); - testList2.add("woof"); - testList2.add(null); - - n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}four"), testType, testProperties).getChildRef(); - - ContentWriter multiWriter = contentService.getWriter(n4, QName.createQName(TEST_NAMESPACE, "content-many-ista"), true); - multiWriter.setEncoding("UTF-16"); - multiWriter.setMimetype("text/plain"); - multiWriter.putContent("multicontent"); - - nodeService.getProperties(n1); - nodeService.getProperties(n2); - nodeService.getProperties(n3); - nodeService.getProperties(n4); - - n5 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}five"), testSuperType, getOrderProperties()).getChildRef(); - n6 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}six"), testSuperType, getOrderProperties()).getChildRef(); - n7 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}seven"), testSuperType, getOrderProperties()).getChildRef(); - n8 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-2"), testSuperType, getOrderProperties()).getChildRef(); - n9 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}nine"), testSuperType, getOrderProperties()).getChildRef(); - n10 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ten"), testSuperType, getOrderProperties()).getChildRef(); - n11 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eleven"), testSuperType, getOrderProperties()).getChildRef(); - n12 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}twelve"), testSuperType, getOrderProperties()).getChildRef(); - n13 = nodeService.createNode(n12, ASSOC_TYPE_QNAME, QName.createQName("{namespace}thirteen"), testSuperType, getOrderProperties()).getChildRef(); - - Map properties = new HashMap(); - - MLText desc1 = new MLText(); - desc1.addValue(Locale.ENGLISH, "Alfresco tutorial"); - desc1.addValue(Locale.US, "Alfresco tutorial"); - - Date explicitCreatedDate = new Date(); - Thread.sleep(2000); - - properties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-8", Locale.UK)); - properties.put(ContentModel.PROP_DESCRIPTION, desc1); - properties.put(ContentModel.PROP_CREATED, explicitCreatedDate); - - //Calendar c = new GregorianCalendar(); - //c.setTime(new Date()); - //c.set(Calendar.MILLISECOND, 0); - //c.set(Calendar.SECOND, 0); - //c.set(Calendar.MINUTE, 0); - //c.set(Calendar.HOUR_OF_DAY, 0); - //testDate = c.getTime(); - //properties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), testDate); - //properties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), testDate); - - // note: cm:content - hence auditable aspect will be applied with any missing mandatory properties (cm:modified, cm:creator, cm:modifier) - n14 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fourteen"), ContentModel.TYPE_CONTENT, properties).getChildRef(); - // nodeService.addAspect(n14, DictionaryBootstrap.ASPECT_QNAME_CONTENT, - // properties); - - assertEquals(explicitCreatedDate, nodeService.getProperty(n14, ContentModel.PROP_CREATED)); - - // note: cm:thumbnail - hence auditable aspect will be applied with mandatory properties (cm:created, cm:modified, cm:creator, cm:modifier) - n15 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fifteen"), ContentModel.TYPE_THUMBNAIL, getOrderProperties()).getChildRef(); - nodeService.setProperty(n15, ContentModel.PROP_CONTENT, new ContentData(null, "text/richtext", 0L, "UTF-8", Locale.FRENCH)); - - ContentWriter writer = contentService.getWriter(n14, ContentModel.PROP_CONTENT, true); - writer.setEncoding("UTF-8"); - // InputStream is = - // this.getClass().getClassLoader().getResourceAsStream("test.doc"); - // writer.putContent(is); - writer.putContent("The quick brown fox jumped over the lazy dog and ate the Alfresco Tutorial, in pdf format, along with the following stop words; a an and are" - + " as at be but by for if in into is it no not of on or such that the their then there these they this to was will with: " - + " and random charcters \u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF"); - // System.out.println("Size is " + writer.getSize()); - - writer = contentService.getWriter(n15, ContentModel.PROP_CONTENT, true); - writer.setEncoding("UTF-8"); - // InputStream is = - // this.getClass().getClassLoader().getResourceAsStream("test.doc"); - // writer.putContent(is); - writer.putContent(" "); - - nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0")); - nodeService.addChild(n1, n8, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-1")); - nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}link")); - - nodeService.addChild(n1, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); - nodeService.addChild(n2, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); - nodeService.addChild(n5, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); - nodeService.addChild(n6, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); - nodeService.addChild(n12, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); - nodeService.addChild(n13, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); - - documentOrder = new NodeRef[] { rootNodeRef, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n3, n1, n2 }; - } - - private double orderDoubleCount = -0.11d; - - private Date orderDate = new Date(); - - private float orderFloatCount = -3.5556f; - - private long orderLongCount = -1999999999999999l; - - private int orderIntCount = -45764576; - - private int orderTextCount = 0; - - /** - * @return properties - */ - public Map getOrderProperties() - { - Map testProperties = new HashMap(); - testProperties.put(createdDate, orderDate); - testProperties.put(orderDouble, orderDoubleCount); - testProperties.put(orderFloat, orderFloatCount); - testProperties.put(orderLong, orderLongCount); - testProperties.put(orderInt, orderIntCount); - testProperties.put(orderText, new String(new char[] { (char) ('a' + orderTextCount) }) + " cabbage"); - - MLText mlText = new MLText(); - mlText.addValue(Locale.ENGLISH, new String(new char[] { (char) ('a' + orderTextCount) }) + " banana"); - mlText.addValue(Locale.FRENCH, new String(new char[] { (char) ('Z' - orderTextCount) }) + " banane"); - mlText.addValue(Locale.CHINESE, new String(new char[] { (char) ('香' + orderTextCount) }) + " 香蕉"); - testProperties.put(orderMLText, mlText); - - orderDate = Duration.subtract(orderDate, new Duration("P1D")); - orderDoubleCount += 0.1d; - orderFloatCount += 0.82f; - orderLongCount += 299999999999999l; - orderIntCount += 8576457; - orderTextCount++; - return testProperties; - } - - @Override - protected void tearDown() throws Exception - { - - if (testTX.getStatus() == Status.STATUS_ACTIVE) - { - testTX.rollback(); - } - AuthenticationUtil.clearCurrentSecurityContext(); - super.tearDown(); - } - - - - /* - * Not normally run as index backup happens at 3.00 - */ - public void doNotTestIndexBackAllowsReadOperations() throws Exception - { - testTX.commit(); - - Thread queryThread = new QueryDuringBackupThread("Query", "PATH:\"//*\"", 2*60*1000); - queryThread.start(); - - Thread createThread = new CreateDuringBackupThread("Create"); - createThread.start(); - - try - { - queryThread.join(); - } - catch (InterruptedException e) - { - e.printStackTrace(); - } - } - - class QueryDuringBackupThread extends Thread - { - String query; - - long period; - - QueryDuringBackupThread(String name, String query, long period) - { - super(name); - this.setDaemon(true); - this.query = query; - this.period = period; - } - - public void run() - { - long startTime = System.currentTimeMillis(); - long currentTime = System.currentTimeMillis(); - authenticationComponent.setSystemUserAsCurrentUser(); - try - { - System.out.println("Start " + this.getName()); - int i = 0; - int length = 0; - while(currentTime - startTime < period) - { - RetryingTransactionCallback queryCallback = new RetryingTransactionCallback() - { - public Integer execute() throws Throwable - { - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery(query); - - ResultSet results = serviceRegistry.getSearchService().query(sp); - int count = results.length(); - results.close(); - return count; - } - }; - length = retryingTransactionHelper.doInTransaction(queryCallback); - i++; - if(i % 1000 == 0) - { - currentTime = System.currentTimeMillis(); - } - System.out.println("Query "+i+" count = "+length); - } - - System.out.println("End " + this.getName()); - } - catch (Exception e) - { - System.out.println("End " + this.getName() + " with error " + e.getMessage()); - e.printStackTrace(); - } - finally - { - authenticationComponent.clearCurrentSecurityContext(); - } - } - - } - - class CreateDuringBackupThread extends Thread - { - - - CreateDuringBackupThread(String name) - { - super(name); - this.setDaemon(true); - } - - public void run() - { - authenticationComponent.setSystemUserAsCurrentUser(); - try - { - System.out.println("Start " + this.getName()); - RetryingTransactionCallback createAndDeleteCallback = new RetryingTransactionCallback() - { - public String execute() throws Throwable - { - String guid = GUID.generate(); - ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}"+guid), testSuperType); - return guid; - } - }; - - while(true) - { - String guid = retryingTransactionHelper.doInTransaction(createAndDeleteCallback); - System.out.println("Created " + guid); - } - } - catch (Exception e) - { - System.out.println("End " + this.getName() + " with error " + e.getMessage()); - e.printStackTrace(); - } - finally - { - authenticationComponent.clearCurrentSecurityContext(); - } - } - - } - - /** - * Not required to run all the time; it's here for profiling. - */ - public void restManyReaders() throws Exception - { - QName propQName = QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"); - - NodeRef base = rootNodeRef; - for (int i = 0; i < 10; i++) - { - NodeRef dir = nodeService.createNode(base, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}d-" + i), testSuperType, null).getChildRef(); - for (int j = 0; j < 100; j++) - { - Map properties = new HashMap(); - properties.put(propQName, "lemon"); - NodeRef file = nodeService.createNode(dir, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}meep"), testSuperType, properties).getChildRef(); - } - } - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//meep\""); - int count = results.length(); - assertTrue(count > 0); - results.close(); - testTX.commit(); - - Thread runner = null; - - // testQuery(searcher, runner, "PATH:\"/d-0/*\""); - // testQuery(searcher, runner, "PATH:\"/d-0/meep\""); - // testQuery(searcher, runner, "PATH:\"/d-0//*\""); - // testQuery(searcher, runner, "PATH:\"/d-0//meep\""); - testQuery(searcher, runner, "PATH:\"//*\""); - // testQuery(searcher, runner, "PATH:\"//meep\""); - // testQuery(searcher, runner, "@"+SearchLanguageConversion.escapeLuceneQuery(propQName.toString())+":\"lemon\""); - - } - - private void testQuery(ADMLuceneSearcherImpl searcher, Thread runner, String query) - { - for (int i = 0; i < 1; i++) - { - runner = new QueryThread("Concurrent-" + i, runner, searcher, query); - } - long start = System.nanoTime(); - if (runner != null) - { - runner.start(); - - try - { - runner.join(); - } - catch (InterruptedException e) - { - e.printStackTrace(); - } - } - long end = System.nanoTime(); - System.out.println(query + "\t" + ((end - start) / 1e9f)); - } - - class QueryThread extends Thread - { - Thread waiter; - - ADMLuceneSearcherImpl searcher; - - String query; - - QueryThread(String name, Thread waiter, ADMLuceneSearcherImpl searcher, String query) - { - super(name); - this.setDaemon(true); - this.waiter = waiter; - this.searcher = searcher; - this.query = query; - } - - public void run() - { - authenticationComponent.setSystemUserAsCurrentUser(); - if (waiter != null) - { - waiter.start(); - } - try - { - // System.out.println("Start " + this.getName()); - - RetryingTransactionCallback createAndDeleteCallback = new RetryingTransactionCallback() - { - public Object execute() throws Throwable - { - for (int i = 0; i < 100; i++) - { - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", query); - int count = results.length(); - for (ResultSetRow row : results) - { - NodeRef nr = row.getNodeRef(); - } - results.close(); - } - return null; - } - }; - retryingTransactionHelper.doInTransaction(createAndDeleteCallback); - - // System.out.println("End " + this.getName()); - } - catch (Exception e) - { - System.out.println("End " + this.getName() + " with error " + e.getMessage()); - e.printStackTrace(); - } - finally - { - authenticationComponent.clearCurrentSecurityContext(); - } - if (waiter != null) - { - try - { - waiter.join(); - } - catch (InterruptedException e) - { - } - } - } - - } - - private IndexReader getIndexReader() - { - ADMLuceneSearcherImpl searcher = buildSearcher(); - return searcher.getSearcher().getIndexReader(); - } - - public void testMaskDeletes() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - ResultSet results = serviceRegistry.getSearchService().query(sp); - int initialCount = results.length(); - results.close(); - - for (int j = 0; j < 20; j++) - { - ArrayList added = new ArrayList(); - for (int i = 0; i < 50; i++) - { - Map properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, "Mask " + i); - added.add(nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "mask-" + i), testSuperType, - properties).getChildRef()); - } - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - int count = 0; - IndexReader indexReader = getIndexReader(); - TermDocs termDocs = indexReader.termDocs(new Term("@{http://www.alfresco.org/model/content/1.0}name", "mask")); - if (termDocs.next()) - { - count++; - while (termDocs.skipTo(termDocs.doc())) - { - count++; - } - } - termDocs.close(); - assertEquals(added.size() + j, count); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//cm:*\" AND @cm\\:name:(0 1 2 3 4 5 6 7 8 9) AND ISNOTNULL:\"cm:name\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - results.close(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("@cm\\:name:\"mask 1\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - results.close(); - - for (int i = 0; i < added.size() - 1; i++) - { - Map properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, "Mask " + i); - nodeService.setProperties(added.get(i), properties); - } - - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//cm:*\" AND @cm\\:name:(0 1 2 3 4 5 6 7 8 9) AND ISNOTNULL:\"cm:name\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - results.close(); - - count = 0; - indexReader = getIndexReader(); - termDocs = indexReader.termDocs(new Term("@{http://www.alfresco.org/model/content/1.0}name", "mask")); - if (termDocs.next()) - { - count++; - while (termDocs.skipTo(termDocs.doc())) - { - count++; - } - } - termDocs.close(); - assertEquals(added.size() + j, count); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("@cm\\:name:\"mask 1\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - results.close(); - - for (int i = 0; i < added.size() - 1; i++) - { - Map properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, "Mask " + i); - nodeService.deleteNode(added.get(i)); - } - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - count = 0; - indexReader = getIndexReader(); - termDocs = indexReader.termDocs(new Term("@{http://www.alfresco.org/model/content/1.0}name", "mask")); - if (termDocs.next()) - { - count++; - while (termDocs.skipTo(termDocs.doc())) - { - count++; - } - } - termDocs.close(); - assertEquals(j+1, count); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//cm:*\" AND @cm\\:name:(0 1 2 3 4 5 6 7 8 9) AND ISNOTNULL:\"cm:name\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - results.close(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("@cm\\:name:\"mask 1\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - results.close(); - } - - } - - public void testQuoting() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("TEXT:\"te\\\"thing\\\"st\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - ResultSet results = serviceRegistry.getSearchService().query(sp); - results.close(); - } - - public void test_ALF_8007() throws Exception - { - // Check that updates before and after queries do not produce duplicates - - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - this.authenticationComponent.setCurrentUser("admin"); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - ResultSet results; - ResultSetMetaData md; - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - Map properties = new HashMap(); - - properties.put(ContentModel.PROP_NAME, "ALF-8007"); - NodeRef one = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ALF-8007"), ContentModel.TYPE_CONTENT, properties).getChildRef(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - MLText desc1 = new MLText(); - desc1.addValue(Locale.ENGLISH, "ALF 8007"); - desc1.addValue(Locale.US, "ALF 8007"); - - nodeService.setProperty(one, ContentModel.PROP_DESCRIPTION, desc1); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - // check delete after update does delete from the index - // ALF-8007 - // Already seen the delete in the TX and it is skipped (should only skip deletes in the same flush) - - nodeService.deleteNode(one); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - // Check unreported ... create, query, update, delete - // ... create, query, move, delete - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-2\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, "ALF-8007-2"); - NodeRef two = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ALF-8007-2"), ContentModel.TYPE_CONTENT, properties).getChildRef(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-2\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - desc1 = new MLText(); - desc1.addValue(Locale.ENGLISH, "ALF 8007 2"); - desc1.addValue(Locale.US, "ALF 8007 2"); - - nodeService.setProperty(two, ContentModel.PROP_DESCRIPTION, desc1); - nodeService.deleteNode(two); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-2\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - // ... create, query, move, delete - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-3\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, "ALF-8007-3"); - NodeRef three = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ALF-8007-3"), ContentModel.TYPE_CONTENT, properties).getChildRef(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-3\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - desc1 = new MLText(); - desc1.addValue(Locale.ENGLISH, "ALF 8007 3"); - desc1.addValue(Locale.US, "ALF 8007 3"); - - nodeService.moveNode(three, n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ALF-8007-3")); - nodeService.deleteNode(three); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-3\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - // ... create, move, query, delete - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-4\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - properties = new HashMap(); - properties.put(ContentModel.PROP_NAME, "ALF-8007-4"); - NodeRef four = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ALF-8007-4"), ContentModel.TYPE_CONTENT, properties).getChildRef(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-4\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - desc1 = new MLText(); - desc1.addValue(Locale.ENGLISH, "ALF 8007 4"); - desc1.addValue(Locale.US, "ALF 8007 4"); - - nodeService.moveNode(four, n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ALF-8007-4")); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-4\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - nodeService.deleteNode(four); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("cm:name:\"ALF-8007-4\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - } - - public void testPublicServiceSearchServicePaging() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - List expected = new ArrayList(15); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("PATH:\"//.\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - ResultSet results; - ResultSetMetaData md; - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - md = results.getResultSetMetaData(); - for (ResultSetRow row : results) - { - expected.add(row.getNodeRef()); - } - results.close(); - for (int skip = 0; skip < 20; skip++) - { - for (int max = 0; max < 20; max++) - { - doPage(expected, skip, max, sp, serviceRegistry.getSearchService()); - } - } - - this.authenticationComponent.setCurrentUser("admin"); - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - sp.setMaxPermissionChecks(2); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(2, results.length()); - results.close(); - - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setMaxPermissionChecks(2); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(2, results.length()); - results.close(); - - // Even though it is picked up they go though before the time moves on - // sp.setMaxPermissionChecks(-1); - // sp.setMaxPermissionCheckTimeMillis(0); - // results = serviceRegistry.getSearchService().query(sp); - // assertEquals(0, results.length()); - // results.close(); - - } - - private void doPage(List expected, int skip, int max, SearchParameters sp, SearchService searcher) - { - sp.setSkipCount(skip); - sp.setMaxItems(max); - ResultSet results = searcher.query(sp); - assertEquals("Skip = " + skip + " max = " + max, skip + max > 16 ? Math.max(16 - skip, 0) : max, results.length()); - assertEquals("Skip = " + skip + " max = " + max, (skip + max) < 16, results.hasMore()); - assertEquals("Skip = " + skip + " max = " + max, skip, results.getStart()); - int actualPosition = skip; - for (ResultSetRow row : results) - { - NodeRef nodeRef = row.getNodeRef(); - assertEquals("Skip = " + skip + " max = " + max + " actual = " + actualPosition, expected.get(actualPosition), nodeRef); - actualPosition++; - } - results.close(); - } - - public void testNonPublicSearchServicePaging() throws InterruptedException - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - List expected = new ArrayList(15); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery("PATH:\"//.\""); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(true); - - ResultSet results; - ResultSetMetaData md; - - results = searcher.query(sp); - assertEquals(16, results.length()); - md = results.getResultSetMetaData(); - for (ResultSetRow row : results) - { - expected.add(row.getNodeRef()); - } - results.close(); - - for (int skip = 0; skip < 20; skip++) - { - for (int max = 0; max < 20; max++) - { - doPage(expected, skip, max, sp, searcher); - } - } - - } - - private void doPage(List expected, int skip, int max, SearchParameters sp, ADMLuceneSearcherImpl searcher) - { - sp.setSkipCount(skip); - sp.setMaxItems(max); - ResultSet results = searcher.query(sp); - assertEquals("Skip = " + skip + " max = " + max, skip + max > 16 ? Math.max(16 - skip, 0) : max, results.length()); - assertEquals("Skip = " + skip + " max = " + max, (skip + max) < 16, results.hasMore()); - assertEquals("Skip = " + skip + " max = " + max, skip, results.getStart()); - int actualPosition = skip; - for (ResultSetRow row : results) - { - NodeRef nodeRef = row.getNodeRef(); - assertEquals("Skip = " + skip + " max = " + max + " actual = " + actualPosition, expected.get(actualPosition), nodeRef); - actualPosition++; - } - results.close(); - } - - public void testAlfrescoSql() throws InterruptedException - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - alfrescoSqlQueryWithCount(searcher, "SELECT * FROM cmis:document", 1); - alfrescoSqlQueryWithCount(searcher, "SELECT * FROM cmis:document D JOIN cm:ownable O ON D.cmis:objectId = O.cmis:objectId", 0); - } - - public void alfrescoSqlQueryWithCount(ADMLuceneSearcherImpl searcher, String query, int count) - { - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), SearchService.LANGUAGE_CMIS_ALFRESCO, query, null); - assertEquals(count, results.length()); - results.getResultSetMetaData(); - results.close(); - } - - public void testCmisSql() throws InterruptedException - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - sqlQueryWithCount(searcher, "SELECT * FROM cmis:document", 1); - sqlQueryWithCount(searcher, "SELECT * FROM cmis:document D WHERE CONTAINS(D,'lazy')", 1); - } - - public void sqlQueryWithCount(ADMLuceneSearcherImpl searcher, String query, int count) - { - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), SearchService.LANGUAGE_CMIS_STRICT, query, null); - assertEquals(count, results.length()); - results.getResultSetMetaData(); - results.close(); - } - - public void testFtsSort() throws Throwable - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery("-eager or -dog"); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.addSort(ContentModel.PROP_NODE_UUID.toString(), true); - ResultSet results = searcher.query(sp); - assertEquals(16, results.length()); - - String f = null; - for (ResultSetRow row : results) - { - String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NODE_UUID)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (f != null) - { - assertTrue(f.compareTo(currentBun) <= 0); - } - f = currentBun; - } - - results.close(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery("-eager or -dog"); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.addSort(ContentModel.PROP_NODE_UUID.toString(), false); - results = searcher.query(sp); - assertEquals(16, results.length()); - - f = null; - for (ResultSetRow row : results) - { - String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NODE_UUID)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (f != null) - { - assertTrue(f.compareTo(currentBun) >= 0); - } - f = currentBun; - } - - results.close(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery("-eager or -dog"); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.addSort("@" + ContentModel.PROP_NODE_UUID.toString(), false); - results = searcher.query(sp); - assertEquals(16, results.length()); - - f = null; - for (ResultSetRow row : results) - { - String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NODE_UUID)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (f != null) - { - assertTrue(f.compareTo(currentBun) >= 0); - } - f = currentBun; - } - - results.close(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery("-eager or -dog"); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.addSort("cm:name", false); - results = searcher.query(sp); - assertEquals(16, results.length()); - - f = null; - for (ResultSetRow row : results) - { - String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NODE_UUID)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (f != null) - { - assertTrue(f.compareTo(currentBun) >= 0); - } - f = currentBun; - } - - results.close(); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery("-eager or -dog"); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.addSort("lucene-test:neverIndexed", false); - results = searcher.query(sp); - assertEquals(16, results.length()); - results.close(); - - } - - public void testFTS() throws InterruptedException - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ftsQueryWithCount(searcher, "\"lazy\"", 1); - ftsQueryWithCount(searcher, "lazy and dog", 1); - ftsQueryWithCount(searcher, "-lazy and -dog", 15); - ftsQueryWithCount(searcher, "-lazy and dog", 0); - ftsQueryWithCount(searcher, "lazy and -dog", 0); - ftsQueryWithCount(searcher, "|lazy and |dog", 1); - ftsQueryWithCount(searcher, "|eager and |dog", 1); - ftsQueryWithCount(searcher, "|lazy and |wolf", 1); - ftsQueryWithCount(searcher, "|eager and |wolf", 0); - ftsQueryWithCount(searcher, "-lazy or -dog", 15); - ftsQueryWithCount(searcher, "-eager or -dog", 16); - ftsQueryWithCount(searcher, "-lazy or -wolf", 16); - ftsQueryWithCount(searcher, "-eager or -wolf", 16); - ftsQueryWithCount(searcher, "lazy dog", 1); - ftsQueryWithCount(searcher, "lazy and not dog", 0); - ftsQueryWithCount(searcher, "lazy not dog", 16); - ftsQueryWithCount(searcher, "lazy and !dog", 0); - ftsQueryWithCount(searcher, "lazy !dog", 16); - ftsQueryWithCount(searcher, "lazy and -dog", 0); - ftsQueryWithCount(searcher, "lazy -dog", 16); - ftsQueryWithCount(searcher, "TEXT:\"lazy\"", 1); - ftsQueryWithCount(searcher, "cm_content:\"lazy\"", 1); - ftsQueryWithCount(searcher, "=cm_content:\"lazy\"", 1); - ftsQueryWithCount(searcher, "~cm_content:\"lazy\"", 1); - ftsQueryWithCount(searcher, "cm:content:big OR cm:content:lazy", 1); - ftsQueryWithCount(searcher, "cm:content:big AND cm:content:lazy", 0); - ftsQueryWithCount(searcher, "{http://www.alfresco.org/model/content/1.0}content:\"lazy\"", 1); - ftsQueryWithCount(searcher, "=lazy", 1); - ftsQueryWithCount(searcher, "@cm:content:big OR @cm:content:lazy", 1); - ftsQueryWithCount(searcher, "@cm:content:big AND @cm:content:lazy", 0); - ftsQueryWithCount(searcher, "@{http://www.alfresco.org/model/content/1.0}content:\"lazy\"", 1); - ftsQueryWithCount(searcher, "~@cm:content:big OR ~@cm:content:lazy", 1); - ftsQueryWithCount(searcher, "brown * quick", 0); - ftsQueryWithCount(searcher, "brown * dog", 1); - ftsQueryWithCount(searcher, "brown * dog", 1); - ftsQueryWithCount(searcher, "brown *(0) dog", 0); - ftsQueryWithCount(searcher, "brown *(1) dog", 0); - ftsQueryWithCount(searcher, "brown *(2) dog", 0); - ftsQueryWithCount(searcher, "brown *(3) dog", 0); - ftsQueryWithCount(searcher, "brown *(4) dog", 1); // "the" does not count - ftsQueryWithCount(searcher, "brown *(5) dog", 1); - ftsQueryWithCount(searcher, "brown *(6) dog", 1); - ftsQueryWithCount(searcher, "TEXT:(\"lazy\")", 1); - ftsQueryWithCount(searcher, "TEXT:(lazy and dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(-lazy and -dog)", 15); - ftsQueryWithCount(searcher, "TEXT:(-lazy and dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(lazy and -dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(|lazy and |dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(|eager and |dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(|lazy and |wolf)", 1); - ftsQueryWithCount(searcher, "TEXT:(|eager and |wolf)", 0); - ftsQueryWithCount(searcher, "TEXT:(-lazy or -dog)", 15); - ftsQueryWithCount(searcher, "TEXT:(-eager or -dog)", 16); - ftsQueryWithCount(searcher, "TEXT:(-lazy or -wolf)", 16); - ftsQueryWithCount(searcher, "TEXT:(-eager or -wolf)", 16); - ftsQueryWithCount(searcher, "TEXT:(lazy dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(lazy and not dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(lazy not dog)", 16); - ftsQueryWithCount(searcher, "TEXT:(lazy and !dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(lazy !dog)", 16); - ftsQueryWithCount(searcher, "TEXT:(lazy and -dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(lazy -dog)", 16); - ftsQueryWithCount(searcher, "cm_content:(\"lazy\")", 1); - ftsQueryWithCount(searcher, "cm:content:(big OR lazy)", 1); - ftsQueryWithCount(searcher, "cm:content:(big AND lazy)", 0); - ftsQueryWithCount(searcher, "{http://www.alfresco.org/model/content/1.0}content:(\"lazy\")", 1); - ftsQueryWithCount(searcher, "TEXT:(=lazy)", 1); - ftsQueryWithCount(searcher, "@cm:content:(big) OR @cm:content:(lazy)", 1); - ftsQueryWithCount(searcher, "@cm:content:(big) AND @cm:content:(lazy)", 0); - ftsQueryWithCount(searcher, "@{http://www.alfresco.org/model/content/1.0}content:(\"lazy\")", 1); - ftsQueryWithCount(searcher, "@cm:content:(~big OR ~lazy)", 1); - ftsQueryWithCount(searcher, "TEXT:(brown * quick)", 0); - ftsQueryWithCount(searcher, "TEXT:(brown * dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(brown * dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(brown *(0) dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(brown *(1) dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(brown *(2) dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(brown *(3) dog)", 0); - ftsQueryWithCount(searcher, "TEXT:(brown *(4) dog)", 1); // "the" does not count - ftsQueryWithCount(searcher, "TEXT:(brown *(5) dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(brown *(6) dog)", 1); - - ftsQueryWithCount(searcher, "cm:content.mimetype:\"text/plain\"", 1); - ftsQueryWithCount(searcher, "cm_content.mimetype:\"text/plain\"", 1); - ftsQueryWithCount(searcher, "@cm:content.mimetype:\"text/plain\"", 1); - ftsQueryWithCount(searcher, "@cm_content.mimetype:\"text/plain\"", 1); - ftsQueryWithCount(searcher, "content.mimetype:\"text/plain\"", 1); - ftsQueryWithCount(searcher, "@{http://www.alfresco.org/model/content/1.0}content.mimetype:\"text/plain\"", 1); - ftsQueryWithCount(searcher, "{http://www.alfresco.org/model/content/1.0}content.mimetype:\"text/plain\"", 1); - - try - { - ftsQueryWithCount(searcher, "brown..dog", 1); // is this allowed?? - fail("Range query should not be supported against type d:content"); - } - catch (UnsupportedOperationException e) - { - - } - - try - { - ftsQueryWithCount(searcher, "TEXT:brown..dog", 1); - fail("Range query should not be supported against type d:content"); - } - catch (UnsupportedOperationException e) - { - - } - - try - { - ftsQueryWithCount(searcher, "cm:content:brown..dog", 1); - fail("Range query should not be supported against type d:content"); - } - catch (UnsupportedOperationException e) - { - - } - - QName qname = QName.createQName(TEST_NAMESPACE, "float\\-ista"); - ftsQueryWithCount(searcher, qname + ":3.40", 1); - ftsQueryWithCount(searcher, qname + ":3..4", 1); - ftsQueryWithCount(searcher, qname + ":3..3.39", 0); - ftsQueryWithCount(searcher, qname + ":3..3.40", 1); - ftsQueryWithCount(searcher, qname + ":3.41..3.9", 0); - ftsQueryWithCount(searcher, qname + ":3.40..3.9", 1); - - ftsQueryWithCount(searcher, qname + ":[3 TO 4]", 1); - ftsQueryWithCount(searcher, qname + ":[3 TO 3.39]", 0); - ftsQueryWithCount(searcher, qname + ":[3 TO 3.4]", 1); - ftsQueryWithCount(searcher, qname + ":[3.41 TO 4]", 0); - ftsQueryWithCount(searcher, qname + ":[3.4 TO 4]", 1); - ftsQueryWithCount(searcher, qname + ":[3 TO 3.4>", 0); - ftsQueryWithCount(searcher, qname + ":<3.4 TO 4]", 0); - ftsQueryWithCount(searcher, qname + ":<3.4 TO 3.4>", 0); - - ftsQueryWithCount(searcher, qname + ":(3.40)", 1); - ftsQueryWithCount(searcher, qname + ":(3..4)", 1); - ftsQueryWithCount(searcher, qname + ":(3..3.39)", 0); - ftsQueryWithCount(searcher, qname + ":(3..3.40)", 1); - ftsQueryWithCount(searcher, qname + ":(3.41..3.9)", 0); - ftsQueryWithCount(searcher, qname + ":(3.40..3.9)", 1); - - ftsQueryWithCount(searcher, qname + ":([3 TO 4])", 1); - ftsQueryWithCount(searcher, qname + ":([3 TO 3.39])", 0); - ftsQueryWithCount(searcher, qname + ":([3 TO 3.4])", 1); - ftsQueryWithCount(searcher, qname + ":([3.41 TO 4])", 0); - ftsQueryWithCount(searcher, qname + ":([3.4 TO 4])", 1); - ftsQueryWithCount(searcher, qname + ":([3 TO 3.4>)", 0); - ftsQueryWithCount(searcher, qname + ":(<3.4 TO 4])", 0); - ftsQueryWithCount(searcher, qname + ":(<3.4 TO 3.4>)", 0); - - ftsQueryWithCount(searcher, "lucene\\-test:float_x002D_ista:3.40", 1); - - ftsQueryWithCount(searcher, "lazy", 1); - ftsQueryWithCount(searcher, "laz*", 1); - ftsQueryWithCount(searcher, "l*y", 1); - ftsQueryWithCount(searcher, "l??y", 1); - ftsQueryWithCount(searcher, "?az?", 1); - ftsQueryWithCount(searcher, "*zy", 1); - - ftsQueryWithCount(searcher, "\"lazy\"", 1); - ftsQueryWithCount(searcher, "\"laz*\"", 1); - ftsQueryWithCount(searcher, "\"l*y\"", 1); - ftsQueryWithCount(searcher, "\"l??y\"", 1); - ftsQueryWithCount(searcher, "\"?az?\"", 1); - ftsQueryWithCount(searcher, "\"*zy\"", 1); - - ftsQueryWithCount(searcher, "cm:content:lazy", 1); - ftsQueryWithCount(searcher, "cm:content:laz*", 1); - ftsQueryWithCount(searcher, "cm:content:l*y", 1); - ftsQueryWithCount(searcher, "cm:content:l??y", 1); - ftsQueryWithCount(searcher, "cm:content:?az?", 1); - ftsQueryWithCount(searcher, "cm:content:*zy", 1); - - ftsQueryWithCount(searcher, "cm:content:\"lazy\"", 1); - ftsQueryWithCount(searcher, "cm:content:\"laz*\"", 1); - ftsQueryWithCount(searcher, "cm:content:\"l*y\"", 1); - ftsQueryWithCount(searcher, "cm:content:\"l??y\"", 1); - ftsQueryWithCount(searcher, "cm:content:\"?az?\"", 1); - ftsQueryWithCount(searcher, "cm:content:\"*zy\"", 1); - - ftsQueryWithCount(searcher, "cm:content:(lazy)", 1); - ftsQueryWithCount(searcher, "cm:content:(laz*)", 1); - ftsQueryWithCount(searcher, "cm:content:(l*y)", 1); - ftsQueryWithCount(searcher, "cm:content:(l??y)", 1); - ftsQueryWithCount(searcher, "cm:content:(?az?)", 1); - ftsQueryWithCount(searcher, "cm:content:(*zy)", 1); - - ftsQueryWithCount(searcher, "cm:content:(\"lazy\")", 1); - ftsQueryWithCount(searcher, "cm:content:(\"laz*\")", 1); - ftsQueryWithCount(searcher, "cm:content:(\"l*y\")", 1); - ftsQueryWithCount(searcher, "cm:content:(\"l??y\")", 1); - ftsQueryWithCount(searcher, "cm:content:(\"?az?\")", 1); - ftsQueryWithCount(searcher, "cm:content:(\"*zy\")", 1); - - ftsQueryWithCount(searcher, "lazy^2 dog^4.2", 1); - - ftsQueryWithCount(searcher, "lazy~0.7", 1); - ftsQueryWithCount(searcher, "cm:content:laxy~0.7", 1); - ftsQueryWithCount(searcher, "laxy~0.7", 1); - ftsQueryWithCount(searcher, "=laxy~0.7", 1); - ftsQueryWithCount(searcher, "~laxy~0.7", 1); - - ftsQueryWithCount(searcher, "\"quick fox\"~0", 0); - ftsQueryWithCount(searcher, "\"quick fox\"~1", 1); - ftsQueryWithCount(searcher, "\"quick fox\"~2", 1); - ftsQueryWithCount(searcher, "\"quick fox\"~3", 1); - - ftsQueryWithCount(searcher, "\"fox quick\"~0", 0); - ftsQueryWithCount(searcher, "\"fox quick\"~1", 0); - ftsQueryWithCount(searcher, "\"fox quick\"~2", 0); - ftsQueryWithCount(searcher, "\"fox quick\"~3", 1); - - ftsQueryWithCount(searcher, "lazy", 1); - ftsQueryWithCount(searcher, "-lazy", 15); - ftsQueryWithCount(searcher, "lazy -lazy", 16, null, n2); - ftsQueryWithCount(searcher, "lazy^20 -lazy", 16, n14, null); - ftsQueryWithCount(searcher, "lazy^20 -lazy^20", 16, n14, null); - - ftsQueryWithCount(searcher, "cm:content:lazy", 1); - // Simple template - ftsQueryWithCount(searcher, "ANDY:lazy", 1); - // default namesapce cm - ftsQueryWithCount(searcher, "content:lazy", 1); - - ftsQueryWithCount(searcher, "PATH:\"//.\"", 16); - - ftsQueryWithCount(searcher, "+PATH:\"/app:company_home/st:sites/cm:rmtestnew1/cm:documentLibrary//*\"", 0); - ftsQueryWithCount(searcher, "+PATH:\"/app:company_home/st:sites/cm:rmtestnew1/cm:documentLibrary//*\" -TYPE:\"{http://www.alfresco.org/model/content/1.0}thumbnail\"", 15); - ftsQueryWithCount(searcher, "+PATH:\"/app:company_home/st:sites/cm:rmtestnew1/cm:documentLibrary//*\" AND -TYPE:\"{http://www.alfresco.org/model/content/1.0}thumbnail\"", - 0); - - ftsQueryWithCount(searcher, "(brown *(6) dog)", 1); - ftsQueryWithCount(searcher, "TEXT:(brown *(6) dog)", 1); - ftsQueryWithCount(searcher, "\"//.\"", 0); - ftsQueryWithCount(searcher, "PATH", "\"//.\"", 16); - ftsQueryWithCount(searcher, "cm:content:brown", 1); - ftsQueryWithCount(searcher, "ANDY:brown", 1); - ftsQueryWithCount(searcher, "andy:brown", 1); - ftsQueryWithCount(searcher, "ANDY", "brown", 1); - ftsQueryWithCount(searcher, "andy", "brown", 1); - - // test date ranges - note: expected 2 results = n14 (cm:content) and n15 (cm:thumbnail) - ftsQueryWithCount(searcher, "modified:*", 2, Arrays.asList(new NodeRef[]{n14,n15})); - ftsQueryWithCount(searcher, "modified:[MIN TO NOW]", 2, Arrays.asList(new NodeRef[]{n14,n15})); - } - - - private ADMLuceneSearcherImpl buildSearcher() - { - ADMLuceneSearcherImpl searcher = ADMLuceneSearcherImpl.getSearcher(rootNodeRef.getStoreRef(), luceneConfig); - searcher.setNodeService(nodeService); - searcher.setDictionaryService(dictionaryService); - searcher.setTenantService(tenantService); - searcher.setNamespacePrefixResolver(getNamespacePrefixResolver("namespace")); - searcher.setQueryRegister(queryRegisterComponent); - searcher.setQueryLanguages(indexerAndSearcher.getQueryLanguages()); - return searcher; - } - - public void testFTSandSort() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - ADMLuceneSearcherImpl searcher = buildSearcher(); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery( "PATH:\"//.\""); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.addSort("@"+ContentModel.PROP_CONTENT.toString()+".size", true); - ResultSet results = searcher.query(sp); - assertEquals(16, results.length()); - results.close(); - } - - public void ftsQueryWithCount(ADMLuceneSearcherImpl searcher, String query, int count) - { - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery(query); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - ResultSet results = searcher.query(sp); - assertEquals(count, results.length()); - results.close(); - } - - public void ftsQueryWithCount(ADMLuceneSearcherImpl searcher, String defaultFieldName, String query, int count) - { - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setQuery(query); - sp.addQueryTemplate("ANDY", "%cm:content"); - sp.setNamespace(NamespaceService.CONTENT_MODEL_1_0_URI); - sp.excludeDataInTheCurrentTransaction(true); - sp.setDefaultFieldName(defaultFieldName); - ResultSet results = searcher.query(sp); - assertEquals(count, results.length()); - results.close(); - } - - public void ftsQueryWithCount(ADMLuceneSearcherImpl searcher, String query, int count, NodeRef first, NodeRef last) - { - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), SearchService.LANGUAGE_FTS_ALFRESCO, query, null); - for (ResultSetRow row : results) - { - System.out.println("" + row.getScore() + nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NAME)); - } - assertEquals(count, results.length()); - if (first != null) - { - assertEquals(first, results.getNodeRef(0)); - } - if (last != null) - { - assertEquals(last, results.getNodeRef(results.length() - 1)); - } - results.close(); - } - - public void ftsQueryWithCount(ADMLuceneSearcherImpl searcher, String query, int count, List expectedList) - { - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), SearchService.LANGUAGE_FTS_ALFRESCO, query, null); - for (ResultSetRow row : results) - { - System.out.println("" + row.getScore() + nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NAME)); - } - assertEquals(count, results.length()); - - List actualList = results.getNodeRefs(); - - for (NodeRef expected : expectedList) - { - assertTrue("did not find "+expected, actualList.contains(expected)); - } - - results.close(); - } - - public void testOverWritetoZeroSize() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - testTX.commit(); - - for (int i = 0; i < 50; i++) - { - testTX = transactionService.getUserTransaction(); - testTX.begin(); - runBaseTests(); - nodeService.setProperty(rootNodeRef, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n1, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n2, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n3, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n4, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n5, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n6, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n7, QName.createQName("{namespace}property-A"), "A"); - runBaseTests(); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - runBaseTests(); - nodeService.setProperty(n8, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n9, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n10, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n11, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n12, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n13, QName.createQName("{namespace}property-A"), "A"); - nodeService.setProperty(n14, QName.createQName("{namespace}property-A"), "A"); - runBaseTests(); - testTX.commit(); - } - - } - - public void testBulkResultSet1() throws Exception - { - doBulkTest(1); - } - - public void testBulkResultSet10() throws Exception - { - doBulkTest(10); - } - - public void testBulkResultSet100() throws Exception - { - - doBulkTest(100); - } - - public void testBulkResultSet1000() throws Exception - { - doBulkTest(1000); - } - - public void xtestBulkResultSet10000() throws Exception - { - doBulkTest(10000); - } - - private void doBulkTest(int n) throws Exception - { - Map testProperties = new HashMap(); - testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"), "BULK"); - for (int i = 0; i < n; i++) - { - nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}texas-" + i), testSuperType, testProperties).getChildRef(); - } - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(false); - results.setBulkFetchSize(10); - assertEquals(n, results.length()); - results.close(); - - getCold(searcher, n); - getWarm(searcher, n); - getCold(searcher, n); - getCold10(searcher, n); - getCold100(searcher, n); - getCold1000(searcher, n); - getCold10000(searcher, n); - - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - } - - private void getCold(ADMLuceneSearcherImpl searcher, int n) - { - nodeBulkLoader.clear(); - - long start; - - long end; - - start = System.nanoTime(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(false); - results.setBulkFetchSize(0); - for (ResultSetRow row : results) - { - nodeService.getAspects(row.getNodeRef()); - nodeService.getProperties(row.getNodeRef()); - } - results.close(); - - end = System.nanoTime(); - - System.out.println(n + " Cold in " + ((end - start) / 10e9)); - } - - private void getWarm(ADMLuceneSearcherImpl searcher, int n) - { - - long start; - - long end; - - start = System.nanoTime(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(false); - results.setBulkFetchSize(0); - for (ResultSetRow row : results) - { - nodeService.getAspects(row.getNodeRef()); - nodeService.getProperties(row.getNodeRef()); - } - results.close(); - - end = System.nanoTime(); - - System.out.println(n + " Warm in " + ((end - start) / 10e9)); - } - - private void getCold10(ADMLuceneSearcherImpl searcher, int n) - { - nodeBulkLoader.clear(); - - long start; - - long end; - - start = System.nanoTime(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(true); - results.setBulkFetchSize(10); - for (ResultSetRow row : results) - { - nodeService.getAspects(row.getNodeRef()); - nodeService.getProperties(row.getNodeRef()); - } - results.close(); - - end = System.nanoTime(); - - System.out.println(n + " Prefetch 10 in " + ((end - start) / 10e9)); - } - - private void getCold100(ADMLuceneSearcherImpl searcher, int n) - { - nodeBulkLoader.clear(); - - long start; - - long end; - - start = System.nanoTime(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(true); - results.setBulkFetchSize(100); - for (ResultSetRow row : results) - { - nodeService.getAspects(row.getNodeRef()); - nodeService.getProperties(row.getNodeRef()); - } - results.close(); - - end = System.nanoTime(); - - System.out.println(n + " Prefetch 100 in " + ((end - start) / 10e9)); - } - - private void getCold1000(ADMLuceneSearcherImpl searcher, int n) - { - nodeBulkLoader.clear(); - - long start; - - long end; - - start = System.nanoTime(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(true); - results.setBulkFetchSize(1000); - for (ResultSetRow row : results) - { - nodeService.getAspects(row.getNodeRef()); - nodeService.getProperties(row.getNodeRef()); - } - results.close(); - - end = System.nanoTime(); - - System.out.println(n + " Prefetch 1000 in " + ((end - start) / 10e9)); - } - - private void getCold10000(ADMLuceneSearcherImpl searcher, int n) - { - nodeBulkLoader.clear(); - - long start; - - long end; - - start = System.nanoTime(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"BULK\""); - ResultSet results = searcher.query(sp); - results.setBulkFetch(true); - results.setBulkFetchSize(10000); - for (ResultSetRow row : results) - { - nodeService.getAspects(row.getNodeRef()); - nodeService.getProperties(row.getNodeRef()); - } - results.close(); - - end = System.nanoTime(); - - System.out.println(n + " Prefetch 10000 in " + ((end - start) / 10e9)); - } - - /** - * Test bug fix - * - * @throws Exception - */ - public void testSortIssue_AR_1515__AND__AR_1466() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - runBaseTests(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - sp.addSort("ID", true); - ResultSet results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - - String current = null; - for (ResultSetRow row : results) - { - String id = row.getNodeRef().getId(); - - if (current != null) - { - if (current.compareTo(id) > 0) - { - fail(); - } - } - current = id; - } - results.close(); - - assertEquals(5, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); - serviceRegistry.getNodeService().createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}texas"), testSuperType).getChildRef(); - assertEquals(6, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - sp.addSort("ID", true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(17, results.length()); - current = null; - for (ResultSetRow row : results) - { - String id = row.getNodeRef().getId(); - - if (current != null) - { - if (current.compareTo(id) > 0) - { - fail(); - } - } - current = id; - } - results.close(); - - assertEquals(6, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); - serviceRegistry.getNodeService().createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}texas"), testSuperType).getChildRef(); - assertEquals(7, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - sp.addSort("ID", true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(18, results.length()); - current = null; - for (ResultSetRow row : results) - { - String id = row.getNodeRef().getId(); - - if (current != null) - { - if (current.compareTo(id) > 0) - { - fail(); - } - } - current = id; - } - results.close(); - - testTX.rollback(); - - } - - /** - * @throws Exception - */ - public void testAuxDataIsPresent() throws Exception - { - luceneFTS.pause(); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ID:\"" + n14 + "\"", null); - assertEquals(1, results.length()); // one node - results.close(); - - nodeService.addAspect(n14, aspectWithChildren, null); - nodeService.createNode(n14, QName.createQName(TEST_NAMESPACE, "unused"), QName.createQName(TEST_NAMESPACE, - "unused"), testSuperType, getOrderProperties()); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - searcher = buildSearcher(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ID:\"" + n14 + "\"", null); - assertEquals(10, results.length()); // one node + 9 aux paths to n14 - results.close(); - } - - /** - * @throws Exception - */ - public void testFirst() throws Exception - { - testReadAgainstDelta(); - } - - /** - * @throws Exception - */ - public void test0() throws Exception - { - - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - - - } - - /** - * @throws Exception - */ - public void testDeleteSecondaryAssocToContainer() throws Exception - { - luceneFTS.pause(); - - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - runBaseTests(); - nodeService.removeChild(n2, n13); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:link\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); - assertEquals(16, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); - assertEquals(24, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); - assertEquals(10, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testDeleteSecondaryAssocToLeaf() throws Exception - { - luceneFTS.pause(); - - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - runBaseTests(); - nodeService.removeChild(n12, n14); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:common\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); - assertEquals(16, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); - assertEquals(27, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); - assertEquals(26, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); - assertEquals(26, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); - assertEquals(26, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); - assertEquals(26, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); - assertEquals(26, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); - assertEquals(9, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testDeleteIssue() throws Exception - { - - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - ChildAssociationRef testFind = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}testFind"), testSuperType); - testTX.commit(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); - assertEquals(1, results.length()); - results.close(); - - RetryingTransactionCallback createAndDeleteCallback = new RetryingTransactionCallback() - { - public Object execute() throws Throwable - { - for (int i = 0; i < 100; i += 10) - { - HashSet refs = new HashSet(); - for (int j = 0; j < i; j++) - { - ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}test"), testSuperType); - refs.add(test); - } - - for (ChildAssociationRef car : refs) - { - nodeService.deleteNode(car.getChildRef()); - } - } - return null; - } - }; - retryingTransactionHelper.doInTransaction(createAndDeleteCallback); - - UserTransaction tx3 = transactionService.getUserTransaction(); - tx3.begin(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); - assertEquals(1, results.length()); - results.close(); - tx3.commit(); - } - - /** - * The test is ignored, see MNT-15976 - * @throws Exception - */ - public void ignoreTestMTDeleteIssue() throws Exception - { - luceneFTS.pause(); - testTX.commit(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - ChildAssociationRef testFind = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}testFind"), testSuperType); - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); - assertEquals(1, results.length()); - results.close(); - testTX.commit(); - - Thread runner = null; - - for (int i = 0; i < 20; i++) - { - runner = new Nester("Concurrent-" + i, runner); - } - if (runner != null) - { - runner.start(); - - try - { - runner.join(); - } - catch (InterruptedException e) - { - e.printStackTrace(); - } - } - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); - assertEquals(1, results.length()); - results.close(); - testTX.commit(); - } - - class Nester extends Thread - { - Thread waiter; - - Nester(String name, Thread waiter) - { - super(name); - this.setDaemon(true); - this.waiter = waiter; - } - - public void run() - { - authenticationComponent.setSystemUserAsCurrentUser(); - if (waiter != null) - { - waiter.start(); - } - try - { - System.out.println("Start " + this.getName()); - RetryingTransactionCallback createAndDeleteCallback = new RetryingTransactionCallback() - { - public Object execute() throws Throwable - { - for (int i = 0; i < 20; i++) - { - HashSet refs = new HashSet(); - for (int j = 0; j < i; j++) - { - ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}test_" - + getName() + "_" + i + "_" + j), testSuperType); - refs.add(test); - } - - for (ChildAssociationRef car : refs) - { - nodeService.deleteNode(car.getChildRef()); - } - } - return null; - } - }; - retryingTransactionHelper.doInTransaction(createAndDeleteCallback); - System.out.println("End " + this.getName()); - } - catch (Exception e) - { - System.out.println("End " + this.getName() + " with error " + e.getMessage()); - e.printStackTrace(); - } - finally - { - authenticationComponent.clearCurrentSecurityContext(); - } - if (waiter != null) - { - try - { - waiter.join(); - } - catch (InterruptedException e) - { - } - } - } - - } - - /** - * @throws Exception - */ - public void testDeltaIssue() throws Exception - { - luceneFTS.pause(); - final NodeService pns = (NodeService) ctx.getBean("NodeService"); - - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - testTX.commit(); - - Thread thread = new Thread(new Runnable() - { - - public void run() - { - try - { - authenticationComponent.setSystemUserAsCurrentUser(); - UserTransaction tx = transactionService.getUserTransaction(); - tx = transactionService.getUserTransaction(); - tx.begin(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - ResultSet results = serviceRegistry.getSearchService().query(sp); - for(ResultSetRow row : results) { - System.out.println("row = " + row.getQName()); - } - assertEquals(15, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(15, results.length()); - results.close(); - - Map props = new HashMap(); - props.put(ContentModel.PROP_TITLE, "woof"); - pns.addAspect(n1, ContentModel.ASPECT_TITLED, props); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(15, results.length()); - results.close(); - - tx.rollback(); - } - catch (Throwable e) - { - throw new RuntimeException(e); - } - - } - - }); - - thread.start(); - thread.join(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - ResultSet results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - runBaseTests(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - Map props = new HashMap(); - props.put(ContentModel.PROP_TITLE, "woof"); - pns.addAspect(n1, ContentModel.ASPECT_TITLED, props); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - pns.setProperty(n1, ContentModel.PROP_TITLE, "cube"); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - } - - /** - * @throws Exception - */ - public void testRepeatPerformance() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - String query = "ID:\"" + rootNodeRef + "\""; - // check that we get the result - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery(query); - ResultSet results = searcher.query(sp); - assertEquals("No results found from query", 1, results.length()); - - long start = System.nanoTime(); - int count = 1000; - // repeat - for (int i = 0; i < count; i++) - { - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery(query); - results = searcher.query(sp); - } - long end = System.nanoTime(); - // dump results - double duration = ((double) (end - start)) / 1E6; // duration in ms - double average = duration / (double) count; - System.out.println("Searched for identifier: \n" - + " count: " + count + "\n" + " average: " + average + " ms/search \n" + " a million searches could take: " + (1E6 * average) / 1E3 / 60D + " minutes"); - // anything over 10ms is dire - if (average > 10.0) - { - logger.error("Search taking longer than 10ms: " + query); - } - } - - /** - * @throws Exception - */ - public void testSort() throws Exception - { - Collator collator = Collator.getInstance(I18NUtil.getLocale()); - - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addSort("ID", true); - ResultSet results = searcher.query(sp); - - String current = null; - for (ResultSetRow row : results) - { - String id = row.getNodeRef().getId(); - - if (current != null) - { - if (collator.compare(current, id) > 0) - { - fail(); - } - } - current = id; - } - results.close(); - - SearchParameters sp2 = new SearchParameters(); - sp2.addStore(rootNodeRef.getStoreRef()); - sp2.setLanguage(SearchService.LANGUAGE_LUCENE); - sp2.setQuery("PATH:\"//.\""); - sp2.addSort("ID", false); - results = searcher.query(sp2); - - current = null; - for (ResultSetRow row : results) - { - String id = row.getNodeRef().getId(); - if (current != null) - { - if (collator.compare(current, id) < 0) - { - fail(); - } - } - current = id; - } - results.close(); - - luceneFTS.resume(); - - SearchParameters sp3 = new SearchParameters(); - sp3.addStore(rootNodeRef.getStoreRef()); - sp3.setLanguage(SearchService.LANGUAGE_LUCENE); - sp3.setQuery("PATH:\"//.\""); - sp3.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_ASCENDING); - results = searcher.query(sp3); - - int count = 0; - for (ResultSetRow row : results) - { - assertEquals(documentOrder[count++], row.getNodeRef()); - } - results.close(); - - SearchParameters sp4 = new SearchParameters(); - sp4.addStore(rootNodeRef.getStoreRef()); - sp4.setLanguage(SearchService.LANGUAGE_LUCENE); - sp4.setQuery("PATH:\"//.\""); - sp4.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING); - results = searcher.query(sp4); - - count = 1; - for (ResultSetRow row : results) - { - assertEquals(documentOrder[documentOrder.length - (count++)], row.getNodeRef()); - } - results.close(); - - SearchParameters sp5 = new SearchParameters(); - sp5.addStore(rootNodeRef.getStoreRef()); - sp5.setLanguage(SearchService.LANGUAGE_LUCENE); - sp5.setQuery("PATH:\"//.\""); - sp5.addSort(SearchParameters.SORT_IN_SCORE_ORDER_ASCENDING); - results = searcher.query(sp5); - - float score = 0; - for (ResultSetRow row : results) - { - assertTrue(score <= row.getScore()); - score = row.getScore(); - } - results.close(); - - SearchParameters sp6 = new SearchParameters(); - sp6.addStore(rootNodeRef.getStoreRef()); - sp6.setLanguage(SearchService.LANGUAGE_LUCENE); - sp6.setQuery("PATH:\"//.\""); - sp6.addSort(SearchParameters.SORT_IN_SCORE_ORDER_DESCENDING); - results = searcher.query(sp6); - - score = 1.0f; - for (ResultSetRow row : results) - { - assertTrue(score >= row.getScore()); - score = row.getScore(); - } - results.close(); - - // sort by created date - - SearchParameters sp7 = new SearchParameters(); - sp7.addStore(rootNodeRef.getStoreRef()); - sp7.setLanguage(SearchService.LANGUAGE_LUCENE); - sp7.setQuery("PATH:\"//.\""); - sp7.addSort("@" + createdDate.getPrefixedQName(namespacePrefixResolver), true); - results = searcher.query(sp7); - - Date date = null; - for (ResultSetRow row : results) - { - Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), createdDate)); - // System.out.println(currentBun); - if (date != null) - { - assertTrue(date.compareTo(currentBun) <= 0); - } - date = currentBun; - } - results.close(); - - SearchParameters sp8 = new SearchParameters(); - sp8.addStore(rootNodeRef.getStoreRef()); - sp8.setLanguage(SearchService.LANGUAGE_LUCENE); - sp8.setQuery("PATH:\"//.\""); - sp8.addSort("@" + createdDate, false); - results = searcher.query(sp8); - - date = null; - for (ResultSetRow row : results) - { - Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), createdDate)); - // System.out.println(currentBun); - if ((date != null) && (currentBun != null)) - { - assertTrue(date.compareTo(currentBun) >= 0); - } - date = currentBun; - } - results.close(); - - SearchParameters sp_7 = new SearchParameters(); - sp_7.addStore(rootNodeRef.getStoreRef()); - sp_7.setLanguage(SearchService.LANGUAGE_LUCENE); - sp_7.setQuery("PATH:\"//.\""); - sp_7.addSort("@" + ContentModel.PROP_MODIFIED, true); - results = searcher.query(sp_7); - - date = null; - for (ResultSetRow row : results) - { - Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED)); - if (currentBun != null) - { - Calendar c = new GregorianCalendar(); - c.setTime(currentBun); - c.set(Calendar.MILLISECOND, 0); - c.set(Calendar.SECOND, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.HOUR_OF_DAY, 0); - currentBun = c.getTime(); - } - if ((date != null) && (currentBun != null)) - { - assertTrue(date.compareTo(currentBun) <= 0); - } - date = currentBun; - } - results.close(); - - SearchParameters sp_8 = new SearchParameters(); - sp_8.addStore(rootNodeRef.getStoreRef()); - sp_8.setLanguage(SearchService.LANGUAGE_LUCENE); - sp_8.setQuery("PATH:\"//.\""); - sp_8.addSort("@" + ContentModel.PROP_MODIFIED, false); - results = searcher.query(sp_8); - - date = null; - for (ResultSetRow row : results) - { - Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED)); - // System.out.println(currentBun); - if (currentBun != null) - { - Calendar c = new GregorianCalendar(); - c.setTime(currentBun); - c.set(Calendar.MILLISECOND, 0); - c.set(Calendar.SECOND, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.HOUR_OF_DAY, 0); - currentBun = c.getTime(); - } - - if ((date != null) && (currentBun != null)) - { - assertTrue(date.compareTo(currentBun) >= 0); - } - date = currentBun; - } - results.close(); - - // sort by double - - SearchParameters sp9 = new SearchParameters(); - sp9.addStore(rootNodeRef.getStoreRef()); - sp9.setLanguage(SearchService.LANGUAGE_LUCENE); - sp9.setQuery("PATH:\"//.\""); - sp9.addSort("@" + orderDouble, true); - results = searcher.query(sp9); - - Double d = null; - for (ResultSetRow row : results) - { - Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class, nodeService.getProperty(row.getNodeRef(), orderDouble)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (d != null) - { - assertTrue(d.compareTo(currentBun) <= 0); - } - d = currentBun; - } - results.close(); - - SearchParameters sp10 = new SearchParameters(); - sp10.addStore(rootNodeRef.getStoreRef()); - sp10.setLanguage(SearchService.LANGUAGE_LUCENE); - sp10.setQuery("PATH:\"//.\""); - sp10.addSort("@" + orderDouble, false); - results = searcher.query(sp10); - - d = null; - for (ResultSetRow row : results) - { - Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class, nodeService.getProperty(row.getNodeRef(), orderDouble)); - // System.out.println(currentBun); - if ((d != null) && (currentBun != null)) - { - assertTrue(d.compareTo(currentBun) >= 0); - } - d = currentBun; - } - results.close(); - - // sort by float - - SearchParameters sp11 = new SearchParameters(); - sp11.addStore(rootNodeRef.getStoreRef()); - sp11.setLanguage(SearchService.LANGUAGE_LUCENE); - sp11.setQuery("PATH:\"//.\""); - sp11.addSort("@" + orderFloat, true); - results = searcher.query(sp11); - - Float f = null; - for (ResultSetRow row : results) - { - Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class, nodeService.getProperty(row.getNodeRef(), orderFloat)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (f != null) - { - assertTrue(f.compareTo(currentBun) <= 0); - } - f = currentBun; - } - results.close(); - - SearchParameters sp12 = new SearchParameters(); - sp12.addStore(rootNodeRef.getStoreRef()); - sp12.setLanguage(SearchService.LANGUAGE_LUCENE); - sp12.setQuery("PATH:\"//.\""); - sp12.addSort("@" + orderFloat, false); - results = searcher.query(sp12); - - f = null; - for (ResultSetRow row : results) - { - Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class, nodeService.getProperty(row.getNodeRef(), orderFloat)); - // System.out.println(currentBun); - if ((f != null) && (currentBun != null)) - { - assertTrue(f.compareTo(currentBun) >= 0); - } - f = currentBun; - } - results.close(); - - // sort by long - - SearchParameters sp13 = new SearchParameters(); - sp13.addStore(rootNodeRef.getStoreRef()); - sp13.setLanguage(SearchService.LANGUAGE_LUCENE); - sp13.setQuery("PATH:\"//.\""); - sp13.addSort("@" + orderLong, true); - results = searcher.query(sp13); - - Long l = null; - for (ResultSetRow row : results) - { - Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(row.getNodeRef(), orderLong)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (l != null) - { - assertTrue(l.compareTo(currentBun) <= 0); - } - l = currentBun; - } - results.close(); - - SearchParameters sp14 = new SearchParameters(); - sp14.addStore(rootNodeRef.getStoreRef()); - sp14.setLanguage(SearchService.LANGUAGE_LUCENE); - sp14.setQuery("PATH:\"//.\""); - sp14.addSort("@" + orderLong, false); - results = searcher.query(sp14); - - l = null; - for (ResultSetRow row : results) - { - Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(row.getNodeRef(), orderLong)); - // System.out.println(currentBun); - if ((l != null) && (currentBun != null)) - { - assertTrue(l.compareTo(currentBun) >= 0); - } - l = currentBun; - } - results.close(); - - // sort by int - - SearchParameters sp15 = new SearchParameters(); - sp15.addStore(rootNodeRef.getStoreRef()); - sp15.setLanguage(SearchService.LANGUAGE_LUCENE); - sp15.setQuery("PATH:\"//.\""); - sp15.addSort("@" + orderInt, true); - results = searcher.query(sp15); - - Integer i = null; - for (ResultSetRow row : results) - { - Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class, nodeService.getProperty(row.getNodeRef(), orderInt)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if (i != null) - { - assertTrue(i.compareTo(currentBun) <= 0); - } - i = currentBun; - } - results.close(); - - SearchParameters sp16 = new SearchParameters(); - sp16.addStore(rootNodeRef.getStoreRef()); - sp16.setLanguage(SearchService.LANGUAGE_LUCENE); - sp16.setQuery("PATH:\"//.\""); - sp16.addSort("@" + orderInt, false); - results = searcher.query(sp16); - - i = null; - for (ResultSetRow row : results) - { - Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class, nodeService.getProperty(row.getNodeRef(), orderInt)); - // System.out.println(currentBun); - if ((i != null) && (currentBun != null)) - { - assertTrue(i.compareTo(currentBun) >= 0); - } - i = currentBun; - } - results.close(); - - // sort by text - - SearchParameters sp17 = new SearchParameters(); - sp17.addStore(rootNodeRef.getStoreRef()); - sp17.setLanguage(SearchService.LANGUAGE_LUCENE); - sp17.setQuery("PATH:\"//.\""); - sp17.addSort("@" + orderText, true); - results = searcher.query(sp17); - - String text = null; - for (ResultSetRow row : results) - { - String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), orderText)); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun); - if ((text != null) && (currentBun != null)) - { - assertTrue(collator.compare(text, currentBun) <= 0); - } - text = currentBun; - } - results.close(); - - SearchParameters sp18 = new SearchParameters(); - sp18.addStore(rootNodeRef.getStoreRef()); - sp18.setLanguage(SearchService.LANGUAGE_LUCENE); - sp18.setQuery("PATH:\"//.\""); - sp18.addSort("@" + orderText, false); - results = searcher.query(sp18); - - text = null; - for (ResultSetRow row : results) - { - String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(row.getNodeRef(), orderText)); - // System.out.println(currentBun); - if ((text != null) && (currentBun != null)) - { - assertTrue(collator.compare(text, currentBun) >= 0); - } - text = currentBun; - } - results.close(); - - // sort by content size - - - - // sort by ML text - - // Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH, Locale.CHINESE }; - Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH }; - for (Locale testLocale : testLocales) - { - Collator localisedCollator = Collator.getInstance(testLocale); - - SearchParameters sp19 = new SearchParameters(); - sp19.addStore(rootNodeRef.getStoreRef()); - sp19.setLanguage(SearchService.LANGUAGE_LUCENE); - sp19.setQuery("PATH:\"//.\""); - sp19.addSort("@" + orderMLText, true); - sp19.addLocale(testLocale); - results = searcher.query(sp19); - - text = null; - for (ResultSetRow row : results) - { - MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class, nodeService.getProperty(row.getNodeRef(), orderMLText)); - if (mltext != null) - { - String currentBun = mltext.getValue(testLocale); - // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " - // "+currentBun); - if ((text != null) && (currentBun != null)) - { - assertTrue(localisedCollator.compare(text, currentBun) <= 0); - } - text = currentBun; - } - } - results.close(); - - SearchParameters sp20 = new SearchParameters(); - sp20.addStore(rootNodeRef.getStoreRef()); - sp20.setLanguage(SearchService.LANGUAGE_LUCENE); - sp20.setQuery("PATH:\"//.\""); - sp20.addSort("@" + orderMLText, false); - sp20.addLocale(testLocale); - results = searcher.query(sp20); - - text = null; - for (ResultSetRow row : results) - { - MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class, nodeService.getProperty(row.getNodeRef(), orderMLText)); - if (mltext != null) - { - String currentBun = mltext.getValue(testLocale); - if ((text != null) && (currentBun != null)) - { - assertTrue(localisedCollator.compare(text, currentBun) >= 0); - } - text = currentBun; - } - } - results.close(); - - } - - luceneFTS.resume(); - - SearchParameters spN = new SearchParameters(); - spN.addStore(rootNodeRef.getStoreRef()); - spN.setLanguage(SearchService.LANGUAGE_LUCENE); - spN.setQuery("PATH:\"//.\""); - spN.addSort("cabbage", false); - results = searcher.query(spN); - results.close(); - - // test sort on unkown properties ALF-4193 - - spN = new SearchParameters(); - spN.addStore(rootNodeRef.getStoreRef()); - spN.setLanguage(SearchService.LANGUAGE_LUCENE); - spN.setQuery("PATH:\"//.\""); - spN.addSort("PARENT", false); - results = searcher.query(spN); - results.close(); - - spN = new SearchParameters(); - spN.addStore(rootNodeRef.getStoreRef()); - spN.setLanguage(SearchService.LANGUAGE_LUCENE); - spN.setQuery("PATH:\"//.\""); - spN.addSort("@PARENT:PARENT", false); - results = searcher.query(spN); - results.close(); - - luceneFTS.resume(); - - - // sort by content size - - SearchParameters sp20 = new SearchParameters(); - sp20.addStore(rootNodeRef.getStoreRef()); - sp20.setLanguage(SearchService.LANGUAGE_LUCENE); - sp20.setQuery("PATH:\"//.\""); - sp20.addSort("@" + ContentModel.PROP_CONTENT+".size", false); - results = searcher.query(sp20); - - Long size = null; - for (ResultSetRow row : results) - { - ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT)); - // System.out.println(currentBun); - if ((size != null) && (currentBun != null)) - { - assertTrue(size.compareTo(currentBun.getSize()) >= 0); - } - if(currentBun != null) - { - size = currentBun.getSize(); - } - } - results.close(); - - // sort by content mimetype - - SearchParameters sp21 = new SearchParameters(); - sp21.addStore(rootNodeRef.getStoreRef()); - sp21.setLanguage(SearchService.LANGUAGE_LUCENE); - sp21.setQuery("PATH:\"//.\""); - sp21.addSort("@" + ContentModel.PROP_CONTENT+".mimetype", false); - results = searcher.query(sp21); - - String mimetype = null; - for (ResultSetRow row : results) - { - ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class, nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT)); - // System.out.println(currentBun); - if ((mimetype != null) && (currentBun != null)) - { - assertTrue(mimetype.compareTo(currentBun.getMimetype()) >= 0); - } - if(currentBun != null) - { - mimetype = currentBun.getMimetype(); - } - } - results.close(); - - } - - /** - * @throws Exception - */ - public void test1() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void test2() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void test3() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void test4() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@\\{namespace\\}property\\-2:\"valuetwo\"", null); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void test5() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void test6() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testNoOp() throws Exception - { - luceneFTS.pause(); - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_1", luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - indexer.prepare(); - indexer.commit(); - luceneFTS.resume(); - } - - /** - * Test basic index and search - * - * @throws Exception - * @throws InterruptedException - */ - - public void testStandAloneIndexerCommit() throws Exception - { - luceneFTS.pause(); - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_1", luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - indexer.deleteIndex(rootNodeRef.getStoreRef()); - - indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}one"), n1)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}two"), n2)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n1, QName.createQName("{namespace}five"), n5)); - indexer.updateNode(n1); - // indexer.deleteNode(new ChildRelationshipRef(rootNode, "path", - // newNode)); - - indexer.prepare(); - indexer.commit(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@\\{namespace\\}property\\-2:\"valuetwo\"", null); - simpleResultSetTest(results); - - ChildAssocRefResultSet r2 = new ChildAssocRefResultSet(nodeService, results.getNodeRefs(), false); - simpleResultSetTest(r2); - - ChildAssocRefResultSet r3 = new ChildAssocRefResultSet(nodeService, results.getNodeRefs(), true); - simpleResultSetTest(r3); - - ChildAssocRefResultSet r4 = new ChildAssocRefResultSet(nodeService, results.getChildAssocRefs()); - simpleResultSetTest(r4); - - DetachedResultSet r5 = new DetachedResultSet(results); - simpleResultSetTest(r5); - - DetachedResultSet r6 = new DetachedResultSet(r2); - simpleResultSetTest(r6); - - DetachedResultSet r7 = new DetachedResultSet(r3); - simpleResultSetTest(r7); - - DetachedResultSet r8 = new DetachedResultSet(r4); - simpleResultSetTest(r8); - - DetachedResultSet r9 = new DetachedResultSet(r5); - simpleResultSetTest(r9); - - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@\\{namespace\\}property\\-1:\"valueone\"", null); - assertEquals(2, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n1.getId(), results.getNodeRef(1).getId()); - assertEquals(1.0f, results.getScore(0)); - assertEquals(1.0f, results.getScore(1)); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@namespace\\:property\\-1:\"valueone\"", null); - assertEquals(2, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n1.getId(), results.getNodeRef(1).getId()); - assertEquals(1.0f, results.getScore(0)); - assertEquals(1.0f, results.getScore(1)); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@namespace\\:property\\-1:\"valueone\"", null); - assertEquals(2, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n1.getId(), results.getNodeRef(1).getId()); - assertEquals(1.0f, results.getScore(0)); - assertEquals(1.0f, results.getScore(1)); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@namespace\\:property\\-1:\"Valueone\"", null); - assertEquals(2, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n1.getId(), results.getNodeRef(1).getId()); - assertEquals(1.0f, results.getScore(0)); - assertEquals(1.0f, results.getScore(1)); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@namespace\\:property\\-1:ValueOne", null); - assertEquals(2, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n1.getId(), results.getNodeRef(1).getId()); - assertEquals(1.0f, results.getScore(0)); - assertEquals(1.0f, results.getScore(1)); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@namespace\\:property\\-1:valueone", null); - assertEquals(2, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n1.getId(), results.getNodeRef(1).getId()); - assertEquals(1.0f, results.getScore(0)); - assertEquals(1.0f, results.getScore(1)); - results.close(); - - QName qname = QName.createQName("", "property-1"); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ID:\"" + n1.toString() + "\"", null); - - assertEquals(2, results.length()); - - results.close(); - luceneFTS.resume(); - } - - private void simpleResultSetTest(ResultSet results) - { - assertEquals(1, results.length()); - assertEquals(n2.getId(), results.getNodeRef(0).getId()); - assertEquals(n2, results.getNodeRef(0)); - assertEquals(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}two"), n2), results.getChildAssocRef(0)); - assertEquals(1, results.getChildAssocRefs().size()); - assertNotNull(results.getChildAssocRefs()); - assertEquals(0, results.getRow(0).getIndex()); - assertEquals(1.0f, results.getRow(0).getScore()); - assertEquals(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}two"), n2), results.getRow(0).getChildAssocRef()); - assertEquals(n2, results.getRow(0).getNodeRef()); - assertEquals(QName.createQName("{namespace}two"), results.getRow(0).getQName()); - assertEquals("valuetwo", results.getRow(0).getValue(QName.createQName("{namespace}property-2"))); - for (ResultSetRow row : results) - { - assertNotNull(row); - } - } - - /** - * @throws Exception - */ - public void testStandAlonePathIndexer() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@\\{namespace\\}property-1:valueone", null); - try - { - assertEquals(2, results.length()); - assertEquals(n1.getId(), results.getNodeRef(0).getId()); - assertEquals(n2.getId(), results.getNodeRef(1).getId()); - // assertEquals(1.0f, results.getScore(0)); - // assertEquals(1.0f, results.getScore(1)); - - QName qname = QName.createQName("", "property-1"); - - } - finally - { - results.close(); - } - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+ID:\"" + n1.toString() + "\"", null); - try - { - assertEquals(2, results.length()); - } - finally - { - results.close(); - } - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ID:\"" + rootNodeRef.toString() + "\"", null); - try - { - assertEquals(1, results.length()); - } - finally - { - results.close(); - } - luceneFTS.resume(); - } - - private void buildBaseIndex() - { - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_" + (new Random().nextInt()), - luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - indexer.setTransformerDebug(transformerDebug); - - indexer.deleteIndex(rootNodeRef.getStoreRef()); - indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}one"), n1)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}two"), n2)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}three"), n3)); - indexer.createNode(new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, QName.createQName("{namespace}four"), n4)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n1, QName.createQName("{namespace}five"), n5)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n1, QName.createQName("{namespace}six"), n6)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("{namespace}seven"), n7)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("{namespace}eight"), n8)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}nine"), n9)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}ten"), n10)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}eleven"), n11)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n5, QName.createQName("{namespace}twelve"), n12)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n12, QName.createQName("{namespace}thirteen"), n13)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n13, QName.createQName("{namespace}fourteen"), n14)); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, n13, QName.createQName("{namespace}fifteen"), n15)); - indexer.updateNode(n3); - indexer.updateNode(n1); - indexer.updateNode(n2); - indexer.prepare(); - indexer.commit(); - } - - /** - * @throws Exception - */ - public void testAllPathSearch() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - - runBaseTests(); - luceneFTS.resume(); - } - - - - - private void runBaseTests() throws LuceneIndexException, IOException - { - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results; - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/.\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(9, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*/*\"", null); - assertEquals(9, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); - assertEquals(28, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); - assertEquals(16, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); - assertEquals(27, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); - assertEquals(27, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); - assertEquals(27, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); - assertEquals(27, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); - assertEquals(27, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//common\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one//common\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); - assertEquals(10, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//.\"", null); - assertEquals(11, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen/.\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen//.\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen//.//.\"", null); - assertEquals(1, results.length()); - results.close(); - - // QNames - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"nine\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PRIMARYASSOCTYPEQNAME:\"lucene-test:assoc\"", null); - assertEquals(11, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASSOCTYPEQNAME:\"lucene-test:assoc\"", null); - assertEquals(11, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PRIMARYASSOCTYPEQNAME:\"sys:children\"", null); - assertEquals(4, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASSOCTYPEQNAME:\"sys:children\"", null); - assertEquals(5, results.length()); - results.close(); - - // Type search tests - - QName qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"1\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":1", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"01\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":01", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + escapeQName(qname) + ":\"001\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@lucene-test\\:int\\-ista:\"0001\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 2]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO 2]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO A]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 1}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO 1}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO A}", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 2}", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{1 TO 2}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{1 TO A}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"2\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"02\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"002\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"0002\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 2]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO 2]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[0 TO A]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 2}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO 2}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{0 TO A}", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 3}", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{2 TO 3}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "long-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{2 TO A}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"3.4\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 4]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3 TO 4]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3 TO A]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 3.4]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO 3.4]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO A]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 3.4}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO 3.4]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[3.3 TO A]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"3.40\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"03.4\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "float-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"03.40\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"5.6\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"05.6\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"5.60\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "double-ista")) + ":\"05.60\"", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[A TO 5.7]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[5.5 TO 5.7]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[5.5 TO A]", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 5.6}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.5 TO 5.6}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.5 TO A}", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{A TO 5.7}", null); - assertEquals(1, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.6 TO 5.7}", null); - assertEquals(0, results.length()); - results.close(); - - qname = QName.createQName(TEST_NAMESPACE, "double-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":{5.6 TO A}", null); - assertEquals(0, results.length()); - results.close(); - - // Dates - - PropertyDefinition propertyDef = dictionaryService.getProperty(QName.createQName(TEST_NAMESPACE, "datetime-ista")); - DataTypeDefinition dataType = propertyDef.getDataType(); - String analyserClassName = propertyDef.resolveAnalyserClassName(); - boolean usesDateTimeAnalyser = analyserClassName.equals(DateTimeAnalyser.class.getCanonicalName()); - - Date date = new Date(); - for (SimpleDateFormatAndResolution df : CachingDateFormat.getLenientFormatters()) - { - if(!usesDateTimeAnalyser && (df.getResolution() < Calendar.DAY_OF_MONTH)) - { - continue; - } - System.out.println("Date format: "+df.getSimpleDateFormat()); - -// if(usesDateTimeAnalyser && (df.getSimpleDateFormat().format(date).length() < 22)) -// { -// continue; -// } - -// String sDate = df.getSimpleDateFormat().format(date); -// results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "DATE-ista")) + ":\"" + sDate + "\"", null); -// assertEquals(1, results.length()); -// results.close(); -// -// results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate + "\"", null); -// assertEquals(usesDateTimeAnalyser ? 0 : 1, results.length()); -// results.close(); - - - String sDate = df.getSimpleDateFormat().format(testDate); - - if(sDate.length() >= 9) - { - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":\"" + sDate + "\"", null); - assertEquals(1, results.length()); - results.close(); - } - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate + "\"", null); - assertEquals(1, results.length()); - results.close(); - - // short and long field ranges - - // note: expected 2 results = n14 (cm:content) and n15 (cm:thumbnail) - - sDate = df.getSimpleDateFormat().format(date); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:CrEaTeD:[MIN TO " + sDate + "]", null); - assertEquals(2, results.length()); - assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); - assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); - results.close(); - - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:created:[MIN TO NOW]", null); - assertEquals(2, results.length()); - assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); - assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); - results.close(); - - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@cm\\:created:[MIN TO NOW]", null); - assertEquals(2, results.length()); - assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); - assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); - results.close(); - - - sDate = df.getSimpleDateFormat().format(date); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(ContentModel.PROP_CREATED) + ":[MIN TO " + sDate + "]", null); - assertEquals(2, results.length()); - assertTrue("n14 not in results", (results.getNodeRef(0).equals(n14) || results.getNodeRef(1).equals(n14))); - assertTrue("n15 not in results", (results.getNodeRef(0).equals(n15) || results.getNodeRef(1).equals(n15))); - results.close(); - - // Date ranges - // Test date collapses but date time does not - - if(sDate.length() >= 9) - { - sDate = df.getSimpleDateFormat().format(testDate); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", - "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":[" + sDate + " TO " + sDate + "]", null); - assertEquals(1, results.length()); - results.close(); - - sDate = df.getSimpleDateFormat().format(testDate); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":[MIN TO " + sDate + "]", null); - assertEquals(1, results.length()); - results.close(); - - sDate = df.getSimpleDateFormat().format(testDate); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "date-ista")) + ":[" + sDate + " TO MAX]", null); - assertEquals(1, results.length()); - results.close(); - } - - if(!usesDateTimeAnalyser) - { - // with date time the result is indeterminate - sDate = CachingDateFormat.getDateFormat().format(testDate); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + sDate + " TO " + sDate + "]", null); - assertEquals(1, results.length()); - results.close(); - } - - sDate = CachingDateFormat.getDateFormat().format(testDate); - results = searcher - .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[MIN TO " + sDate + "]", null); - assertEquals(1, results.length()); - results.close(); - - - - sDate = CachingDateFormat.getDateFormat().format(testDate); - System.out.println("SD = " + sDate); - System.out.println("D = " + date); - - if(!usesDateTimeAnalyser) - { - results = searcher - .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":\"" + sDate+"\"", null); - //TODO: Fix date time resolution - uses 000 MS - assertEquals(1, results.length()); - results.close(); - } - - if(!usesDateTimeAnalyser) - { - results = searcher - .query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + sDate + " TO MAX]", null); - assertEquals(1, results.length()); - results.close(); - } - - if (usesDateTimeAnalyser) - { - sDate = df.getSimpleDateFormat().format(testDate); - System.out.println("Test Date = " + testDate); - System.out.println("Formatted = " + sDate); - - for (long i : new long[] { 333, 20000, 20 * 60 * 1000, 8 * 60 * 60 * 1000, 10 * 24 * 60 * 60 * 1000, 4 * 30 * 24 * 60 * 60 * 1000, - 10 * 12 * 30 * 24 * 60 * 60 * 1000 }) - { - System.out.println("I = "+i); - - String startDate = df.getSimpleDateFormat().format(new Date(testDate.getTime() - i)); - System.out.println("\tStart = " + startDate); - - String endDate = df.getSimpleDateFormat().format(new Date(testDate.getTime() + i)); - System.out.println("\tEnd = " + endDate); - - boolean equalsStart = startDate.equals(sDate); - boolean equalsEnd = endDate.equals(sDate); - boolean equalsStartOrEnd = equalsStart || equalsEnd; - - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + startDate + " TO " + endDate + "]", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + sDate + " TO " + endDate + "]", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":[" + startDate + " TO " + sDate + "]", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":{" + sDate + " TO " + endDate + "}", null); - assertEquals(0 , results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "datetime-ista")) + ":{" + startDate + " TO " + sDate + "}", null); - assertEquals(0 , results.length()); - results.close(); - } - } - } - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "boolean-ista")) + ":\"true\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "qname-ista")) + ":\"{wibble}wobble\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "category-ista")) + ":\"" - + DefaultTypeConverter.INSTANCE.convert(String.class, new NodeRef(rootNodeRef.getStoreRef(), "CategoryId")) + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "noderef-ista")) + ":\"" + n1 + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "path-ista")) + ":\"" + nodeService.getPath(n3) + "\"", - null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - // d:any - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "any-many-ista")) + ":\"100\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "any-many-ista")) + ":\"anyValueAsString\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "any-many-ista")) + ":\"nintc\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); - results.close(); - - // proximity searches - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~0", null); - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~1", null); - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~2", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~3", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Alfresco Tutorial\"", null); - - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"", null); - - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~0", null); - - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~1", null); - - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~2", null); - - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Tutorial Alfresco\"~3", null); - - assertEquals(1, results.length()); - results.close(); - - // multi ml text - - QName multimlQName = QName.createQName(TEST_NAMESPACE, "mltext-many-ista"); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":лемур"); - sp.addLocale(new Locale("ru")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":lemur"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":chou"); - sp.addLocale(new Locale("fr")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cabbage"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cabba*"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":ca*ge"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":*bage"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cabage~"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":*b?ag?"); - sp.addLocale(new Locale("en")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(multimlQName.toString()) + ":cho*"); - sp.setMlAnalaysisMode(MLAnalysisMode.LOCALE_AND_ALL_CONTAINED_LOCALES); - sp.addLocale(new Locale("fr")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // multivalued content in type d:any - // This should not be indexed as we can not know what to do with content here. - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(QName.createQName(TEST_NAMESPACE, "content-many-ista").toString()) + ":multicontent"); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - // locale - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":\"en_GB_\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":en_GB_", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":en_*", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":*_GB_*", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "locale-ista")) + ":*_gb_*", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - // Period - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "period-ista")) + ":\"period|12\"", null); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "path-ista"))); - results.close(); - - // Type - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testType.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testType.toPrefixString(namespacePrefixResolver) + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testType.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testType.toPrefixString(namespacePrefixResolver) + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testSuperType.toString() + "\"", null); - assertEquals(13, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + testSuperType.toPrefixString(namespacePrefixResolver) + "\"", null); - assertEquals(13, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + ContentModel.TYPE_CONTENT.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"cm:content\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"cm:CONTENT\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"CM:CONTENT\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"CONTENT\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"content\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" + ContentModel.TYPE_THUMBNAIL.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TYPE:\"" - + ContentModel.TYPE_THUMBNAIL.toString() + "\" TYPE:\"" + ContentModel.TYPE_CONTENT.toString() + "\"", null); - assertEquals(2, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testSuperType.toString() + "\"", null); - assertEquals(12, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTTYPE:\"" + testSuperType.toPrefixString(namespacePrefixResolver) + "\"", null); - assertEquals(12, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASPECT:\"" + testAspect.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "ASPECT:\"" + testAspect.toPrefixString(namespacePrefixResolver) + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTASPECT:\"" + testAspect.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "EXACTASPECT:\"" + testAspect.toPrefixString(namespacePrefixResolver) + "\"", null); - assertEquals(1, results.length()); - results.close(); - - // Test for AR-384 - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fox AND TYPE:\"" + ContentModel.PROP_CONTENT.toString() + "\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fox cm\\:name:fox", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fo AND TYPE:\"" + ContentModel.PROP_CONTENT.toString() + "\"", null); - assertEquals(0, results.length()); - results.close(); - - // Test stop words are equivalent - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"the\"", null); - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"and\"", null); - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"over the lazy\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"over a lazy\"", null); - assertEquals(1, results.length()); - results.close(); - - // Test wildcards in text - - //ALF-2389 - //results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":*en*", null); - //assertEquals(0, results.length()); - //results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":*a*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":*A*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":\"*a*\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":\"*A\"*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":*s*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":*S*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":\"*s*\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"))+":\"*S\"*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*A*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*a*\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*A*\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*a*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*Z*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*z*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*Z*\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"*z*\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:laz*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:laz~", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:la?y", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:?a?y", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*azy", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*az*", null); - assertEquals(1, results.length()); - results.close(); - - // Accents - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"\u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"aeidnouy\"", null); - assertEquals(1, results.length()); - results.close(); - - // FTS test - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"fox\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":\"fox\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".mimetype:\"text/plain\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".locale:\"en_GB\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".locale:en_*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".locale:e*_GB", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ".size:\"298\"", null); - assertEquals(1, results.length()); - results.close(); - - QName queryQName = QName.createQName("alf:test1", namespacePrefixResolver); - results = searcher.query(rootNodeRef.getStoreRef(), queryQName, null); - assertEquals(1, results.length()); - results.close(); - - // Configuration of TEXT - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":\"fox\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"fox\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"fox\""); - sp.addTextAttribute("@" + ContentModel.PROP_NAME.toString()); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp.addTextAttribute("@" + ContentModel.PROP_CONTENT.toString()); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"cabbage\""); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"cab*\""); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*bage\""); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*ba*\""); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - // term - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:cabbage"); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:*cab*"); - sp.addTextAttribute("@" + orderText.toString()); - sp.addLocale(Locale.ENGLISH); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:*bage"); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:*ba*"); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:dabbage~0.8"); - sp.addTextAttribute("@" + orderText.toString()); - results = searcher.query(sp); - assertEquals(13, results.length()); - results.close(); - - // Wild cards in TEXT phrase - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfresc?\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfres??\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfre???\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfr????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alf?????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"al??????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"a???????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"a??re???\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"?lfresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"??fresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"???resco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"???res?o\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"????e?co\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"????e?c?\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"???????o\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"???re???\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfresc*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfres*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfre*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfr*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alf*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"al*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"a*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"a****\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*lfresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*fresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*resco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*esco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*sco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*co\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*o\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"****lf**sc***\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*??*lf**sc***\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alfresc*tutorial\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"alf* tut*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("TEXT:\"*co *al\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // Wild cards in ML phrases - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfresc?\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfres??\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfre???\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfr????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alf?????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"al??????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a???????\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a??re???\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"?lfresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"??fresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???resco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???res?o\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"????e?co\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"????e?c?\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???????o\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"???re???\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfresc*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfres*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfre*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alfr*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"alf*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"al*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"a****\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*lfresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*fresco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*resco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*esco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*sco\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*co\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*o\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"****lf**sc***\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*??*lf**sc***\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Alfresc*tutorial\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"Alf* tut*\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_DESCRIPTION.toString()) + ":\"*co *al\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // ALL and its configuration - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ALL:\"fox\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ALL:\"fox\""); - sp.addAllAttribute("@" + ContentModel.PROP_NAME.toString()); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp.addAllAttribute("@" + ContentModel.PROP_CONTENT.toString()); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ALL:\"5.6\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // Search by data type - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("d\\:double:\"5.6\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("d\\:content:\"fox\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // locale serach in en_US for en_UK - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("d\\:content:\"fox\""); - sp.addLocale(Locale.US); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // Direct ML tests - - QName mlQName = QName.createQName(TEST_NAMESPACE, "ml"); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setMlAnalaysisMode(MLAnalysisMode.ALL_ONLY); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":and"); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setMlAnalaysisMode(MLAnalysisMode.ALL_ONLY); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":\"and\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setMlAnalaysisMode(MLAnalysisMode.ALL_ONLY); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - sp.addLocale(Locale.UK); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - sp.setMlAnalaysisMode(MLAnalysisMode.LOCALE_AND_ALL_CONTAINING_LOCALES); - sp.addLocale(Locale.UK); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - sp.addLocale(Locale.ENGLISH); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banane"); - sp.addLocale(Locale.FRENCH); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":香蕉"); - sp.addLocale(Locale.CHINESE); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banaan"); - sp.addLocale(new Locale("nl")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banane"); - sp.addLocale(Locale.GERMAN); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":μπανάνα"); - sp.addLocale(new Locale("el")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - sp.addLocale(Locale.ITALIAN); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":バナナ"); - sp.addLocale(new Locale("ja")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":바나나"); - sp.addLocale(new Locale("ko")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":banana"); - sp.addLocale(new Locale("pt")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":банан"); - sp.addLocale(new Locale("ru")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(mlQName.toString()) + ":plátano"); - sp.addLocale(new Locale("es")); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - // Test ISNULL/ISUNSET/ISNOTNULL - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISUNSET:\"" + QName.createQName(TEST_NAMESPACE, "null").toString() + "\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISNULL:\"" + QName.createQName(TEST_NAMESPACE, "null").toString() + "\""); - results = searcher.query(sp); - // assertEquals(62, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISUNSET:\"" + QName.createQName(TEST_NAMESPACE, "path-ista").toString() + "\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISNULL:\"" + QName.createQName(TEST_NAMESPACE, "path-ista").toString() + "\""); - results = searcher.query(sp); - // assertEquals(61, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISNOTNULL:\"" + QName.createQName(TEST_NAMESPACE, "null").toString() + "\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISNOTNULL:\"" + QName.createQName(TEST_NAMESPACE, "path-ista").toString() + "\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISUNSET:\"" + QName.createQName(TEST_NAMESPACE, "aspectProperty").toString() + "\""); - results = searcher.query(sp); - assertEquals(1, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISNULL:\"" + QName.createQName(TEST_NAMESPACE, "aspectProperty").toString() + "\""); - results = searcher.query(sp); - // assertEquals(62, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage("lucene"); - sp.setQuery("ISNOTNULL:\"" + QName.createQName(TEST_NAMESPACE, "aspectProperty").toString() + "\""); - results = searcher.query(sp); - assertEquals(0, results.length()); - results.close(); - - // Test non field queries - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fox", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:fo*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:f*x", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:*ox", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":fox", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":fo*", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":f*x", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toString()) + ":*ox", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":fox", - null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":fo*", - null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":f*x", - null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_CONTENT.toPrefixString(namespacePrefixResolver)) + ":*ox", - null); - assertEquals(1, results.length()); - results.close(); - - // Parameters - - queryQName = QName.createQName("alf:test2", namespacePrefixResolver); - results = searcher.query(rootNodeRef.getStoreRef(), queryQName, null); - assertEquals(1, results.length()); - results.close(); - - queryQName = QName.createQName("alf:test2", namespacePrefixResolver); - QueryParameter qp = new QueryParameter(QName.createQName("alf:banana", namespacePrefixResolver), "woof"); - results = searcher.query(rootNodeRef.getStoreRef(), queryQName, new QueryParameter[] { qp }); - assertEquals(0, results.length()); - results.close(); - - queryQName = QName.createQName("alf:test3", namespacePrefixResolver); - qp = new QueryParameter(QName.createQName("alf:banana", namespacePrefixResolver), "/one/five//*"); - results = searcher.query(rootNodeRef.getStoreRef(), queryQName, new QueryParameter[] { qp }); - assertEquals(7, results.length()); - results.close(); - - // TODO: should not have a null property type definition - QueryParameterDefImpl paramDef = new QueryParameterDefImpl(QName.createQName("alf:lemur", namespacePrefixResolver), (DataTypeDefinition) null, true, "fox"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"${alf:lemur}\"", new QueryParameterDefinition[] { paramDef }); - assertEquals(1, results.length()); - results.close(); - - paramDef = new QueryParameterDefImpl(QName.createQName("alf:intvalue", namespacePrefixResolver), (DataTypeDefinition) null, true, "1"); - qname = QName.createQName(TEST_NAMESPACE, "int-ista"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":\"${alf:intvalue}\"", new QueryParameterDefinition[] { paramDef }); - assertEquals(1, results.length()); - assertNotNull(results.getRow(0).getValue(qname)); - results.close(); - - // Open ended ranges - - qname = QName.createQName("{namespace}property-1"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[v TO w]", null); - assertEquals(2, results.length()); - results.close(); - - qname = QName.createQName("{namespace}property-1"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[v TO \uFFFF]", null); - assertEquals(2, results.length()); - results.close(); - - qname = QName.createQName("{namespace}property-1"); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" + escapeQName(qname) + ":[\u0000 TO w]", null); - assertEquals(2, results.length()); - results.close(); - } - - /** - * @throws Exception - */ - public void testPathSearch() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - // //* - - ResultSet - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//common\"", null); - assertEquals(7, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one//common\"", null); - assertEquals(5, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); - assertEquals(10, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//.\"", null); - assertEquals(11, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testXPathSearch() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - // //* - - ResultSet - - results = searcher.query(rootNodeRef.getStoreRef(), "xpath", "//./*", null); - assertEquals(15, results.length()); - results.close(); - luceneFTS.resume(); - - QueryParameterDefinition paramDef = new QueryParameterDefImpl(QName.createQName("alf:query", namespacePrefixResolver), (DataTypeDefinition) null, true, "//./*"); - results = searcher.query(rootNodeRef.getStoreRef(), "xpath", "${alf:query}", new QueryParameterDefinition[] { paramDef }); - assertEquals(15, results.length()); - results.close(); - } - - /** - * @throws Exception - */ - public void testMissingIndex() throws Exception - { - luceneFTS.pause(); - StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "_missing_"); - ADMLuceneSearcherImpl searcher = buildSearcher(); - - // //* - - ResultSet - - results = searcher.query(storeRef, "xpath", "//./*", null); - assertEquals(0, results.length()); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testUpdateIndex() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - - runBaseTests(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - indexer.updateNode(rootNodeRef); - indexer.updateNode(n1); - indexer.updateNode(n2); - indexer.updateNode(n3); - indexer.updateNode(n4); - indexer.updateNode(n5); - indexer.updateNode(n6); - indexer.updateNode(n7); - indexer.updateNode(n8); - indexer.updateNode(n9); - indexer.updateNode(n10); - indexer.updateNode(n11); - indexer.updateNode(n12); - indexer.updateNode(n13); - indexer.updateNode(n14); - - indexer.commit(); - - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testDeleteLeaf() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - testTX.commit(); - - // Delete - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - nodeService.deleteNode(n14); - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); - assertEquals(3, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); - assertEquals(3, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); - assertEquals(19, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); - assertEquals(18, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); - assertEquals(18, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); - assertEquals(18, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); - assertEquals(18, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); - assertEquals(18, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(0, results.length()); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testAddEscapedChild() throws Exception - { - String COMPLEX_LOCAL_NAME = "\u0020\u0060\u00ac\u00a6\u0021\"\u00a3\u0024\u0025\u005e\u0026\u002a\u0028\u0029\u002d\u005f\u003d\u002b\t\n\\\u0000\u005b\u005d\u007b\u007d\u003b\u0027\u0023\u003a\u0040\u007e\u002c\u002e\u002f\u003c\u003e\u003f\\u007c\u005f\u0078\u0054\u0036\u0035\u0041\u005f"; - if (dialect instanceof PostgreSQLDialect) - { - // Note: PostgreSQL does not support \u0000 char embedded in a string - // http://archives.postgresql.org/pgsql-jdbc/2007-02/msg00115.php - COMPLEX_LOCAL_NAME = "\u0020\u0060\u00ac\u00a6\u0021\"\u00a3\u0024\u0025\u005e\u0026\u002a\u0028\u0029\u002d\u005f\u003d\u002b\t\n\\\u005b\u005d\u007b\u007d\u003b\u0027\u0023\u003a\u0040\u007e\u002c\u002e\u002f\u003c\u003e\u003f\\u007c\u005f\u0078\u0054\u0036\u0035\u0041\u005f"; - } - - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - ChildAssociationRef car = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}" + COMPLEX_LOCAL_NAME), testSuperType); - indexer.createNode(car); - - indexer.commit(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:" + ISO9075.encode(COMPLEX_LOCAL_NAME) + "\"", null); - assertEquals(1, results.length()); - results.close(); - } - - /** - * @throws Exception - */ - public void testNumericInPath() throws Exception - { - String COMPLEX_LOCAL_NAME = "Woof12"; - - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - ChildAssociationRef car = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}" + COMPLEX_LOCAL_NAME), testSuperType); - indexer.createNode(car); - - indexer.commit(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:" + ISO9075.encode(COMPLEX_LOCAL_NAME) + "\"", null); - assertEquals(1, results.length()); - results.close(); - } - - /** - * @throws Exception - */ - public void testDeleteContainer() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - testTX.commit(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - nodeService.deleteNode(n13); - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); - assertEquals(3, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); - assertEquals(3, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); - assertEquals(13, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); - assertEquals(12, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); - assertEquals(12, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); - assertEquals(12, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); - assertEquals(12, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); - assertEquals(12, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); - assertEquals(14, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(0, results.length()); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testDeleteAndAddReference() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - nodeService.removeChild(n2, n13); - indexer.deleteChildRelationship(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("{namespace}link"), n13)); - - indexer.commit(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:three\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:four\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:eight-0\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:five\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:one\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:two\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:six\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:seven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-1\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-2\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-2\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-1\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:two/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:eight-0\"", null); - assertEquals(0, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:ten\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:eleven\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:five/namespace:twelve/namespace:thirteen/namespace:fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/namespace:*/namespace:*/namespace:*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:*/namespace:five/namespace:*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/namespace:*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/*/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/*/*/*\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*\"", null); - assertEquals(4, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/*/namespace:five/*\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/namespace:one/*/namespace:nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//.\"", null); - assertEquals(16, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//.\"", null); - assertEquals(24, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/.\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//*/./.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//*/./.\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//./*\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//./*\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//././*/././.\"", null); - assertEquals(15, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//././*/././.\"", null); - assertEquals(23, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//common\"", null); - assertEquals(6, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//common\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one//common\"", null); - assertEquals(5, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//*\"", null); - assertEquals(7, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//*\"", null); - assertEquals(10, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one/five//.\"", null); - assertEquals(8, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"/one/five//.\"", null); - assertEquals(11, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//five/nine\"", null); - assertEquals(1, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"/one//thirteen/fourteen\"", null); - assertEquals(1, results.length()); - results.close(); - - indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - - nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}link")); - indexer.createChildRelationship(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("{namespace}link"), n13)); - - indexer.commit(); - - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testRenameReference() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:link//.\"", null); - assertEquals(3, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//namespace:link//.\"", null); - assertEquals(4, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:renamed_link//.\"", null); - assertEquals(0, results.length()); - results.close(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis(), luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - - nodeService.removeChild(n2, n13); - nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}renamed_link")); - - indexer.updateChildRelationship(new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, QName.createQName("namespace", "link"), n13), new ChildAssociationRef(ASSOC_TYPE_QNAME, n2, - QName.createQName("namespace", "renamed_link"), n13)); - - indexer.commit(); - - runBaseTests(); - - searcher = buildSearcher(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:link//.\"", null); - assertEquals(0, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"//namespace:renamed_link//.\"", null); - assertEquals(3, results.length()); - results.close(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PATHWITHREPEATS:\"//namespace:renamed_link//.\"", null); - assertEquals(4, results.length()); - results.close(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testDelayIndex() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"KEYONE\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) + ":\"KEYUNSTORED\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) + ":\"KEYTWO\"", null); - assertEquals(0, results.length()); - results.close(); - - // Do index - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_" + (new Random().nextInt()), - luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - indexer.updateFullTextSearch(1000); - indexer.prepare(); - indexer.commit(); - - searcher = buildSearcher(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"keyone\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) + ":\"keytwo\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) + ":\"keyunstored\"", null); - assertEquals(1, results.length()); - results.close(); - - runBaseTests(); - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testWaitForIndex() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"KEYONE\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) + ":\"KEYUNSTORED\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) + ":\"KEYTWO\"", null); - assertEquals(0, results.length()); - results.close(); - - // Do index - - searcher = buildSearcher(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic")) + ":\"keyone\"", null); - assertEquals(1, results.length()); - results.close(); - - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_" + (new Random().nextInt()), - luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - indexer.updateFullTextSearch(1000); - indexer.prepare(); - indexer.commit(); - - luceneFTS.resume(); - // luceneFTS.requiresIndex(rootNodeRef.getStoreRef()); - // luceneFTS.index(); - // luceneFTS.index(); - // luceneFTS.index(); - - Thread.sleep(35000); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic")) + ":\"keytwo\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "\\@" - + escapeQName(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic")) + ":\"KEYUNSTORED\"", null); - assertEquals(1, results.length()); - results.close(); - - runBaseTests(); - } - - private String escapeQName(QName qname) - { - return SearchLanguageConversion.escapeLuceneQuery(qname.toString()); - } - - /** - * @throws Exception - */ - public void testForKev() throws Exception - { - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "PARENT:\"" + rootNodeRef.toString() + "\"", null); - assertEquals(5, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "+PARENT:\"" + rootNodeRef.toString() + "\" +QNAME:\"one\"", null); - assertEquals(1, results.length()); - results.close(); - - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", - "( +TYPE:\"{http://www.alfresco.org/model/content/1.0}content\" +@\\{http\\://www.alfresco.org/model/content/1.0\\}name:\"content woof\") OR TEXT:\"content\"", - null); - - luceneFTS.resume(); - } - - /** - * @throws Exception - */ - public void testIssueAR47() throws Exception - { - // This bug arose from repeated deletes and adds creating empty index - // segments. - // Two segements each containing one deletyed entry were merged together - // producing a single empty entry. - // This seemed to be bad for lucene - I am not sure why - - // So we add something, add and delete someting repeatedly and then - // check we can still do the search. - - // Running in autocommit against the index - testTX.commit(); - UserTransaction tx = transactionService.getUserTransaction(); - tx.begin(); - ChildAssociationRef testFind = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}testFind"), testSuperType); - tx.commit(); - - ADMLuceneSearcherImpl searcher = buildSearcher(); - - ResultSet results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); - assertEquals(1, results.length()); - results.close(); - - for (int i = 0; i < 100; i++) - { - UserTransaction tx1 = transactionService.getUserTransaction(); - tx1.begin(); - ChildAssociationRef test = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}test"), testSuperType); - tx1.commit(); - - UserTransaction tx2 = transactionService.getUserTransaction(); - tx2.begin(); - nodeService.deleteNode(test.getChildRef()); - tx2.commit(); - } - - UserTransaction tx3 = transactionService.getUserTransaction(); - tx3.begin(); - results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "QNAME:\"namespace:testFind\""); - assertEquals(1, results.length()); - results.close(); - tx3.commit(); - } - - // public void testMany() throws Exception - // { - // for(int i = 0; i < 100; i++) - // { - // testReadAgainstDelta(); - // System.out.println("At "+i); - // testTX.rollback(); - // testTX = transactionService.getUserTransaction(); - // testTX.begin(); - // } - // } - - /** - * @throws Exception - */ - public void testReadAgainstDelta() throws Exception - { - testTX.commit(); - testTX = transactionService.getUserTransaction(); - testTX.begin(); - luceneFTS.pause(); - buildBaseIndex(); - runBaseTests(); - testTX.commit(); - - // Delete - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - runBaseTests(); - - serviceRegistry.getNodeService().deleteNode(n1); - assertFalse(serviceRegistry.getNodeService().exists(n13)); - - SearchParameters sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - ResultSet results = serviceRegistry.getSearchService().query(sp); - assertEquals(6, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addSort("ID", true); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - // Delete - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - runBaseTests(); - - serviceRegistry.getNodeService().deleteNode(n2); - assertTrue(serviceRegistry.getNodeService().exists(n13)); - assertFalse(serviceRegistry.getNodeService().exists(n7)); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(13, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addSort("ID", true); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - // Create - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - runBaseTests(); - - assertEquals(5, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); - serviceRegistry.getNodeService().createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}texas"), testSuperType).getChildRef(); - assertEquals(6, serviceRegistry.getNodeService().getChildAssocs(rootNodeRef).size()); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(17, results.length()); - results.close(); - - testTX.rollback(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addSort("ID", true); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - // update property - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - runBaseTests(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("\\@\\{namespace\\}property\\-1:\"valueone\""); - sp.addSort("ID", true); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - - assertEquals(2, results.length()); - results.close(); - - nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "Different"); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("\\@\\{namespace\\}property\\-1:\"valueone\""); - sp.addSort("ID", true); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - - assertEquals(1, results.length()); - results.close(); - - testTX.rollback(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("\\@\\{namespace\\}property\\-1:\"valueone\""); - sp.excludeDataInTheCurrentTransaction(false); - sp.addSort("ID", true); - results = serviceRegistry.getSearchService().query(sp); - - assertEquals(2, results.length()); - results.close(); - - testTX.rollback(); - - // Add and delete - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - runBaseTests(); - - serviceRegistry.getNodeService().deleteNode(n1); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(6, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - NodeRef created = serviceRegistry.getNodeService().createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}texas"), testSuperType).getChildRef(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(7, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - serviceRegistry.getNodeService().deleteNode(created); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(6, results.length()); - results.close(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.excludeDataInTheCurrentTransaction(true); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - testTX.rollback(); - - testTX = transactionService.getUserTransaction(); - testTX.begin(); - - sp = new SearchParameters(); - sp.addStore(rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"//.\""); - sp.addSort("ID", true); - sp.excludeDataInTheCurrentTransaction(false); - results = serviceRegistry.getSearchService().query(sp); - assertEquals(16, results.length()); - results.close(); - - } - - public void test_MNT_10796() throws Exception - { - String contentName = "testContent7.txt"; - String quary = "cm:name:\"" + contentName + "\""; - this.authenticationComponent.setCurrentUser("admin"); - - SearchParameters sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery(quary); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - ResultSet results; - ResultSetMetaData md; - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - - Map properties = new HashMap(); - - properties.put(ContentModel.PROP_NAME, "folder"); - NodeRef folder = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, QName.createQName("{namespace}MNT-10796"), ContentModel.TYPE_FOLDER, properties).getChildRef(); - //System.out.println("folder=" + folder.toString()); - - properties.put(ContentModel.PROP_NAME, "folder2"); - NodeRef folder2 = nodeService.createNode(folder, ASSOC_TYPE_QNAME, QName.createQName("{namespace}MNT-10796"), ContentModel.TYPE_FOLDER, properties).getChildRef(); - //System.out.println("folder2=" + folder2.toString()); - - properties.put(ContentModel.PROP_NAME, contentName); - NodeRef testContent = nodeService.createNode(folder2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}MNT-10796"), ContentModel.TYPE_CONTENT, properties).getChildRef(); - //System.out.println("testContent=" + testContent.toString()); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery(quary); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(1, results.length()); - results.close(); - - nodeService.deleteNode(folder); - - sp = new SearchParameters(); - sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - sp.setQuery(quary); - sp.addStore(rootNodeRef.getStoreRef()); - sp.excludeDataInTheCurrentTransaction(false); - - results = serviceRegistry.getSearchService().query(sp); - assertEquals(0, results.length()); - results.close(); - } - - private void runPerformanceTest(double time, boolean clear) - { - ADMLuceneIndexerImpl indexer = ADMLuceneIndexerImpl.getUpdateIndexer(rootNodeRef.getStoreRef(), "delta" + System.currentTimeMillis() + "_" + (new Random().nextInt()), - luceneConfig); - indexer.setMaxAtomicTransformationTime(1000000); - indexer.setNodeService(nodeService); - // indexer.setLuceneIndexLock(luceneIndexLock); - indexer.setDictionaryService(dictionaryService); - indexer.setTenantService(tenantService); - indexer.setFullTextSearchIndexer(luceneFTS); - indexer.setContentService(contentService); - indexer.setTransactionService(transactionService); - if (clear) - { - // indexer.clearIndex(); - } - indexer.createNode(new ChildAssociationRef(null, null, null, rootNodeRef)); - - long startTime = System.currentTimeMillis(); - int count = 0; - for (int i = 0; i < 10000000; i++) - { - if (i % 10 == 0) - { - if (System.currentTimeMillis() - startTime > time) - { - count = i; - break; - } - } - - QName qname = QName.createQName("{namespace}a_" + i); - NodeRef ref = nodeService.createNode(rootNodeRef, ASSOC_TYPE_QNAME, qname, ContentModel.TYPE_CONTAINER).getChildRef(); - indexer.createNode(new ChildAssociationRef(ASSOC_TYPE_QNAME, rootNodeRef, qname, ref)); - - } - indexer.commit(); - float delta = ((System.currentTimeMillis() - startTime) / 1000.0f); - // System.out.println("\tCreated " + count + " in " + delta + " = " + - // (count / delta)); - } - - private NamespacePrefixResolver getNamespacePrefixResolver(String defaultURI) - { - DynamicNamespacePrefixResolver nspr = new DynamicNamespacePrefixResolver(null); - nspr.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI); - nspr.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI); - nspr.registerNamespace(NamespaceService.DICTIONARY_MODEL_PREFIX, NamespaceService.DICTIONARY_MODEL_1_0_URI); - nspr.registerNamespace(NamespaceService.SYSTEM_MODEL_PREFIX, NamespaceService.SYSTEM_MODEL_1_0_URI); - nspr.registerNamespace("namespace", "namespace"); - nspr.registerNamespace("lucene-test", TEST_NAMESPACE); - nspr.registerNamespace(NamespaceService.DEFAULT_PREFIX, defaultURI); - return nspr; - } - - /** - * @param args String[] - * @throws Exception - */ - public static void main(String[] args) throws Exception - { - ADMLuceneTest test = new ADMLuceneTest(); - test.setUp(); - // test.testForKev(); - // test.testDeleteContainer(); - - // test.testReadAgainstDelta(); - - NodeRef targetNode = test.rootNodeRef; - Path path = test.serviceRegistry.getNodeService().getPath(targetNode); - - SearchParameters sp = new SearchParameters(); - sp.addStore(test.rootNodeRef.getStoreRef()); - sp.setLanguage(SearchService.LANGUAGE_LUCENE); - sp.setQuery("PATH:\"" + path + "//." + "\""); - ResultSet results = test.serviceRegistry.getSearchService().query(sp); - - results.close(); - - // test.dictionaryService.getType(test.nodeService.getType(test.rootNodeRef)).getDefaultAspects(); - } - - /** - * @author andyh - */ - public static class UnknownDataType implements Serializable - { - - /** - * - */ - private static final long serialVersionUID = -6729690518573349055L; - - } -} diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/ALF947Test.java b/src/test/java/org/alfresco/repo/search/impl/lucene/ALF947Test.java deleted file mode 100644 index 016e3df724..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/ALF947Test.java +++ /dev/null @@ -1,423 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.transaction.Status; -import javax.transaction.UserTransaction; - -import junit.framework.TestCase; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.CopyService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.ResultSetRow; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; - -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class ALF947Test extends TestCase -{ - private ApplicationContext ctx; - - private NodeService nodeService; - private LuceneIndexerAndSearcher indexerAndSearcher; - private TransactionService transactionService; - private AuthenticationComponent authenticationComponent; - private CopyService copyService; - private FileFolderService fileFolderService; - - private UserTransaction testTX; - - private StoreRef storeRef = null; - - public ALF947Test() - { - super(); - } - - public void setUp() throws Exception - { - ctx = ApplicationContextHelper.getApplicationContext(); - this.nodeService = (NodeService) ctx.getBean("dbNodeService"); - ChildApplicationContextFactory luceneSubSystem = (ChildApplicationContextFactory) ctx.getBean("buildonly"); - this.indexerAndSearcher = (LuceneIndexerAndSearcher) luceneSubSystem.getApplicationContext().getBean("search.admLuceneIndexerAndSearcherFactory"); - this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); - this.transactionService = (TransactionService) ctx.getBean("transactionComponent"); - this.copyService = (CopyService) ctx.getBean("CopyService"); - this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService"); - } - - @Override - protected void tearDown() throws Exception - { - if (testTX.getStatus() == Status.STATUS_ACTIVE) - { - testTX.rollback(); - } - AuthenticationUtil.clearCurrentSecurityContext(); - super.tearDown(); - } - - private NodeRef folder1; - private NodeRef folder2; - private NodeRef folder3; - private NodeRef folder4; - private NodeRef folder5; - private NodeRef folder6; - private NodeRef folder7; - - private NodeRef file1; - private NodeRef file2; - private NodeRef file3; - private NodeRef file4; - - private void buildBigTree(NodeRef rootNodeRef) - { - Map properties = new HashMap(); - - // create node hierarchy - properties.put(ContentModel.PROP_NAME, "folder1"); - QName assoc1Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "root_p_f1"); - folder1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, assoc1Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "folder2"); - QName assoc2Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "root_p_f2"); - folder2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, assoc2Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "folder3"); - QName assoc3Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "root_p_f3"); - folder3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, assoc3Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "folder4"); - QName assoc4Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f1_p_f4"); - folder4 = nodeService.createNode(folder1, ContentModel.ASSOC_CONTAINS, assoc4Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "folder5"); - QName assoc5Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f4_p_f5"); - folder5 = nodeService.createNode(folder4, ContentModel.ASSOC_CONTAINS, assoc5Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "folder6"); - QName assoc6Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f5_p_f6"); - folder6 = nodeService.createNode(folder5, ContentModel.ASSOC_CONTAINS, assoc6Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - //properties.put(ContentModel.PROP_NAME, "folder7"); - //QName assoc7Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f6_p_f7"); - //folder7 = nodeService.createNode(folder6, ContentModel.ASSOC_CONTAINS, assoc6Name, ContentModel.TYPE_FOLDER, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "file1"); - QName assoc8Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f1_p_file1"); - file1 = nodeService.createNode(folder1, ContentModel.ASSOC_CONTAINS, assoc8Name, ContentModel.TYPE_CONTENT, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "file2"); - QName assoc9Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f4_p_file2"); - file2 = nodeService.createNode(folder4, ContentModel.ASSOC_CONTAINS, assoc8Name, ContentModel.TYPE_CONTENT, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "file3"); - QName assoc10Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f5_p_file3"); - file3 = nodeService.createNode(folder5, ContentModel.ASSOC_CONTAINS, assoc9Name, ContentModel.TYPE_CONTENT, properties).getChildRef(); - - properties.put(ContentModel.PROP_NAME, "file4"); - QName assoc11Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "f3_p_file4"); - file4 = nodeService.createNode(folder3, ContentModel.ASSOC_CONTAINS, assoc10Name, ContentModel.TYPE_CONTENT, properties).getChildRef(); - - nodeService.addChild(Arrays.asList(folder1, folder4, folder5, folder6), file4, ContentModel.ASSOC_CONTAINS, - QName.createQName("stuff")); - } - - /** - * This moves a node under a different parent and then checks that a search does - * not return duplicates - * - * @throws Exception - */ - public void testALF947_1() throws Exception - { - StoreRef storeRef = null; - NodeRef rootNodeRef = null; - String queryString = null; - SearchService searchService = null; - ResultSet results = null; - - try { - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - buildBigTree(rootNodeRef); - - // perform a search, which should flush the index delta - // this is key to getting the duplicates - searchService = indexerAndSearcher.getSearcher(storeRef, true); - queryString = "@cm\\:name:n4"; - results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, queryString); // should call flushPending - results.close(); - - // move folder1 under folder2 - nodeService.moveNode(folder1, folder2, ContentModel.ASSOC_CONTAINS, QName.createQName("{namespace}test")); - - // search for all nodes in the store - queryString = "PATH:\"//*\""; - results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, queryString); - - for (ResultSetRow row : results) - { - NodeRef nodeRef = row.getNodeRef(); - System.out.println("Node ref = " + nodeRef); - Map nodeProperties = nodeService.getProperties(nodeRef); - for(QName propName : nodeProperties.keySet()) - { - System.out.println("Property " + propName + "=" + nodeProperties.get(propName)); - } - } - System.out.println("==================="); - - results.close(); - - assertEquals(10, results.length()); // expect 10 nodes from the search i.e. no duplicates - List parents = nodeService.getParentAssocs(file4); - assertEquals(5, parents.size()); // expect 5 parents (including primary parent) - } - finally - { - if(null != storeRef) - { - //nodeService.deleteStore(storeRef); - } - if(null != testTX) - { - testTX.commit(); - } - } - } - - /** - * The same as testALF942_1 but the search is performed in a different txn - * @throws Exception - */ - public void testALF947_2() throws Exception - { - StoreRef storeRef = null; - NodeRef rootNodeRef = null; - String queryString = null; - SearchService searchService = null; - ResultSet results = null; - - try { - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - buildBigTree(rootNodeRef); - - // perform a search, which should flush the delta index - // this is key to getting the duplicates - searchService = indexerAndSearcher.getSearcher(storeRef, true); - queryString = "@cm\\:name:n4"; - results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, queryString); // should call flushPending - results.close(); - - // move n1 under n2 - nodeService.moveNode(folder1, folder2, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "n2_p_n1")/*QName.createQName("{namespace}test")*/); - } - finally - { - if(null != storeRef) - { - ////nodeService.deleteStore(storeRef); - } - if(null != testTX) - { - testTX.commit(); - } - } - - try { - // start another transaction to perform a fresh search - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - // perform a search, which should flush the index delta - queryString = "PATH:\"//*\""; - searchService = indexerAndSearcher.getSearcher(storeRef, true); - results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, queryString); - - for (ResultSetRow row : results) - { - NodeRef nodeRef = row.getNodeRef(); - System.out.println("Node ref = " + nodeRef); - Map nodeProperties = nodeService.getProperties(nodeRef); - for(QName propName : nodeProperties.keySet()) - { - System.out.println("Property " + propName + "=" + nodeProperties.get(propName)); - } - } - System.out.println("==================="); - - results.close(); - - assertEquals(10, results.length()); // expect 5 nodes from the search i.e. no duplicates - - List parents = nodeService.getParentAssocs(file4); - assertEquals(5, parents.size()); // expect 5 parents (including primary parent) - } - finally - { - if(null != storeRef) - { - //nodeService.deleteStore(storeRef); - } - if(null != testTX) - { - testTX.commit(); - } - } - } - - /** - * This is duplicating what is happening in the bug report but without rules. - * It results in a rename of the copied node which subsequently results in - * a move node operation (with the parent staying the same). - * - * A search is performed in a different txn to mimic the bug report - * - * @throws Exception - */ - public void testALF947_3() throws Exception - { - NodeRef rootNodeRef = null; - String queryString = null; - SearchService searchService = null; - ResultSet results = null; - - try { - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); - rootNodeRef = nodeService.getRootNode(storeRef); - - buildBigTree(rootNodeRef); - - // copy folder1 node hierarchy under folder2 - NodeRef newNode = copyService.copyAndRename(folder1, folder2, ContentModel.ASSOC_CONTAINS, null, true); - - // perform a search, which should flush the index delta - // this is key to getting the duplicates - searchService = indexerAndSearcher.getSearcher(storeRef, true); - queryString = "PATH:\"//*\""; - results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, queryString); // should call flushPending - results.close(); - - // rename the copied node - FileInfo fileInfo = fileFolderService.rename(newNode, "folder7"); - } - finally - { - if(null != storeRef) - { - ////nodeService.deleteStore(storeRef); - } - if(null != testTX) - { - testTX.commit(); - } - } - - try { - // start another transaction to perform a fresh search - testTX = transactionService.getUserTransaction(); - testTX.begin(); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - queryString = "PATH:\"//*\""; - searchService = indexerAndSearcher.getSearcher(storeRef, true); - results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, queryString); - - for (ResultSetRow row : results) - { - NodeRef nodeRef = row.getNodeRef(); - System.out.println("Node ref = " + nodeRef); - Map nodeProperties = nodeService.getProperties(nodeRef); - for(QName propName : nodeProperties.keySet()) - { - System.out.println("Property " + propName + "=" + nodeProperties.get(propName)); - } - } - System.out.println("==================="); - - results.close(); - - // expect 9 nodes from the search i.e. no duplicates - // n1, n2, n3, n4, n5, copies of n1 (renamed to n6), n3, n4, n5 - assertEquals(17, results.length()); - - List parents = nodeService.getParentAssocs(file4); - // expect 9 parents (including primary parent) i.e. 4 parents from each copy of the subtree - assertEquals(9, parents.size()); - } - finally - { - if(null != storeRef) - { - ////nodeService.deleteStore(storeRef); - } - if(null != testTX) - { - testTX.commit(); - } - } - } -} diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/LuceneIndexBackupComponentTest.java b/src/test/java/org/alfresco/repo/search/impl/lucene/LuceneIndexBackupComponentTest.java deleted file mode 100644 index 1aed985ba2..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/LuceneIndexBackupComponentTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene; - -import java.io.File; -import java.util.Collections; - -import junit.framework.TestCase; - -import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory; -import org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.LuceneIndexBackupComponent; -import org.alfresco.repo.security.authentication.AuthenticationComponent; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.test_category.OwnJVMTestsCategory; -import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.TempFileProvider; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; -import org.springframework.context.ApplicationContext; - -/** - * - * @author Derek Hulley - */ -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class LuceneIndexBackupComponentTest extends TestCase -{ - private ApplicationContext ctx; - - private LuceneIndexBackupComponent backupComponent; - private File tempTargetDir; - - private AuthenticationComponent authenticationComponent; - - @Override - public void setUp() throws Exception - { - ctx = ApplicationContextHelper.getApplicationContext(); - TransactionService transactionService = (TransactionService) ctx.getBean("transactionComponent"); - NodeService nodeService = (NodeService) ctx.getBean("NodeService"); - - ChildApplicationContextFactory luceneSubSystem = (ChildApplicationContextFactory) ctx.getBean("buildonly"); - LuceneIndexerAndSearcher factory = (LuceneIndexerAndSearcher) luceneSubSystem.getApplicationContext().getBean("search.admLuceneIndexerAndSearcherFactory"); - - this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent"); - this.authenticationComponent.setSystemUserAsCurrentUser(); - - tempTargetDir = new File(TempFileProvider.getTempDir(), getName()); - tempTargetDir.mkdir(); - - backupComponent = new LuceneIndexBackupComponent(); - backupComponent.setTransactionService(transactionService); - backupComponent.setFactories(Collections.singleton(factory)); - backupComponent.setNodeService(nodeService); - backupComponent.setTargetLocation(tempTargetDir.toString()); - } - - @Override - protected void tearDown() throws Exception - { - authenticationComponent.clearCurrentSecurityContext(); - super.tearDown(); - } - - /** - * Test back up - */ - public void testBackup() - { - backupComponent.backup(); - - // make sure that the target directory was created - assertTrue("Target location doesn't exist", tempTargetDir.exists()); - } -} diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/MultiReaderTest.java b/src/test/java/org/alfresco/repo/search/impl/lucene/MultiReaderTest.java deleted file mode 100644 index e167a15dfa..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/MultiReaderTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; - -import junit.framework.TestCase; -import org.alfresco.util.testing.category.LuceneTests; -import org.junit.experimental.categories.Category; - -@Category(LuceneTests.class) -public class MultiReaderTest extends TestCase -{ - - public MultiReaderTest() - { - super(); - } - - public MultiReaderTest(String arg0) - { - super(arg0); - } - - public void testMultiReader_single() throws IOException - { - String first = "my first string"; - String second = "another little string"; - - StringReader one = new StringReader(first); - StringReader two = new StringReader(second); - - Reader multiReader = new MultiReader(one, two); - StringBuilder builder = new StringBuilder(); - int c; - while ((c = multiReader.read()) != -1) - { - builder.append((char) c); - } - assertEquals(builder.toString(), first + second); - - } - - public void testMultiReader_bits() throws IOException - { - String first = "my first string"; - String second = "another little string"; - - StringReader one = new StringReader(first); - StringReader two = new StringReader(second); - - Reader multiReader = new MultiReader(one, two); - StringBuilder builder = new StringBuilder(); - for (int chunk = 1; chunk < 100; chunk++) - { - char[] c = new char[chunk]; - int i = 0; - while (i != -1) - { - i = multiReader.read(c); - for (int j = 0; j < i; j++) - { - builder.append(c[j]); - } - } - assertEquals(builder.toString(), first + second); - } - } - - public void testSkip() throws IOException - { - String first = "my first string"; - String second = "another little string"; - - StringReader one = new StringReader(first); - StringReader two = new StringReader(second); - - Reader multiReader = new MultiReader(one, two); - - multiReader.skip(3); - String all = first + second; - assertEquals((char)multiReader.read(), all.charAt(3)); - - multiReader.skip(15); - assertEquals((char)multiReader.read(), all.charAt(3+15+1)); - } - -} diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/fts/FullTextSearchIndexerBootstrapBeanTest.java b/src/test/java/org/alfresco/repo/search/impl/lucene/fts/FullTextSearchIndexerBootstrapBeanTest.java deleted file mode 100644 index 1d0095ce57..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/fts/FullTextSearchIndexerBootstrapBeanTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene.fts; - -import static org.mockito.Mockito.*; -import static org.junit.Assert.*; - -import java.text.MessageFormat; - -import org.alfresco.util.testing.category.LuceneTests; -import org.apache.log4j.Appender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.mockito.ArgumentCaptor; -import org.springframework.extensions.surf.util.I18NUtil; -import org.junit.BeforeClass; -import static org.hamcrest.CoreMatchers.is; - -@Category(LuceneTests.class) -public class FullTextSearchIndexerBootstrapBeanTest -{ - private FullTextSearchIndexerBootstrapBean bean; - - private final static Appender appender = mock(Appender.class); - - private final static Logger logger = Logger.getRootLogger(); - - @BeforeClass - public static void setupBeforeClass() - { - I18NUtil.registerResourceBundle("alfresco.messages.system-messages"); - I18NUtil.registerResourceBundle("alfresco.version"); - logger.addAppender(appender); - } - - @Test - public void test() - { - // when - bean = new FullTextSearchIndexerBootstrapBean(); - try - { - bean.onBootstrap(null); - } - catch (NullPointerException n) - { - // expected for this test, since there is no nodeService - } - - // then - ArgumentCaptor argument = ArgumentCaptor.forClass(LoggingEvent.class); - verify(appender).doAppend(argument.capture()); - assertThat(argument.getValue().getLevel(), is(Level.ERROR)); - - String majorVersion = I18NUtil.getMessage("version.major"); - String minorVersion = I18NUtil.getMessage("version.minor"); - String pattern = "docs.alfresco.com/{0}"; - pattern = MessageFormat.format(pattern, majorVersion + "." + minorVersion); - assertTrue(String.valueOf(argument.getValue().getMessage()).contains(pattern)); - } - - @AfterClass - public static void cleanupAfterClass() - { - logger.removeAppender(appender); - } -} diff --git a/src/test/java/org/alfresco/repo/search/impl/lucene/index/IndexInfoTest.java b/src/test/java/org/alfresco/repo/search/impl/lucene/index/IndexInfoTest.java deleted file mode 100644 index c210206055..0000000000 --- a/src/test/java/org/alfresco/repo/search/impl/lucene/index/IndexInfoTest.java +++ /dev/null @@ -1,912 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.repo.search.impl.lucene.index; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; - -import junit.framework.TestCase; - -import org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.util.GUID; -import org.alfresco.util.TempFileProvider; -import org.alfresco.util.testing.category.LuceneTests; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermDocs; -import org.junit.experimental.categories.Category; - -@Category(LuceneTests.class) -public class IndexInfoTest extends TestCase -{ - - public static final String[] WORD_LIST = { "aardvark", "banana", "cucumber", "daffodil", "emu", "frog", "gibbon", - "humour", "injection", "jelly", "key", "lemur", "monkey", "number", "open", "plummet", "quest", - "replication", "steam", "tunnel", "uncommon", "verbose", "where", "xylem", "yellow", "zebra", "alpha", - "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "indigo", "juliet", "kilo", "lima", - "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whisky", - "xray", "yankee", "zulu" }; - - public static final String[] CREATE_LIST = { "aardvark", "banana", "cucumber", "daffodil", "emu", "frog", "gibbon", - "humour", "injection", "jelly", "key", "lemur", "monkey", "number", "open", "plummet", "quest", - "replication", "steam", "tunnel", "uncommon", "verbose", "where", "xylem", "yellow", "zebra", }; - - public static final String[] UPDATE_LIST = { "alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", - "hotel", "indigo", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", - "sierra", "tango", "uniform", "victor", "whisky", "xray", "yankee", "zulu" }; - - public static final String[] CREATE_LIST_2 = { "aardvark2", "banana2", "cucumber2", "daffodil2", "emu2", "frog2", "gibbon2", - "humour2", "injection2", "jelly2", "key2", "lemur2", "monkey2", "number2", "open2", "plummet2", "quest2", - "replication2", "steam2", "tunnel2", "uncommon2", "verbose2", "where2", "xylem2", "yellow2", "zebra2", }; - -public static final String[] UPDATE_LIST_2 = { "alpha2", "bravo2", "charlie2", "delta2", "echo2", "foxtrot2", "golf2", - "hotel2", "indigo2", "juliet2", "kilo2", "lima2", "mike2", "november2", "oscar2", "papa2", "quebec2", "romeo2", - "sierra2", "tango2", "uniform2", "victor2", "whisky2", "xray2", "yankee2", "zulu2" }; - - public IndexInfoTest() - { - super(); - } - - public IndexInfoTest(String arg0) - { - super(arg0); - } - - public void testCreateAndSearch() throws IOException - { - System.setProperty("disableLuceneLocks", "true"); - - // no deletions - create only - HashSet deletions = new HashSet(); - for (int i = 0; i < 0; i++) - { - deletions.add(new NodeRef(new StoreRef("woof", "bingle"), GUID.generate()).toString()); - } - - File tempLocation = TempFileProvider.getTempDir(); - File testArea = new File(tempLocation, "IndexInfoTest"); - File testDir = new File(testArea, "" + System.currentTimeMillis()); - final IndexInfo ii = IndexInfo.getIndexInfo(testDir, null); - - for (int i = 0; i < WORD_LIST.length; i++) - { - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i); - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - IndexWriter writer = ii.getDeltaIndexWriter(guid, new AlfrescoStandardAnalyser()); - - Document doc = new Document(); - for (int k = 0; k < 15; k++) - { - doc.add(new Field("ID" + k, guid, Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - } - doc.add(new Field("TEXT", WORD_LIST[i], Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - writer.addDocument(doc); - - ii.closeDeltaIndexWriter(guid); - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, deletions, Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i); - for (int j = 0; j < WORD_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", WORD_LIST[j])); - if (j < i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, deletions, Collections.emptySet(), false); - assertEquals(reader.numDocs(), i + 1); - for (int j = 0; j < WORD_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", WORD_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i + 1); - for (int j = 0; j < WORD_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", WORD_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - } - - } - - public void testCreateDeleteAndSearch() throws IOException - { - assertEquals(CREATE_LIST.length, UPDATE_LIST.length); - - StoreRef storeRef = new StoreRef("woof", "bingle"); - - System.setProperty("disableLuceneLocks", "true"); - - // no deletions - create only - ArrayList nodeRefs = new ArrayList(); - - File tempLocation = TempFileProvider.getTempDir(); - File testArea = new File(tempLocation, "IndexInfoTest"); - File testDir = new File(testArea, "" + System.currentTimeMillis()); - final IndexInfo ii = IndexInfo.getIndexInfo(testDir, null); - - for (int i = 0; i < CREATE_LIST.length; i++) - { - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i); - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - IndexWriter writer = ii.getDeltaIndexWriter(guid, new AlfrescoStandardAnalyser()); - - Document doc = new Document(); - for (int k = 0; k < 15; k++) - { - doc.add(new Field("ID" + k, guid, Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - } - doc.add(new Field("TEXT", CREATE_LIST[i], Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - NodeRef nodeRef = new NodeRef(storeRef, GUID.generate()); - nodeRefs.add(nodeRef); - doc.add(new Field("ID", nodeRef.toString(), Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - writer.addDocument(doc); - - ii.closeDeltaIndexWriter(guid); - - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, Collections.emptySet(), Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i); - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j < i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, Collections.emptySet(), Collections.emptySet(), false); - assertEquals(reader.numDocs(), i + 1); - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i + 1); - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - } - - for (int i = 0; i < CREATE_LIST.length; i++) - { - HashSet deletions = new HashSet(); - deletions.add(nodeRefs.get(i).toString()); - - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), CREATE_LIST.length - i); - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - ii.closeDeltaIndexWriter(guid); - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, deletions, Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), CREATE_LIST.length - i); - int lastDoc = -1; - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j >= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, deletions, Collections.emptySet(), false); - assertEquals(reader.numDocs(), UPDATE_LIST.length - i - 1); - lastDoc = -1; - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j > i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), UPDATE_LIST.length - i - 1); - lastDoc = -1; - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j > i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - - reader.close(); - - IndexReader reader1 = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - IndexReader reader2 = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - IndexReader reader3 = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - reader3.close(); - reader2.close(); - reader1.close(); - - } - - } - - public void testCreateUpdateAndSearch() throws IOException - { - assertEquals(CREATE_LIST.length, UPDATE_LIST.length); - - StoreRef storeRef = new StoreRef("woof", "bingle"); - - System.setProperty("disableLuceneLocks", "true"); - - // no deletions - create only - ArrayList nodeRefs = new ArrayList(); - - File tempLocation = TempFileProvider.getTempDir(); - File testArea = new File(tempLocation, "IndexInfoTest"); - File testDir = new File(testArea, "" + System.currentTimeMillis()); - final IndexInfo ii = IndexInfo.getIndexInfo(testDir, null); - - for (int i = 0; i < CREATE_LIST.length; i++) - { - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i); - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - IndexWriter writer = ii.getDeltaIndexWriter(guid, new AlfrescoStandardAnalyser()); - - Document doc = new Document(); - for (int k = 0; k < 15; k++) - { - doc.add(new Field("ID" + k, guid, Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - } - doc.add(new Field("TEXT", CREATE_LIST[i], Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - NodeRef nodeRef = new NodeRef(storeRef, GUID.generate()); - nodeRefs.add(nodeRef); - doc.add(new Field("ID", nodeRef.toString(), Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - writer.addDocument(doc); - - ii.closeDeltaIndexWriter(guid); - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, Collections.emptySet(), Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i); - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j < i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, Collections.emptySet(), Collections.emptySet(), false); - assertEquals(reader.numDocs(), i + 1); - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), i + 1); - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertEquals(tds.doc(), j); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - } - - for (int i = 0; i < UPDATE_LIST.length; i++) - { - HashSet deletions = new HashSet(); - deletions.add(nodeRefs.get(i).toString()); - - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), UPDATE_LIST.length); - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - IndexWriter writer = ii.getDeltaIndexWriter(guid, new AlfrescoStandardAnalyser()); - - Document doc = new Document(); - for (int k = 0; k < 15; k++) - { - doc.add(new Field("ID" + k, guid, Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - } - doc.add(new Field("TEXT", UPDATE_LIST[i], Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - writer.addDocument(doc); - - ii.closeDeltaIndexWriter(guid); - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, deletions, Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), UPDATE_LIST.length); - int lastDoc = -1; - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j >= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - for (int j = 0; j < UPDATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", UPDATE_LIST[j])); - if (j < i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, deletions, Collections.emptySet(), false); - assertEquals(reader.numDocs(), UPDATE_LIST.length); - lastDoc = -1; - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j > i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - for (int j = 0; j < UPDATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", UPDATE_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - assertEquals(reader.numDocs(), UPDATE_LIST.length); - lastDoc = -1; - for (int j = 0; j < CREATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", CREATE_LIST[j])); - if (j > i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - for (int j = 0; j < UPDATE_LIST.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", UPDATE_LIST[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - } - - } - - public void testMultiThreadedCreateAndSearch() - { - - System.setProperty("disableLuceneLocks", "true"); - - File tempLocation = TempFileProvider.getTempDir(); - File testArea = new File(tempLocation, "IndexInfoTest"); - File testDir = new File(testArea, "" + System.currentTimeMillis()); - final IndexInfo ii = IndexInfo.getIndexInfo(testDir, null); - - Thread thread1 = new Thread(new Test(ii, CREATE_LIST, UPDATE_LIST)); - Thread thread2 = new Thread(new Test(ii, CREATE_LIST_2, UPDATE_LIST_2)); - thread1.start(); - thread2.start(); - try - { - thread1.join(); - thread2.join(); - } - catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public static class Test implements Runnable - { - String[] create; - String[] update; - IndexInfo ii; - - Test(IndexInfo ii, String[] create, String[] update) - { - this.ii = ii; - this.create = create; - this.update = update; - } - - public void run() - { - try - { - assertEquals(create.length, update.length); - - StoreRef storeRef = new StoreRef("woof", "bingle"); - - // no deletions - create only - ArrayList nodeRefs = new ArrayList(); - - for (int i = 0; i < create.length; i++) - { - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - IndexWriter writer = ii.getDeltaIndexWriter(guid, new AlfrescoStandardAnalyser()); - - Document doc = new Document(); - for (int k = 0; k < 15; k++) - { - doc.add(new Field("ID" + k, guid, Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - } - doc.add(new Field("TEXT", create[i], Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - NodeRef nodeRef = new NodeRef(storeRef, GUID.generate()); - nodeRefs.add(nodeRef); - doc.add(new Field("ID", nodeRef.toString(), Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - writer.addDocument(doc); - - ii.closeDeltaIndexWriter(guid); - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, Collections.emptySet(), Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - - int lastDoc = -1; - - for (int j = 0; j < create.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", create[j])); - if (j < i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, Collections.emptySet(), Collections.emptySet(), false); - lastDoc = -1; - for (int j = 0; j < create.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", create[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - lastDoc = -1; - for (int j = 0; j < create.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", create[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - } - - for (int i = 0; i < update.length; i++) - { - HashSet deletions = new HashSet(); - deletions.add(nodeRefs.get(i).toString()); - - IndexReader reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - - reader.close(); - - String guid = GUID.generate(); - ii.setStatus(guid, TransactionStatus.ACTIVE, null, null); - IndexWriter writer = ii.getDeltaIndexWriter(guid, new AlfrescoStandardAnalyser()); - - Document doc = new Document(); - for (int k = 0; k < 15; k++) - { - doc.add(new Field("ID" + k, guid, Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - } - doc.add(new Field("TEXT", update[i], Field.Store.NO, Field.Index.UN_TOKENIZED, Field.TermVector.NO)); - writer.addDocument(doc); - - ii.closeDeltaIndexWriter(guid); - ii.setStatus(guid, TransactionStatus.PREPARING, null, null); - ii.setPreparedState(guid, deletions, Collections.emptySet(), 1, false); - ii.getDeletions(guid); - ii.setStatus(guid, TransactionStatus.PREPARED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - - int lastDoc = -1; - for (int j = 0; j < create.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", create[j])); - if (j >= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - for (int j = 0; j < update.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", update[j])); - if (j < i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(guid, deletions, Collections.emptySet(), false); - - lastDoc = -1; - for (int j = 0; j < create.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", create[j])); - if (j > i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - for (int j = 0; j < update.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", update[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - - reader.close(); - - ii.setStatus(guid, TransactionStatus.COMMITTING, null, null); - ii.setStatus(guid, TransactionStatus.COMMITTED, null, null); - - reader = ii.getMainIndexReferenceCountingReadOnlyIndexReader(); - - lastDoc = -1; - for (int j = 0; j < create.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", create[j])); - if (j > i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - for (int j = 0; j < update.length; j++) - { - TermDocs tds = reader.termDocs(new Term("TEXT", update[j])); - if (j <= i) - { - assertTrue(tds.next()); - assertTrue(tds.doc() > lastDoc); - lastDoc = tds.doc(); - } - else - { - assertFalse(tds.next()); - } - tds.close(); - } - reader.close(); - - } - - } - catch (IOException e) - { - System.exit(-1); - } - } - - } -} diff --git a/src/test/java/org/alfresco/repo/search/impl/querymodel/impl/db/DBQueryTest.java b/src/test/java/org/alfresco/repo/search/impl/querymodel/impl/db/DBQueryTest.java index 59c7dcbf87..3f515e9105 100644 --- a/src/test/java/org/alfresco/repo/search/impl/querymodel/impl/db/DBQueryTest.java +++ b/src/test/java/org/alfresco/repo/search/impl/querymodel/impl/db/DBQueryTest.java @@ -51,7 +51,6 @@ import org.alfresco.repo.dictionary.DictionaryNamespaceComponent; import org.alfresco.repo.dictionary.M2Model; import org.alfresco.repo.dictionary.NamespaceDAO; import org.alfresco.repo.node.BaseNodeServiceTest; -import org.alfresco.repo.search.impl.lucene.ADMLuceneTest.UnknownDataType; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.transaction.RetryingTransactionHelper; @@ -949,4 +948,9 @@ public class DBQueryTest implements DictionaryListener results.getResultSetMetaData(); results.close(); } + + private static class UnknownDataType implements Serializable + { + private static final long serialVersionUID = -6729690518573349055L; + } } diff --git a/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index 5cba7e58fd..f6a7303b26 100644 --- a/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -82,6 +82,7 @@ import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.FixMethodOrder; import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; @@ -346,13 +347,15 @@ public class AuthorityServiceTest extends TestCase assertEquals(1, pubAuthorityService.getAllRootAuthoritiesInZone("Three", AuthorityType.GROUP).size()); } + @Category(RedundantTests.class) public void test_ETWOTWO_400() { pubAuthorityService.createAuthority(AuthorityType.GROUP, "wo\"of"); Set authorities = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, true, "wo\"of*", AuthorityService.ZONE_APP_DEFAULT); assertEquals(1, authorities.size()); } - + + @Category(RedundantTests.class) public void testGroupWildcards() { long before, after; diff --git a/src/test/java/org/alfresco/repo/security/permissions/impl/ReadPermissionTest.java b/src/test/java/org/alfresco/repo/security/permissions/impl/ReadPermissionTest.java index 2001989e7d..609a2fe471 100644 --- a/src/test/java/org/alfresco/repo/security/permissions/impl/ReadPermissionTest.java +++ b/src/test/java/org/alfresco/repo/security/permissions/impl/ReadPermissionTest.java @@ -37,10 +37,11 @@ import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.QName; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; // Unit tests for ALF-3952 "Search/Read Permissions Evaluation Performance" -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) +@Category({OwnJVMTestsCategory.class, LuceneTests.class, RedundantTests.class}) public class ReadPermissionTest extends AbstractReadPermissionTest { // public void testDynamicAuthority() throws Exception diff --git a/src/test/java/org/alfresco/repo/security/person/PersonTest.java b/src/test/java/org/alfresco/repo/security/person/PersonTest.java index 67c6b29f4d..55cfb71fb0 100644 --- a/src/test/java/org/alfresco/repo/security/person/PersonTest.java +++ b/src/test/java/org/alfresco/repo/security/person/PersonTest.java @@ -75,11 +75,10 @@ import org.alfresco.util.EqualsHelper; import org.alfresco.util.GUID; import org.alfresco.util.Pair; import org.alfresco.util.PropertyMap; -import org.alfresco.util.testing.category.LuceneTests; import org.junit.experimental.categories.Category; import org.springframework.context.ApplicationContext; -@Category({OwnJVMTestsCategory.class, LuceneTests.class}) +@Category({OwnJVMTestsCategory.class}) public class PersonTest extends TestCase { private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); @@ -1697,85 +1696,4 @@ public class PersonTest extends TestCase } }, false, true); } - - // Test case for MNT-8539 - // note: This test can be removed as and when we remove the deprecated "getPeople" impl. - // also, the test currently works with Lucene only. In other words, it won't work with Solr. - public void testPeopleFiltering_deprecatedFTS() - { - personService.setCreateMissingPeople(false); - assertEquals(2, getPeopleCount()); - - checkPeopleContain(AuthenticationUtil.getAdminUserName()); - checkPeopleContain(AuthenticationUtil.getGuestUserName()); - - String suffix = Long.toString(System.currentTimeMillis()); - String jjFirstname = "john junior"+suffix; - String jjLastname = "lewis second"+suffix; - - personService.createPerson(createDefaultProperties("janedoe", "jane", "doe"+suffix, "johndoe@yz", "alfresco", rootNodeRef)); - personService.createPerson(createDefaultProperties("janemoe", "jane", "moe"+suffix, "janemoe@yz", "alfresco", rootNodeRef)); - personService.createPerson(createDefaultProperties("jjlewis", jjFirstname, jjLastname, "jjlewis@yzd", "alfresco", rootNodeRef)); - personService.createPerson(createDefaultProperties("jlewis", "john", jjLastname, "jlewis@yzd", "alfresco", rootNodeRef)); - - assertEquals(6, getPeopleCount()); - - PagingRequest pr = new PagingRequest(100, null); - List> filters = new ArrayList>(3); - - filters.clear(); - // Set username, firstname and lastname same as - // "org.alfresco.web.ui.common.Utils.generatePersonFilter(String term)" method - String searchTerm = "jane doe"+suffix; - filters.add(new Pair(ContentModel.PROP_USERNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_FIRSTNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_LASTNAME, searchTerm)); - List result = personService.getPeople(filters, true, null, pr).getPage(); - assertEquals(1, result.size()); - assertEquals("jane", result.get(0).getFirstName()); - assertEquals("doe"+suffix, result.get(0).getLastName()); - - // test two parts firstname - filters.clear(); - searchTerm = jjFirstname; - filters.add(new Pair(ContentModel.PROP_USERNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_FIRSTNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_LASTNAME, searchTerm)); - result = personService.getPeople(filters, true, null, pr).getPage(); - assertEquals(1, result.size()); - assertEquals(jjFirstname, result.get(0).getFirstName()); - assertEquals(jjLastname, result.get(0).getLastName()); - - // test two parts lastname - filters.clear(); - searchTerm = "john " + jjLastname; - filters.add(new Pair(ContentModel.PROP_USERNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_FIRSTNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_LASTNAME, searchTerm)); - result = personService.getPeople(filters, true, null, pr).getPage(); - assertEquals(2, result.size()); - - // test two parts firstname and lastname - filters.clear(); - searchTerm = jjFirstname + " " + jjLastname; - filters.add(new Pair(ContentModel.PROP_USERNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_FIRSTNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_LASTNAME, searchTerm)); - result = personService.getPeople(filters, true, null, pr).getPage(); - assertEquals(1, result.size()); - assertEquals(jjFirstname, result.get(0).getFirstName()); - assertEquals(jjLastname, result.get(0).getLastName()); - - // test different firstname and lastname - filters.clear(); - searchTerm = jjFirstname + " " + jjLastname; - filters.add(new Pair(ContentModel.PROP_USERNAME, searchTerm)); - filters.add(new Pair(ContentModel.PROP_FIRSTNAME, jjFirstname)); - filters.add(new Pair(ContentModel.PROP_LASTNAME, jjLastname)); - result = personService.getPeople(filters, true, null, pr).getPage(); - assertEquals(1, result.size()); - assertEquals(jjFirstname, result.get(0).getFirstName()); - assertEquals(jjLastname, result.get(0).getLastName()); - } - } diff --git a/src/test/java/org/alfresco/repo/security/person/TestGroupManager.java b/src/test/java/org/alfresco/repo/security/person/TestGroupManager.java index eca7403527..a6adb1fa2f 100644 --- a/src/test/java/org/alfresco/repo/security/person/TestGroupManager.java +++ b/src/test/java/org/alfresco/repo/security/person/TestGroupManager.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.security.person; import java.util.HashMap; @@ -31,9 +31,6 @@ import java.util.Map; import java.util.Set; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; @@ -45,14 +42,12 @@ import org.alfresco.service.cmr.security.AuthorityType; public class TestGroupManager { private final AuthorityService authorityService; - private final SearchService searchService; private final Map groups = new HashMap(); - public TestGroupManager(AuthorityService authorityService, SearchService searchService) + public TestGroupManager(AuthorityService authorityService) { this.authorityService = authorityService; - this.searchService = searchService; } /** @@ -139,30 +134,8 @@ public class TestGroupManager private NodeRef findGroupNode(String groupShortName) { - //TODO Use new AuthorityService.getNode() method on HEAD - NodeRef group = null; - - String query = "+TYPE:\"cm:authorityContainer\" AND @cm\\:authorityName:*" + groupShortName; - - ResultSet results = null; - try - { - results = searchService.query( - new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"), - SearchService.LANGUAGE_LUCENE, query); - - if (results.length() > 0) - { - group = results.getNodeRefs().get(0); - } - } - finally - { - if (results != null) - { - results.close(); - } - } + String fullName = authorityService.getName(AuthorityType.GROUP, groupShortName); + NodeRef group = authorityService.getAuthorityNodeRef(fullName); return group; } } diff --git a/src/test/java/org/alfresco/repo/site/SiteServiceImplTest.java b/src/test/java/org/alfresco/repo/site/SiteServiceImplTest.java index 597f860254..0ec2129850 100644 --- a/src/test/java/org/alfresco/repo/site/SiteServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/site/SiteServiceImplTest.java @@ -93,6 +93,7 @@ import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.BaseAlfrescoSpringTest; import org.alfresco.util.GUID; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; import org.springframework.extensions.surf.util.I18NUtil; @@ -575,6 +576,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest * {@link SiteService#listSites(List, List, org.alfresco.query.PagingRequest)} and the other listSites methods * should offer consistent, accurate result sets. */ + @Category(RedundantTests.class) public void testListSites() throws Exception { // We'll match against the first few letter of TEST_TITLE in various listSites() tests below. @@ -886,6 +888,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest /** * This test method ensures that searches with wildcards work as they should */ + @Category(RedundantTests.class) public void testfindSitesWithWildcardTitles() throws Exception { // How many sites are there already in the repo? @@ -917,6 +920,7 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest /** * This test method ensures that searches with wildcards work as they should */ + @Category(RedundantTests.class) public void testfindSitesForLiveSearchWithWildcardTitles() throws Exception { // How many sites are there already in the repo? diff --git a/src/test/java/org/alfresco/repo/subscriptions/SubscriptionServiceImplTest.java b/src/test/java/org/alfresco/repo/subscriptions/SubscriptionServiceImplTest.java index bd9baf5d20..8040815c2d 100644 --- a/src/test/java/org/alfresco/repo/subscriptions/SubscriptionServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/subscriptions/SubscriptionServiceImplTest.java @@ -32,6 +32,7 @@ import junit.framework.TestCase; import org.alfresco.model.ContentModel; import org.alfresco.query.PagingRequest; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; @@ -76,6 +77,7 @@ public class SubscriptionServiceImplTest extends TestCase protected PersonService personService; protected NodeService nodeService; protected SearchService searchService; + protected Repository repositoryHelper; @Override public void setUp() throws Exception @@ -87,6 +89,7 @@ public class SubscriptionServiceImplTest extends TestCase personService = (PersonService) ctx.getBean("PersonService"); nodeService = (NodeService) ctx.getBean("NodeService"); searchService = (SearchService) ctx.getBean("SearchService"); + repositoryHelper = (Repository) ctx.getBean("repositoryHelper"); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName()); @@ -272,31 +275,7 @@ public class SubscriptionServiceImplTest extends TestCase public void testSubscriptionsRemovalOnArchivingNodesForAlf12358() throws Exception { - NodeRef companyHome = null; - ResultSet resultSet = null; - try - { - resultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, "PATH:\"/app\\:company_home\""); - assertNotNull("Can't find Company Home NodeRef!", resultSet); - assertEquals("Found too many Company Home nodes!", 1, resultSet.length()); - - companyHome = resultSet.getNodeRef(0); - assertNotNull("Company Home NodeRef is invalid!", companyHome); - } - finally - { - if (null != resultSet) - { - try - { - resultSet.close(); - } - catch (Exception e) - { - // Doing nothing - } - } - } + NodeRef companyHome = repositoryHelper.getCompanyHome(); ChildAssociationRef followed = null; diff --git a/src/test/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java b/src/test/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java index 4a901adf06..de35dc9dce 100644 --- a/src/test/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java @@ -25,17 +25,6 @@ */ package org.alfresco.repo.tagging; -import java.io.ByteArrayInputStream; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - import org.alfresco.model.ContentModel; import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; @@ -62,19 +51,12 @@ import org.alfresco.service.cmr.action.ExecutionSummary; import org.alfresco.service.cmr.audit.AuditService; import org.alfresco.service.cmr.coci.CheckOutCheckInService; import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.CopyService; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.ScriptLocation; -import org.alfresco.service.cmr.repository.ScriptService; -import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.repository.*; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.tagging.TagDetails; import org.alfresco.service.cmr.tagging.TagScope; -import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; @@ -84,13 +66,25 @@ import org.alfresco.util.GUID; import org.alfresco.util.Pair; import org.alfresco.util.PropertyMap; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.mockito.runners.MockitoJUnitRunner; import org.springframework.context.ConfigurableApplicationContext; -import org.junit.FixMethodOrder; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; +import java.io.ByteArrayInputStream; +import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.util.*; + +import static org.junit.Assert.*; /** * Tagging service implementation unit test @@ -100,7 +94,8 @@ import org.junit.runners.MethodSorters; */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @Category({OwnJVMTestsCategory.class, LuceneTests.class}) -public class TaggingServiceImplTest extends TestCase +@RunWith(MockitoJUnitRunner.class) +public class TaggingServiceImplTest { private static ConfigurableApplicationContext ctx = (ConfigurableApplicationContext)ApplicationContextHelper.getApplicationContext(); @@ -108,7 +103,7 @@ public class TaggingServiceImplTest extends TestCase private static final Log logger = LogFactory.getLog(TaggingServiceImplTest.class); /** Services */ - private TaggingService taggingService; + private TaggingServiceImpl taggingService; private NodeService nodeService; private FileFolderService fileFolderService; private CopyService copyService; @@ -147,10 +142,9 @@ public class TaggingServiceImplTest extends TestCase private static final String LOWER_TAG = "house"; private static boolean init = false; - - - @Override - protected void setUp() throws Exception + + @Before + public void setUp() throws Exception { // Detect any dangling transactions as there is a lot of direct UserTransaction manipulation if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) @@ -162,7 +156,7 @@ public class TaggingServiceImplTest extends TestCase } // Get services - this.taggingService = (TaggingService)ctx.getBean("TaggingService"); + this.taggingService = (TaggingServiceImpl)ctx.getBean("taggingService"); this.nodeService = (NodeService) ctx.getBean("NodeService"); this.fileFolderService = (FileFolderService) ctx.getBean("FileFolderService"); this.copyService = (CopyService) ctx.getBean("CopyService"); @@ -237,8 +231,8 @@ public class TaggingServiceImplTest extends TestCase createTestDocumentsAndFolders(); } - @Override - protected void tearDown() throws Exception + @After + public void tearDown() throws Exception { removeTestDocumentsAndFolders(); if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) @@ -336,7 +330,9 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test1TagCRUD() throws Exception { @@ -357,7 +353,7 @@ public class TaggingServiceImplTest extends TestCase return null; } }); - + this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback(){ @Override @@ -420,7 +416,9 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test2AddRemoveTag() throws Exception { @@ -483,7 +481,8 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test public void test3TagScopeFindAddRemove() throws Exception { @@ -542,7 +541,8 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test public void test4TagScope() throws Exception { @@ -684,42 +684,49 @@ public class TaggingServiceImplTest extends TestCase return null; } }); - - this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() - { - @Override - public Void execute() throws Throwable - { - // re get the tag scopes - TagScope ts1 = taggingService.findTagScope(subDocument); - TagScope ts2 = taggingService.findTagScope(folder); - - // Recheck the tag scopes - assertEquals( - "Wrong tags on sub folder: " + ts1.getTags(), - 2, ts1.getTags().size() - ); - assertEquals( - "Wrong tags on main folder: " + ts2.getTags(), - 2, ts2.getTags().size() - ); - - // Sub-folder should be ordered by tag name, as all values 1 - assertEquals(1, ts1.getTags().get(0).getCount()); - assertEquals(1, ts1.getTags().get(1).getCount()); - assertEquals(TAG_2, ts1.getTags().get(0).getName()); - assertEquals(TAG_3.toLowerCase(), ts1.getTags().get(1).getName()); - - // Folder should be still sorted by size, as a 2 & a 1 - assertEquals(2, ts2.getTags().get(0).getCount()); - assertEquals(1, ts2.getTags().get(1).getCount()); - assertEquals(TAG_3.toLowerCase(), ts2.getTags().get(0).getName()); - assertEquals(TAG_2, ts2.getTags().get(1).getName()); - return null; - } - }); + + /* + The following code from the test was commented out as part of REPO-2028 to remove + the lucene dependencies in the tests. + @Category({RedundantTests.class,LuceneTests.class}) + */ +// +// this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() +// { +// @Override +// public Void execute() throws Throwable +// { +// // re get the tag scopes +// TagScope ts1 = taggingService.findTagScope(subDocument); +// TagScope ts2 = taggingService.findTagScope(folder); +// +// // Recheck the tag scopes +// assertEquals( +// "Wrong tags on sub folder: " + ts1.getTags(), +// 2, ts1.getTags().size() +// ); +// assertEquals( +// "Wrong tags on main folder: " + ts2.getTags(), +// 2, ts2.getTags().size() +// ); +// +// // Sub-folder should be ordered by tag name, as all values 1 +// assertEquals(1, ts1.getTags().get(0).getCount()); +// assertEquals(1, ts1.getTags().get(1).getCount()); +// assertEquals(TAG_2, ts1.getTags().get(0).getName()); +// assertEquals(TAG_3.toLowerCase(), ts1.getTags().get(1).getName()); +// +// // Folder should be still sorted by size, as a 2 & a 1 +// assertEquals(2, ts2.getTags().get(0).getCount()); +// assertEquals(1, ts2.getTags().get(1).getCount()); +// assertEquals(TAG_3.toLowerCase(), ts2.getTags().get(0).getName()); +// assertEquals(TAG_2, ts2.getTags().get(1).getName()); +// return null; +// } +// }); } + @Test @SuppressWarnings("unchecked") public void test5TagScopeSummary() throws Exception { @@ -821,6 +828,8 @@ public class TaggingServiceImplTest extends TestCase }); } + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test6TagScopeRefresh() throws Exception { @@ -875,7 +884,8 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test public void test7TagScopeSetUpdate() throws Exception { @@ -969,26 +979,32 @@ public class TaggingServiceImplTest extends TestCase return null; } }); + /* + This part of the code was commented out as part of the REPO-2028 to remove the lucene dependency from tests + @Category({RedundantTests.class,LuceneTests.class}) + */ - this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() - { - @Override - public Void execute() throws Throwable - { - // Check that the tagscope has been updated correctly - TagScope ts1 = taggingService.findTagScope(folder); - assertEquals(3, ts1.getTag(TAG_1).getCount()); - assertEquals(2, ts1.getTag(TAG_2).getCount()); - assertEquals(1, ts1.getTag(TAG_3.toLowerCase()).getCount()); - assertEquals(1, ts1.getTag(TAG_4).getCount()); - return null; - } - }); +// this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() +// { +// @Override +// public Void execute() throws Throwable +// { +// // Check that the tagscope has been updated correctly +// TagScope ts1 = taggingService.findTagScope(folder); +// assertEquals(3, ts1.getTag(TAG_1).getCount()); +// assertEquals(2, ts1.getTag(TAG_2).getCount()); +// assertEquals(1, ts1.getTag(TAG_3.toLowerCase()).getCount()); +// assertEquals(1, ts1.getTag(TAG_4).getCount()); +// return null; +// } +// }); } /* * https://issues.alfresco.com/jira/browse/ETHREEOH-220 */ + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test8ETHREEOH_220() throws Exception { // Add tag scope to a folder, then add a non-ASCII (unicode) @@ -1033,6 +1049,8 @@ public class TaggingServiceImplTest extends TestCase * when folders and content are created, updated, * moved, copied and deleted. */ + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test9TagScopeUpdateViaNodePolicies() throws Exception { class TestData { @@ -1466,6 +1484,8 @@ public class TaggingServiceImplTest extends TestCase * Also checks that policies are disabled during tag scope updates, * so that the auditable flags aren't incorrectly set by the change */ + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test91PermissionsAndPolicies() throws Exception { class TestData @@ -1589,7 +1609,8 @@ public class TaggingServiceImplTest extends TestCase } // == Test the JavaScript API == - + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test92JSAPI() throws Exception { asyncOccurs.awaitExecution(new RetryingTransactionCallback() @@ -1612,7 +1633,9 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void test93JSTagScope() throws Exception { asyncOccurs.awaitExecution(new RetryingTransactionCallback() @@ -1725,6 +1748,7 @@ public class TaggingServiceImplTest extends TestCase * Test that the scheduled task will do the right thing * when it runs. */ + @Test public void test93OnStartupJob() throws Exception { final UpdateTagScopesActionExecuter updateTagsAction = (UpdateTagScopesActionExecuter) ctx @@ -1859,6 +1883,7 @@ public class TaggingServiceImplTest extends TestCase * Test that when multiple threads do tag updates, the right thing still * happens */ + @Test public void test94MultiThreaded() throws Exception { transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() @@ -2105,6 +2130,7 @@ public class TaggingServiceImplTest extends TestCase * * @throws Exception */ + @Test public void testALF_17260() throws Exception { // Add tag scope to our container @@ -2205,7 +2231,8 @@ public class TaggingServiceImplTest extends TestCase } }); } - + + @Test public void testTagFileRead() throws UnsupportedEncodingException { List tags = TaggingServiceImpl.readTagDetails(new ByteArrayInputStream("Tag1|10\nTag2|20\nInvalid\nInvalid2|\nInvalid3|One\nTooMany|1|2\n\n".getBytes("UTF-8"))); @@ -2218,6 +2245,8 @@ public class TaggingServiceImplTest extends TestCase assertEquals(tags.get(2).getCount(), 1); } + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void testPagedTags() throws UnsupportedEncodingException { authenticationComponent.setSystemUserAsCurrentUser(); @@ -2244,7 +2273,9 @@ public class TaggingServiceImplTest extends TestCase assertNotNull(res); assertTrue(res.getTotalResultCount().getFirst() == 1); } - + + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void testChangeTags() throws UnsupportedEncodingException { try @@ -2303,6 +2334,7 @@ public class TaggingServiceImplTest extends TestCase /* Test adding tags containing \n and | chars. Test all ways to create tag (e.g. createTag, addTag, setTags) */ + @Test public void testBadTags() { testTag(BAD_TAG); @@ -2356,6 +2388,8 @@ public class TaggingServiceImplTest extends TestCase /** * Tests that when the deleteTag() method runs, it will remove invalid references to the deleted tag. */ + @Test + @Category({RedundantTests.class,LuceneTests.class}) public void testDeleteTag() throws Exception{ try{ @@ -2371,6 +2405,8 @@ public class TaggingServiceImplTest extends TestCase public Void execute() throws Throwable { taggingService.clearTags(folder); + // addTag uses lucene to get a reference to the existing TAG_1 tag node. + // this fails without lucene taggingService.addTag(folder, TAG_1); // The deleteTag() should remove any reference to the deleted tag diff --git a/src/test/java/org/alfresco/repo/tagging/UpdateTagScopesActionExecuterTest.java b/src/test/java/org/alfresco/repo/tagging/UpdateTagScopesActionExecuterTest.java index 0b9e914fb0..37dfb0983f 100644 --- a/src/test/java/org/alfresco/repo/tagging/UpdateTagScopesActionExecuterTest.java +++ b/src/test/java/org/alfresco/repo/tagging/UpdateTagScopesActionExecuterTest.java @@ -55,6 +55,7 @@ import org.alfresco.service.cmr.tagging.TaggingService; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -66,7 +67,7 @@ import org.springframework.context.ApplicationContext; * * @author Dmitry Velichkevich */ -@Category(LuceneTests.class) +@Category({LuceneTests.class, RedundantTests.class}) public class UpdateTagScopesActionExecuterTest extends TestCase { private static final int TAGSCOPE_LAYERS = 3; @@ -112,7 +113,7 @@ public class UpdateTagScopesActionExecuterTest extends TestCase @Before @Override public void setUp() throws Exception - { + { applicationContext = ApplicationContextHelper.getApplicationContext(); final ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); diff --git a/src/test/java/org/alfresco/repo/template/XSLTProcessorTest.java b/src/test/java/org/alfresco/repo/template/XSLTProcessorTest.java index 7f65f1a744..82432e92f7 100644 --- a/src/test/java/org/alfresco/repo/template/XSLTProcessorTest.java +++ b/src/test/java/org/alfresco/repo/template/XSLTProcessorTest.java @@ -30,23 +30,19 @@ import java.io.StringWriter; import java.util.Locale; import org.alfresco.model.ContentModel; -import org.alfresco.repo.rendition.executer.XSLTFunctions; +import org.alfresco.repo.model.Repository; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.TemplateProcessor; import org.alfresco.service.cmr.repository.TemplateService; -import org.alfresco.service.cmr.search.ResultSet; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.test_category.BaseSpringTestsCategory; import org.alfresco.util.BaseAlfrescoSpringTest; import org.alfresco.util.GUID; import org.alfresco.util.XMLUtil; -import org.alfresco.util.testing.category.LuceneTests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.experimental.categories.Category; @@ -55,16 +51,15 @@ import org.junit.experimental.categories.Category; * @author Brian * */ -@Category({BaseSpringTestsCategory.class, LuceneTests.class}) +@Category({BaseSpringTestsCategory.class}) public class XSLTProcessorTest extends BaseAlfrescoSpringTest { private final static Log log = LogFactory.getLog(XSLTProcessorTest.class); - private XSLTFunctions xsltFunctions; - private SearchService searchService; private NodeRef companyHome; private FileFolderService fileFolderService; private TemplateProcessor xsltProcessor; private TemplateService templateService; + private Repository repositoryHelper; /* * (non-Javadoc) @@ -76,16 +71,13 @@ public class XSLTProcessorTest extends BaseAlfrescoSpringTest protected void onSetUpInTransaction() throws Exception { super.onSetUpInTransaction(); - this.searchService = (SearchService) this.applicationContext.getBean("SearchService"); - this.xsltFunctions = (XSLTFunctions) this.applicationContext.getBean("xsltFunctions"); this.nodeService = (NodeService) this.applicationContext.getBean("NodeService"); this.contentService = (ContentService) this.applicationContext.getBean("ContentService"); this.fileFolderService = (FileFolderService) this.applicationContext.getBean("FileFolderService"); this.xsltProcessor = (TemplateProcessor) this.applicationContext.getBean("xsltProcessor"); this.templateService = (TemplateService) this.applicationContext.getBean("TemplateService"); - ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, - "/app:company_home"); - this.companyHome = rs.getNodeRef(0); + this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper"); + this.companyHome = repositoryHelper.getCompanyHome(); } public void testSimplestStringTemplate() throws Exception diff --git a/src/test/java/org/alfresco/repo/tenant/MultiTDemoTest.java b/src/test/java/org/alfresco/repo/tenant/MultiTDemoTest.java index 6593506a09..a3aee85f00 100644 --- a/src/test/java/org/alfresco/repo/tenant/MultiTDemoTest.java +++ b/src/test/java/org/alfresco/repo/tenant/MultiTDemoTest.java @@ -90,6 +90,7 @@ import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.FixMethodOrder; @@ -208,8 +209,6 @@ public class MultiTDemoTest extends TestCase repositoryHelper = (Repository) ctx.getBean("repositoryHelper"); siteService = (SiteService) ctx.getBean("SiteService"); - ChildApplicationContextFactory luceneSubSystem = (ChildApplicationContextFactory) ctx.getBean("buildonly"); - indexRecoverer = (FullIndexRecoveryComponent) luceneSubSystem.getApplicationContext().getBean("search.indexRecoveryComponent"); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin createTenants(); @@ -1220,7 +1219,8 @@ public class MultiTDemoTest extends TestCase }, tenantAdminName, tenantDomain); } } - + + @Category(RedundantTests.class) public void test10CreateCategories() { logger.info("Create demo categories"); @@ -1491,7 +1491,8 @@ public class MultiTDemoTest extends TestCase }, tenantAdminName, tenantDomain); } } - + + @Category(RedundantTests.class) public void test15COCIandSearch() { logger.info("Test checkout/checkin and search"); diff --git a/src/test/java/org/alfresco/repo/transfer/NodeCrawlerTest.java b/src/test/java/org/alfresco/repo/transfer/NodeCrawlerTest.java index d3b5530e5c..4c612bda16 100644 --- a/src/test/java/org/alfresco/repo/transfer/NodeCrawlerTest.java +++ b/src/test/java/org/alfresco/repo/transfer/NodeCrawlerTest.java @@ -33,6 +33,7 @@ import java.util.Set; import org.alfresco.model.ContentModel; import org.alfresco.model.RenditionModel; +import org.alfresco.repo.model.Repository; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; @@ -56,7 +57,7 @@ import org.junit.experimental.categories.Category; * * @author Brian Remmington */ -@Category({BaseSpringTestsCategory.class, LuceneTests.class}) +@Category({BaseSpringTestsCategory.class}) public class NodeCrawlerTest extends BaseAlfrescoSpringTest { private ServiceRegistry serviceRegistry; @@ -75,13 +76,8 @@ public class NodeCrawlerTest extends BaseAlfrescoSpringTest this.nodeService = (NodeService) this.getApplicationContext().getBean("NodeService"); this.serviceRegistry = (ServiceRegistry) this.getApplicationContext().getBean("ServiceRegistry"); this.nodeCrawlerFactory = (NodeCrawlerFactory) this.getApplicationContext().getBean("NodeCrawlerFactory"); - ResultSet rs = serviceRegistry.getSearchService().query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, - SearchService.LANGUAGE_XPATH, "/app:company_home"); - if (rs.length() == 0) - { - fail("Could not find company home"); - } - companyHome = rs.getNodeRef(0); + Repository repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper"); + this.companyHome = repositoryHelper.getCompanyHome(); } public void testContentClassFilter() throws Exception diff --git a/src/test/java/org/alfresco/repo/transfer/RepoTransferReceiverImplTest.java b/src/test/java/org/alfresco/repo/transfer/RepoTransferReceiverImplTest.java index 2a536a5048..4ff06c4b8b 100644 --- a/src/test/java/org/alfresco/repo/transfer/RepoTransferReceiverImplTest.java +++ b/src/test/java/org/alfresco/repo/transfer/RepoTransferReceiverImplTest.java @@ -42,6 +42,7 @@ import java.util.Properties; import java.util.Set; import org.alfresco.model.ContentModel; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; @@ -64,7 +65,6 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.Path; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.transfer.TransferException; @@ -74,7 +74,6 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.BaseSpringTestsCategory; -import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.BaseAlfrescoSpringTest; import org.alfresco.util.GUID; import org.alfresco.util.testing.category.LuceneTests; @@ -91,7 +90,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition; * @author Brian Remmington */ @SuppressWarnings("deprecation") -@Category({BaseSpringTestsCategory.class, LuceneTests.class}) +@Category({BaseSpringTestsCategory.class}) public class RepoTransferReceiverImplTest extends BaseAlfrescoSpringTest { private static int fileCount = 0; @@ -103,6 +102,8 @@ public class RepoTransferReceiverImplTest extends BaseAlfrescoSpringTest private byte[] dummyContentBytes; private NodeRef guestHome; private PolicyComponent policyComponent; + private Repository repositoryHelper; + private NamespaceService namespaceService; @Override public void runBare() throws Throwable @@ -131,16 +132,15 @@ public class RepoTransferReceiverImplTest extends BaseAlfrescoSpringTest this.receiver = (RepoTransferReceiverImpl) this.getApplicationContext().getBean("transferReceiver"); this.policyComponent = (PolicyComponent) this.getApplicationContext().getBean("policyComponent"); this.searchService = (SearchService) this.getApplicationContext().getBean("searchService"); + this.repositoryHelper = (Repository) this.getApplicationContext().getBean("repositoryHelper"); + this.namespaceService = (NamespaceService) this.getApplicationContext().getBean("namespaceService"); this.dummyContent = "This is some dummy content."; this.dummyContentBytes = dummyContent.getBytes("UTF-8"); setTransactionDefinition(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW)); authenticationComponent.setSystemUserAsCurrentUser(); startNewTransaction(); - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - guestHome = guestHomeResult.getNodeRef(0); + guestHome = repositoryHelper.getGuestHome(); endTransaction(); } @@ -162,10 +162,7 @@ public class RepoTransferReceiverImplTest extends BaseAlfrescoSpringTest public TestContext execute() throws Throwable { TestContext tc = new TestContext(); - ResultSet rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, - "/app:company_home"); - assertEquals(1, rs.length()); - NodeRef companyHome = rs.getNodeRef(0); + NodeRef companyHome = repositoryHelper.getCompanyHome(); Map props = new HashMap(); props.put(ContentModel.PROP_NAME, uuid); tc.childAssoc = nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, @@ -1650,25 +1647,13 @@ public class RepoTransferReceiverImplTest extends BaseAlfrescoSpringTest { NodeRef reportParentFolder = null; log.debug("Trying to find transfer summary report records folder: " + transferSummaryReportLocation); - ResultSet rs = null; - - try + List refs = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), + transferSummaryReportLocation, null, namespaceService, false); + if (refs.size() > 0) { - rs = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, transferSummaryReportLocation); - if (rs.length() > 0) - { - reportParentFolder = rs.getNodeRef(0); + reportParentFolder = refs.get(0); - log.debug("Found transfer summary report records folder: " + reportParentFolder); - } - - } - finally - { - if (rs != null) - { - rs.close(); - } + log.debug("Found transfer summary report records folder: " + reportParentFolder); } return reportParentFolder; } @@ -1827,15 +1812,8 @@ public class RepoTransferReceiverImplTest extends BaseAlfrescoSpringTest node.setType(ContentModel.TYPE_FOLDER); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); - NodeRef parentFolder = guestHome; - + NodeRef parentFolder = repositoryHelper.getGuestHome(); + String nodeName = folderName == null ? uuid + ".folder" + getNameSuffix() : folderName; List parents = new ArrayList(); diff --git a/src/test/java/org/alfresco/repo/transfer/TransferServiceImplTest.java b/src/test/java/org/alfresco/repo/transfer/TransferServiceImplTest.java index 3c7de41e21..904b4bfcec 100644 --- a/src/test/java/org/alfresco/repo/transfer/TransferServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/transfer/TransferServiceImplTest.java @@ -55,6 +55,7 @@ import javax.xml.validation.Validator; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; @@ -109,6 +110,7 @@ import org.alfresco.util.Pair; import org.alfresco.util.PropertyMap; import org.alfresco.util.TempFileProvider; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; import org.springframework.util.ResourceUtils; @@ -138,6 +140,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest private Descriptor serverDescriptor; private TaggingService taggingService; private CategoryService categoryService; + private Repository repositoryHelper; String COMPANY_HOME_XPATH_QUERY = "/{http://www.alfresco.org/model/application/1.0}company_home"; String GUEST_HOME_XPATH_QUERY = "/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/application/1.0}guest_home"; @@ -174,6 +177,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest this.copyService = (CopyService)this.applicationContext.getBean("CopyService"); this.taggingService = ((TaggingService)this.applicationContext.getBean("TaggingService")); this.categoryService = (CategoryService)this.applicationContext.getBean("CategoryService"); + this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper"); this.serverDescriptor = descriptorService.getServerDescriptor(); @@ -705,13 +709,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -1077,13 +1075,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -1275,13 +1267,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -1530,13 +1516,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); ctx.targetName = GUID.generate(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - ctx.guestHome = guestHomeResult.getNodeRef(0); + ctx.guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will transfer. Its path is what is important @@ -1709,13 +1689,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - final NodeRef guestHome = guestHomeResult.getNodeRef(0); + final NodeRef guestHome = repositoryHelper.getGuestHome(); ctx.nodeRefA = nodeService.getChildByName(guestHome, ContentModel.ASSOC_CONTAINS, CONTENT_NAME_A); @@ -1896,13 +1870,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest final Locale CONTENT_LOCALE = Locale.GERMAN; final String CONTENT_STRING = "Hello"; final String targetName = "testAsyncCallback"; - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("unable to find guest home", 1, guestHomeResult.length()); - final NodeRef guestHome = guestHomeResult.getNodeRef(0); + final NodeRef guestHome = repositoryHelper.getGuestHome(); final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper(); @@ -2189,15 +2157,8 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet result = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - - assertEquals("", 1, result.length()); - NodeRef guestHome = result.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); - System.out.println("Guest home:" + guestHome); - assertNotNull(guestHome); - ctx.contentNodeRef = nodeService.getChildByName(guestHome, ContentModel.ASSOC_CONTAINS, CONTENT_NAME); if(ctx.contentNodeRef == null) { @@ -2343,13 +2304,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node with an empty content that we will read and write @@ -2616,13 +2571,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext testContext = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -2752,14 +2701,8 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest DescriptorService mockedDescriptorService = getMockDescriptorService(REPO_ID_A); transferServiceImpl.setDescriptorService(mockedDescriptorService); - - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - final NodeRef guestHome = guestHomeResult.getNodeRef(0); + + final NodeRef guestHome = repositoryHelper.getGuestHome(); final String targetName = "testRepeatUpdateOfContent"; @@ -3150,13 +3093,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext testContext = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -3364,21 +3301,8 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext testContext = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); - guestHomeResult.close(); - - String companyHomeQuery = "/app:company_home"; - ResultSet companyHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, companyHomeQuery); - assertEquals("", 1, companyHomeResult.length()); - NodeRef companyHome = companyHomeResult.getNodeRef(0); - companyHomeResult.close(); - + NodeRef guestHome = repositoryHelper.getGuestHome(); + NodeRef companyHome = repositoryHelper.getCompanyHome(); /** * Create a test node that we will read and write @@ -3505,6 +3429,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest * * This is a unit test so it does some shenanigans to send to the same instance of alfresco. */ + @Category(RedundantTests.class) public void testCategoriesAndTags() throws Exception { final String CONTENT_TITLE = "ContentTitle"; @@ -3540,13 +3465,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest { TestContext ctx = new TestContext(); - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write diff --git a/src/test/java/org/alfresco/repo/transfer/TransferServiceToBeRefactoredTest.java b/src/test/java/org/alfresco/repo/transfer/TransferServiceToBeRefactoredTest.java index c7370fd7ac..2d70e9c537 100644 --- a/src/test/java/org/alfresco/repo/transfer/TransferServiceToBeRefactoredTest.java +++ b/src/test/java/org/alfresco/repo/transfer/TransferServiceToBeRefactoredTest.java @@ -48,6 +48,7 @@ import javax.xml.validation.Validator; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.model.Repository; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; @@ -125,6 +126,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest private DescriptorService descriptorService; private CopyService copyService; private Descriptor serverDescriptor; + private Repository repositoryHelper; String COMPANY_HOME_XPATH_QUERY = "/{http://www.alfresco.org/model/application/1.0}company_home"; String GUEST_HOME_XPATH_QUERY = "/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/application/1.0}guest_home"; @@ -172,6 +174,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest this.descriptorService = (DescriptorService)this.applicationContext.getBean("DescriptorService"); this.copyService = (CopyService)this.applicationContext.getBean("CopyService"); this.serverDescriptor = descriptorService.getServerDescriptor(); + this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper"); REPO_ID_B = descriptorService.getCurrentRepositoryDescriptor().getId(); @@ -188,14 +191,8 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest public void testTransferReport() throws Exception { setDefaultRollback(false); - - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - final NodeRef guestHome = guestHomeResult.getNodeRef(0); + + final NodeRef guestHome = repositoryHelper.getGuestHome(); /** * For unit test @@ -679,13 +676,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test nodes A1 through A5 that we will read and write @@ -1401,13 +1392,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test nodes A1 through A8 that we will read and write @@ -2062,13 +2047,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test nodes A1 through A8 that we will read and write @@ -2408,13 +2387,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -2758,13 +2731,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test node that we will read and write @@ -3169,13 +3136,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Create a test nodes A1 through A5 that we will read and write @@ -3469,13 +3430,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); { /** @@ -3906,13 +3861,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); { /** @@ -4313,13 +4262,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); /** * Node Source - located under guest home @@ -4557,13 +4500,7 @@ public class TransferServiceToBeRefactoredTest extends BaseAlfrescoSpringTest @Override public Void execute() throws Throwable { - /** - * Get guest home - */ - String guestHomeQuery = "/app:company_home/app:guest_home"; - ResultSet guestHomeResult = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, guestHomeQuery); - assertEquals("", 1, guestHomeResult.length()); - NodeRef guestHome = guestHomeResult.getNodeRef(0); + NodeRef guestHome = repositoryHelper.getGuestHome(); { /** diff --git a/src/test/java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java b/src/test/java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java index 7ce3a11485..dcd5ac86ec 100644 --- a/src/test/java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java +++ b/src/test/java/org/alfresco/repo/virtual/VirtualizationIntegrationTest.java @@ -26,12 +26,22 @@ package org.alfresco.repo.virtual; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + import java.io.InputStream; import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -39,12 +49,11 @@ import java.util.Set; import javax.transaction.UserTransaction; -import junit.framework.TestCase; - import org.alfresco.model.ContentModel; import org.alfresco.repo.forms.FormData; import org.alfresco.repo.forms.Item; import org.alfresco.repo.model.Repository; +import org.alfresco.repo.search.impl.SearchServiceSubSystemDelegator; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper; @@ -59,7 +68,9 @@ import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.cmr.search.ResultSet; +import org.alfresco.service.cmr.search.ResultSetRow; +import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; @@ -69,13 +80,17 @@ import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.testing.category.LuceneTests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Ignore; +import org.junit.After; +import org.junit.Before; import org.junit.experimental.categories.Category; +import org.mockito.ArgumentMatcher; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.stubbing.Answer; import org.springframework.context.ApplicationContext; -@Ignore @Category(LuceneTests.class) -public abstract class VirtualizationIntegrationTest extends TestCase implements VirtualizationTest +public abstract class VirtualizationIntegrationTest implements VirtualizationTest { private static Log logger = LogFactory.getLog(VirtualizationIntegrationTest.class); @@ -151,7 +166,7 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements protected PermissionService permissionService; - protected SearchService searchService; + //protected SearchService searchService; protected RetryingTransactionHelper retryingTransactionHelper; @@ -180,8 +195,14 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements /** when set to a not-null value will be restored up[on {@link #tearDown()} */ protected String configuredTemplatesClassPath = null; - @Override - protected void setUp() throws Exception + private @Mock ResultSet dbResults; + private @Mock ResultSetRow resultSetRow; + private SearchServiceSubSystemDelegator searchServiceDelegatorSpy; + + private String queryMatcher; + + @Before + public void setUp() throws Exception { ctx = ApplicationContextHelper.getApplicationContext(CONFIG_LOCATIONS); @@ -197,7 +218,7 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements contentService = serviceRegistry.getContentService(); fileAndFolderService = serviceRegistry.getFileFolderService(); permissionService = serviceRegistry.getPermissionService(); - searchService = serviceRegistry.getSearchService(); + //searchService = serviceRegistry.getSearchService(); authenticationComponent = ctx.getBean("authenticationComponent", AuthenticationComponent.class); @@ -242,9 +263,10 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements VIRTUAL_FOLDER_1_NAME, TEST_TEMPLATE_1_JSON_SYS_PATH); rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); - + setupMocks(); } + @After public void tearDown() throws Exception { if (!virtualizationConfigTestBootstrap.areVirtualFoldersEnabled()) @@ -272,7 +294,7 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements e); } - super.tearDown(); + // super.tearDown(); } /** @@ -474,4 +496,87 @@ public abstract class VirtualizationIntegrationTest extends TestCase implements writer.putContent(contentString); return nodeAssoc; } + + protected void setupMocks() + { + SearchServiceSubSystemDelegator searchServiceDelegator = (SearchServiceSubSystemDelegator) ctx.getBean("searchService"); + searchServiceDelegatorSpy = spy(searchServiceDelegator); + searchServiceDelegator.setSubSystem(searchServiceDelegatorSpy); + + doReturn(dbResults).when(searchServiceDelegatorSpy).query(Matchers.argThat(getArgMatcher())); + } + + protected void prepareMocks(String queryMatcher, NodeRef realNodeToReturn) + { + this.queryMatcher = queryMatcher; + List dbRows = new ArrayList(); + dbRows.add(resultSetRow); + when(resultSetRow.getNodeRef()).thenReturn(realNodeToReturn); + // make sure we return a new iterator each time + when(dbResults.iterator()).thenAnswer(new Answer>() + { + public Iterator answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable + { + return dbRows.iterator(); + }; + }); + when(dbResults.hasMore()).thenReturn(false); + when(dbResults.getNumberFound()).thenReturn(1L); + when(dbResults.getStart()).thenReturn(0); + } + protected void prepareMocks(String queryMatcher, List realNodeToReturn) + { + this.queryMatcher = queryMatcher; + List dbRows = new ArrayList(); + for(NodeRef node: realNodeToReturn) + { + ResultSetRow mock = mock(ResultSetRow.class); + dbRows.add(mock); + when(mock.getNodeRef()).thenReturn(node); + } + + // make sure we return a new iterator each time + when(dbResults.iterator()).thenAnswer(new Answer>() + { + public Iterator answer(org.mockito.invocation.InvocationOnMock invocation) throws Throwable + { + return dbRows.iterator(); + }; + }); + when(dbResults.hasMore()).thenReturn(false); + when(dbResults.getNumberFound()).thenReturn(2L); + when(dbResults.getStart()).thenReturn(0); + } + + protected void resetMocks() + { + // this will invalidate any match on the parameter for the query function, + // so the queries will go to the real object + this.queryMatcher = null; + } + + protected ArgumentMatcher getArgMatcher() + { + return new ArgumentMatcher() + { + @Override + public boolean matches(Object argument) + { + if (argument instanceof SearchParameters) + { + String matchingString = getMatchingString(); + if (matchingString != null && argument.toString().contains(matchingString)) + { + return true; + } + } + return false; + } + }; + } + + protected String getMatchingString() + { + return queryMatcher; + } } diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/FileInfoPropsComparatorTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/FileInfoPropsComparatorTest.java index 1c3be0d90f..24e6c81030 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/FileInfoPropsComparatorTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/FileInfoPropsComparatorTest.java @@ -25,21 +25,23 @@ */ package org.alfresco.repo.virtual.bundle; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.virtual.VirtualizationIntegrationTest; -import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.Pair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.virtual.VirtualizationIntegrationTest; +import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; public class FileInfoPropsComparatorTest extends VirtualizationIntegrationTest diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualCheckOutCheckInServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualCheckOutCheckInServiceExtensionTest.java index 75edcd71f5..17a7d4297f 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualCheckOutCheckInServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualCheckOutCheckInServiceExtensionTest.java @@ -25,6 +25,8 @@ */ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.*; + import java.io.Serializable; import java.util.HashMap; import java.util.List; @@ -45,6 +47,8 @@ import org.alfresco.service.cmr.version.Version; import org.alfresco.service.cmr.version.VersionService; import org.alfresco.service.cmr.version.VersionType; import org.alfresco.util.testing.category.LuceneTests; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; import org.springframework.extensions.surf.util.I18NUtil; @@ -84,8 +88,8 @@ public class VirtualCheckOutCheckInServiceExtensionTest extends VirtualizationIn private NodeRef physicalFileNodeRef; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); PROP_WORKING_COPY_NAME = CheckOutCheckInServiceImpl @@ -113,7 +117,7 @@ public class VirtualCheckOutCheckInServiceExtensionTest extends VirtualizationIn PROP_FILE_NAME); } - @Override + @After public void tearDown() throws Exception { super.tearDown(); @@ -387,7 +391,8 @@ public class VirtualCheckOutCheckInServiceExtensionTest extends VirtualizationIn sourceAssocs.get(0).getSourceRef()); checkOutCheckInService.cancelCheckout(workingCopyVirtualContext); } - + + @Test public void test_ACE_4699() throws Exception { checkOutCheckInService.checkout(originalContentNodeRef); diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualFileFolderServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualFileFolderServiceExtensionTest.java index f142942c88..d29a65e656 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualFileFolderServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualFileFolderServiceExtensionTest.java @@ -26,6 +26,12 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.Serializable; import java.util.ArrayList; @@ -41,19 +47,24 @@ import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.virtual.VirtualizationIntegrationTest; +import org.alfresco.repo.virtual.store.VirtualStoreImpl; import org.alfresco.service.cmr.coci.CheckOutCheckInService; import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.alfresco.util.TempFileProvider; import org.alfresco.util.testing.category.LuceneTests; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; @Category(LuceneTests.class) +@RunWith(MockitoJUnitRunner.class) public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegrationTest { @@ -61,6 +72,15 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra private static final String NEW_FILE_NAME_1 = "RenamedTest"; + private VirtualStoreImpl smartStore; + + @Before + public void setUp() throws Exception + { + super.setUp(); + smartStore = ctx.getBean("smartStore", VirtualStoreImpl.class); + } + @Test public void testListOne() throws Exception { @@ -290,14 +310,16 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra final HashMap properties = new HashMap(); properties.put(ContentModel.PROP_DESCRIPTION, "Node2_folder_FR"); - createFolder(vf, + ChildAssociationRef createFolder = createFolder(vf, folderName, properties); final String contentName = "ContentVirtualChild"; - createContent(node2, + ChildAssociationRef createContent = createContent(node2, contentName); + prepareMocks("Node2", createFolder.getChildRef()); + try { PagingResults folderChildren = fileAndFolderService.list(node2, false, @@ -313,7 +335,13 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra assertMissesNames(page, contentName); } - + finally + { + resetMocks(); + } + + prepareMocks("Node2", smartStore.materializeIfPossible(createContent.getChildRef())); + try { PagingResults contentChildren = fileAndFolderService.list(node2, true, @@ -329,7 +357,10 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra assertContainsNames(page, contentName); } - + finally + { + resetMocks(); + } } @Test @@ -465,13 +496,13 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra NodeRef node1 = nodeService.getChildByName(vf, ContentModel.ASSOC_CONTAINS, "Node1"); - createContent(node1, + ChildAssociationRef createContent = createContent(node1, name, "0", MimetypeMap.MIMETYPE_TEXT_PLAIN, "UTF-8"); - createContent(node1, + ChildAssociationRef createContent1 = createContent(node1, name1, "01", MimetypeMap.MIMETYPE_TEXT_PLAIN, @@ -482,8 +513,15 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra "1", MimetypeMap.MIMETYPE_TEXT_PLAIN, "UTF-8"); - String namePattern = "A N.&ame*.txt"; + + List querySolution = new ArrayList(); + querySolution.add(smartStore.materializeIfPossible(createContent1.getChildRef())); + querySolution.add(smartStore.materializeIfPossible(createContent.getChildRef())); + + prepareMocks("A", querySolution); + try + { PagingResults results = fileAndFolderService.list(node1, true, false, @@ -499,6 +537,11 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra name1); assertEquals(page.get(1).getName(), name); + } + finally + { + resetMocks(); + } } @Test @@ -540,6 +583,9 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra .getFileInfo(aNameNodeRef) .getContentData() .getMimetype()); + prepareMocks("=cm:name:AName", smartStore.materializeIfPossible(aNameNodeRef)); + try + { PagingResults results = fileAndFolderService .list(nodeService.getPrimaryParent(aNameNodeRef).getParentRef(), true, @@ -550,13 +596,15 @@ public class VirtualFileFolderServiceExtensionTest extends VirtualizationIntegra new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE)); List page = results.getPage(); - FileInfo fileInfo = null; - if (page.size() > 0) - { - fileInfo = page.get(0); - lastDup = fileInfo.getNodeRef(); + + assertTrue(page.size() > 0); + + assertFalse(page.get(0).getNodeRef().equals(nameAfterNodeRef)); + } + finally + { + resetMocks(); } - assertFalse(lastDup.equals(nameAfterNodeRef)); } private String addWildCardInName(String name, String mimetype) diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualLockableAspectInterceptorExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualLockableAspectInterceptorExtensionTest.java index 7fda0e0326..f55f536601 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualLockableAspectInterceptorExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualLockableAspectInterceptorExtensionTest.java @@ -26,13 +26,16 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.*; + import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.lock.mem.Lifetime; import org.alfresco.repo.virtual.VirtualizationIntegrationTest; import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockType; -import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Before; import org.junit.Test; public class VirtualLockableAspectInterceptorExtensionTest extends VirtualizationIntegrationTest @@ -41,8 +44,8 @@ public class VirtualLockableAspectInterceptorExtensionTest extends Virtualizatio private NodeRef originalContentNodeRef; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); lockService = ctx.getBean("lockService", diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtensionTest.java index 5f4c3bfe42..167abc334d 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualNodeServiceExtensionTest.java @@ -26,6 +26,13 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.Serializable; import java.util.Arrays; import java.util.HashMap; @@ -49,7 +56,6 @@ import org.alfresco.repo.virtual.ref.GetActualNodeRefMethod; import org.alfresco.repo.virtual.ref.GetParentReferenceMethod; import org.alfresco.repo.virtual.ref.Protocols; import org.alfresco.repo.virtual.ref.Reference; -import org.alfresco.repo.virtual.ref.ReferenceEncodingException; import org.alfresco.repo.virtual.ref.VirtualProtocol; import org.alfresco.repo.virtual.store.VirtualStore; import org.alfresco.service.cmr.repository.AssociationRef; @@ -64,11 +70,15 @@ import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.testing.category.LuceneTests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; @Category(LuceneTests.class) +@RunWith(MockitoJUnitRunner.class) public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTest { private static final String NODE2TEST1_2_TXT = "NODE2test1_2.txt"; @@ -87,8 +97,8 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe private NodeRef node2Test1_2_TXTNodeRef; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { // TODO:is the store really needed when testing node service ? why ? super.setUp(); @@ -98,6 +108,7 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe DownloadStorage.class); } + @Test public void testCreateNode_withFilingRuleAspects() throws Exception { @@ -346,18 +357,6 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe } } - private void createNode(Reference reference, final QName assocQName, HashMap properties) - throws ReferenceEncodingException - { - ChildAssociationRef childAssocsRef = nodeService.createNode(reference.toNodeRef(), - ContentModel.ASSOC_CONTAINS, - assocQName, - ContentModel.TYPE_CONTENT, - properties); - assertNewVirtualChildAssocRef(reference, - childAssocsRef); - } - private void uploadNode(Reference reference, String name) { fileAndFolderService.create(reference.toNodeRef(), @@ -1079,6 +1078,9 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe "Node1"); assertNotNull(node1); + prepareMocks("cm:TestFolder//cm:FOLDER", createFolder); + try + { NodeRef physicalFolderInVirtualContext = nodeService.getChildByName(node1, ContentModel.ASSOC_CONTAINS, "FOLDER"); @@ -1091,6 +1093,11 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe assertEquals("testFile1", nodeService.getProperty(childAssocs.get(0).getChildRef(), ContentModel.PROP_NAME)); + } + finally + { + resetMocks(); + } } @Test @@ -1138,6 +1145,9 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe "Node1"); assertNotNull(node1); + prepareMocks("FOLDER", physicalFolder); + try + { NodeRef physicalFolderInVirtualContext = nodeService.getChildByName(node1, ContentModel.ASSOC_CONTAINS, "FOLDER"); @@ -1162,8 +1172,14 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe childFolderNodeRef = nodeService.getChildByName(physicalFolder,ContentModel.ASSOC_CONTAINS, "testFolder1"); assertNotNull(childFolderNodeRef); + } + finally + { + resetMocks(); + } } + @Test public void testChildByName_ACE_4700() throws Exception { NodeRef node1 = nodeService.getChildByName(virtualFolder1NodeRef, @@ -1206,7 +1222,8 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe ContentModel.ASSOC_CONTAINS, suportedCharsFileName2)); } - + + @Test public void testHasAspect() throws Exception { // test for virtual folder @@ -1230,7 +1247,7 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT)); // test for folder in virtual context - createFolder(testRootFolder.getNodeRef(), + NodeRef realFolderNode= createFolder(testRootFolder.getNodeRef(), "FOLDER").getChildRef(); NodeRef virtualFolder = createVirtualizedFolder(testRootFolder.getNodeRef(), VIRTUAL_FOLDER_2_NAME, @@ -1240,6 +1257,9 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe "Node1"); assertNotNull(node1_1); + prepareMocks("cm:TestFolder//cm:FOLDER", realFolderNode); + try + { NodeRef physicalFolderInVirtualContext = nodeService.getChildByName(node1_1, ContentModel.ASSOC_CONTAINS, "FOLDER"); @@ -1265,7 +1285,11 @@ public class VirtualNodeServiceExtensionTest extends VirtualizationIntegrationTe VirtualContentModel.ASPECT_VIRTUAL)); assertFalse(nodeService.hasAspect(childFileNodeRef, VirtualContentModel.ASPECT_VIRTUAL_DOCUMENT)); - + } + finally + { + resetMocks(); + } } private NodeRef createDownloadNode() diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPermissionServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPermissionServiceExtensionTest.java index 6db770c652..57156031d2 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPermissionServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPermissionServiceExtensionTest.java @@ -26,6 +26,11 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -42,6 +47,7 @@ import org.alfresco.repo.security.permissions.PermissionServiceSPI; import org.alfresco.repo.virtual.VirtualizationIntegrationTest; import org.alfresco.repo.virtual.store.VirtualStoreImpl; import org.alfresco.repo.virtual.store.VirtualUserPermissions; +import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AccessPermission; @@ -50,10 +56,15 @@ import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.util.testing.category.LuceneTests; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; @Category(LuceneTests.class) +@RunWith(MockitoJUnitRunner.class) public class VirtualPermissionServiceExtensionTest extends VirtualizationIntegrationTest { private PermissionServiceSPI permissionService; @@ -81,8 +92,8 @@ public class VirtualPermissionServiceExtensionTest extends VirtualizationIntegra private NodeRef contributionsSMF; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); // we set our own virtual user permissions in order to be context xml @@ -160,7 +171,7 @@ public class VirtualPermissionServiceExtensionTest extends VirtualizationIntegra smartStore.setUserPermissions(testPermissions); } - @Override + @After public void tearDown() throws Exception { if (savedUserPermissions != null) @@ -839,9 +850,11 @@ public class VirtualPermissionServiceExtensionTest extends VirtualizationIntegra // test that the admin user can see documents from virtual nodes // with filing path with no inherited parent permissions - fileAndFolderService.create(contributionsSMF, + FileInfo t1File = fileAndFolderService.create(contributionsSMF, "T1", ContentModel.TYPE_CONTENT); + //"cm:Contribution" taken from testTemplate7.json smart folder query + prepareMocks("cm:Contribution", smartStore.materializeIfPossible(t1File.getNodeRef())); NodeRef childContet = nodeService.getChildByName(contributionsSMF, ContentModel.ASSOC_CONTAINS, @@ -867,6 +880,7 @@ public class VirtualPermissionServiceExtensionTest extends VirtualizationIntegra } finally { + resetMocks(); if (contributionDocsFolder != null) { nodeService.deleteNode(contributionDocsFolder); diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPreferenceServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPreferenceServiceExtensionTest.java index dea4871b7e..c179f6a953 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPreferenceServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualPreferenceServiceExtensionTest.java @@ -26,6 +26,11 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -38,9 +43,14 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.testing.category.LuceneTests; +import org.junit.Before; +import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; @Category(LuceneTests.class) +@RunWith(MockitoJUnitRunner.class) public class VirtualPreferenceServiceExtensionTest extends VirtualizationIntegrationTest { private static final String DOCUMENTS_FAVOURITES_KEY = "org.alfresco.share.documents.favourites"; @@ -55,14 +65,15 @@ public class VirtualPreferenceServiceExtensionTest extends VirtualizationIntegra private PreferenceService preferenceService; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); preferenceService = ctx.getBean("preferenceService", PreferenceService.class); } + @Test public void testSetFavoritesPreferencesForDocuments() throws Exception { NodeRef node2 = nodeService.getChildByName(virtualFolder1NodeRef, @@ -141,7 +152,7 @@ public class VirtualPreferenceServiceExtensionTest extends VirtualizationIntegra EXT_DOCUMENTS_FAVOURITES + physicalTestfile1.toString() + CREATED_AT)); } - + @Test public void testSetFavoritesPreferencesForFolders() throws Exception { NodeRef physicalFolder = createFolder(testRootFolder.getNodeRef(), @@ -154,6 +165,9 @@ public class VirtualPreferenceServiceExtensionTest extends VirtualizationIntegra "Node1"); assertNotNull(node1); + prepareMocks("FOLDER", physicalFolder); + try + { NodeRef physicalFolderInVirtualContext = nodeService.getChildByName(node1, ContentModel.ASSOC_CONTAINS, "FOLDER"); @@ -206,5 +220,10 @@ public class VirtualPreferenceServiceExtensionTest extends VirtualizationIntegra assertNull((String) preferenceService.getPreference("admin", EXT_FOLDERS_FAVOURITES + physicalFolder.toString() + CREATED_AT)); + } + finally + { + resetMocks(); + } } } \ No newline at end of file diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualRatingServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualRatingServiceExtensionTest.java index 1a9567cc39..ceaa9086ee 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualRatingServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualRatingServiceExtensionTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.*; + import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; @@ -35,6 +37,7 @@ import org.alfresco.repo.virtual.ref.Reference; import org.alfresco.service.cmr.rating.RatingService; import org.alfresco.service.cmr.rating.RatingServiceException; import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Before; import org.junit.Test; public class VirtualRatingServiceExtensionTest extends VirtualizationIntegrationTest @@ -53,8 +56,8 @@ public class VirtualRatingServiceExtensionTest extends VirtualizationIntegration private String user2; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); @@ -119,13 +122,14 @@ public class VirtualRatingServiceExtensionTest extends VirtualizationIntegration 1f, LIKES_RATING_SCHEME, user2); - + + double delta = 0.0000001; assertEquals(1f, ratingService.getAverageRating(virtualContent, - LIKES_RATING_SCHEME)); + LIKES_RATING_SCHEME), delta); assertEquals(1f, ratingService.getAverageRating(actualNodeRef, - LIKES_RATING_SCHEME)); + LIKES_RATING_SCHEME), delta); applyRatingAs(virtualContent, 1f, @@ -137,9 +141,9 @@ public class VirtualRatingServiceExtensionTest extends VirtualizationIntegration user2); assertEquals(2f, ratingService.getAverageRating(virtualContent, - FIVE_STAR_RATING_SCHEME)); + FIVE_STAR_RATING_SCHEME), delta); assertEquals(2f, ratingService.getAverageRating(actualNodeRef, - FIVE_STAR_RATING_SCHEME)); + FIVE_STAR_RATING_SCHEME), delta); } } diff --git a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtensionTest.java b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtensionTest.java index 6546db33bc..90206f2012 100644 --- a/src/test/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtensionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/bundle/VirtualVersionServiceExtensionTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.bundle; +import static org.junit.Assert.*; + import java.util.Collection; import org.alfresco.model.ContentModel; @@ -38,6 +40,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.version.Version; import org.alfresco.service.cmr.version.VersionHistory; import org.alfresco.service.cmr.version.VersionService; +import org.junit.Before; import org.junit.Test; public class VirtualVersionServiceExtensionTest extends VirtualizationIntegrationTest @@ -49,8 +52,8 @@ public class VirtualVersionServiceExtensionTest extends VirtualizationIntegratio private NodeRef node2_1; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); diff --git a/src/test/java/org/alfresco/repo/virtual/config/NodeRefPathExpressionTest.java b/src/test/java/org/alfresco/repo/virtual/config/NodeRefPathExpressionTest.java index 34ba870647..7348bd04e1 100644 --- a/src/test/java/org/alfresco/repo/virtual/config/NodeRefPathExpressionTest.java +++ b/src/test/java/org/alfresco/repo/virtual/config/NodeRefPathExpressionTest.java @@ -26,12 +26,17 @@ package org.alfresco.repo.virtual.config; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; + import java.io.Serializable; import org.alfresco.model.ContentModel; import org.alfresco.repo.virtual.VirtualizationIntegrationTest; import org.alfresco.repo.virtual.VirtualizationTest; import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Before; import org.junit.Test; public class NodeRefPathExpressionTest extends VirtualizationIntegrationTest implements VirtualizationTest @@ -40,8 +45,8 @@ public class NodeRefPathExpressionTest extends VirtualizationIntegrationTest imp private NodeRefPathExpressionFactory nodeRefPathExpressionFactory; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); nodeRefPathExpressionFactory = (NodeRefPathExpressionFactory) ctx.getBean(NODE_REF_PATH_EXPRESSION_FACTORY_ID); diff --git a/src/test/java/org/alfresco/repo/virtual/model/SystemTemplateLocationsConstraintTest.java b/src/test/java/org/alfresco/repo/virtual/model/SystemTemplateLocationsConstraintTest.java index a346a65b98..e933b0269b 100644 --- a/src/test/java/org/alfresco/repo/virtual/model/SystemTemplateLocationsConstraintTest.java +++ b/src/test/java/org/alfresco/repo/virtual/model/SystemTemplateLocationsConstraintTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.model; +import static org.junit.Assert.*; + import java.io.InputStream; import java.util.Collections; import java.util.LinkedList; @@ -43,7 +45,9 @@ import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.QName; +import org.junit.After; +import org.junit.Before; import org.junit.Test; public class SystemTemplateLocationsConstraintTest extends VirtualizationIntegrationTest @@ -54,8 +58,8 @@ public class SystemTemplateLocationsConstraintTest extends VirtualizationIntegra private NodeRefExpression templatesParentRepositoryPath; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry"); @@ -63,7 +67,7 @@ public class SystemTemplateLocationsConstraintTest extends VirtualizationIntegra } - @Override + @After public void tearDown() throws Exception { if (templatesParentRepositoryPath != null) diff --git a/src/test/java/org/alfresco/repo/virtual/store/SystemVirtualizationMethodTest.java b/src/test/java/org/alfresco/repo/virtual/store/SystemVirtualizationMethodTest.java index 2939252e1e..3551899e43 100644 --- a/src/test/java/org/alfresco/repo/virtual/store/SystemVirtualizationMethodTest.java +++ b/src/test/java/org/alfresco/repo/virtual/store/SystemVirtualizationMethodTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.store; +import static org.junit.Assert.*; + import java.io.InputStream; import org.alfresco.model.ContentModel; @@ -37,6 +39,7 @@ import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Before; import org.junit.Test; public class SystemVirtualizationMethodTest extends VirtualizationIntegrationTest @@ -46,8 +49,8 @@ public class SystemVirtualizationMethodTest extends VirtualizationIntegrationTes private SystemVirtualizationMethod systemVirtualizationMethod; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); systemVirtualizationMethod = ctx.getBean("systemVirtualizationMethod", diff --git a/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodIntegrationTest.java b/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodIntegrationTest.java new file mode 100644 index 0000000000..7eda907002 --- /dev/null +++ b/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodIntegrationTest.java @@ -0,0 +1,241 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.repo.virtual.store; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.InputStream; +import java.io.Serializable; +import java.util.Collections; +import java.util.List; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.site.SiteModel; +import org.alfresco.repo.virtual.VirtualizationIntegrationTest; +import org.alfresco.repo.virtual.config.NodeRefExpression; +import org.alfresco.repo.virtual.ref.ClasspathResource; +import org.alfresco.repo.virtual.ref.Parameter; +import org.alfresco.repo.virtual.ref.Protocols; +import org.alfresco.repo.virtual.ref.Reference; +import org.alfresco.repo.virtual.ref.RepositoryLocation; +import org.alfresco.repo.virtual.ref.RepositoryResource; +import org.alfresco.repo.virtual.ref.Resource; +import org.alfresco.repo.virtual.ref.ResourceParameter; +import org.alfresco.repo.virtual.ref.ResourceProcessingError; +import org.alfresco.repo.virtual.ref.ResourceProcessor; +import org.alfresco.repo.virtual.ref.VanillaProtocol; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TypeVirtualizationMethodIntegrationTest extends VirtualizationIntegrationTest +{ + + private static final QName TEST_FOLDER_TYPE = SiteModel.TYPE_SITE; + + private static final QName TEST_ASPECT = SiteModel.ASPECT_SITE_CONTAINER; + + private TypeVirtualizationMethod typeVirtualizationMethod; + + @Before + public void setUp() throws Exception + { + super.setUp(); + typeVirtualizationMethod = ctx.getBean("typeVirtualizationMethod", TypeVirtualizationMethod.class); + } + + @After + public void tearDown() throws Exception + { + super.tearDown(); + typeVirtualizationMethod.setQnameFilters(virtualizationConfigTestBootstrap.getTypeTemplatesQNameFilter()); + } + + @Test + public void testFiltering() throws Exception + { + typeVirtualizationMethod.setQnameFilters("st:site"); + + ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), "TypeVirtualized", TEST_FOLDER_TYPE); + NodeRef virtuaChildRef = typedNodeAssocRef.getChildRef(); + assertFalse(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + addTypeTemplate(TEST_FOLDER_TYPE, TEST_TEMPLATE_1_JS_CLASSPATH); + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + typeVirtualizationMethod.setQnameFilters("alf:site"); + + assertFalse(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + typeVirtualizationMethod.setQnameFilters("st:*"); + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + typeVirtualizationMethod.setQnameFilters("alf:site"); + + assertFalse(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + typeVirtualizationMethod.setQnameFilters("*"); + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + typeVirtualizationMethod.setQnameFilters("none"); + + assertFalse(typeVirtualizationMethod.canVirtualize(environment, virtuaChildRef)); + + } + + @Test + public void testVirtualizeCmFolder_recusive() throws Exception + { + ChildAssociationRef templateContentChildRef = addTypeTemplate(ContentModel.TYPE_FOLDER, TEST_TEMPLATE_1_JS_CLASSPATH); + virtualize(templateContentChildRef.getChildRef(), ContentModel.TYPE_FOLDER); + } + + @Test + public void testCanVirtualize() throws Exception + { + ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), "TypeVirtualized", TEST_FOLDER_TYPE); + NodeRef typeNode = typedNodeAssocRef.getChildRef(); + + assertFalse(typeVirtualizationMethod.canVirtualize(environment, typeNode)); + + addTypeTemplate(TEST_FOLDER_TYPE, TEST_TEMPLATE_1_JS_CLASSPATH); + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, typeNode)); + + } + + @Test + public void testCanVirtualizeAspect() throws Exception + { + ChildAssociationRef aspectNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), "TypeVirtualized", ContentModel.TYPE_FOLDER); + NodeRef aspectNode = aspectNodeAssocRef.getChildRef(); + + nodeService.addAspect(aspectNode, TEST_ASPECT, Collections. emptyMap()); + + assertFalse(typeVirtualizationMethod.canVirtualize(environment, aspectNode)); + + addTypeTemplate(TEST_ASPECT, TEST_TEMPLATE_1_JS_CLASSPATH); + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, aspectNode)); + + } + + @Test + public void testVirtualizeAspect() throws Exception + { + ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_ASPECT, TEST_TEMPLATE_1_JS_CLASSPATH); + virtualize(templateContentChildRef.getChildRef(), ContentModel.TYPE_FOLDER, TEST_ASPECT); + } + + @Test + public void testVirtualizeType() throws Exception + { + ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_FOLDER_TYPE, TEST_TEMPLATE_1_JS_CLASSPATH); + + virtualize(templateContentChildRef.getChildRef(), TEST_FOLDER_TYPE); + } + + private void virtualize(NodeRef expectedTemplateNodeRef, QName fodlerType, QName... aspects) throws Exception + { + + ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), "TypeVirtualized", fodlerType); + NodeRef typeNode = typedNodeAssocRef.getChildRef(); + + for (QName aspect : aspects) + { + nodeService.addAspect(typeNode, aspect, Collections. emptyMap()); + } + + assertTrue(typeVirtualizationMethod.canVirtualize(environment, typeNode)); + + Reference theVirtualizedNode = typeVirtualizationMethod.virtualize(environment, typeNode); + assertEquals(Protocols.VANILLA.protocol, theVirtualizedNode.getProtocol()); + + List parameters = theVirtualizedNode.getParameters(); + ResourceParameter vanillaResourceParameter = (ResourceParameter) parameters.get(VanillaProtocol.VANILLA_TEMPLATE_PARAM_INDEX); + Resource vanillaResource = vanillaResourceParameter.getValue(); + + NodeRef resourceNodeRef = vanillaResource.processWith(new ResourceProcessor() + { + + @Override + public NodeRef process(Resource resource) throws ResourceProcessingError + { + fail("Inavlid resource type"); + return null; + } + + @Override + public NodeRef process(ClasspathResource classpath) throws ResourceProcessingError + { + fail("Inavlid resource type"); + return null; + } + + @Override + public NodeRef process(RepositoryResource repository) throws ResourceProcessingError + { + RepositoryLocation location = repository.getLocation(); + return location.asNodeRef(environment); + } + }); + + assertEquals(expectedTemplateNodeRef, resourceNodeRef); + } + + private synchronized ChildAssociationRef addTypeTemplate(QName theType, String cp) + { + NodeRefExpression templatesLocationExpr = virtualizationConfigTestBootstrap.getTypeTemplatesPath(); + NodeRef templatesLocation = templatesLocationExpr.resolve(); + + assertNotNull(templatesLocation); + + final String prefixedType = theType.toPrefixString(environment.getNamespacePrefixResolver()); + String contentName = prefixedType; + contentName = contentName.replaceAll(":", "_") + ".json"; + + InputStream testTemplsteJsonIS = getClass().getResourceAsStream(cp); + ChildAssociationRef templateContentChildRef = createContent(templatesLocation, contentName, testTemplsteJsonIS, "application/json", "UTF-8", + ContentModel.TYPE_CONTENT); + + typeVirtualizationMethod.setQnameFilters(prefixedType); + + return templateContentChildRef; + } +} diff --git a/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodTest.java b/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodTest.java deleted file mode 100644 index 7e47158f6c..0000000000 --- a/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodTest.java +++ /dev/null @@ -1,381 +0,0 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ - -package org.alfresco.repo.virtual.store; - - -import java.io.InputStream; -import java.io.Serializable; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.site.SiteModel; -import org.alfresco.repo.virtual.VirtualizationIntegrationTest; -import org.alfresco.repo.virtual.config.NodeRefExpression; -import org.alfresco.repo.virtual.ref.ClasspathResource; -import org.alfresco.repo.virtual.ref.Parameter; -import org.alfresco.repo.virtual.ref.Protocols; -import org.alfresco.repo.virtual.ref.Reference; -import org.alfresco.repo.virtual.ref.RepositoryLocation; -import org.alfresco.repo.virtual.ref.RepositoryResource; -import org.alfresco.repo.virtual.ref.Resource; -import org.alfresco.repo.virtual.ref.ResourceParameter; -import org.alfresco.repo.virtual.ref.ResourceProcessingError; -import org.alfresco.repo.virtual.ref.ResourceProcessor; -import org.alfresco.repo.virtual.ref.VanillaProtocol; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.NamespaceException; -import org.alfresco.service.namespace.NamespacePrefixResolver; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.mockito.Mockito; -import org.mockito.internal.stubbing.answers.ThrowsException; - -public class TypeVirtualizationMethodTest extends TestSuite -{ - private static Log logger = LogFactory.getLog(TypeVirtualizationMethodTest.class); - - private static final QName TEST_FOLDER_TYPE = SiteModel.TYPE_SITE; - - private static final QName TEST_ASPECT = SiteModel.ASPECT_SITE_CONTAINER; - - public static class Integration extends VirtualizationIntegrationTest - { - private TypeVirtualizationMethod typeVirtualizationMethod; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - typeVirtualizationMethod = ctx.getBean("typeVirtualizationMethod", - TypeVirtualizationMethod.class); - } - - @Override - public void tearDown() throws Exception - { - super.tearDown(); - typeVirtualizationMethod.setQnameFilters(virtualizationConfigTestBootstrap.getTypeTemplatesQNameFilter()); - } - - public void testFiltering() throws Exception - { - typeVirtualizationMethod.setQnameFilters("st:site"); - - ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), - "TypeVirtualized", - TEST_FOLDER_TYPE); - NodeRef virtuaChildRef = typedNodeAssocRef.getChildRef(); - assertFalse(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - addTypeTemplate(TEST_FOLDER_TYPE, - TEST_TEMPLATE_1_JS_CLASSPATH); - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - typeVirtualizationMethod.setQnameFilters("alf:site"); - - assertFalse(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - typeVirtualizationMethod.setQnameFilters("st:*"); - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - typeVirtualizationMethod.setQnameFilters("alf:site"); - - assertFalse(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - typeVirtualizationMethod.setQnameFilters("*"); - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - typeVirtualizationMethod.setQnameFilters("none"); - - assertFalse(typeVirtualizationMethod.canVirtualize(environment, - virtuaChildRef)); - - } - - public void testVirtualizeCmFolder_recusive() throws Exception - { - ChildAssociationRef templateContentChildRef = addTypeTemplate(ContentModel.TYPE_FOLDER, - TEST_TEMPLATE_1_JS_CLASSPATH); - virtualize(templateContentChildRef.getChildRef(), - ContentModel.TYPE_FOLDER); - } - - public void testCanVirtualize() throws Exception - { - ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), - "TypeVirtualized", - TEST_FOLDER_TYPE); - NodeRef typeNode = typedNodeAssocRef.getChildRef(); - - assertFalse(typeVirtualizationMethod.canVirtualize(environment, - typeNode)); - - addTypeTemplate(TEST_FOLDER_TYPE, - TEST_TEMPLATE_1_JS_CLASSPATH); - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - typeNode)); - - } - - public void testCanVirtualizeAspect() throws Exception - { - ChildAssociationRef aspectNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), - "TypeVirtualized", - ContentModel.TYPE_FOLDER); - NodeRef aspectNode = aspectNodeAssocRef.getChildRef(); - - nodeService.addAspect(aspectNode, - TEST_ASPECT, - Collections. emptyMap()); - - assertFalse(typeVirtualizationMethod.canVirtualize(environment, - aspectNode)); - - addTypeTemplate(TEST_ASPECT, - TEST_TEMPLATE_1_JS_CLASSPATH); - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - aspectNode)); - - } - - public void testVirtualizeAspect() throws Exception - { - ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_ASPECT, - TEST_TEMPLATE_1_JS_CLASSPATH); - virtualize(templateContentChildRef.getChildRef(), - ContentModel.TYPE_FOLDER, - TEST_ASPECT); - } - - public void testVirtualizeType() throws Exception - { - ChildAssociationRef templateContentChildRef = addTypeTemplate(TEST_FOLDER_TYPE, - TEST_TEMPLATE_1_JS_CLASSPATH); - - virtualize(templateContentChildRef.getChildRef(), - TEST_FOLDER_TYPE); - } - - private void virtualize(NodeRef expectedTemplateNodeRef, QName fodlerType, QName... aspects) throws Exception - { - - ChildAssociationRef typedNodeAssocRef = createTypedNode(testRootFolder.getNodeRef(), - "TypeVirtualized", - fodlerType); - NodeRef typeNode = typedNodeAssocRef.getChildRef(); - - for (QName aspect : aspects) - { - nodeService.addAspect(typeNode, - aspect, - Collections. emptyMap()); - } - - assertTrue(typeVirtualizationMethod.canVirtualize(environment, - typeNode)); - - Reference theVirtualizedNode = typeVirtualizationMethod.virtualize(environment, - typeNode); - assertEquals(Protocols.VANILLA.protocol, - theVirtualizedNode.getProtocol()); - - List parameters = theVirtualizedNode.getParameters(); - ResourceParameter vanillaResourceParameter = (ResourceParameter) parameters - .get(VanillaProtocol.VANILLA_TEMPLATE_PARAM_INDEX); - Resource vanillaResource = vanillaResourceParameter.getValue(); - - NodeRef resourceNodeRef = vanillaResource.processWith(new ResourceProcessor() - { - - @Override - public NodeRef process(Resource resource) throws ResourceProcessingError - { - fail("Inavlid resource type"); - return null; - } - - @Override - public NodeRef process(ClasspathResource classpath) throws ResourceProcessingError - { - fail("Inavlid resource type"); - return null; - } - - @Override - public NodeRef process(RepositoryResource repository) throws ResourceProcessingError - { - RepositoryLocation location = repository.getLocation(); - return location.asNodeRef(environment); - } - }); - - assertEquals(expectedTemplateNodeRef, - resourceNodeRef); - } - - private synchronized ChildAssociationRef addTypeTemplate(QName theType, String cp) - { - NodeRefExpression templatesLocationExpr = virtualizationConfigTestBootstrap.getTypeTemplatesPath(); - NodeRef templatesLocation = templatesLocationExpr.resolve(); - - assertNotNull(templatesLocation); - - final String prefixedType = theType.toPrefixString(environment.getNamespacePrefixResolver()); - String contentName = prefixedType; - contentName = contentName.replaceAll(":", - "_") + ".json"; - - InputStream testTemplsteJsonIS = getClass().getResourceAsStream(cp); - ChildAssociationRef templateContentChildRef = createContent(templatesLocation, - contentName, - testTemplsteJsonIS, - "application/json", - "UTF-8", - ContentModel.TYPE_CONTENT); - - typeVirtualizationMethod.setQnameFilters(prefixedType); - - return templateContentChildRef; - } - } - - public static class Unit extends TestCase - { - public void testQNameFiltersSetter_invalidFilters() throws Exception - { - assertIllegalQNameFilters(null, - this); - assertIllegalQNameFilters("", - this); - - } - - public void testQNameFiltersSetter_validFilters() throws Exception - { - assertQNameFilters("st:site", - this); - assertQNameFilters("st:site,cm:folder", - this); - assertQNameFilters("st:site,cm:test-folder", - this); - assertQNameFilters("st:*", - this); - assertQNameFilters("st:*,cm:*", - this); - - assertQNameFilters("*", - this); - - assertQNameFilters("none", - this); - - } - } - - private static NamespacePrefixResolver mockNamespacePrefixResolver() - { - NamespacePrefixResolver mockNamespacePrefixResolver = Mockito - .mock(NamespacePrefixResolver.class, - - new ThrowsException(new NamespaceException("Mock exception "))); - - Mockito.doReturn(Arrays. asList(SiteModel.SITE_MODEL_PREFIX)) - .when(mockNamespacePrefixResolver) - .getPrefixes(SiteModel.SITE_MODEL_URL); - Mockito.doReturn(SiteModel.SITE_MODEL_URL) - .when(mockNamespacePrefixResolver) - .getNamespaceURI(SiteModel.SITE_MODEL_PREFIX); - - Mockito.doReturn(Arrays. asList(NamespaceService.CONTENT_MODEL_PREFIX)) - .when(mockNamespacePrefixResolver) - .getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI); - Mockito.doReturn(NamespaceService.CONTENT_MODEL_1_0_URI) - .when(mockNamespacePrefixResolver) - .getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX); - - Mockito.doReturn("mock(NamespacePrefixResolver)@" + TypeVirtualizationMethod.class.toString()) - .when(mockNamespacePrefixResolver) - .toString(); - return mockNamespacePrefixResolver; - } - - private static void assertIllegalQNameFilters(String filters, TestCase test) - { - TypeVirtualizationMethod tvm = new TypeVirtualizationMethod(); - try - { - tvm.setNamespacePrefixResolver(mockNamespacePrefixResolver()); - tvm.setQnameFilters(filters); - TestCase.fail("Should not be able to set filters string " + filters); - } - catch (IllegalArgumentException e) - { - // void as expected - logger.info(e.getMessage()); - } - } - - private static void assertQNameFilters(String filters, TestCase test) - { - TypeVirtualizationMethod tvm = new TypeVirtualizationMethod(); - tvm.setNamespacePrefixResolver(mockNamespacePrefixResolver()); - tvm.setQnameFilters(filters); - } - - public static Test suite() - { - TestSuite suite = new TestSuite(); - suite.addTest(new JUnit4TestAdapter(Integration.class)); - suite.addTest(new JUnit4TestAdapter(Unit.class)); - return suite; - } -} diff --git a/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodUnitTest.java b/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodUnitTest.java new file mode 100644 index 0000000000..449e2496be --- /dev/null +++ b/src/test/java/org/alfresco/repo/virtual/store/TypeVirtualizationMethodUnitTest.java @@ -0,0 +1,107 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.repo.virtual.store; + +import static org.junit.Assert.fail; + +import java.util.Arrays; + +import org.alfresco.repo.site.SiteModel; +import org.alfresco.service.namespace.NamespaceException; +import org.alfresco.service.namespace.NamespacePrefixResolver; +import org.alfresco.service.namespace.NamespaceService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.stubbing.answers.ThrowsException; + +public class TypeVirtualizationMethodUnitTest +{ + private static Log logger = LogFactory.getLog(TypeVirtualizationMethodUnitTest.class); + + @Test + public void testQNameFiltersSetter_invalidFilters() throws Exception + { + assertIllegalQNameFilters(null); + assertIllegalQNameFilters(""); + } + + @Test + public void testQNameFiltersSetter_validFilters() throws Exception + { + assertQNameFilters("st:site"); + assertQNameFilters("st:site,cm:folder"); + assertQNameFilters("st:site,cm:test-folder"); + assertQNameFilters("st:*"); + assertQNameFilters("st:*,cm:*"); + assertQNameFilters("*"); + assertQNameFilters("none"); + } + + static NamespacePrefixResolver mockNamespacePrefixResolver() + { + NamespacePrefixResolver mockNamespacePrefixResolver = Mockito.mock(NamespacePrefixResolver.class, + new ThrowsException(new NamespaceException("Mock exception "))); + + Mockito.doReturn(Arrays. asList(SiteModel.SITE_MODEL_PREFIX)).when(mockNamespacePrefixResolver).getPrefixes(SiteModel.SITE_MODEL_URL); + Mockito.doReturn(SiteModel.SITE_MODEL_URL).when(mockNamespacePrefixResolver).getNamespaceURI(SiteModel.SITE_MODEL_PREFIX); + + Mockito.doReturn(Arrays. asList(NamespaceService.CONTENT_MODEL_PREFIX)).when(mockNamespacePrefixResolver) + .getPrefixes(NamespaceService.CONTENT_MODEL_1_0_URI); + Mockito.doReturn(NamespaceService.CONTENT_MODEL_1_0_URI).when(mockNamespacePrefixResolver) + .getNamespaceURI(NamespaceService.CONTENT_MODEL_PREFIX); + + Mockito.doReturn("mock(NamespacePrefixResolver)@" + TypeVirtualizationMethod.class.toString()).when(mockNamespacePrefixResolver).toString(); + + return mockNamespacePrefixResolver; + } + + static void assertIllegalQNameFilters(String filters) + { + TypeVirtualizationMethod tvm = new TypeVirtualizationMethod(); + try + { + tvm.setNamespacePrefixResolver(mockNamespacePrefixResolver()); + tvm.setQnameFilters(filters); + fail("Should not be able to set filters string " + filters); + } + catch (IllegalArgumentException e) + { + // void as expected + logger.info(e.getMessage()); + } + } + + static void assertQNameFilters(String filters) + { + TypeVirtualizationMethod tvm = new TypeVirtualizationMethod(); + tvm.setNamespacePrefixResolver(mockNamespacePrefixResolver()); + tvm.setQnameFilters(filters); + } + +} diff --git a/src/test/java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java b/src/test/java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java index 3b9e0b2d39..7d0550f18d 100644 --- a/src/test/java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java +++ b/src/test/java/org/alfresco/repo/virtual/store/VirtualStoreImplTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.store; +import static org.junit.Assert.*; + import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.util.HashMap; @@ -49,6 +51,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Before; import org.junit.Test; public class VirtualStoreImplTest extends VirtualizationIntegrationTest @@ -57,8 +60,8 @@ public class VirtualStoreImplTest extends VirtualizationIntegrationTest private VirtualStoreImpl smartStore; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); @@ -67,6 +70,7 @@ public class VirtualStoreImplTest extends VirtualizationIntegrationTest } + @Test public void testResolveVirtualFolderDefinition_inactiveSynchronization() throws Exception { txnTamperHint = "VirtualStoreImplTest::testResolveVirtualFolderDefinition_inactiveSynchronization"; diff --git a/src/test/java/org/alfresco/repo/virtual/template/ApplyTemplateMethodTest.java b/src/test/java/org/alfresco/repo/virtual/template/ApplyTemplateMethodTest.java index e02a107ee7..c9cfd8e1ee 100644 --- a/src/test/java/org/alfresco/repo/virtual/template/ApplyTemplateMethodTest.java +++ b/src/test/java/org/alfresco/repo/virtual/template/ApplyTemplateMethodTest.java @@ -26,6 +26,9 @@ package org.alfresco.repo.virtual.template; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.nio.charset.StandardCharsets; import java.util.List; @@ -38,15 +41,16 @@ import org.alfresco.repo.virtual.ref.Reference; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.Test; import org.junit.experimental.categories.Category; @Category(LuceneTests.class) public class ApplyTemplateMethodTest extends VirtualizationIntegrationTest { + @Category(RedundantTests.class) @Test public void testExecute_vanillaISO9075ActualPath() throws Exception { @@ -87,9 +91,12 @@ public class ApplyTemplateMethodTest extends VirtualizationIntegrationTest searchParameters.setQuery(query.getQueryString()); searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); searchParameters.setLanguage(query.getLanguage()); - ResultSet qresult = searchService.query(searchParameters); - assertEquals(1, - qresult.getNumberFound()); + + /* Code commented out as part of REPO-2028 + * If this test needs to be reactivated, please refactor this to use the prepareMocks/resetMocks methods + */ + // ResultSet qresult = searchService.query(searchParameters); + // assertEquals(1, qresult.getNumberFound()); } @@ -160,6 +167,7 @@ public class ApplyTemplateMethodTest extends VirtualizationIntegrationTest } + @Category(RedundantTests.class) @Test public void testExecuteRepositoryJS() throws Exception { diff --git a/src/test/java/org/alfresco/repo/virtual/template/TemplateFilingRuleTest.java b/src/test/java/org/alfresco/repo/virtual/template/TemplateFilingRuleTest.java index 9a41fa5a53..a11acf2e0a 100644 --- a/src/test/java/org/alfresco/repo/virtual/template/TemplateFilingRuleTest.java +++ b/src/test/java/org/alfresco/repo/virtual/template/TemplateFilingRuleTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.template; +import static org.junit.Assert.*; + import org.alfresco.model.ContentModel; import org.alfresco.repo.virtual.VirtualizationIntegrationTest; import org.alfresco.repo.virtual.ref.Reference; diff --git a/src/test/java/org/alfresco/repo/virtual/template/TemplateResourceProcessorTest.java b/src/test/java/org/alfresco/repo/virtual/template/TemplateResourceProcessorTest.java index bf251b0b42..a4972b165c 100644 --- a/src/test/java/org/alfresco/repo/virtual/template/TemplateResourceProcessorTest.java +++ b/src/test/java/org/alfresco/repo/virtual/template/TemplateResourceProcessorTest.java @@ -26,6 +26,8 @@ package org.alfresco.repo.virtual.template; +import static org.junit.Assert.*; + import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -36,6 +38,7 @@ import org.alfresco.repo.virtual.VirtualizationIntegrationTest; import org.alfresco.repo.virtual.VirtualContext; import org.alfresco.repo.virtual.ref.ClasspathResource; import org.apache.commons.io.IOUtils; +import org.junit.Before; import org.junit.Test; public class TemplateResourceProcessorTest extends VirtualizationIntegrationTest @@ -43,8 +46,8 @@ public class TemplateResourceProcessorTest extends VirtualizationIntegrationTest private VirtualFolderDefinition testTemplate2Definition; - @Override - protected void setUp() throws Exception + @Before + public void setUp() throws Exception { super.setUp(); diff --git a/src/test/java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java b/src/test/java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java index 574033bbfa..ad6ca29b1a 100644 --- a/src/test/java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java +++ b/src/test/java/org/alfresco/repo/workflow/AbstractWorkflowServiceIntegrationTest.java @@ -52,7 +52,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.PersonService; @@ -1361,7 +1360,6 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService(); AuthorityService authorityService = serviceRegistry.getAuthorityService(); PersonService personService = serviceRegistry.getPersonService(); - SearchService searchService = serviceRegistry.getSearchService(); authenticationComponent.setSystemUserAsCurrentUser(); @@ -1370,7 +1368,7 @@ public abstract class AbstractWorkflowServiceIntegrationTest extends BaseSpringT // create test users this.personManager = new TestPersonManager(authenticationService, personService, nodeService); - this.groupManager = new TestGroupManager(authorityService, searchService); + this.groupManager = new TestGroupManager(authorityService); personManager.createPerson(USER1); personManager.createPerson(USER2); diff --git a/src/test/java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java b/src/test/java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java index a8eb91ad6e..3bb05506f8 100644 --- a/src/test/java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java +++ b/src/test/java/org/alfresco/repo/workflow/activiti/ActivitiWorkflowServiceIntegrationTest.java @@ -62,6 +62,7 @@ import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; import org.alfresco.util.testing.category.LuceneTests; +import org.alfresco.util.testing.category.RedundantTests; import org.junit.experimental.categories.Category; /** @@ -510,7 +511,8 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ taskQuery.setProcessId(workflowInstanceId); checkNoTasksFoundUsingQuery(taskQuery); } - + + @Category(RedundantTests.class) public void testStartWorkflowFromTaskListener() throws Exception { WorkflowDefinition testDefinition = deployDefinition("activiti/testStartWfFromListener.bpmn20.xml"); diff --git a/src/test/resources/org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml b/src/test/resources/org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml deleted file mode 100644 index 6b1d70a16d..0000000000 --- a/src/test/resources/org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml +++ /dev/null @@ -1,385 +0,0 @@ - - - Test Model for Lucene tests - Alfresco - 2005-07-13 - 0.1 - - - - - - - - - - - - - Test Super Type - sys:container - - - d:any - false - false - - - - d:date - true - false - - true - true - true - - - - d:double - true - false - - true - true - true - - - - d:float - true - false - - true - true - true - - - - d:long - true - false - - true - true - true - - - - d:int - true - false - - true - true - true - - - - d:text - true - false - - true - true - both - - - - d:mltext - true - false - - true - true - both - - - - - - - false - true - - - sys:base - false - true - - - - - - - Test Type - lucene-test:testSuperType - - - d:text - true - false - - true - true - true - - - - d:text - true - false - - true - false - true - - - - d:text - true - false - - false - true - true - - - - d:int - true - false - - true - true - true - - - - d:long - true - false - - true - true - true - - - - d:float - true - false - - true - true - true - - - - d:double - true - false - - true - true - true - - - - d:date - true - false - - true - true - true - - - - d:datetime - true - false - - true - true - true - - - - d:boolean - true - false - - true - true - true - - - - d:qname - true - false - - true - true - true - - - - d:category - true - false - - true - true - true - - - - d:noderef - true - false - - true - true - true - - - - d:text - true - false - - true - true - false - - - - d:mltext - true - false - - true - true - true - - - - d:text - false - false - - true - true - true - - - - d:path - false - false - - true - true - true - - - - d:locale - false - false - - true - true - true - - - - - d:any - false - true - - true - true - true - - - - - d:any - false - true - - true - true - true - - - - d:mltext - false - true - - true - true - true - - - - d:period - false - false - - true - true - true - - - - - lucene-test:testAspect - - - - - - - Aspect With Children - - - - false - true - - - sys:base - false - true - - - - - - Test Super Aspect - - - Titled - lucene-test:testSuperAspect - - - d:text - false - false - - true - true - true - - - - - - - \ No newline at end of file diff --git a/src/test/resources/org/alfresco/repo/search/impl/lucene/test_categoryService.js b/src/test/resources/org/alfresco/repo/search/impl/lucene/test_categoryService.js deleted file mode 100644 index e52fe6d686..0000000000 --- a/src/test/resources/org/alfresco/repo/search/impl/lucene/test_categoryService.js +++ /dev/null @@ -1,69 +0,0 @@ -// Checks the finding and adding of Root Categories -function testRootCategories() -{ - // TODO - // CategoryNode[] getAllCategoryNodes(String aspect) - // string[] getAllClassificationAspects() - // CategoryNode createRootCategory(string aspect, string name) - // CategoryNode[] getRootCategories(string aspect) -} - -// Checks that we can correctly query a test category -// that ADMLuceneCategoryTest setup for us -function testCategoryListings() -{ - // Check things are correctly detected as categories - test.assertEquals(true, catACBase.isCategory); - test.assertEquals(true, catACOne.isCategory); - test.assertEquals(true, catACTwo.isCategory); - test.assertEquals(true, catACThree.isCategory); - - // These tests are taken from testCategoryServiceImpl() - - //result = impl.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.IMMEDIATE); - test.assertEquals(1, catACBase.immediateCategoryMembers.length); - - //result = impl.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.IMMEDIATE); - test.assertEquals(3, catACBase.immediateMembersAndSubCategories.length); - - //result = impl.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE); - test.assertEquals(2, catACBase.immediateSubCategories.length); - - //result = impl.getChildren(catACBase , CategoryService.Mode.MEMBERS, CategoryService.Depth.ANY); - test.assertEquals(14, catACBase.categoryMembers.length); - - //result = impl.getChildren(catACBase , CategoryService.Mode.ALL, CategoryService.Depth.ANY); - test.assertEquals(17, catACBase.membersAndSubCategories.length); - - //result = impl.getChildren(catACBase , CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY); - test.assertEquals(3, catACBase.subCategories.length); -} - -// Tests that we can add and remove sub-categories -function testSubCategories() -{ - // catACBase starts with 3 - test.assertEquals(3, catACBase.subCategories.length); - - // Add a 4th - var testCat = catACBase.createSubCategory("testCat"); - test.assertEquals(4, catACBase.subCategories.length); - - // Delete it - testCat.removeCategory(); - test.assertEquals(3, catACBase.subCategories.length); - - // Add 2 more, as parent/child - var testCatA = catACBase.createSubCategory("testCatA"); - var testCatB = testCatA.createSubCategory("testCatB"); - test.assertEquals(5, catACBase.subCategories.length); - - // Delete the parent - testCatA.removeCategory(); - test.assertEquals(3, catACBase.subCategories.length); -} - -// Execute Tests -testRootCategories(); -testCategoryListings(); -testSubCategories(); \ No newline at end of file diff --git a/src/test/resources/org/alfresco/repo/site/script/test_siteService.js b/src/test/resources/org/alfresco/repo/site/script/test_siteService.js index a421274e3d..02a9fb5aff 100644 --- a/src/test/resources/org/alfresco/repo/site/script/test_siteService.js +++ b/src/test/resources/org/alfresco/repo/site/script/test_siteService.js @@ -57,45 +57,45 @@ function testListSites() // TODO .. check the filters } -function testFindSites() -{ - // Find all the sites - var sites = siteService.findSites(null, null, -1); - test.assertEquals(preexistingSiteCount + 2, sites.length); - - // find all sites with "short" in the name - sites = siteService.findSites("short", null, -1); - test.assertEquals(2, sites.length); - - sites = siteService.findSites("short", null, 0); - test.assertEquals(2, sites.length); - - // find just one site with "short" in the name - sites = siteService.findSites("short", null, 1); - test.assertEquals(1, sites.length); -} +// function testFindSites() +// { +// // Find all the sites +// var sites = siteService.findSites(null, null, -1); +// test.assertEquals(preexistingSiteCount + 2, sites.length); +// +// // find all sites with "short" in the name +// sites = siteService.findSites("short", null, -1); +// test.assertEquals(2, sites.length); +// +// sites = siteService.findSites("short", null, 0); +// test.assertEquals(2, sites.length); +// +// // find just one site with "short" in the name +// sites = siteService.findSites("short", null, 1); +// test.assertEquals(1, sites.length); +// } -function testGetSites() -{ - // get all the sites - var sites = siteService.getSites(null, null, -1); - test.assertEquals(preexistingSiteCount + 2, sites.length); - - sites = siteService.getSites("*", null, -1); - test.assertEquals(preexistingSiteCount + 2, sites.length); - - // get all sites whose name starts with "site" - sites = siteService.getSites("site", null, -1); - test.assertEquals(2, sites.length); - - // get all sites whose name starts with "short" - sites = siteService.getSites("short", null, -1); - test.assertEquals(0, sites.length); - - // get all sites with "short" in the name - sites = siteService.getSites("*short", null, -1); - test.assertEquals(2, sites.length); -} +// function testGetSites() +// { +// // get all the sites +// var sites = siteService.getSites(null, null, -1); +// test.assertEquals(preexistingSiteCount + 2, sites.length); +// +// sites = siteService.getSites("*", null, -1); +// test.assertEquals(preexistingSiteCount + 2, sites.length); +// +// // get all sites whose name starts with "site" +// sites = siteService.getSites("site", null, -1); +// test.assertEquals(2, sites.length); +// +// // get all sites whose name starts with "short" +// sites = siteService.getSites("short", null, -1); +// test.assertEquals(0, sites.length); +// +// // get all sites with "short" in the name +// sites = siteService.getSites("*short", null, -1); +// test.assertEquals(2, sites.length); +// } function testMembership() { @@ -302,8 +302,9 @@ function testSiteCustomProperties() // Execute test's testCRUD(); testListSites(); -testFindSites(); -testGetSites(); +// redundant, tests search +// testFindSites(); +// testGetSites(); testMembership(); testContainer(); testPermissions();