mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129199 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1) 129059 adavis: REPO-243 People Live Search - Use id (in fields and orderBy) rather than userName as it is an id that is returned in the Person entity - Added tests to test id can be used in fields and orderBy - Added 'wildcard' tests created by Alexandru-Eusebiu Epure git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129373 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -57,7 +57,7 @@ public interface Queries
|
||||
static int MIN_TERM_LENGTH_NODES = 3;
|
||||
|
||||
// People query
|
||||
static String PARAM_USERNAME = ContentModel.PROP_USERNAME.getLocalName();
|
||||
static String PARAM_PERSON_ID = "id";
|
||||
static String PARAM_FIRSTNAME = ContentModel.PROP_FIRSTNAME.getLocalName();
|
||||
static String PARAM_LASTNAME = ContentModel.PROP_LASTNAME.getLocalName();
|
||||
static int MIN_TERM_LENGTH_PEOPLE = 2;
|
||||
|
@@ -94,7 +94,7 @@ public class QueriesImpl implements Queries, InitializingBean
|
||||
PARAM_MODIFIEDAT, ContentModel.PROP_MODIFIED);
|
||||
|
||||
private final static Map<String, QName> PEOPLE_SORT_PARAMS_TO_QNAMES = sortParamsToQNames(
|
||||
ContentModel.PROP_USERNAME,
|
||||
PARAM_PERSON_ID, ContentModel.PROP_USERNAME,
|
||||
ContentModel.PROP_FIRSTNAME,
|
||||
ContentModel.PROP_LASTNAME);
|
||||
|
||||
@@ -447,14 +447,6 @@ public class QueriesImpl implements Queries, InitializingBean
|
||||
T t = convert(nodeRef, includeParam);
|
||||
collection.add(t);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (queryResults != null)
|
||||
{
|
||||
queryResults.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (sort == POST_QUERY_SORT)
|
||||
{
|
||||
@@ -465,6 +457,14 @@ public class QueriesImpl implements Queries, InitializingBean
|
||||
return CollectionWithPagingInfo.asPaged(paging, collection, queryResults.hasMore(), new Long(queryResults.getNumberFound()).intValue());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (queryResults != null)
|
||||
{
|
||||
queryResults.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds up the query and is expected to call {@link SearchParameters#setDefaultFieldName(String)}
|
||||
|
@@ -27,7 +27,10 @@ package org.alfresco.rest.api.tests;
|
||||
|
||||
import static org.alfresco.rest.api.Queries.PARAM_FIRSTNAME;
|
||||
import static org.alfresco.rest.api.Queries.PARAM_LASTNAME;
|
||||
import static org.alfresco.rest.api.Queries.PARAM_PERSON_ID;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -67,7 +70,7 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||
// deleting users is hard from from static methods. For the moment do it
|
||||
// in the first and last tests, but we have to get the TEST count right!
|
||||
// If we don't, a test fails or the users get left behind (not too bad).
|
||||
private static int TEST_COUNT = 13;
|
||||
private static int TEST_COUNT = 20;
|
||||
private static int testCounter = 0;
|
||||
|
||||
// Test usernames
|
||||
@@ -246,10 +249,12 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||
|
||||
response = getAll(URL_QUERIES_LSP, paging, params, expectedStatus);
|
||||
|
||||
if (expectedPeople != null && expectedStatus == 200)
|
||||
if (expectedStatus == 200)
|
||||
{
|
||||
people = Person.parsePeople(response.getJsonResponse()).getList();
|
||||
|
||||
if (expectedPeople != null)
|
||||
{
|
||||
StringJoiner actual = new StringJoiner("\n");
|
||||
StringJoiner expected = new StringJoiner("\n");
|
||||
for (int i=0; i<expectedPeople.length; i++)
|
||||
@@ -262,6 +267,7 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||
assertEquals(exp, act);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createParamIdNotNull(String param, String value)
|
||||
{
|
||||
@@ -404,6 +410,15 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderbyId() throws Exception
|
||||
{
|
||||
orderBy = PARAM_PERSON_ID;
|
||||
expectedPeople = expectedPeople(USER1, USER2, USER3, USER4, USER5, USER6);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadOrderByField() throws Exception
|
||||
{
|
||||
@@ -428,6 +443,74 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldsId() throws Exception
|
||||
{
|
||||
fields = PARAM_PERSON_ID;
|
||||
term = LAST_A;
|
||||
expectedPeople = new String[]
|
||||
{
|
||||
"Person [id=user5@org.alfresco.rest.api.tests.queriespeopleapitest, ]", // USER5
|
||||
"Person [id=user1@org.alfresco.rest.api.tests.queriespeopleapitest, ]", // USER1
|
||||
"Person [id=user3@org.alfresco.rest.api.tests.queriespeopleapitest, ]", // USER3
|
||||
};
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchFirstnameWithWildcard() throws Exception
|
||||
{
|
||||
term = FIRST_A;
|
||||
term = term.substring(0,term.length()-3) + "*A";
|
||||
|
||||
expectedPeople = expectedPeople(USER1, USER2);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchLastNameWithWildcard() throws Exception
|
||||
{
|
||||
term = LAST_A;
|
||||
term = term.substring(0,term.length()-3) + "*A";
|
||||
expectedPeople = expectedPeople(USER5, USER1, USER3);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchUsernameWithWildcard() throws Exception
|
||||
{
|
||||
term = TEST_TERM_PREFIX+"us*1";
|
||||
expectedPeople = expectedPeople(USER1);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderbyDescAndAscWithWildcard() throws Exception
|
||||
{
|
||||
// 3 B A
|
||||
// 1 A A
|
||||
// 5 A
|
||||
term = TEST_TERM_PREFIX+"la*A";
|
||||
expectedPeople = expectedPeople(USER3, USER1, USER5);
|
||||
|
||||
orderBy = "firstName desc,lastName";
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnlyWildcard() throws Exception
|
||||
{
|
||||
term = "*";
|
||||
expectedStatus = 400;
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
// // TODO Rubbish is taken to be "asc" so returns 200 rather than 400 - is this a framework bug?
|
||||
// @Test
|
||||
// public void testBadOrderByDirection() throws Exception
|
||||
|
Reference in New Issue
Block a user