mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
wip CMIS tests for MNT-20822
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
<maven.build.sourceVersion>1.8</maven.build.sourceVersion>
|
||||
<alfresco.rm.share>alfresco-rm-community-share</alfresco.rm.share>
|
||||
<alfresco.rm.repo>alfresco-rm-community-repo</alfresco.rm.repo>
|
||||
<tas.restapi.version>5.2.0-10</tas.restapi.version>
|
||||
<tas.restapi.version>5.2.0.15</tas.restapi.version>
|
||||
<fluent.json.version>2.0.0</fluent.json.version>
|
||||
</properties>
|
||||
|
||||
@@ -73,5 +73,11 @@
|
||||
<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>
|
||||
|
@@ -86,11 +86,15 @@ public class RestAPIFactory
|
||||
return getRmRestWrapper().withCoreAPI();
|
||||
}
|
||||
|
||||
private SearchAPI getSearchAPI(UserModel userModel)
|
||||
public SearchAPI getSearchAPI(UserModel userModel)
|
||||
{
|
||||
getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser());
|
||||
return getRmRestWrapper().withSearchAPI();
|
||||
}
|
||||
}
|
||||
public SearchAPI getSearchAPI()
|
||||
{
|
||||
return getSearchAPI(null);
|
||||
}
|
||||
|
||||
public Node getNodeAPI(RepoTestModel model) throws RuntimeException
|
||||
{
|
||||
|
@@ -1,2 +1,3 @@
|
||||
alfresco.server=localhost
|
||||
rest.rmPath=alfresco/api/-default-/public/gs/versions/1
|
||||
rest.rmPath=alfresco/api/-default-/public/gs/versions/1
|
||||
alfresco.port=8080
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* #%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);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* #%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.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.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FileType;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains the tests for v1 Search API with CMIS query
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 2.6.0.2
|
||||
*/
|
||||
public class SearchDocumentsV1CmisTest extends BaseRMRestTest
|
||||
{
|
||||
private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1CmisTest.class);
|
||||
private SiteModel collaborationSite;
|
||||
private FileModel fileModel;
|
||||
private RestRequestQueryModel queryModel;
|
||||
/**
|
||||
* Create a collaboration site and some in place records.
|
||||
*/
|
||||
@BeforeClass (alwaysRun = true)
|
||||
public void setupSearchAPIWithCMIS() throws Exception
|
||||
{
|
||||
STEP("Create a collaboration site");
|
||||
collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
|
||||
|
||||
STEP("Create 10 documents ending with SEARCH_TERM");
|
||||
for (int i=0;++i<=10;)
|
||||
{
|
||||
fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extention));
|
||||
dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel);
|
||||
}
|
||||
queryModel = new RestRequestQueryModel();
|
||||
queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'");
|
||||
queryModel.setLanguage("cmis");
|
||||
}
|
||||
|
||||
/**
|
||||
* Given some documents ending with a particular text
|
||||
* 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
|
||||
private void searchWhenMaxItemReach () throws Exception
|
||||
{
|
||||
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5))
|
||||
.setFieldsBuilder(asList("id", "name"));
|
||||
|
||||
SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().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
|
||||
private 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().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 false
|
||||
*/
|
||||
@Test
|
||||
private 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().search(sqlRequest);
|
||||
assertEquals(searchResponse.getPagination().getCount(), 4);
|
||||
assertEquals(searchResponse.getPagination().getSkipCount(), 5);
|
||||
assertTrue(searchResponse.getPagination().isHasMoreItems());
|
||||
assertEquals(searchResponse.getEntries().size(), 4);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* #%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.model.user.UserRoles.ROLE_RM_MANAGER;
|
||||
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.rest.core.search.SearchRequestBuilder;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
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.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.Assert;
|
||||
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
|
||||
{
|
||||
private static final String SEARCH_TERM = generateTestPrefix(SearchRecordsV1CmisTests.class);
|
||||
private SiteModel collaborationSite;
|
||||
private UserModel nonRMUser, rmUser;
|
||||
private FileModel fileModel;
|
||||
private RestRequestQueryModel queryModel;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a collaboration site and some in place records.
|
||||
*/
|
||||
@BeforeClass (alwaysRun = true)
|
||||
public void setupSearchRecordsV1Cmis() throws Exception
|
||||
{
|
||||
STEP("Create a collaboration site");
|
||||
collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
|
||||
|
||||
STEP("Create a collaborator user for the collaboration site");
|
||||
nonRMUser = getDataUser().createRandomTestUser();
|
||||
getDataUser().addUserToSite(nonRMUser, collaborationSite, UserRole.SiteManager);
|
||||
|
||||
STEP("Create an rm user");
|
||||
rmUser = getDataUser().createRandomTestUser();
|
||||
|
||||
STEP("Create 10 documents and declare as records");
|
||||
for (int i=0;++i<=10;)
|
||||
{
|
||||
fileModel = new FileModel(String.format("%s.%s", "Record" + SEARCH_TERM + i, FileType.TEXT_PLAIN.extention));
|
||||
fileModel = dataContent.usingUser(nonRMUser).usingSite(collaborationSite).createContent(fileModel);
|
||||
getRestAPIFactory().getFilesAPI(nonRMUser).declareAsRecord(fileModel.getNodeRefWithoutVersion());
|
||||
}
|
||||
STEP("Create record folder and some records ");
|
||||
RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
|
||||
assignFillingPermissionsOnCategory(rmUser, recordFolder.getId(), UserPermissions.PERMISSION_READ_RECORDS,
|
||||
ROLE_RM_MANAGER);
|
||||
for (int i=0;++i<=10;)
|
||||
{
|
||||
createElectronicRecord(recordFolder.getId(),"Record" + SEARCH_TERM + i );
|
||||
}
|
||||
|
||||
queryModel = new RestRequestQueryModel();
|
||||
queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE 'Record" + SEARCH_TERM + "%'");
|
||||
queryModel.setLanguage("cmis");
|
||||
}
|
||||
/**
|
||||
* Given some documents with names starting with a particular test
|
||||
* 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
|
||||
private void searchWhenTotalItemsReach () throws Exception
|
||||
{
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 15))
|
||||
.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);
|
||||
}
|
||||
|
||||
@Test
|
||||
private void searchWhenTotalItemsReachWithNonRM () throws Exception
|
||||
{
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5))
|
||||
.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);
|
||||
}
|
||||
/**
|
||||
* Given some documents with names starting 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
|
||||
private void searchWhenTotalItemsExceedRMUser () throws Exception
|
||||
{
|
||||
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 16))
|
||||
.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);
|
||||
}
|
||||
|
||||
@Test
|
||||
private void searchWhenTotalItemsExceedNonRMUser () throws Exception
|
||||
{
|
||||
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
|
||||
.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 false
|
||||
*/
|
||||
@Test
|
||||
private void searchResultsUnderTotalItemsRMUser() throws Exception
|
||||
{
|
||||
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 15))
|
||||
.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);
|
||||
}
|
||||
@Test
|
||||
private void searchResultsUnderTotalItemsNonRMUser() throws Exception
|
||||
{
|
||||
|
||||
final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
|
||||
.setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
|
||||
.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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user