mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-7145 Addressed code review comments
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
<groupId>org.alfresco.tas</groupId>
|
||||
<artifactId>restapi-test</artifactId>
|
||||
<version>${tas.restapi.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.alfresco.tas</groupId>
|
||||
@@ -73,11 +74,5 @@
|
||||
<artifactId>alfresco-testng</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.alfresco.tas</groupId>
|
||||
<artifactId>restapi-test</artifactId>
|
||||
<version>${tas.restapi.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -34,8 +34,6 @@ import org.alfresco.rest.search.SearchRequest;
|
||||
|
||||
/**
|
||||
* Builder class for creating a search api request
|
||||
* @author Rodica Sutu
|
||||
* @since 2.6.0.2
|
||||
*/
|
||||
public class SearchRequestBuilder extends SearchRequest
|
||||
{
|
||||
@@ -49,7 +47,7 @@ public class SearchRequestBuilder extends SearchRequest
|
||||
/**
|
||||
* Set the sql statement for the SearchRequest
|
||||
*
|
||||
* @param query
|
||||
* @param query sql statement
|
||||
* @return search request
|
||||
*/
|
||||
public SearchRequestBuilder setQueryBuilder(RestRequestQueryModel query)
|
||||
@@ -61,7 +59,7 @@ public class SearchRequestBuilder extends SearchRequest
|
||||
/**
|
||||
* Set the paging statement for the SearchRequest
|
||||
*
|
||||
* @param paging
|
||||
* @param paging pagination requested
|
||||
* @return search request
|
||||
*/
|
||||
public SearchRequestBuilder setPagingBuilder(Pagination paging)
|
||||
@@ -82,9 +80,9 @@ public class SearchRequestBuilder extends SearchRequest
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paging statement for the SearchRequest
|
||||
* Set the requested fields for the SearchRequest
|
||||
*
|
||||
* @param fields
|
||||
* @param fields requested fields
|
||||
* @return search request
|
||||
*/
|
||||
public SearchRequestBuilder setFieldsBuilder(List<String> fields)
|
||||
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* #%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 org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertTrue;
|
||||
|
||||
import org.alfresco.dataprep.ContentActions;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.apache.chemistry.opencmis.client.api.ItemIterable;
|
||||
import org.apache.chemistry.opencmis.client.api.QueryResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class CMISTests extends BaseRMRestTest
|
||||
{
|
||||
@Autowired
|
||||
private ContentActions contentActions;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Given the RM site created
|
||||
* When I execute cmis query
|
||||
* Then I get the correct response
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
@AlfrescoTest (jira="MNT-19442")
|
||||
public void executeCmisQuery()
|
||||
{
|
||||
// execute the cmis query
|
||||
String cql = "SELECT cmis:name FROM cmis:document";
|
||||
ItemIterable<QueryResult> results =
|
||||
contentActions.getCMISSession(getAdminUser().getUsername(), getAdminUser().getPassword()).query(cql,
|
||||
false);
|
||||
|
||||
// check the total number of items is 100 and has more items is true
|
||||
assertTrue("Has more items not true. ", results.getHasMoreItems());
|
||||
assertTrue("Total number of items is greater than 100 ", results.getTotalNumItems() > 100);
|
||||
assertEquals("Pagination supports only 100 items per page", results.getPageNumItems(), 100);
|
||||
}
|
||||
|
||||
}
|
@@ -97,16 +97,19 @@ public class SearchDocumentsV1Test extends BaseRMRestTest
|
||||
fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extention));
|
||||
dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel);
|
||||
}
|
||||
waitIndexing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the query to wait for solr indexing
|
||||
*
|
||||
* @param queryType the query being executed
|
||||
* @throws Exception when maximum retry period is reached
|
||||
*/
|
||||
private void waitIndexing(RestRequestQueryModel queryType) throws Exception
|
||||
private void waitIndexing() throws Exception
|
||||
{
|
||||
RestRequestQueryModel queryType = new RestRequestQueryModel();
|
||||
queryType.setQuery("cm:name:*" + SEARCH_TERM);
|
||||
queryType.setLanguage("afts");
|
||||
Utility.sleep(1000, 80000, () ->
|
||||
{
|
||||
SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
|
||||
@@ -124,11 +127,9 @@ public class SearchDocumentsV1Test extends BaseRMRestTest
|
||||
* And setting the skipCount and maxItems to reach the number of total items
|
||||
* Then hasMoreItems will be set to false
|
||||
*/
|
||||
@Test
|
||||
(dataProvider = "queryTypes")
|
||||
@Test(dataProvider = "queryTypes")
|
||||
public void searchWhenMaxItemsReach(RestRequestQueryModel queryType) throws Exception
|
||||
{
|
||||
waitIndexing(queryType);
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5))
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
@@ -146,11 +147,9 @@ public class SearchDocumentsV1Test extends BaseRMRestTest
|
||||
* And setting skipCount and maxItems to exceed the number of total items
|
||||
* Then hasMoreItems will be set to false
|
||||
*/
|
||||
@Test
|
||||
(dataProvider = "queryTypes")
|
||||
@Test(dataProvider = "queryTypes")
|
||||
public void searchWhenTotalItemsExceed(RestRequestQueryModel queryType) throws Exception
|
||||
{
|
||||
waitIndexing(queryType);
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
@@ -168,11 +167,9 @@ public class SearchDocumentsV1Test extends BaseRMRestTest
|
||||
* And setting skipCount and maxItems under the number of total items
|
||||
* Then hasMoreItems will be set to true
|
||||
*/
|
||||
@Test
|
||||
(dataProvider = "queryTypes")
|
||||
@Test(dataProvider = "queryTypes")
|
||||
public void searchResultsUnderTotalItems(RestRequestQueryModel queryType) throws Exception
|
||||
{
|
||||
waitIndexing(queryType);
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
@@ -184,7 +181,6 @@ public class SearchDocumentsV1Test extends BaseRMRestTest
|
||||
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void tearDown()
|
||||
{
|
||||
|
@@ -41,19 +41,19 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.user.UserPermissions;
|
||||
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||
import org.alfresco.rest.search.SearchResponse;
|
||||
import org.alfresco.rest.v0.UserTrashcanAPI;
|
||||
import org.alfresco.utility.constants.UserRole;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FileType;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains the tests for v1 Search API with records with CMIS query
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 2.6.0.2
|
||||
*/
|
||||
public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
{
|
||||
@@ -63,6 +63,8 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
private FileModel fileModel;
|
||||
private RestRequestQueryModel queryModel;
|
||||
|
||||
@Autowired
|
||||
private UserTrashcanAPI userTrashcanAPI;
|
||||
|
||||
/**
|
||||
* Create a collaboration site and some in place records.
|
||||
@@ -115,10 +117,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 5);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 15);
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 5);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen");
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
|
||||
assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,10 +131,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 5);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 5);
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 5);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
|
||||
assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,10 +151,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 16);
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 4);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 16, "Expected skip count to be sixteen");
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
|
||||
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,10 +165,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 6);
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 4);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six");
|
||||
assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
|
||||
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,10 +185,10 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 15);
|
||||
assertTrue(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 4);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen");
|
||||
assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
|
||||
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -197,9 +199,16 @@ public class SearchRecordsV1CmisTests extends BaseRMRestTest
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 5);
|
||||
assertTrue(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 4);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
|
||||
assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
|
||||
assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
|
||||
}
|
||||
|
||||
@AfterClass (alwaysRun = true)
|
||||
public void tearDown()
|
||||
{
|
||||
dataSite.usingAdmin().deleteSite(collaborationSite);
|
||||
userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user