mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-7145 Added test for AFTS query
This commit is contained in:
@@ -39,6 +39,7 @@ import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
|||||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||||
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
||||||
import org.alfresco.test.AlfrescoTest;
|
import org.alfresco.test.AlfrescoTest;
|
||||||
|
import org.alfresco.utility.Utility;
|
||||||
import org.alfresco.utility.constants.UserRole;
|
import org.alfresco.utility.constants.UserRole;
|
||||||
import org.alfresco.utility.model.FileModel;
|
import org.alfresco.utility.model.FileModel;
|
||||||
import org.alfresco.utility.model.FileType;
|
import org.alfresco.utility.model.FileType;
|
||||||
@@ -49,6 +50,7 @@ import org.apache.chemistry.opencmis.client.api.OperationContext;
|
|||||||
import org.apache.chemistry.opencmis.client.api.QueryResult;
|
import org.apache.chemistry.opencmis.client.api.QueryResult;
|
||||||
import org.apache.chemistry.opencmis.client.runtime.OperationContextImpl;
|
import org.apache.chemistry.opencmis.client.runtime.OperationContextImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@@ -125,28 +127,13 @@ public class CmisQueryTests extends BaseRMRestTest
|
|||||||
|
|
||||||
|
|
||||||
//do a cmis query to wait for solr indexing
|
//do a cmis query to wait for solr indexing
|
||||||
long currentTime = System.currentTimeMillis();
|
Utility.sleep(5000, 80000, () ->
|
||||||
long endTime = 0;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
endTime = System.currentTimeMillis();
|
|
||||||
ItemIterable<QueryResult> results = contentActions.getCMISSession(getAdminUser().getUsername(),
|
ItemIterable<QueryResult> results = contentActions.getCMISSession(getAdminUser().getUsername(),
|
||||||
getAdminUser().getPassword()).query(SQL_WITH_NAME, false);
|
getAdminUser().getPassword()).query(SQL_WITH_NAME, false);
|
||||||
assertEquals("Total number of items is not 30, got " + results.getTotalNumItems() + "total items",
|
Assert.assertEquals(results.getTotalNumItems(), 30,
|
||||||
30, results.getTotalNumItems());
|
"Total number of items is not 10, got " + results.getTotalNumItems() + " total items");
|
||||||
break;
|
});
|
||||||
}
|
|
||||||
catch (AssertionError | Exception e)
|
|
||||||
{
|
|
||||||
if (endTime - currentTime > 30000)
|
|
||||||
{
|
|
||||||
throw new AssertionError("Maximum retry period reached, test failed.", e);
|
|
||||||
}
|
|
||||||
Thread.sleep(5000);
|
|
||||||
}
|
|
||||||
} while (true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,7 +170,7 @@ public class CmisQueryTests extends BaseRMRestTest
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@AlfrescoTest (jira = "MNT-19442")
|
@AlfrescoTest (jira = "MNT-19442")
|
||||||
public void getDocumentsWithSpecificNamesCmisQuery() throws Exception
|
public void getDocumentsWithSpecificNamesCmisQuery()
|
||||||
{
|
{
|
||||||
// execute the cmis query
|
// execute the cmis query
|
||||||
ItemIterable<QueryResult> results =
|
ItemIterable<QueryResult> results =
|
||||||
@@ -206,7 +193,7 @@ public class CmisQueryTests extends BaseRMRestTest
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@AlfrescoTest (jira = "MNT-19442")
|
@AlfrescoTest (jira = "MNT-19442")
|
||||||
public void getDocumentsCmisQueryWithPagination() throws Exception
|
public void getDocumentsCmisQueryWithPagination()
|
||||||
{
|
{
|
||||||
OperationContext oc = new OperationContextImpl();
|
OperationContext oc = new OperationContextImpl();
|
||||||
oc.setMaxItemsPerPage(10);
|
oc.setMaxItemsPerPage(10);
|
||||||
|
@@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Records Management Module
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.rm.community.search;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||||
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.alfresco.dataprep.ContentActions;
|
||||||
|
import org.alfresco.rest.core.search.SearchRequestBuilder;
|
||||||
|
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||||
|
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||||
|
import org.alfresco.rest.search.SearchResponse;
|
||||||
|
import org.alfresco.rest.v0.UserTrashcanAPI;
|
||||||
|
import org.alfresco.test.AlfrescoTest;
|
||||||
|
import org.alfresco.utility.Utility;
|
||||||
|
import org.alfresco.utility.model.FileModel;
|
||||||
|
import org.alfresco.utility.model.FileType;
|
||||||
|
import org.alfresco.utility.model.SiteModel;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains the tests for v1 Search API for documents using AFTS query
|
||||||
|
*
|
||||||
|
* @author Roxana Lucanu
|
||||||
|
* @since 2.6.3
|
||||||
|
*/
|
||||||
|
public class SearchDocumentsV1AftsTest extends BaseRMRestTest
|
||||||
|
{
|
||||||
|
private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1AftsTest.class);
|
||||||
|
private SiteModel collaborationSite;
|
||||||
|
private FileModel fileModel;
|
||||||
|
private RestRequestQueryModel queryModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserTrashcanAPI userTrashcanAPI;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ContentActions contentActions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a collaboration site and some documents in it.
|
||||||
|
*/
|
||||||
|
@BeforeClass (alwaysRun = true)
|
||||||
|
public void setupSearchAPI() throws Exception
|
||||||
|
{
|
||||||
|
STEP("Create a collaboration site");
|
||||||
|
collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
|
||||||
|
|
||||||
|
STEP("Create 10 documents with name ending with SEARCH_TERM");
|
||||||
|
for (int i = 0; ++i <= 10; )
|
||||||
|
{
|
||||||
|
fileModel = new FileModel("Doc" + i + SEARCH_TERM, FileType.UNDEFINED);
|
||||||
|
fileModel = dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel);
|
||||||
|
}
|
||||||
|
queryModel = new RestRequestQueryModel();
|
||||||
|
queryModel.setLanguage("afts");
|
||||||
|
queryModel.setQuery("cm:name:*" + SEARCH_TERM);
|
||||||
|
|
||||||
|
//do a cmis query to wait for solr indexing
|
||||||
|
Utility.sleep(5000, 80000, () ->
|
||||||
|
{
|
||||||
|
SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
|
.setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0))
|
||||||
|
.setFieldsBuilder(asList("id", "name"));
|
||||||
|
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
|
||||||
|
assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 10,
|
||||||
|
"Total number of items is not 10, got " + searchResponse.getPagination().getTotalItems() + " total items");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given some documents having a common term in the name
|
||||||
|
* When executing the search query with paging
|
||||||
|
* And setting the skipCount and maxItems to reach the number of total items
|
||||||
|
* Then hasMoreItems will be set to false
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@AlfrescoTest (jira = "RM-7145")
|
||||||
|
public void searchWhenMaxItemsReached() throws Exception
|
||||||
|
{
|
||||||
|
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
|
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5))
|
||||||
|
.setFieldsBuilder(asList("id", "name"));
|
||||||
|
|
||||||
|
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
|
||||||
|
assertEquals(searchResponse.getPagination().getCount(), 5);
|
||||||
|
assertEquals(searchResponse.getPagination().getSkipCount(), 5);
|
||||||
|
assertFalse(searchResponse.getPagination().isHasMoreItems());
|
||||||
|
assertEquals(searchResponse.getEntries().size(), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given some documents ending with a particular text
|
||||||
|
* When executing the search query with paging
|
||||||
|
* And setting skipCount and maxItems to exceed the number of total items
|
||||||
|
* Then hasMoreItems will be set to false
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void searchWhenTotalItemsExceed() throws Exception
|
||||||
|
{
|
||||||
|
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
|
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
|
||||||
|
.setFieldsBuilder(asList("id", "name"));
|
||||||
|
|
||||||
|
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
|
||||||
|
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||||
|
assertEquals(searchResponse.getPagination().getSkipCount(), 6);
|
||||||
|
assertFalse(searchResponse.getPagination().isHasMoreItems());
|
||||||
|
assertEquals(searchResponse.getEntries().size(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given some documents ending with a particular text
|
||||||
|
* When executing the search query with paging
|
||||||
|
* And setting skipCount and maxItems under the number of total items
|
||||||
|
* Then hasMoreItems will be set to true
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void searchResultsUnderTotalItems() throws Exception
|
||||||
|
{
|
||||||
|
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
|
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
|
||||||
|
.setFieldsBuilder(asList("id", "name"));
|
||||||
|
|
||||||
|
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
|
||||||
|
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||||
|
assertEquals(searchResponse.getPagination().getSkipCount(), 5);
|
||||||
|
assertTrue(searchResponse.getPagination().isHasMoreItems());
|
||||||
|
assertEquals(searchResponse.getEntries().size(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -38,6 +38,7 @@ import org.alfresco.rest.core.search.SearchRequestBuilder;
|
|||||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||||
import org.alfresco.rest.search.RestRequestQueryModel;
|
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||||
import org.alfresco.rest.search.SearchResponse;
|
import org.alfresco.rest.search.SearchResponse;
|
||||||
|
import org.alfresco.utility.Utility;
|
||||||
import org.alfresco.utility.model.FileModel;
|
import org.alfresco.utility.model.FileModel;
|
||||||
import org.alfresco.utility.model.FileType;
|
import org.alfresco.utility.model.FileType;
|
||||||
import org.alfresco.utility.model.SiteModel;
|
import org.alfresco.utility.model.SiteModel;
|
||||||
@@ -45,7 +46,7 @@ import org.testng.annotations.BeforeClass;
|
|||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains the tests for v1 Search API with CMIS query
|
* This class contains the tests for v1 Search API with documents with CMIS query
|
||||||
*
|
*
|
||||||
* @author Rodica Sutu
|
* @author Rodica Sutu
|
||||||
* @since 2.6.0.2
|
* @since 2.6.0.2
|
||||||
@@ -57,7 +58,7 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest
|
|||||||
private FileModel fileModel;
|
private FileModel fileModel;
|
||||||
private RestRequestQueryModel queryModel;
|
private RestRequestQueryModel queryModel;
|
||||||
/**
|
/**
|
||||||
* Create a collaboration site and some in place records.
|
* Create a collaboration site and some documents.
|
||||||
*/
|
*/
|
||||||
@BeforeClass (alwaysRun = true)
|
@BeforeClass (alwaysRun = true)
|
||||||
public void setupSearchAPIWithCMIS() throws Exception
|
public void setupSearchAPIWithCMIS() throws Exception
|
||||||
@@ -74,6 +75,17 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest
|
|||||||
queryModel = new RestRequestQueryModel();
|
queryModel = new RestRequestQueryModel();
|
||||||
queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'");
|
queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'");
|
||||||
queryModel.setLanguage("cmis");
|
queryModel.setLanguage("cmis");
|
||||||
|
|
||||||
|
//do a cmis query to wait for solr indexing
|
||||||
|
Utility.sleep(5000, 80000, () ->
|
||||||
|
{
|
||||||
|
SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
|
.setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0))
|
||||||
|
.setFieldsBuilder(asList("id", "name"));
|
||||||
|
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
|
||||||
|
assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 10,
|
||||||
|
"Total number of items is not 10, got " + searchResponse.getPagination().getTotalItems() + " total items");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +95,7 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest
|
|||||||
* Then hasMoreItems will be set to false
|
* Then hasMoreItems will be set to false
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
private void searchWhenMaxItemReach () throws Exception
|
public void searchWhenMaxItemReach () throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
@@ -104,7 +116,7 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest
|
|||||||
* Then hasMoreItems will be set to false
|
* Then hasMoreItems will be set to false
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
private void searchWhenTotalItemsExceed () throws Exception
|
public void searchWhenTotalItemsExceed () throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
@@ -122,10 +134,10 @@ public class SearchDocumentsV1CmisTest extends BaseRMRestTest
|
|||||||
* Given some documents ending with a particular text
|
* Given some documents ending with a particular text
|
||||||
* When executing the search query with paging
|
* When executing the search query with paging
|
||||||
* And setting skipCount and maxItems under the number of total items
|
* And setting skipCount and maxItems under the number of total items
|
||||||
* Then hasMoreItems will be set to false
|
* Then hasMoreItems will be set to true
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
private void searchResultsUnderTotalItems() throws Exception
|
public void searchResultsUnderTotalItems() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||||
|
Reference in New Issue
Block a user