REPO-1058 / REPO-1244: REST API - list Sites - orderBy

- add automated unit tests

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130796 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-09-19 14:46:29 +00:00
parent 6242e57e6c
commit 94efedd1b1
2 changed files with 293 additions and 12 deletions

View File

@@ -77,13 +77,13 @@ public class TestPersonSites extends EnterpriseTestApi
private TestSite site1;
private TestSite site2;
private TestSite site3;
private String site1_name = "a_" + GUID.generate();
private String site1_id = "a_" + GUID.generate();
private String site1_title = "c_" + GUID.generate();
private SiteRole site1_role = SiteRole.SiteContributor;
private String site2_name = "b_" + GUID.generate();
private String site2_id = "b_" + GUID.generate();
private String site2_title = "a_" + GUID.generate();
private SiteRole site2_role = SiteRole.SiteManager;
private String site3_name = "c_" + GUID.generate();
private String site3_id = "c_" + GUID.generate();
private String site3_title = "b_" + GUID.generate();
private SiteRole site3_role = SiteRole.SiteConsumer;
@@ -172,7 +172,8 @@ public class TestPersonSites extends EnterpriseTestApi
}, person12.getId(), network1.getId());
}
public void initializeSites() throws Exception
// TODO switch to use V1 createSite (instead of RepoService)
private void initializeSites() throws Exception
{
/*
* Create data for testing the site sorting. We create the sites as
@@ -195,7 +196,7 @@ public class TestPersonSites extends EnterpriseTestApi
@Override
public TestSite doWork() throws Exception
{
SiteInformation siteInfo = new SiteInformation(site1_name, site1_title, site1_title, SiteVisibility.PRIVATE);
SiteInformation siteInfo = new SiteInformation(site1_id, site1_title, site1_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site1_role);
return site;
@@ -207,7 +208,7 @@ public class TestPersonSites extends EnterpriseTestApi
@Override
public TestSite doWork() throws Exception
{
SiteInformation siteInfo = new SiteInformation(site2_name, site2_title, site2_title, SiteVisibility.PRIVATE);
SiteInformation siteInfo = new SiteInformation(site2_id, site2_title, site2_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site2_role);
return site;
@@ -219,7 +220,7 @@ public class TestPersonSites extends EnterpriseTestApi
@Override
public TestSite doWork() throws Exception
{
SiteInformation siteInfo = new SiteInformation(site3_name, site3_title, site3_title, SiteVisibility.PRIVATE);
SiteInformation siteInfo = new SiteInformation(site3_id, site3_title, site3_title, SiteVisibility.PRIVATE);
TestSite site = network1.createSite(siteInfo);
site.inviteToSite(person32.getId(), site3_role);
return site;
@@ -627,7 +628,7 @@ public class TestPersonSites extends EnterpriseTestApi
*
* @throws Exception
*/
public void testSortingAndPagingBySiteNameAsc() throws Exception
public void testSortingAndPagingBySiteIdAsc() throws Exception
{
// paging
int skipCount = 1;
@@ -652,7 +653,7 @@ public class TestPersonSites extends EnterpriseTestApi
*
* @throws Exception
*/
public void testSortingAndPagingBySiteNameDesc() throws Exception
public void testSortingAndPagingBySiteIdDesc() throws Exception
{
// paging
int skipCount = 1;
@@ -673,7 +674,7 @@ public class TestPersonSites extends EnterpriseTestApi
/**
* Tests the capability to sort and paginate the site memberships associated
* default sorting, all results
* default sorting (title asc), all results
*
* @throws Exception
*/
@@ -696,6 +697,7 @@ public class TestPersonSites extends EnterpriseTestApi
}
// see also TestSites.testSortingAndPaging
@Test
public void testSortingAndPaging() throws Exception
{
@@ -705,8 +707,8 @@ public class TestPersonSites extends EnterpriseTestApi
testSortingAndPagingByTitleDesc();
testSortingAndPagingByRoleAsc();
testSortingAndPagingByRoleDesc();
testSortingAndPagingBySiteNameAsc();
testSortingAndPagingBySiteNameDesc();
testSortingAndPagingBySiteIdAsc();
testSortingAndPagingBySiteIdDesc();
testSortingAndPagingDefault();
}

View File

@@ -30,8 +30,11 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
@@ -65,10 +68,29 @@ public class TestSites extends EnterpriseTestApi
private String person1Id;
private String person2Id;
private String person3Id;
private Site site1;
private Site site2;
private Site site3;
// network with sites to test sorting and paging
private TestNetwork network2;
private SiteImpl site4;
private SiteImpl site5;
private SiteImpl site6;
private String site4_id = "a_" + GUID.generate();
private String site4_title = "c_" + GUID.generate();
private String site4_description = "b_" + GUID.generate();
private String site5_id = "b_" + GUID.generate();
private String site5_title = "a_" + GUID.generate();
private String site5_description = "c_" + GUID.generate();
private String site6_id = "c_" + GUID.generate();
private String site6_title = "b_" + GUID.generate();
private String site6_description = "a_" + GUID.generate();
@Override
@Before
public void
@@ -386,4 +408,261 @@ public class TestSites extends EnterpriseTestApi
// user invited to network and user invited to site
// user invited to network and user not invited to site
}
/**
* Tests the capability to sort and paginate the sites list
* orderBy = title ASC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByTitleAsc() throws Exception
{
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(paging, "title", true);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site6);
expectedList.add(site4);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
/**
* Tests the capability to sort and paginate the sites list
* orderBy = title DESC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByTitleDesc() throws Exception
{
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(paging, "title", false);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site6);
expectedList.add(site5);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
/**
* Tests the capability to sort and paginate the sites list
* orderBy = description ASC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByDescriptionAsc() throws Exception
{
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(paging, "description", true);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site4);
expectedList.add(site5);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
/**
* Tests the capability to sort and paginate the sites list
* orderBy = description DESC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByDescriptionDesc() throws Exception
{
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(paging, "description", false);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site4);
expectedList.add(site6);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
/**
* Tests the capability to sort and paginate the sites list
* orderBy = id ASC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingBySiteIdAsc() throws Exception
{
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(paging, "id", true);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site5);
expectedList.add(site6);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
/**
* Tests the capability to sort and paginate the sites list
* orderBy = id DESC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingBySiteIdDesc() throws Exception
{
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(paging, "id", false);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site5);
expectedList.add(site4);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
/**
* Tests the capability to sort and paginate the sites list
* default sorting (id asc), all results
*
* @throws Exception
*/
public void testSortingAndPagingDefault() throws Exception
{
// paging
int totalResults = 3;
Paging paging = getPaging(null, null, totalResults, totalResults);
// list sites
ListResponse<Site> resp = listSites(null, null, false);
// check results
List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site4);
expectedList.add(site5);
expectedList.add(site6);
checkList(expectedList, paging.getExpectedPaging(), resp);
}
// based on TestPersonSites.testSortingAndPaging
@Test
public void testSortingAndPaging() throws Exception
{
initializeSites();
publicApiClient.setRequestContext(new RequestContext(network2.getId(), person3Id));
testSortingAndPagingByTitleAsc();
testSortingAndPagingByTitleDesc();
testSortingAndPagingByDescriptionAsc();
testSortingAndPagingByDescriptionDesc();
testSortingAndPagingBySiteIdAsc();
testSortingAndPagingBySiteIdDesc();
testSortingAndPagingDefault();
}
private ListResponse<Site> listSites(final Paging paging, String sortColumn, boolean asc) throws Exception
{
final Sites sitesProxy = publicApiClient.sites();
// sort params
final Map<String, String> params = new HashMap<String, String>();
if (sortColumn != null)
{
params.put("orderBy", sortColumn + " " + (asc ? "ASC" : "DESC"));
}
return sitesProxy.getSites(createParams(paging, params));
}
// TODO switch to use V1 createSite (instead of RepoService)
private void initializeSites() throws Exception
{
network2 = getRepoService().createNetwork(this.getClass().getName().toLowerCase(), true);
network2.create();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
person3Id = network2.createUser().getId();
return null;
}
}, network2.getId());
this.site4 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
{
@Override
public TestSite doWork() throws Exception
{
RepoService.SiteInformation siteInfo = new RepoService.SiteInformation(site4_id, site4_title, site4_description, SiteVisibility.PRIVATE);
TestSite site = network2.createSite(siteInfo);
return site;
}
}, person3Id, network2.getId());
this.site5 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
{
@Override
public TestSite doWork() throws Exception
{
RepoService.SiteInformation siteInfo = new RepoService.SiteInformation(site5_id, site5_title, site5_description, SiteVisibility.PRIVATE);
TestSite site = network2.createSite(siteInfo);
return site;
}
}, person3Id, network2.getId());
this.site6 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
{
@Override
public TestSite doWork() throws Exception
{
RepoService.SiteInformation siteInfo = new RepoService.SiteInformation(site6_id, site6_title, site6_description, SiteVisibility.PRIVATE);
TestSite site = network2.createSite(siteInfo);
return site;
}
}, person3Id, network2.getId());
}
}