REPO-5630 Fix for intermittent failing test PeopleTest.testPagingAndSortingByFirstNameDesc (#461)

* Fix for failing test
* Fixes post review
This commit is contained in:
Bruno Bossola
2021-05-14 14:05:33 +01:00
committed by GitHub
parent 083e9285fb
commit 8ecf27674b

View File

@@ -43,6 +43,7 @@ import org.alfresco.rest.api.tests.client.PublicApiClient.People;
import org.alfresco.rest.api.tests.client.PublicApiException; import org.alfresco.rest.api.tests.client.PublicApiException;
import org.alfresco.rest.api.tests.client.RequestContext; 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.Company;
import org.alfresco.rest.api.tests.client.data.ExpectedComparison;
import org.alfresco.rest.api.tests.client.data.JSONAble; import org.alfresco.rest.api.tests.client.data.JSONAble;
import org.alfresco.rest.api.tests.client.data.Person; import org.alfresco.rest.api.tests.client.data.Person;
import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.rest.api.tests.util.RestApiUtil;
@@ -115,9 +116,9 @@ public class TestPeople extends AbstractBaseApiTest
private String account2Admin; private String account2Admin;
private String account3Admin; private String account3Admin;
private static String account4Admin; private static String account4Admin;
private static Person personAlice; private static Person personAliceSmith;
private static Person personAliceD; private static Person personAliceDavis;
private static Person personBen; private static Person personBenCarson;
private Person personBob; private Person personBob;
private NodeService nodeService; private NodeService nodeService;
private PersonService personService; private PersonService personService;
@@ -142,36 +143,36 @@ public class TestPeople extends AbstractBaseApiTest
account4Admin = "admin@" + account4.getId(); account4Admin = "admin@" + account4.getId();
publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin")); publicApiClient.setRequestContext(new RequestContext(account4.getId(), account4Admin, "admin"));
personAlice = new Person(); personAliceSmith = new Person();
personAlice.setUserName("alice@" + account4.getId()); personAliceSmith.setUserName("alice@" + account4.getId());
personAlice.setId("alice@" + account4.getId()); personAliceSmith.setId("alice@" + account4.getId());
personAlice.setFirstName("Alice"); personAliceSmith.setFirstName("Alice");
personAlice.setLastName("Smith"); personAliceSmith.setLastName("Smith");
personAlice.setEmail("alison.smith@example.com"); personAliceSmith.setEmail("alison.smith@example.com");
personAlice.setPassword("password"); personAliceSmith.setPassword("password");
personAlice.setEnabled(true); personAliceSmith.setEnabled(true);
personAlice.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich")); personAliceSmith.setProperties(Collections.singletonMap("papi:lunch", "Magical sandwich"));
people.create(personAlice); people.create(personAliceSmith);
personAliceD = new Person(); personAliceDavis = new Person();
personAliceD.setUserName("aliced@" + account4.getId()); personAliceDavis.setUserName("aliced@" + account4.getId());
personAliceD.setId("aliced@" + account4.getId()); personAliceDavis.setId("aliced@" + account4.getId());
personAliceD.setFirstName("Alice"); personAliceDavis.setFirstName("Alice");
personAliceD.setLastName("Davis"); personAliceDavis.setLastName("Davis");
personAliceD.setEmail("alison.davis@example.com"); personAliceDavis.setEmail("alison.davis@example.com");
personAliceD.setPassword("password"); personAliceDavis.setPassword("password");
personAliceD.setEnabled(true); personAliceDavis.setEnabled(true);
people.create(personAliceD); people.create(personAliceDavis);
personBen = new Person(); personBenCarson = new Person();
personBen.setUserName("ben@" + account4.getId()); personBenCarson.setUserName("ben@" + account4.getId());
personBen.setId("ben@" + account4.getId()); personBenCarson.setId("ben@" + account4.getId());
personBen.setFirstName("Ben"); personBenCarson.setFirstName("Ben");
personBen.setLastName("Carson"); personBenCarson.setLastName("Carson");
personBen.setEmail("ben.smythe@example.com"); personBenCarson.setEmail("ben.smythe@example.com");
personBen.setPassword("password"); personBenCarson.setPassword("password");
personBen.setEnabled(true); personBenCarson.setEnabled(true);
people.create(personBen); people.create(personBenCarson);
} }
account1Admin = "admin@" + account1.getId(); account1Admin = "admin@" + account1.getId();
account2Admin = "admin@" + account2.getId(); account2Admin = "admin@" + account2.getId();
@@ -1571,10 +1572,10 @@ public class TestPeople extends AbstractBaseApiTest
// orderBy=firstName ASC // orderBy=firstName ASC
PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName", true, 200); PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName", true, 200);
List<Person> expectedList = new LinkedList<>(); List<ExpectedComparison> expectedList = new LinkedList<>();
expectedList.add(personAlice); expectedList.add(expectedFirstName(personAliceSmith));
expectedList.add(personAliceD); expectedList.add(expectedFirstName(personAliceDavis));
expectedList.add(personBen); expectedList.add(expectedFirstName(personBenCarson));
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -1599,10 +1600,10 @@ public class TestPeople extends AbstractBaseApiTest
// orderBy=firstName DESC // orderBy=firstName DESC
PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName", false, 200); PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName", false, 200);
List<Person> expectedList = new LinkedList<>(); List<ExpectedComparison> expectedList = new LinkedList<>();
expectedList.add((Person) personBen); expectedList.add(expectedFirstName(personBenCarson));
expectedList.add((Person) personAlice); expectedList.add(expectedFirstName(personAliceSmith));
expectedList.add((Person) personAliceD); expectedList.add(expectedFirstName(personAliceDavis));
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -1627,9 +1628,9 @@ public class TestPeople extends AbstractBaseApiTest
PublicApiClient.ListResponse<Person> resp = listPeople(paging, null, false, 200); PublicApiClient.ListResponse<Person> resp = listPeople(paging, null, false, 200);
List<Person> expectedList = new LinkedList<>(); List<Person> expectedList = new LinkedList<>();
expectedList.add((Person) personAlice); expectedList.add((Person) personAliceSmith);
expectedList.add((Person) personAliceD); expectedList.add((Person) personAliceDavis);
expectedList.add((Person) personBen); expectedList.add((Person) personBenCarson);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -1655,9 +1656,9 @@ public class TestPeople extends AbstractBaseApiTest
PublicApiClient.ListResponse<Person> resp = listPeople(paging, "id", false, 200); PublicApiClient.ListResponse<Person> resp = listPeople(paging, "id", false, 200);
List<Person> expectedList = new LinkedList<>(); List<Person> expectedList = new LinkedList<>();
expectedList.add((Person) personBen); expectedList.add((Person) personBenCarson);
expectedList.add((Person) personAliceD); expectedList.add((Person) personAliceDavis);
expectedList.add((Person) personAlice); expectedList.add((Person) personAliceSmith);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -1704,9 +1705,9 @@ public class TestPeople extends AbstractBaseApiTest
PublicApiClient.ListResponse<Person> resp = listPeople(paging, "lastName", true, 200); PublicApiClient.ListResponse<Person> resp = listPeople(paging, "lastName", true, 200);
List<Person> expectedList = new LinkedList<>(); List<Person> expectedList = new LinkedList<>();
expectedList.add((Person) personBen); expectedList.add((Person) personBenCarson);
expectedList.add((Person) personAliceD); expectedList.add((Person) personAliceDavis);
expectedList.add((Person) personAlice); expectedList.add((Person) personAliceSmith);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -1732,9 +1733,9 @@ public class TestPeople extends AbstractBaseApiTest
PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName,lastName", true, 200); PublicApiClient.ListResponse<Person> resp = listPeople(paging, "firstName,lastName", true, 200);
List<Person> expectedList = new LinkedList<>(); List<Person> expectedList = new LinkedList<>();
expectedList.add((Person) personAliceD); expectedList.add((Person) personAliceDavis);
expectedList.add((Person) personAlice); expectedList.add((Person) personAliceSmith);
expectedList.add((Person) personBen); expectedList.add((Person) personBenCarson);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -2371,4 +2372,24 @@ public class TestPeople extends AbstractBaseApiTest
{ {
return "public"; return "public";
} }
private ExpectedComparison expectedFirstName(Person person)
{
return new ExpectedComparison()
{
@Override
public void expected(Object other)
{
if (other instanceof Person)
{
assertEquals("firstName", person.getFirstName(), ((Person) other).getFirstName());
}
else
{
fail("Not a person? " + other);
}
}
};
}
} }