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)
129190 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1) 129017 adavis: REPO-243 People Live Search - Added additional tests - Removed check in Person constructor for no id as we want to be able to create a Person from json which might not have the id. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129364 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -385,7 +385,8 @@ public class QueriesImpl implements Queries, InitializingBean
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CollectionWithPagingInfo<T> find(Parameters parameters,
|
public CollectionWithPagingInfo<T> find(Parameters parameters,
|
||||||
String termName, int minTermLength, String queryTemplateName, Sort sort, Map<String, QName> sortParamsToQNames, SortColumn... defaultSort)
|
String termName, int minTermLength, String queryTemplateName,
|
||||||
|
Sort sort, Map<String, QName> sortParamsToQNames, SortColumn... defaultSort)
|
||||||
{
|
{
|
||||||
SearchParameters sp = new SearchParameters();
|
SearchParameters sp = new SearchParameters();
|
||||||
sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
|
sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
|
||||||
@@ -541,6 +542,10 @@ public class QueriesImpl implements Queries, InitializingBean
|
|||||||
for (SortColumn sortCol : sortCols)
|
for (SortColumn sortCol : sortCols)
|
||||||
{
|
{
|
||||||
QName sortPropQName = sortParamsToQNames.get(sortCol.column);
|
QName sortPropQName = sortParamsToQNames.get(sortCol.column);
|
||||||
|
if (sortPropQName == null)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException("Invalid sort field: "+sortCol.column);
|
||||||
|
}
|
||||||
sortPropQNames.add(sortPropQName);
|
sortPropQNames.add(sortPropQName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,14 +56,15 @@ import com.sun.star.lang.IllegalArgumentException;
|
|||||||
*/
|
*/
|
||||||
public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||||
{
|
{
|
||||||
private static final String URL_QUERIES_LSN = "queries/live-search-people";
|
private static final String URL_QUERIES_LSP = "queries/live-search-people";
|
||||||
|
|
||||||
private static String TEST_TERM_PREFIX = Long.toString(System.currentTimeMillis()/1000);
|
private static String TEST_TERM_PREFIX = Long.toString(System.currentTimeMillis()/1000);
|
||||||
|
|
||||||
// TODO Yuck: Would like to use @BeforeClass and @AfterClass. But creating and
|
// TODO Yuck: Would like to use @BeforeClass and @AfterClass. But creating and
|
||||||
// deleting users is hard from from static methods. For the moment do it
|
// 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!
|
// in the first and last tests, but we have to get the TEST count right!
|
||||||
private static int TEST_COUNT = 6;
|
// If we don't, a test fails or the users get left behind (not too bad).
|
||||||
|
private static int TEST_COUNT = 12;
|
||||||
private static int testCounter = 0;
|
private static int testCounter = 0;
|
||||||
|
|
||||||
// Test usernames
|
// Test usernames
|
||||||
@@ -103,6 +104,7 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void setup() throws Exception
|
public void setup() throws Exception
|
||||||
{
|
{
|
||||||
super.setup();
|
super.setup();
|
||||||
@@ -239,9 +241,9 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
createParamIdNotNull(Queries.PARAM_ORDERBY, orderBy);
|
createParamIdNotNull(Queries.PARAM_ORDERBY, orderBy);
|
||||||
createParamIdNotNull(Queries.PARAM_FIELDS, fields);
|
createParamIdNotNull(Queries.PARAM_FIELDS, fields);
|
||||||
|
|
||||||
response = getAll(URL_QUERIES_LSN, paging, params, expectedStatus);
|
response = getAll(URL_QUERIES_LSP, paging, params, expectedStatus);
|
||||||
|
|
||||||
if (expectedPeople != null)
|
if (expectedPeople != null && expectedStatus == 200)
|
||||||
{
|
{
|
||||||
people = Person.parsePeople(response.getJsonResponse()).getList();
|
people = Person.parsePeople(response.getJsonResponse()).getList();
|
||||||
|
|
||||||
@@ -254,17 +256,13 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
}
|
}
|
||||||
String exp = expected.toString().replaceAll(TEST_TERM_PREFIX, "");
|
String exp = expected.toString().replaceAll(TEST_TERM_PREFIX, "");
|
||||||
String act = actual.toString().replaceAll(TEST_TERM_PREFIX, "");
|
String act = actual.toString().replaceAll(TEST_TERM_PREFIX, "");
|
||||||
if (!exp.equals(act))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
assertEquals(exp, act);
|
assertEquals(exp, act);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createParamIdNotNull(String param, String value)
|
private void createParamIdNotNull(String param, String value)
|
||||||
{
|
{
|
||||||
if (value != null)
|
if (value != null && params != null)
|
||||||
{
|
{
|
||||||
params.put(param, value);
|
params.put(param, value);
|
||||||
}
|
}
|
||||||
@@ -282,11 +280,28 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
return list.toArray(new String[list.size()]);
|
return list.toArray(new String[list.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void testUnauthenticated() throws Exception
|
||||||
|
{
|
||||||
|
setRequestContext(null);
|
||||||
|
expectedStatus = 401;
|
||||||
|
|
||||||
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnlyTestUsersAndDefaultOrder() throws Exception
|
public void testOnlyTestUsersAndDefaultOrder() throws Exception
|
||||||
{
|
{
|
||||||
// Checks only test users are found as a result of using TEST_TERM_PREFIX.
|
// Checks only test users are found as a result of using TEST_TERM_PREFIX.
|
||||||
// Also checks the default sort order.
|
|
||||||
|
// Also checks the default sort order (firstname lastname):
|
||||||
|
// 5 A
|
||||||
|
// 6 C
|
||||||
|
// 1 A A
|
||||||
|
// 2 A B
|
||||||
|
// 3 B A
|
||||||
|
// 4 C
|
||||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,12 +332,20 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoParams() throws Exception
|
||||||
|
{
|
||||||
|
params = null;
|
||||||
|
expectedStatus = 400;
|
||||||
|
|
||||||
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoTerm() throws Exception
|
public void testNoTerm() throws Exception
|
||||||
{
|
{
|
||||||
term = null;
|
term = null;
|
||||||
expectedStatus = 400;
|
expectedStatus = 400;
|
||||||
expectedPeople = null;
|
|
||||||
|
|
||||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
}
|
}
|
||||||
@@ -332,26 +355,60 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
{
|
{
|
||||||
term = "X";
|
term = "X";
|
||||||
expectedStatus = 400;
|
expectedStatus = 400;
|
||||||
expectedPeople = null;
|
|
||||||
|
|
||||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO commented out tests:
|
@Test
|
||||||
|
public void testOrderbySameAsDefault() throws Exception
|
||||||
|
{
|
||||||
|
orderBy = "firstName asc, lastName"; // same as default (asc is default order)
|
||||||
|
|
||||||
// Returns 500 rather than 400
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
// @Test
|
}
|
||||||
// public void testUnknownOrderByField() throws Exception
|
|
||||||
// {
|
|
||||||
// orderBy = "rubbish";
|
|
||||||
// expectedStatus = 400;
|
|
||||||
//
|
|
||||||
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Rubbish is taken to be "asc" - is this a bug?
|
@Test
|
||||||
|
public void testOrderbyDescAndAsc() throws Exception
|
||||||
|
{
|
||||||
|
// 4 C
|
||||||
|
// 3 B A
|
||||||
|
// 1 A A
|
||||||
|
// 2 A B
|
||||||
|
// 5 A
|
||||||
|
// 6 C
|
||||||
|
orderBy = "firstName desc, lastName";
|
||||||
|
expectedPeople = expectedPeople(USER4, USER3, USER1, USER2, USER5, USER6);
|
||||||
|
|
||||||
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBadOrderByField() throws Exception
|
||||||
|
{
|
||||||
|
orderBy = "rubbish";
|
||||||
|
expectedStatus = 400;
|
||||||
|
|
||||||
|
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFieldsFirstLast() throws Exception
|
||||||
|
{
|
||||||
|
fields = PARAM_FIRSTNAME+","+PARAM_LASTNAME;
|
||||||
|
term = LAST_A;
|
||||||
|
expectedPeople = new String[]
|
||||||
|
{
|
||||||
|
"Person ["+ "lastName=LastA, ]", // USER5
|
||||||
|
"Person ["+"firstName=FirstA, lastName=LastA, ]", // USER1
|
||||||
|
"Person ["+"firstName=FirstB, lastName=LastA, ]", // USER3
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
// @Test
|
||||||
// public void testOrderByDirection() throws Exception
|
// public void testBadOrderByDirection() throws Exception
|
||||||
// {
|
// {
|
||||||
// orderBy = "firstName rubbish, lastName asc";
|
// orderBy = "firstName rubbish, lastName asc";
|
||||||
// expectedStatus = 400;
|
// expectedStatus = 400;
|
||||||
@@ -359,45 +416,21 @@ public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Server response is 500 from the first call.
|
// // TODO Having a space in the list discards everything after the space - found in manual testing - is this a framework bug?
|
||||||
// @Test
|
// @Test
|
||||||
// public void testOrderby() throws Exception
|
// public void testFieldsWithSpace() throws Exception
|
||||||
// {
|
|
||||||
// // {USER_1, FIRST_A, LAST_A},
|
|
||||||
// // {USER_2, FIRST_A, LAST_B},
|
|
||||||
// // {USER_3, FIRST_B, LAST_A},
|
|
||||||
// // {USER_4, FIRST_C, },
|
|
||||||
// // {USER_5, null, LAST_A},
|
|
||||||
// // {USER_6, null, LAST_C},
|
|
||||||
//
|
|
||||||
// orderBy = "firstName asc, lastName"; // same as default (asc is default order)
|
|
||||||
//
|
|
||||||
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
|
||||||
//
|
|
||||||
// orderBy = "firstName desc, lastName"; // with desc and asc
|
|
||||||
//
|
|
||||||
// expectedPeople = new String[] {"TODO"};
|
|
||||||
// expectedPeople = expectedPeople(USER4, USER3, USER1, USER2, USER5, USER6);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// This test causes the following exception because we did not request the id field!
|
|
||||||
// testFields(org.alfresco.rest.api.tests.QueriesPeopleApiTest) Time elapsed: 6.21 sec <<< ERROR!
|
|
||||||
// java.lang.IllegalArgumentException: null
|
|
||||||
// at org.alfresco.rest.api.tests.client.data.Person.<init>(Person.java:73)
|
|
||||||
// at org.alfresco.rest.api.tests.client.data.Person.parsePerson(Person.java:278)
|
|
||||||
// at org.alfresco.rest.api.tests.client.data.Person.parsePeople(Person.java:503)
|
|
||||||
// at org.alfresco.rest.api.tests.QueriesPeopleApiTest.checkApiCall(QueriesPeopleApiTest.java:246)
|
|
||||||
// at org.alfresco.rest.api.tests.QueriesPeopleApiTest.testFields(QueriesPeopleApiTest.java:353)
|
|
||||||
// @Test
|
|
||||||
// public void testFields() throws Exception
|
|
||||||
// {
|
// {
|
||||||
// fields = PARAM_FIRSTNAME+", "+PARAM_LASTNAME;
|
// fields = PARAM_FIRSTNAME+", "+PARAM_LASTNAME;
|
||||||
// term = LAST_A;
|
// term = LAST_A;
|
||||||
// expectedPeople = new String[]
|
// expectedPeople = new String[]
|
||||||
// {
|
// {
|
||||||
// "lastName=LastA,", // USER5
|
// "Person ["+ "lastName=LastA, ]", // USER5
|
||||||
// "firstName=FirstA, lastName=LastA,", // USER1
|
// "Person ["+"firstName=FirstA, lastName=LastA, ]", // USER1
|
||||||
// "firstName=FirstB, lastName=LastA,", // USER3
|
// "Person ["+"firstName=FirstB, lastName=LastA, ]", // USER3
|
||||||
|
// // But is the following:
|
||||||
|
//// "Person ["+ "]",
|
||||||
|
//// "Person ["+"firstName=FirstA, ]",
|
||||||
|
//// "Person ["+"firstName=FirstB, ]",
|
||||||
// };
|
// };
|
||||||
//
|
//
|
||||||
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||||
|
@@ -68,10 +68,6 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
|
|||||||
String mob, String instantmsg, String google, String description)
|
String mob, String instantmsg, String google, String description)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
if(id == null)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
Reference in New Issue
Block a user