mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Merge branch 'Search-1359' into 'master'
Search 1359 See merge request search_discovery/SearchAnalyticsE2ETest!9
This commit is contained in:
@@ -73,7 +73,16 @@
|
|||||||
<type>d:text</type>
|
<type>d:text</type>
|
||||||
<mandatory>false</mandatory>
|
<mandatory>false</mandatory>
|
||||||
<index enabled="true">
|
<index enabled="true">
|
||||||
<tokenised>TRUE</tokenised>
|
<tokenised>BOTH</tokenised>
|
||||||
|
<facetable>false</facetable>
|
||||||
|
</index>
|
||||||
|
</property>
|
||||||
|
<property name="finance:Desc">
|
||||||
|
<title>Description</title>
|
||||||
|
<type>d:text</type>
|
||||||
|
<mandatory>false</mandatory>
|
||||||
|
<index enabled="true">
|
||||||
|
<tokenised>false</tokenised>
|
||||||
<facetable>false</facetable>
|
<facetable>false</facetable>
|
||||||
</index>
|
</index>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package org.alfresco.service.search;
|
|||||||
|
|
||||||
import org.alfresco.cmis.CmisWrapper;
|
import org.alfresco.cmis.CmisWrapper;
|
||||||
import org.alfresco.dataprep.ContentService;
|
import org.alfresco.dataprep.ContentService;
|
||||||
|
import org.alfresco.dataprep.SiteService.Visibility;
|
||||||
import org.alfresco.rest.core.RestProperties;
|
import org.alfresco.rest.core.RestProperties;
|
||||||
import org.alfresco.rest.core.RestWrapper;
|
import org.alfresco.rest.core.RestWrapper;
|
||||||
import org.alfresco.rest.search.RestRequestQueryModel;
|
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||||
@@ -20,7 +21,10 @@ import org.alfresco.utility.Utility;
|
|||||||
import org.alfresco.utility.data.DataContent;
|
import org.alfresco.utility.data.DataContent;
|
||||||
import org.alfresco.utility.data.DataSite;
|
import org.alfresco.utility.data.DataSite;
|
||||||
import org.alfresco.utility.data.DataUser;
|
import org.alfresco.utility.data.DataUser;
|
||||||
|
import org.alfresco.utility.data.RandomData;
|
||||||
import org.alfresco.utility.model.FileModel;
|
import org.alfresco.utility.model.FileModel;
|
||||||
|
import org.alfresco.utility.model.SiteModel;
|
||||||
|
import org.alfresco.utility.model.UserModel;
|
||||||
import org.alfresco.utility.network.ServerHealth;
|
import org.alfresco.utility.network.ServerHealth;
|
||||||
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
import org.apache.chemistry.opencmis.client.api.CmisObject;
|
||||||
import org.apache.chemistry.opencmis.client.api.Session;
|
import org.apache.chemistry.opencmis.client.api.Session;
|
||||||
@@ -71,6 +75,12 @@ public abstract class AbstractSearchServiceE2E extends AbstractTestNGSpringConte
|
|||||||
@Autowired
|
@Autowired
|
||||||
@Getter(value = PROTECTED)
|
@Getter(value = PROTECTED)
|
||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
|
|
||||||
|
protected UserModel testUser, adminUserModel;
|
||||||
|
protected SiteModel testSite;
|
||||||
|
protected UserModel searchedUser;
|
||||||
|
|
||||||
|
protected static String unique_searchString;
|
||||||
|
|
||||||
public static final String NODE_PREFIX = "workspace/SpacesStore/";
|
public static final String NODE_PREFIX = "workspace/SpacesStore/";
|
||||||
|
|
||||||
@@ -88,6 +98,16 @@ public abstract class AbstractSearchServiceE2E extends AbstractTestNGSpringConte
|
|||||||
{
|
{
|
||||||
LOG.warn("Error Loading Custom Model", e);
|
LOG.warn("Error Loading Custom Model", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adminUserModel = dataUser.getAdminUser();
|
||||||
|
testUser = dataUser.createRandomTestUser("UserSearch");
|
||||||
|
|
||||||
|
testSite = new SiteModel(RandomData.getRandomName("SiteSearch"));
|
||||||
|
testSite.setVisibility(Visibility.PRIVATE);
|
||||||
|
|
||||||
|
testSite = dataSite.usingUser(testUser).createSite(testSite);
|
||||||
|
|
||||||
|
unique_searchString = testSite.getTitle().replace("SiteSearch", "Unique");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deployCustomModel(String path)
|
public boolean deployCustomModel(String path)
|
||||||
@@ -257,17 +277,31 @@ public abstract class AbstractSearchServiceE2E extends AbstractTestNGSpringConte
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a search and return the response
|
* Run a search as admin user and return the response
|
||||||
|
*
|
||||||
* @param queryString: string to search for, unique search string will guarantee accurate results
|
* @param queryString: string to search for, unique search string will guarantee accurate results
|
||||||
* @return the search response from the API
|
* @return the search response from the API
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public SearchResponse query(String queryString) throws Exception
|
public SearchResponse query(String queryString) throws Exception
|
||||||
|
{
|
||||||
|
return queryAsUser(dataUser.getAdminUser(), queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run a search as given user and return the response
|
||||||
|
*
|
||||||
|
* @param user: UserModel for the user you wish to run the query as
|
||||||
|
* @param queryString: string to search for, unique search string will guarantee accurate results
|
||||||
|
* @return the search response from the API
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public SearchResponse queryAsUser(UserModel user, String queryString) throws Exception
|
||||||
{
|
{
|
||||||
SearchRequest searchRequest = new SearchRequest();
|
SearchRequest searchRequest = new SearchRequest();
|
||||||
RestRequestQueryModel queryModel = new RestRequestQueryModel();
|
RestRequestQueryModel queryModel = new RestRequestQueryModel();
|
||||||
queryModel.setQuery(queryString);
|
queryModel.setQuery(queryString);
|
||||||
searchRequest.setQuery(queryModel);
|
searchRequest.setQuery(queryModel);
|
||||||
return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(searchRequest);
|
return restClient.authenticateUser(user).withSearchAPI().search(searchRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,234 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 Alfresco Software, Ltd. All rights reserved.
|
||||||
|
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||||
|
* pursuant to a written agreement and any use of this program without such an
|
||||||
|
* agreement is prohibited.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.service.search;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.rest.search.SearchResponse;
|
||||||
|
import org.alfresco.service.search.AbstractSearchServiceE2E;
|
||||||
|
import org.alfresco.utility.constants.UserRole;
|
||||||
|
import org.alfresco.utility.data.DataContent;
|
||||||
|
import org.alfresco.utility.data.DataSite;
|
||||||
|
import org.alfresco.utility.model.FileModel;
|
||||||
|
import org.alfresco.utility.model.FileType;
|
||||||
|
import org.alfresco.utility.model.FolderModel;
|
||||||
|
import org.alfresco.utility.model.TestGroup;
|
||||||
|
import org.apache.chemistry.opencmis.commons.PropertyIds;
|
||||||
|
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purpose of this TestClass is to test that the search range query tests work as expected with CustomModels
|
||||||
|
* Tests added for Search-1359
|
||||||
|
*
|
||||||
|
* @author meenal bhave
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SearchWithCustomModelTest extends AbstractSearchServiceE2E
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
protected DataSite dataSite;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected DataContent dataContent;
|
||||||
|
|
||||||
|
private FolderModel testFolder;
|
||||||
|
|
||||||
|
private FileModel expenseLondon, expenseParis, expenseNoLocation;
|
||||||
|
|
||||||
|
@BeforeClass(alwaysRun = true)
|
||||||
|
public void setupEnvironment() throws Exception
|
||||||
|
{
|
||||||
|
serverHealth.assertServerIsOnline();
|
||||||
|
|
||||||
|
dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor);
|
||||||
|
|
||||||
|
testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder();
|
||||||
|
|
||||||
|
Long uniqueRef = System.currentTimeMillis();
|
||||||
|
|
||||||
|
expenseLondon = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "Expense");
|
||||||
|
expenseLondon.setName("fin1-" + expenseLondon.getName());
|
||||||
|
|
||||||
|
Map<String, Object> properties = new HashMap<String, Object>();
|
||||||
|
properties.put(PropertyIds.OBJECT_TYPE_ID, "D:finance:Expense");
|
||||||
|
properties.put(PropertyIds.NAME, expenseLondon.getName());
|
||||||
|
properties.put("finance:No", uniqueRef);
|
||||||
|
properties.put("finance:amount", 300);
|
||||||
|
|
||||||
|
cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(expenseLondon, properties, VersioningState.MAJOR)
|
||||||
|
.assertThat().existsInRepo();
|
||||||
|
|
||||||
|
// Location value is set to London
|
||||||
|
cmisApi.authenticateUser(testUser).usingResource(expenseLondon).addSecondaryTypes("P:finance:ParkEx").assertThat()
|
||||||
|
.secondaryTypeIsAvailable("P:finance:ParkEx");
|
||||||
|
cmisApi.authenticateUser(testUser).usingResource(expenseLondon).updateProperty("finance:Location", "London");
|
||||||
|
|
||||||
|
expenseParis = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "Expense");
|
||||||
|
expenseParis.setName("fin2-" + expenseParis.getName());
|
||||||
|
|
||||||
|
properties = new HashMap<String, Object>();
|
||||||
|
properties.put(PropertyIds.OBJECT_TYPE_ID, "D:finance:Expense");
|
||||||
|
properties.put(PropertyIds.NAME, expenseParis.getName());
|
||||||
|
properties.put("finance:No", uniqueRef + 1);
|
||||||
|
properties.put("finance:amount", 100);
|
||||||
|
properties.put("finance:Title", "Airport Taxi Outgoing");
|
||||||
|
properties.put("finance:Emp", "David A");
|
||||||
|
properties.put("finance:Desc", "David's Taxi");
|
||||||
|
|
||||||
|
cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(expenseParis, properties, VersioningState.MAJOR)
|
||||||
|
.assertThat().existsInRepo();
|
||||||
|
|
||||||
|
// Location value is set to Paris
|
||||||
|
cmisApi.authenticateUser(testUser).usingResource(expenseParis).addSecondaryTypes("P:finance:ParkEx").assertThat()
|
||||||
|
.secondaryTypeIsAvailable("P:finance:ParkEx");
|
||||||
|
cmisApi.authenticateUser(testUser).usingResource(expenseParis).updateProperty("finance:Location", "Paris");
|
||||||
|
|
||||||
|
expenseNoLocation = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "receipt");
|
||||||
|
expenseNoLocation.setName("fin3-" + expenseNoLocation.getName());
|
||||||
|
|
||||||
|
properties = new HashMap<String, Object>();
|
||||||
|
properties.put(PropertyIds.OBJECT_TYPE_ID, "D:finance:Expense");
|
||||||
|
properties.put(PropertyIds.NAME, expenseNoLocation.getName());
|
||||||
|
properties.put("finance:No", uniqueRef + 2);
|
||||||
|
properties.put("finance:amount", 0);
|
||||||
|
properties.put("finance:Title", "Hotel Stay");
|
||||||
|
properties.put("finance:Emp", "Daniel S");
|
||||||
|
properties.put("finance:Desc", "Daniel's Taxi");
|
||||||
|
|
||||||
|
cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(expenseNoLocation, properties, VersioningState.MAJOR)
|
||||||
|
.assertThat().existsInRepo();
|
||||||
|
|
||||||
|
// Location value is set to null
|
||||||
|
cmisApi.authenticateUser(testUser).usingResource(expenseNoLocation).addSecondaryTypes("P:finance:ParkEx").assertThat()
|
||||||
|
.secondaryTypeIsAvailable("P:finance:ParkEx");
|
||||||
|
|
||||||
|
// Wait for the file to be indexed
|
||||||
|
waitForIndexing(expenseNoLocation.getName(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search-1359: Search AFTS Query with Range
|
||||||
|
@Test(priority = 1, groups = { TestGroup.ASS_14 })
|
||||||
|
public void testRangeQueryTextField() throws Exception
|
||||||
|
{
|
||||||
|
// Search Range Query
|
||||||
|
SearchResponse response = queryAsUser(testUser, "finance_Location:[* TO London]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
|
||||||
|
// Content where Location = London is returned, If property is not set, its ignored.
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 1);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance_Location:[London TO *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
// Content where Location = London, Paris is returned, If property is not set, its ignored.
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance_Location:[London To Paris]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance_Location:[* To *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(priority = 2, groups = { TestGroup.ASS_14 })
|
||||||
|
public void testRangeQueryTextFieldWhiteSpace() throws Exception
|
||||||
|
{
|
||||||
|
SearchResponse response = queryAsUser(testUser, "finance:Emp:[* TO Daniel]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
// Tockenised field, so Returns Daniel, David A (A before Daniel)
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Emp:[Dan TO *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Emp:[Dan To David]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Emp:[* To *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(priority = 3, groups = { TestGroup.ASS_14 })
|
||||||
|
public void testRangeQueryTextFieldNonFacetable() throws Exception
|
||||||
|
{
|
||||||
|
// Search Range Query
|
||||||
|
SearchResponse response = queryAsUser(testUser, "finance:Title:[* TO H]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 1);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Title:[Hotel TO *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
// Tockenised field, so Includes: Hotel, (Airport) Taxi Outgoing
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Title:[B To Hotel]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
// Tockenised field, so Includes: (Airport) Taxi Outgoing
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 1);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Title:[B To I]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 1);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Title:[* To *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(priority = 4, groups = { TestGroup.ASS_14 })
|
||||||
|
public void testRangeQueryTextFieldNotTockenised() throws Exception
|
||||||
|
{
|
||||||
|
SearchResponse response = queryAsUser(testUser, "finance:Desc:[* TO David]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
// Includes: Daniel's Taxi
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 1);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Desc:[Dan TO *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Desc:[Dan To David]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 1);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance:Desc:[* To *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(priority = 5, groups = { TestGroup.ASS_14 })
|
||||||
|
public void testRangeQueryDoubleField() throws Exception
|
||||||
|
{
|
||||||
|
// Search Range Query
|
||||||
|
SearchResponse response = queryAsUser(testUser, "finance:amount:[* TO 100]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance_amount:[100 TO *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance_amount:[100 To 300]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 2);
|
||||||
|
|
||||||
|
response = queryAsUser(testUser, "finance_amount:[* To *]");
|
||||||
|
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||||
|
Assert.assertEquals(response.getPagination().getCount(), 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,9 @@
|
|||||||
<groups>
|
<groups>
|
||||||
<run>
|
<run>
|
||||||
<include name="ASS_1.0.0" />
|
<include name="ASS_1.0.0" />
|
||||||
|
<include name="ASS_1.4.0" />
|
||||||
<exclude name="InsightEngine_1.0.0" />
|
<exclude name="InsightEngine_1.0.0" />
|
||||||
|
<exclude name="InsightEngine_1.1.0" />
|
||||||
</run>
|
</run>
|
||||||
</groups>
|
</groups>
|
||||||
<classes>
|
<classes>
|
||||||
|
|||||||
Reference in New Issue
Block a user