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

- tweak the default (as agreed with GC)
- update automated unit test (and also refactor to make it re-runnable and to consistently use create site api)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130854 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-09-21 10:13:59 +00:00
parent b69a0ab012
commit 0aed749b05
3 changed files with 112 additions and 113 deletions

View File

@@ -683,7 +683,7 @@ public class SitesImpl implements Sites
else else
{ {
// default sort order // default sort order
sortProps.add(new Pair<>(ContentModel.PROP_NAME, Boolean.TRUE)); sortProps.add(new Pair<>(ContentModel.PROP_TITLE, Boolean.TRUE));
} }
final PagingResults<SiteInfo> pagingResult = siteService.listSites(null, sortProps, pagingRequest); final PagingResults<SiteInfo> pagingResult = siteService.listSites(null, sortProps, pagingRequest);

View File

@@ -26,12 +26,10 @@
package org.alfresco.rest.api.tests; package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -64,30 +62,32 @@ import org.junit.Test;
*/ */
public class TestSites extends EnterpriseTestApi public class TestSites extends EnterpriseTestApi
{ {
private static final String RUNID = System.currentTimeMillis()+"";
// test network 1
private TestNetwork network1; private TestNetwork network1;
private String person1Id; private String person1Id;
private String person2Id; private String person2Id;
private String person3Id;
private Site site1; private Site site1;
private Site site2; private Site site2;
private Site site3; private Site site3;
// network with sites to test sorting and paging // test network 2
private TestNetwork network2; private TestNetwork network2;
private String person3Id;
private SiteImpl site4; private Site site4;
private SiteImpl site5; private Site site5;
private SiteImpl site6; private Site site6;
private String site4_id = "a_" + GUID.generate(); private String site4_id = "a-" + GUID.generate();
private String site4_title = "c_" + GUID.generate(); private String site4_title = "c_" + GUID.generate();
private String site4_description = "b_" + GUID.generate(); private String site4_description = "b_" + GUID.generate();
private String site5_id = "b_" + GUID.generate(); private String site5_id = "b-" + GUID.generate();
private String site5_title = "a_" + GUID.generate(); private String site5_title = "a_" + GUID.generate();
private String site5_description = "c_" + GUID.generate(); private String site5_description = "c_" + GUID.generate();
private String site6_id = "c_" + GUID.generate(); private String site6_id = "c-" + GUID.generate();
private String site6_title = "b_" + GUID.generate(); private String site6_title = "b_" + GUID.generate();
private String site6_description = "a_" + GUID.generate(); private String site6_description = "a_" + GUID.generate();
@@ -96,21 +96,61 @@ public class TestSites extends EnterpriseTestApi
public void public void
setup() throws Exception setup() throws Exception
{ {
// init networks initializeNetwork1();
super.setup();
// Test: user is member of an account
this.network1 = getTestFixture().getRandomNetwork();
Iterator<String> personIt = network1.getPersonIds().iterator();
this.person1Id = personIt.next();
assertNotNull(person1Id);
this.person2Id = personIt.next();
assertNotNull(person2Id);
} }
private void initializeNetwork1() throws Exception
{
if (network1 == null)
{
network1 = getRepoService().createNetwork(this.getClass().getName().toLowerCase()+"-1-"+RUNID, true);
network1.create();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
person1Id = network1.createUser().getId();
person2Id = network1.createUser().getId();
return null;
}
}, network1.getId());
}
}
private void initializeNetwork2WithSites() throws Exception
{
if (network2 == null)
{
network2 = getRepoService().createNetwork(this.getClass().getName().toLowerCase()+"-2-"+RUNID, true);
network2.create();
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
person3Id = network2.createUser().getId();
return null;
}
}, network2.getId());
publicApiClient.setRequestContext(new RequestContext(network2.getId(), person3Id));
Sites sitesProxy = publicApiClient.sites();
Site site = new SiteImpl(site4_id, site4_title, site4_description, SiteVisibility.PRIVATE.toString());
site4 = sitesProxy.createSite(site);
site = new SiteImpl(site5_id, site5_title, site5_description, SiteVisibility.PRIVATE.toString());
site5 = sitesProxy.createSite(site);
site = new SiteImpl(site6_id, site6_title, site6_description, SiteVisibility.PRIVATE.toString());
site6 = sitesProxy.createSite(site);
}
}
@Test @Test
public void testGetSiteAndListSites() throws Exception public void testGetSiteAndListSites() throws Exception
{ {
@@ -428,8 +468,8 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site6); expectedList.add((SiteImpl)site6);
expectedList.add(site4); expectedList.add((SiteImpl)site4);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
@@ -454,8 +494,8 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site6); expectedList.add((SiteImpl)site6);
expectedList.add(site5); expectedList.add((SiteImpl)site5);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -479,8 +519,8 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site4); expectedList.add((SiteImpl)site4);
expectedList.add(site5); expectedList.add((SiteImpl)site5);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -504,8 +544,8 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site4); expectedList.add((SiteImpl)site4);
expectedList.add(site6); expectedList.add((SiteImpl)site6);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -529,8 +569,8 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site5); expectedList.add((SiteImpl)site5);
expectedList.add(site6); expectedList.add((SiteImpl)site6);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -554,8 +594,8 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site5); expectedList.add((SiteImpl)site5);
expectedList.add(site4); expectedList.add((SiteImpl)site4);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
} }
@@ -577,9 +617,9 @@ public class TestSites extends EnterpriseTestApi
// check results // check results
List<SiteImpl> expectedList = new LinkedList<>(); List<SiteImpl> expectedList = new LinkedList<>();
expectedList.add(site4); expectedList.add((SiteImpl)site5);
expectedList.add(site5); expectedList.add((SiteImpl)site6);
expectedList.add(site6); expectedList.add((SiteImpl)site4);
checkList(expectedList, paging.getExpectedPaging(), resp); checkList(expectedList, paging.getExpectedPaging(), resp);
@@ -589,7 +629,7 @@ public class TestSites extends EnterpriseTestApi
@Test @Test
public void testSortingAndPaging() throws Exception public void testSortingAndPaging() throws Exception
{ {
initializeSites(); initializeNetwork2WithSites();
publicApiClient.setRequestContext(new RequestContext(network2.getId(), person3Id)); publicApiClient.setRequestContext(new RequestContext(network2.getId(), person3Id));
@@ -615,54 +655,4 @@ public class TestSites extends EnterpriseTestApi
return sitesProxy.getSites(createParams(paging, params)); 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());
}
} }

