mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
129004 adavis: REPO-243 People Live Search - First cut of this code - Includes a re-factor of the code used by GET /queries/live-search-nodes as there is much in common. - Still have some tests to write and there are bound to be comments from the review. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129187 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -45,6 +45,7 @@ import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Company;
|
||||
import org.alfresco.rest.api.tests.client.data.ContentInfo;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.api.tests.client.data.Folder;
|
||||
@@ -452,10 +453,15 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
return createUser(username, "password", null);
|
||||
}
|
||||
|
||||
protected String createUser(String usernameIn, String password, TestNetwork network)
|
||||
{
|
||||
return createUser(new PersonInfo(usernameIn, usernameIn, usernameIn, password, null, null, null, null, null, null, null), network);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO implement as remote api call
|
||||
*/
|
||||
protected String createUser(final String usernameIn, final String password, final TestNetwork network)
|
||||
protected String createUser(final PersonInfo personInfo, final TestNetwork network)
|
||||
{
|
||||
final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);
|
||||
|
||||
@@ -468,8 +474,8 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
{
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
String username = repoService.getPublicApiContext().createUserName(usernameIn, tenantDomain);
|
||||
PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null);
|
||||
String username = repoService.getPublicApiContext().createUserName(personInfo.getUsername(), tenantDomain);
|
||||
personInfo.setUsername(username);
|
||||
RepoService.TestPerson person = repoService.createUser(personInfo, username, network);
|
||||
return person.getId();
|
||||
|
||||
|
@@ -45,7 +45,7 @@ import org.junit.runners.Suite;
|
||||
NodeApiTest.class,
|
||||
NodeAssociationsApiTest.class,
|
||||
NodeVersionsApiTest.class,
|
||||
QueriesApiTest.class,
|
||||
QueriesNodesApiTest.class,
|
||||
RenditionsTest.class,
|
||||
SharedLinkApiTest.class,
|
||||
ActivitiesPostingTest.class,
|
||||
|
@@ -47,16 +47,12 @@ public class PersonInfo
|
||||
String location, String tel, String mob, String instantmsg,
|
||||
String google)
|
||||
{
|
||||
super();
|
||||
if(username == null)
|
||||
{
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
super();
|
||||
setUsername(username);
|
||||
this.company = company;
|
||||
this.networkAdmin = false;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.skype = skype;
|
||||
this.location = location;
|
||||
@@ -64,7 +60,16 @@ public class PersonInfo
|
||||
this.mob = mob;
|
||||
this.instantmsg = instantmsg;
|
||||
this.google = google;
|
||||
}
|
||||
}
|
||||
|
||||
void setUsername(String username)
|
||||
{
|
||||
if (username == null)
|
||||
{
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public boolean isNetworkAdmin()
|
||||
{
|
||||
|
@@ -51,15 +51,15 @@ import java.util.Map;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* V1 REST API tests for pre-defined 'live' search Queries
|
||||
* V1 REST API tests for pre-defined 'live' search Queries on Nodes
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/queries} </li>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/queries/live-search-nodes} </li>
|
||||
* </ul>
|
||||
*
|
||||
* @author janv
|
||||
*/
|
||||
public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
public class QueriesNodesApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String URL_QUERIES_LSN = "queries/live-search-nodes";
|
||||
|
||||
@@ -220,7 +220,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// Search - include optional fields - eg. aspectNames, properties, path, isLink
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("include", "aspectNames,properties,path,isLink");
|
||||
params.put(Queries.PARAM_INCLUDE, "aspectNames,properties,path,isLink");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, allIds, null);
|
||||
@@ -319,7 +319,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
term = title+String.format("%05d", 2)+title;
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, "\""+term+"\"");
|
||||
params.put("include", "properties");
|
||||
params.put(Queries.PARAM_INCLUDE, "properties");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(3, nodes.size());
|
||||
@@ -331,7 +331,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
term = descrip+String.format("%05d", 3)+descrip;
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, "\""+term+"\"");
|
||||
params.put("include", "properties");
|
||||
params.put(Queries.PARAM_INCLUDE, "properties");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(3, nodes.size());
|
||||
@@ -483,7 +483,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - modifiedAt asc
|
||||
params = new HashMap<>(1);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "modifiedAt asc");
|
||||
params.put(Queries.PARAM_ORDERBY, "modifiedAt asc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, allIds, false);
|
||||
@@ -491,7 +491,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - modifiedAt desc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "modifiedAt desc");
|
||||
params.put(Queries.PARAM_ORDERBY, "modifiedAt desc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, allIds, true);
|
||||
@@ -499,7 +499,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - createdAt asc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "createdAt asc");
|
||||
params.put(Queries.PARAM_ORDERBY, "createdAt asc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, allIds, true);
|
||||
@@ -507,7 +507,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - createdAt desc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "createdAt desc");
|
||||
params.put(Queries.PARAM_ORDERBY, "createdAt desc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, allIds, false);
|
||||
@@ -515,7 +515,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - name asc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "name asc");
|
||||
params.put(Queries.PARAM_ORDERBY, "name asc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, idsSortedByNameAsc, true);
|
||||
@@ -523,7 +523,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - name desc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "name desc");
|
||||
params.put(Queries.PARAM_ORDERBY, "name desc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, idsSortedByNameAsc, false);
|
||||
@@ -531,7 +531,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - name desc, createdAt asc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "name desc, createdAt asc");
|
||||
params.put(Queries.PARAM_ORDERBY, "name desc, createdAt asc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, idsSortedByNameDescCreatedAtAsc, false);
|
||||
@@ -539,7 +539,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// sort order - name asc, createdAt asc
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "name asc, createdAt desc");
|
||||
params.put(Queries.PARAM_ORDERBY, "name asc, createdAt desc");
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
checkNodeIds(nodes, idsSortedByNameDescCreatedAtAsc, true);
|
||||
@@ -574,7 +574,7 @@ public class QueriesApiTest extends AbstractSingleNetworkSiteTest
|
||||
// -ve test - invalid sort field
|
||||
params = new HashMap<>(2);
|
||||
params.put(Queries.PARAM_TERM, testTerm);
|
||||
params.put("orderBy", "invalid asc");
|
||||
params.put(Queries.PARAM_ORDERBY, "invalid asc");
|
||||
getAll(URL_QUERIES_LSN, paging, params, 400);
|
||||
|
||||
// -ve test - unauthenticated - belts-and-braces ;-)
|
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 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.api.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.alfresco.rest.api.Queries.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.Queries;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||
import org.alfresco.rest.api.tests.client.data.Company;
|
||||
import org.alfresco.rest.api.tests.client.data.Person;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* V1 REST API tests for pre-defined 'live' search Queries on People
|
||||
*
|
||||
* <ul>
|
||||
* <li> {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/queries/people} </li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Alan Davis
|
||||
*/
|
||||
public class QueriesPeopleApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
private static final String URL_QUERIES_LSN = "queries/live-search-people";
|
||||
|
||||
private static String TEST_TERM_PREFIX = Long.toString(System.currentTimeMillis()/1000);
|
||||
|
||||
// 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
|
||||
// in the first and last tests, but we have to get the TEST count right!
|
||||
private static int TEST_COUNT = 6;
|
||||
private static int testCounter = 0;
|
||||
|
||||
// Test usernames
|
||||
private static final String USER1 = TEST_TERM_PREFIX+"user1";
|
||||
private static final String USER2 = TEST_TERM_PREFIX+"user2";
|
||||
private static final String USER3 = TEST_TERM_PREFIX+"user3";
|
||||
private static final String USER4 = TEST_TERM_PREFIX+"user4";
|
||||
private static final String USER5 = TEST_TERM_PREFIX+"user5";
|
||||
private static final String USER6 = TEST_TERM_PREFIX+"user6";
|
||||
|
||||
// Test firstnames
|
||||
private static final String FIRST_A = TEST_TERM_PREFIX+"FirstA";
|
||||
private static final String FIRST_B = TEST_TERM_PREFIX+"FirstB";
|
||||
private static final String FIRST_C = TEST_TERM_PREFIX+"FirstC";
|
||||
|
||||
// Test Lastnames
|
||||
private static final String LAST_A = TEST_TERM_PREFIX+"LastA";
|
||||
private static final String LAST_B = TEST_TERM_PREFIX+"LastB";
|
||||
private static final String LAST_C = TEST_TERM_PREFIX+"LastC";
|
||||
|
||||
private static Map<String, Person> testUsers = new HashMap<String, Person>();
|
||||
|
||||
// inputs
|
||||
private String term = "";
|
||||
private String orderBy = null;
|
||||
private String fields = null;
|
||||
private Paging paging;
|
||||
|
||||
// available for extra tests after call.
|
||||
private Map<String, String> params;
|
||||
private HttpResponse response;
|
||||
private List<Person> people;
|
||||
|
||||
// expected values
|
||||
private int expectedStatus;
|
||||
private String[] expectedPeople;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setup() throws Exception
|
||||
{
|
||||
super.setup();
|
||||
|
||||
setRequestContext(user1);
|
||||
|
||||
if (testCounter++ == 0)
|
||||
{
|
||||
createTestUsers(new String[][]
|
||||
{
|
||||
{USER1, FIRST_A, LAST_A},
|
||||
{USER2, FIRST_A, LAST_B},
|
||||
{USER3, FIRST_B, LAST_A},
|
||||
{USER4, FIRST_C, },
|
||||
{USER5, null, LAST_A},
|
||||
{USER6, null, LAST_C},
|
||||
});
|
||||
}
|
||||
|
||||
paging = getPaging(0, 100);
|
||||
params = new HashMap<>();
|
||||
term = TEST_TERM_PREFIX;
|
||||
orderBy = null;
|
||||
fields = null;
|
||||
|
||||
// Default sort order is: firstname asc, lastname asc
|
||||
expectedPeople = expectedPeople(USER5, USER6, USER1, USER2, USER3, USER4);
|
||||
expectedStatus = 200;
|
||||
}
|
||||
|
||||
@After
|
||||
@Override
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
|
||||
if (testCounter == TEST_COUNT)
|
||||
{
|
||||
deleteTestUsers();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to create users. These are deleted on tearDown.
|
||||
// The prefix is added to the username, firstname and lastname if they exist.
|
||||
private Map<String, Person> createTestUsers(String[][] userProperties) throws IllegalArgumentException
|
||||
{
|
||||
for (String[] properties: userProperties)
|
||||
{
|
||||
int l = properties.length;
|
||||
if (l > 0)
|
||||
{
|
||||
PersonInfo personInfo = newPersonInfo(properties);
|
||||
String originalUsername = personInfo.getUsername();
|
||||
String id = createUser(personInfo, networkOne);
|
||||
Person person = new Person(
|
||||
id,
|
||||
null, // Not set to originalUsername, as the returned JSON does not set it
|
||||
true, // enabled
|
||||
personInfo.getFirstName(),
|
||||
personInfo.getLastName(),
|
||||
personInfo.getCompany(),
|
||||
personInfo.getSkype(),
|
||||
personInfo.getLocation(),
|
||||
personInfo.getTel(),
|
||||
personInfo.getMob(),
|
||||
personInfo.getInstantmsg(),
|
||||
personInfo.getGoogle(),
|
||||
null); // description
|
||||
testUsers.put(originalUsername, person);
|
||||
|
||||
// The following would automatically delete users after a test, but
|
||||
// we need to clear other data and as we created them we should delete
|
||||
// them.
|
||||
// super.users.add(id);
|
||||
}
|
||||
}
|
||||
return testUsers;
|
||||
}
|
||||
|
||||
private void deleteTestUsers()
|
||||
{
|
||||
for (String id: testUsers.keySet())
|
||||
{
|
||||
try
|
||||
{
|
||||
deleteUser(id, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("Failed to delete test user "+id);
|
||||
}
|
||||
}
|
||||
testUsers.clear();
|
||||
}
|
||||
|
||||
// Helper method to create a PersonInfo object
|
||||
// first 3 parameters are username, firstname, lastname unlike PersonInfo
|
||||
// password defaults to "password"
|
||||
private static PersonInfo newPersonInfo(String... properties) throws IllegalArgumentException
|
||||
{
|
||||
int l = properties.length;
|
||||
if (l > 17)
|
||||
{
|
||||
throw new IllegalArgumentException("Too many properties supplied for "+properties);
|
||||
}
|
||||
return new PersonInfo(
|
||||
(l <= 1 ? null : properties[ 1]), // firstName
|
||||
(l <= 2 ? null : properties[ 2]), // lastName
|
||||
(l <= 0 ? null : properties[ 0]), // username
|
||||
|
||||
(l <= 3 || properties[ 3] == null
|
||||
? "password" : properties[ 3]), // password
|
||||
(l <= 4 ? null : new Company(
|
||||
properties[ 4], // organization
|
||||
(l <= 5 ? null : properties[ 5]), // address1
|
||||
(l <= 6 ? null : properties[ 6]), // address2
|
||||
(l <= 7 ? null : properties[ 7]), // address3
|
||||
(l <= 8 ? null : properties[ 8]), // postcode
|
||||
(l <= 9 ? null : properties[ 9]), // telephone
|
||||
(l <= 10 ? null : properties[10]), // fax
|
||||
(l <= 11 ? null : properties[11]))),// email
|
||||
(l <= 12 ? null : properties[12]), // skype
|
||||
(l <= 13 ? null : properties[13]), // location
|
||||
(l <= 14 ? null : properties[14]), // tel
|
||||
(l <= 15 ? null : properties[15]), // mob
|
||||
(l <= 16 ? null : properties[16]), // instantmsg
|
||||
(l <= 17 ? null : properties[17])); // google
|
||||
}
|
||||
|
||||
private void checkApiCall(String term, String orderBy, String fields, Paging paging,
|
||||
int expectedStatus, String[] expectedPeople) throws Exception
|
||||
{
|
||||
createParamIdNotNull(Queries.PARAM_TERM, term);
|
||||
createParamIdNotNull(Queries.PARAM_ORDERBY, orderBy);
|
||||
createParamIdNotNull(Queries.PARAM_FIELDS, fields);
|
||||
|
||||
response = getAll(URL_QUERIES_LSN, paging, params, expectedStatus);
|
||||
|
||||
if (expectedPeople != null)
|
||||
{
|
||||
people = Person.parsePeople(response.getJsonResponse()).getList();
|
||||
|
||||
StringJoiner actual = new StringJoiner("\n");
|
||||
StringJoiner expected = new StringJoiner("\n");
|
||||
for (int i=0; i<expectedPeople.length; i++)
|
||||
{
|
||||
actual.add(people.get(i).toString());
|
||||
expected.add(expectedPeople[i]);
|
||||
}
|
||||
String exp = expected.toString().replaceAll(TEST_TERM_PREFIX, "");
|
||||
String act = actual.toString().replaceAll(TEST_TERM_PREFIX, "");
|
||||
if (!exp.equals(act))
|
||||
{
|
||||
|
||||
}
|
||||
assertEquals(exp, act);
|
||||
}
|
||||
}
|
||||
|
||||
private void createParamIdNotNull(String param, String value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
params.put(param, value);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] expectedPeople(String... testUserIds)
|
||||
{
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String id: testUserIds)
|
||||
{
|
||||
Person person = testUsers.get(id);
|
||||
String string = person.toString();
|
||||
list.add(string);
|
||||
}
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnlyTestUsersAndDefaultOrder() throws Exception
|
||||
{
|
||||
// Checks only test users are found as a result of using TEST_TERM_PREFIX.
|
||||
// Also checks the default sort order.
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchFirstname() throws Exception
|
||||
{
|
||||
term = FIRST_A;
|
||||
expectedPeople = expectedPeople(USER1, USER2);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchLastName() throws Exception
|
||||
{
|
||||
term = LAST_A;
|
||||
expectedPeople = expectedPeople(USER5, USER1, USER3);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchUsername() throws Exception
|
||||
{
|
||||
term = USER1;
|
||||
expectedPeople = expectedPeople(USER1);
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTerm() throws Exception
|
||||
{
|
||||
term = null;
|
||||
expectedStatus = 400;
|
||||
expectedPeople = null;
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTermShorterThan2() throws Exception
|
||||
{
|
||||
term = "X";
|
||||
expectedStatus = 400;
|
||||
expectedPeople = null;
|
||||
|
||||
checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
}
|
||||
|
||||
// TODO commented out tests:
|
||||
|
||||
// Returns 500 rather than 400
|
||||
// @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 testOrderByDirection() throws Exception
|
||||
// {
|
||||
// orderBy = "firstName rubbish, lastName asc";
|
||||
// expectedStatus = 400;
|
||||
//
|
||||
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
// }
|
||||
|
||||
// Server response is 500 from the first call.
|
||||
// @Test
|
||||
// public void testOrderby() 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;
|
||||
// term = LAST_A;
|
||||
// expectedPeople = new String[]
|
||||
// {
|
||||
// "lastName=LastA,", // USER5
|
||||
// "firstName=FirstA, lastName=LastA,", // USER1
|
||||
// "firstName=FirstB, lastName=LastA,", // USER3
|
||||
// };
|
||||
//
|
||||
// checkApiCall(term, orderBy, fields, paging, expectedStatus, expectedPeople);
|
||||
// }
|
||||
}
|
@@ -25,26 +25,24 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.simple.JSONArray;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.sun.star.uno.RuntimeException;
|
||||
|
||||
public class Person implements Serializable, Comparable<Person>, ExpectedComparison
|
||||
{
|
||||
private static final long serialVersionUID = 3185698391792389751L;
|
||||
@@ -107,7 +105,7 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@@ -203,7 +201,7 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
|
||||
{
|
||||
return "Person [" + (id != null ? "id=" + id + ", " : "")
|
||||
+ (enabled != null ? "enabled=" + enabled + ", " : "")
|
||||
+ (username != null ? "email=" + username + ", " : "")
|
||||
+ (username != null ? "username=" + username + ", " : "")
|
||||
+ (firstName != null ? "firstName=" + firstName + ", " : "")
|
||||
+ (lastName != null ? "lastName=" + lastName + ", " : "")
|
||||
+ (company != null ? "company=" + company + ", " : "")
|
||||
@@ -246,7 +244,7 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
|
||||
String instantMessageId = (String)jsonObject.get("instantMessageId");
|
||||
String googleId = (String)jsonObject.get("googleId");
|
||||
String skypeId = (String)jsonObject.get("skypeId");
|
||||
String email = (String)jsonObject.get("email");
|
||||
String username = (String)jsonObject.get("username");
|
||||
String telephone = (String)jsonObject.get("telephone");
|
||||
String mobile = (String)jsonObject.get("mobile");
|
||||
String userId = (String)jsonObject.get("id");
|
||||
@@ -265,16 +263,25 @@ public class Person implements Serializable, Comparable<Person>, ExpectedCompari
|
||||
String postcode = (String)companyJSON.get("postcode");
|
||||
String companyTelephone = (String)companyJSON.get("telephone");
|
||||
String fax = (String)companyJSON.get("fax");
|
||||
String companyEmail = (String)companyJSON.get("email");
|
||||
company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail);
|
||||
String companyEmail = (String)companyJSON.get("email");
|
||||
if (organization != null ||
|
||||
address2 != null ||
|
||||
address3 != null ||
|
||||
postcode != null ||
|
||||
companyTelephone != null ||
|
||||
fax != null ||
|
||||
companyEmail != null)
|
||||
{
|
||||
company = new Company(organization, address1, address2, address3, postcode, companyTelephone, fax, companyEmail);
|
||||
}
|
||||
}
|
||||
Person person = new Person(userId, email, enabled, firstName, lastName, company, skypeId, location, telephone, mobile, instantMessageId, googleId, description);
|
||||
Person person = new Person(userId, username, enabled, firstName, lastName, company, skypeId, location, telephone, mobile, instantMessageId, googleId, description);
|
||||
return person;
|
||||
}
|
||||
|
||||
public Person restriced()
|
||||
{
|
||||
Person p = new Person(getId(), getEmail(), getEnabled(), getFirstName(), getLastName(), null, null, null, null, null, null, null, null);
|
||||
Person p = new Person(getId(), getUsername(), getEnabled(), getFirstName(), getLastName(), null, null, null, null, null, null, null, null);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user