View File

@@ -1,24 +1,24 @@
/* /*
* #%L * #%L
* Alfresco Remote API * Alfresco Remote API
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
@@ -101,6 +101,15 @@ public class SiteImpl implements Serializable, Site, Comparable<SiteImpl>, Expec
this.guid = siteInfo.getNodeRef().getId(); this.guid = siteInfo.getNodeRef().getId();
} }
public SiteImpl(String siteId, String title, String description, String visibility)
{
super();
this.siteId = siteId;
this.title = title;
this.description = description;
this.visibility = visibility;
}
public SiteImpl(String networkId, String siteId, String guid, String title, String description, public SiteImpl(String networkId, String siteId, String guid, String title, String description,
String visibility, String type, SiteRole siteRole) String visibility, String type, SiteRole siteRole)
{ {
@@ -218,11 +227,11 @@ public class SiteImpl implements Serializable, Site, Comparable<SiteImpl>, Expec
public static Site parseSite(JSONObject jsonObject) public static Site parseSite(JSONObject jsonObject)
{ {
if (jsonObject == null) if (jsonObject == null)
{ {
return null; return null;
} }
String id = (String)jsonObject.get("id"); String id = (String)jsonObject.get("id");
String guid = (String)jsonObject.get("guid"); String guid = (String)jsonObject.get("guid");
String title = (String)jsonObject.get("title"); String title = (String)jsonObject.get("title");
@@ -292,10 +301,10 @@ public class SiteImpl implements Serializable, Site, Comparable<SiteImpl>, Expec
{ {
siteJson.put("title", getTitle()); siteJson.put("title", getTitle());
} }
if (getDescription() != null) if (getDescription() != null)
{ {
siteJson.put("description", getDescription()); siteJson.put("description", getDescription());
} }
if (getVisibility() != null) if (getVisibility() != null)
{ {
siteJson.put("visibility", getVisibility()); siteJson.put("visibility", getVisibility());