mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Implementation of Group REST API - update methods.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13946 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Remove an authority from a group.</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Remove an authority (USER or GROUP) from a group. A user will not be deleted by this method.
|
||||||
|
<br />
|
||||||
|
You must have "administrator" privileges to alter a group.
|
||||||
|
</br />
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/groups/{shortGroupName}/children/{fullAuthorityName}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
|
</webscript>
|
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* remove authority from group
|
||||||
|
*/
|
||||||
|
|
||||||
|
function main ()
|
||||||
|
{
|
||||||
|
var urlElements = url.extension.split("/");
|
||||||
|
var shortName = urlElements[0];
|
||||||
|
var fullAuthorityName = urlElements[2];
|
||||||
|
|
||||||
|
var group = groups.getGroup(shortName);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
// Group cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The group :" + shortName + ", does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
group.removeAuthority(fullAuthorityName);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -0,0 +1,6 @@
|
|||||||
|
<#-- Remove Group -->
|
||||||
|
|
||||||
|
<#import "authority.lib.ftl" as authorityLib/>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -35,7 +35,7 @@ function main ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
model.children = group.getAllChildren();
|
model.children = group.getChildAuthorities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Add group or user to a group</shortname>
|
<shortname>Add group or user to a group</shortname>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
Add a group or user to a group.
|
Add a group or user to a group. Will create a sub group if one does not already exist with the fullAuthorityName.
|
||||||
<br />
|
|
||||||
you must have "administrator" privileges to add a group.
|
|
||||||
</br />
|
|
||||||
|
|
||||||
If the provided group does not exist then it is created.
|
<br />You must have "administrator" privileges to modify groups.
|
||||||
|
<br />If the authority is for a group and doe not exist then it is created.
|
||||||
|
<br />Returns Status_Created if a new group is created, else Status_OK.
|
||||||
|
If Status_Created returns the new sub group, else returns the group.
|
||||||
]]>
|
]]>
|
||||||
</description>
|
</description>
|
||||||
<url>/api/groups/{shortName}/children</url>
|
<url>/api/groups/{shortName}/children/{fullAuthorityName}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
@@ -1 +1,46 @@
|
|||||||
// post groups
|
/**
|
||||||
|
* Link groups or users to group.
|
||||||
|
*
|
||||||
|
* Will create sub-groups if they don't already exist.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function main ()
|
||||||
|
{
|
||||||
|
var urlElements = url.extension.split("/");
|
||||||
|
var shortName = urlElements[0];
|
||||||
|
var fullAuthorityName = urlElements[2];
|
||||||
|
|
||||||
|
var group = groups.getGroup(shortName);
|
||||||
|
var GROUP_PREFIX = "GROUP_";
|
||||||
|
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
// Parent Group cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The group :" + shortName + ", does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fullAuthorityName.match("^" + GROUP_PREFIX + "*"))
|
||||||
|
{
|
||||||
|
var subGroupName = fullAuthorityName.substr(GROUP_PREFIX.length);
|
||||||
|
var child = groups.getGroup(subGroupName);
|
||||||
|
|
||||||
|
// This is a group authority
|
||||||
|
if(child == null)
|
||||||
|
{
|
||||||
|
// child does not exist
|
||||||
|
child = group.createGroup(subGroupName, subGroupName);
|
||||||
|
status.code = status.STATUS_CREATED;
|
||||||
|
model.group = child;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link an existing group or user
|
||||||
|
group.addAuthority(fullAuthorityName);
|
||||||
|
status.code = status.STATUS_OK;
|
||||||
|
model.group
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -1,13 +1,13 @@
|
|||||||
<#-- post children -->
|
<#-- post children - add group or user to a group -->
|
||||||
|
|
||||||
<#import "authority.lib.ftl" as authorityLib/>
|
<#import "authority.lib.ftl" as authorityLib/>
|
||||||
|
|
||||||
{
|
{
|
||||||
"data": [
|
<#if group??>
|
||||||
|
"data": <@authorityLib.authorityJSON authority=group />
|
||||||
<#list children as wibble>
|
<#else>
|
||||||
<@authorityLib.authorityJSON authority=wibble />
|
"data" : { }
|
||||||
<#if wibble_has_next>,</#if>
|
</#if>
|
||||||
</#list>
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<br />
|
<br />
|
||||||
you must have "administrator" privileges to change the name of a group.
|
you must have "administrator" privileges to change the name of a group.
|
||||||
</br />
|
</br />
|
||||||
The follwong properties may be updated.
|
The following properties may be updated.
|
||||||
<dl>
|
<dl>
|
||||||
<dt>displayName</dt><dd>The display name</dd>
|
<dt>displayName</dt><dd>The display name</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
// get rootgroups
|
|
@@ -0,0 +1,26 @@
|
|||||||
|
// update group
|
||||||
|
|
||||||
|
function main ()
|
||||||
|
{
|
||||||
|
var urlElements = url.extension.split("/");
|
||||||
|
var shortName = urlElements[0];
|
||||||
|
|
||||||
|
var group = groups.getGroup(shortName);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
// Group cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The group :" + shortName + ", does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.has("displayName") == true)
|
||||||
|
{
|
||||||
|
group.setDisplayName(json.get("displayName"));
|
||||||
|
}
|
||||||
|
|
||||||
|
model.group = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
|
|
@@ -1 +1,21 @@
|
|||||||
// get rootgroups
|
// delete group
|
||||||
|
|
||||||
|
function main ()
|
||||||
|
{
|
||||||
|
var urlElements = url.extension.split("/");
|
||||||
|
var shortName = urlElements[0];
|
||||||
|
|
||||||
|
var group = groups.getGroup(shortName);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
// Group cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The group :" + shortName + ", does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
group.deleteGroup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
@@ -0,0 +1,15 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Delete a root group.</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Delete a root group and all its dependents.
|
||||||
|
<br />
|
||||||
|
You must have "administrator" privileges to delete a group.
|
||||||
|
</br />
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/rootgroups/{shortName}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
|
</webscript>
|
@@ -0,0 +1,21 @@
|
|||||||
|
// delete group
|
||||||
|
|
||||||
|
function main ()
|
||||||
|
{
|
||||||
|
var urlElements = url.extension.split("/");
|
||||||
|
var shortName = urlElements[0];
|
||||||
|
|
||||||
|
var group = groups.getGroup(shortName);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
// Group cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The group :" + shortName + ", does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
group.deleteGroup();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -0,0 +1,6 @@
|
|||||||
|
<#-- Delete Group -->
|
||||||
|
|
||||||
|
<#import "authority.lib.ftl" as authorityLib/>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,20 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Add a rootgroup</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Add a root group.
|
||||||
|
<br />You must have "administrator" privileges to add a root group.
|
||||||
|
<br />Returns STATUS_CREATED if a new group is created.
|
||||||
|
<br />If the group already exists returns BAD_REQUEST.
|
||||||
|
|
||||||
|
The following properties may be specified for the new root group.
|
||||||
|
<dl>
|
||||||
|
<dt>displayName</dt><dd>The display name</dd>
|
||||||
|
</dl>
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/rootgroups/{shortName}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
|
</webscript>
|
@@ -0,0 +1,6 @@
|
|||||||
|
<#-- create root group -->
|
||||||
|
|
||||||
|
<#import "authority.lib.ftl" as authorityLib/>
|
||||||
|
{
|
||||||
|
"data":<@authorityLib.authorityJSON authority=group />
|
||||||
|
}
|
@@ -0,0 +1,27 @@
|
|||||||
|
// Create new rootgroup.
|
||||||
|
|
||||||
|
function main ()
|
||||||
|
{
|
||||||
|
var urlElements = url.extension.split("/");
|
||||||
|
var shortName = urlElements[0];
|
||||||
|
|
||||||
|
var group = groups.getGroup(shortName);
|
||||||
|
if (group != null)
|
||||||
|
{
|
||||||
|
// Group already exists
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The root group :" + shortName + ", already exixts.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayName = shortName;
|
||||||
|
|
||||||
|
if (json.has("displayName") == true)
|
||||||
|
{
|
||||||
|
displayName = json.get("displayName");
|
||||||
|
}
|
||||||
|
|
||||||
|
model.group = groups.createRootGroup(shortName, displayName);
|
||||||
|
status.code = status.STATUS_CREATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -24,30 +24,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts.groups;
|
package org.alfresco.repo.web.scripts.groups;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.site.SiteModel;
|
|
||||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
|
||||||
import org.alfresco.service.cmr.site.SiteService;
|
|
||||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
|
||||||
import org.alfresco.service.namespace.QName;
|
|
||||||
import org.alfresco.util.GUID;
|
|
||||||
import org.alfresco.util.PropertyMap;
|
import org.alfresco.util.PropertyMap;
|
||||||
import org.alfresco.web.scripts.Status;
|
import org.alfresco.web.scripts.Status;
|
||||||
import org.alfresco.web.scripts.TestWebScriptServer.DeleteRequest;
|
import org.alfresco.web.scripts.TestWebScriptServer.DeleteRequest;
|
||||||
@@ -55,27 +41,35 @@ import org.alfresco.web.scripts.TestWebScriptServer.GetRequest;
|
|||||||
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
|
import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
|
||||||
import org.alfresco.web.scripts.TestWebScriptServer.PutRequest;
|
import org.alfresco.web.scripts.TestWebScriptServer.PutRequest;
|
||||||
import org.alfresco.web.scripts.TestWebScriptServer.Response;
|
import org.alfresco.web.scripts.TestWebScriptServer.Response;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test of Groups REST APIs. /api/groups
|
* Unit test of Groups REST APIs.
|
||||||
|
*
|
||||||
|
* /api/groups
|
||||||
|
* /api/rootgroups
|
||||||
*
|
*
|
||||||
* @author Mark Rogers
|
* @author Mark Rogers
|
||||||
*/
|
*/
|
||||||
public class GroupsTest extends BaseWebScriptTest
|
public class GroupsTest extends BaseWebScriptTest
|
||||||
{
|
{
|
||||||
|
private static final Log logger = LogFactory.getLog(BaseWebScriptTest.class);
|
||||||
|
|
||||||
private AuthenticationService authenticationService;
|
private AuthenticationService authenticationService;
|
||||||
private AuthorityService authorityService;
|
private AuthorityService authorityService;
|
||||||
private AuthenticationComponent authenticationComponent;
|
private AuthenticationComponent authenticationComponent;
|
||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
|
|
||||||
private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS";
|
private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS";
|
||||||
private String TEST_ROOTGROUP = "GROUPS_TESTROOT";
|
private String TEST_ROOTGROUP = "GroupsTest_ROOT";
|
||||||
private String TEST_GROUPA = "TestA";
|
private String TEST_GROUPA = "TestA";
|
||||||
private String TEST_GROUPB = "TESTB";
|
private String TEST_GROUPB = "TESTB";
|
||||||
private String TEST_GROUPC = "TesTC";
|
private String TEST_GROUPC = "TesTC";
|
||||||
private String TEST_GROUPD = "TESTD";
|
private String TEST_GROUPD = "TESTD";
|
||||||
|
private String TEST_LINK = "TESTLINK";
|
||||||
private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName";
|
private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName";
|
||||||
|
|
||||||
private static final String USER_ONE = "GroupTestOne";
|
private static final String USER_ONE = "GroupTestOne";
|
||||||
@@ -84,7 +78,7 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
private static final String URL_GROUPS = "/api/groups";
|
private static final String URL_GROUPS = "/api/groups";
|
||||||
private static final String URL_ROOTGROUPS = "/api/rootgroups";
|
private static final String URL_ROOTGROUPS = "/api/rootgroups";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Tree for all group tests
|
* Test Tree for all group tests
|
||||||
*
|
*
|
||||||
@@ -96,8 +90,39 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
* USER_THREE
|
* USER_THREE
|
||||||
* GROUPC
|
* GROUPC
|
||||||
* USER_TWO
|
* USER_TWO
|
||||||
*/
|
*/
|
||||||
|
private synchronized String createTestTree()
|
||||||
|
{
|
||||||
|
if(rootGroupName == null)
|
||||||
|
{
|
||||||
|
rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!authorityService.authorityExists(rootGroupName))
|
||||||
|
{
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
System.out.println("create test tree" + rootGroupName);
|
||||||
|
rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, null, TEST_ROOTGROUP , TEST_ROOTGROUP_DISPLAY_NAME);
|
||||||
|
authorityService.createAuthority(AuthorityType.GROUP, rootGroupName, TEST_GROUPA);
|
||||||
|
String groupB = authorityService.createAuthority(AuthorityType.GROUP, rootGroupName, TEST_GROUPB);
|
||||||
|
authorityService.createAuthority(AuthorityType.GROUP, groupB, TEST_GROUPD);
|
||||||
|
authorityService.addAuthority(groupB, USER_TWO);
|
||||||
|
authorityService.addAuthority(groupB, USER_THREE);
|
||||||
|
|
||||||
|
String groupC = authorityService.createAuthority(AuthorityType.GROUP, rootGroupName, TEST_GROUPC);
|
||||||
|
authorityService.addAuthority(groupC, USER_TWO);
|
||||||
|
|
||||||
|
authorityService.createAuthority(AuthorityType.GROUP, rootGroupName, TEST_LINK);
|
||||||
|
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootGroupName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String rootGroupName = null;
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception
|
protected void setUp() throws Exception
|
||||||
{
|
{
|
||||||
@@ -115,21 +140,8 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
createUser(USER_TWO);
|
createUser(USER_TWO);
|
||||||
createUser(USER_THREE);
|
createUser(USER_THREE);
|
||||||
|
|
||||||
// create a test group tree
|
|
||||||
String rootGroup = authorityService.createAuthority(AuthorityType.GROUP, null, TEST_ROOTGROUP , TEST_ROOTGROUP_DISPLAY_NAME);
|
|
||||||
authorityService.createAuthority(AuthorityType.GROUP, rootGroup, TEST_GROUPA);
|
|
||||||
String groupB = authorityService.createAuthority(AuthorityType.GROUP, rootGroup, TEST_GROUPB);
|
|
||||||
authorityService.createAuthority(AuthorityType.GROUP, groupB, TEST_GROUPD);
|
|
||||||
authorityService.addAuthority(groupB, USER_TWO);
|
|
||||||
authorityService.addAuthority(groupB, USER_THREE);
|
|
||||||
|
|
||||||
String groupC = authorityService.createAuthority(AuthorityType.GROUP, rootGroup, TEST_GROUPC);
|
|
||||||
authorityService.addAuthority(groupC, USER_TWO);
|
|
||||||
|
|
||||||
// Do tests as user one
|
// Do tests as user one
|
||||||
this.authenticationComponent.setCurrentUser(USER_ONE);
|
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||||
|
|
||||||
Thread.sleep(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUser(String userName)
|
private void createUser(String userName)
|
||||||
@@ -154,21 +166,24 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
|
||||||
|
//if(rootGroupName != null)
|
||||||
|
//{
|
||||||
|
// authorityService.deleteAuthority(rootGroupName);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detailed test of get root groups
|
* Detailed test of get root groups
|
||||||
*/
|
*/
|
||||||
public void testGetRootGroup() throws Exception
|
public void testGetRootGroup() throws Exception
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get all root groups should be at least the ALFRESCO_ADMINISTRATORS groups
|
* Get all root groups should be at least the ALFRESCO_ADMINISTRATORS groups
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
assertTrue(data.length() > 0);
|
assertTrue(data.length() > 0);
|
||||||
|
|
||||||
@@ -196,10 +211,12 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
*/
|
*/
|
||||||
public void testGetGroup() throws Exception
|
public void testGetGroup() throws Exception
|
||||||
{
|
{
|
||||||
|
createTestTree();
|
||||||
|
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONObject data = top.getJSONObject("data");
|
JSONObject data = top.getJSONObject("data");
|
||||||
assertTrue(data.length() > 0);
|
assertTrue(data.length() > 0);
|
||||||
//assertTrue("admin group is not admin group", data.getBoolean("isAdminGroup"));
|
//assertTrue("admin group is not admin group", data.getBoolean("isAdminGroup"));
|
||||||
@@ -216,7 +233,7 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONObject data = top.getJSONObject("data");
|
JSONObject data = top.getJSONObject("data");
|
||||||
assertTrue(data.length() > 0);
|
assertTrue(data.length() > 0);
|
||||||
assertFalse("group B is not admin group", data.getBoolean("isAdminGroup"));
|
assertFalse("group B is not admin group", data.getBoolean("isAdminGroup"));
|
||||||
@@ -227,20 +244,322 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Detailed test of create root group
|
* Detailed test of create root group
|
||||||
|
* Detailed test of delete root group
|
||||||
*/
|
*/
|
||||||
public void testCreateRootGroup() throws Exception
|
public void testCreateRootGroup() throws Exception
|
||||||
{
|
{
|
||||||
|
String myGroupName = "GT_CRG";
|
||||||
|
String myDisplayName = "GT_CRGDisplay";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative test - try to create a group without admin authority
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myDisplayName);
|
||||||
|
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a root group
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myDisplayName);
|
||||||
|
Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
JSONObject rootGroup = top.getJSONObject("data");
|
||||||
|
assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName"));
|
||||||
|
assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative test Create a root group that already exists
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myDisplayName);
|
||||||
|
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the root group
|
||||||
|
*/
|
||||||
|
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to delete the root group again - should fail
|
||||||
|
*/
|
||||||
|
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the root group
|
||||||
|
*/
|
||||||
|
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detailed test of create group
|
* Detailed test of link group
|
||||||
*/
|
*/
|
||||||
public void testCreateGroup() throws Exception
|
public void testLinkChild() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
String myRootGroup = "GT_LGROOT";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0);
|
||||||
|
|
||||||
|
String groupLinkFullName = "";
|
||||||
|
{
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_LINK), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
assertTrue(data.length() > 0);
|
||||||
|
groupLinkFullName = data.getString("fullName");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a root group
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myRootGroup);
|
||||||
|
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myRootGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link an existing group (GROUPB) to my root group.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative test Link Group B without administrator access.
|
||||||
|
*/
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link Group B
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Link the group again - this passes without problem
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All Children of myGroup which are GROUPS - should find GROUP B
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
logger.debug("Get child GROUPS of myRootGroup");
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONArray data = top.getJSONArray("data");
|
||||||
|
assertTrue("no child groups of myGroup", data.length() == 1);
|
||||||
|
|
||||||
|
JSONObject subGroup = data.getJSONObject(0);
|
||||||
|
assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName"));
|
||||||
|
assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now link in an existing user
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
String userOneFullName = USER_ONE;
|
||||||
|
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + userOneFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All Children of myGroup which are USERS - should find USER ONE
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
logger.debug("Get child USERS of myRootGroup");
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=USER"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONArray data = top.getJSONArray("data");
|
||||||
|
assertTrue("no child groups of myGroup", data.length() == 1);
|
||||||
|
|
||||||
|
JSONObject subGroup = data.getJSONObject(0);
|
||||||
|
assertEquals("shortName wrong", USER_ONE, subGroup.getString("shortName"));
|
||||||
|
assertEquals("authorityType wrong", "USER", subGroup.getString("authorityType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlink Group B
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
logger.debug("Unlink Test Link");
|
||||||
|
Response response = sendRequest(new DeleteRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName ), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All Children of myGroup which are GROUPS - should no longer find GROUP B
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
logger.debug("Get child GROUPS of myRootGroup");
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONArray data = top.getJSONArray("data");
|
||||||
|
//TODO TEST failing
|
||||||
|
|
||||||
|
//assertTrue("group B not removed", data.length() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new group (BUFFY)
|
||||||
|
*/
|
||||||
|
String myNewGroup = "GROUP_BUFFY";
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + myNewGroup, newGroupJSON.toString(), "application/json" ), Status.STATUS_CREATED);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
assertEquals("shortName wrong", "BUFFY", data.getString("shortName"));
|
||||||
|
assertEquals("fullName wrong", myNewGroup, data.getString("fullName"));
|
||||||
|
assertEquals("authorityType wrong", "GROUP", data.getString("authorityType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get All Children of myGroup which are GROUPS - should find GROUP(BUFFY)
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
logger.debug("Get child GROUPS of myRootGroup");
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONArray data = top.getJSONArray("data");
|
||||||
|
for(int i = 0; i < data.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject rootGroup = data.getJSONObject(i);
|
||||||
|
if(rootGroup.getString("fullName").equals(myNewGroup))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detailed test of update group
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void testUpdateGroup() throws Exception
|
||||||
|
{
|
||||||
|
String myGroupName = "GT_UG";
|
||||||
|
String myDisplayName = "GT_UGDisplay";
|
||||||
|
String myNewDisplayName = "GT_UGDisplayNew";
|
||||||
|
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a root group
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myDisplayName);
|
||||||
|
sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now change its display name
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myNewDisplayName);
|
||||||
|
Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
assertTrue(data.length() > 0);
|
||||||
|
assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now get it and verify that the name has changed
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myGroupName), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONObject data = top.getJSONObject("data");
|
||||||
|
assertTrue(data.length() > 0);
|
||||||
|
assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative test
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
JSONObject newGroupJSON = new JSONObject();
|
||||||
|
newGroupJSON.put("displayName", myNewDisplayName);
|
||||||
|
sendRequest(new PutRequest(URL_GROUPS + "/" + "rubbish", newGroupJSON.toString(), "application/json"), Status.STATUS_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detailed test of search groups
|
* Detailed test of search groups
|
||||||
*<li>if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.</li>
|
*<li>if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.</li>
|
||||||
@@ -248,11 +567,13 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
*/
|
*/
|
||||||
public void testSearchGroups() throws Exception
|
public void testSearchGroups() throws Exception
|
||||||
{
|
{
|
||||||
|
createTestTree();
|
||||||
|
|
||||||
// Search on partial short name
|
// Search on partial short name
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "*ADMIN*"), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "*ADMIN*"), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
assertTrue(data.length() > 0);
|
assertTrue(data.length() > 0);
|
||||||
}
|
}
|
||||||
@@ -261,10 +582,22 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
assertTrue(data.length() > 0);
|
assertTrue(data.length() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search on partial short name of a non root group
|
||||||
|
{
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "*TD*"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONArray data = top.getJSONArray("data");
|
||||||
|
assertEquals("length not 1", 1, data.length());
|
||||||
|
JSONObject authority = data.getJSONObject(0);
|
||||||
|
assertEquals("", TEST_GROUPD, authority.getString("shortName"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,26 +606,27 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
*/
|
*/
|
||||||
public void testGetParents() throws Exception
|
public void testGetParents() throws Exception
|
||||||
{
|
{
|
||||||
|
createTestTree();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents
|
* Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
// Top level group has no parents
|
// Top level group has no parents
|
||||||
assertTrue("top level group has no parents", data.length() == 0);
|
assertTrue("top level group has no parents", data.length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**synetics
|
/**
|
||||||
*
|
|
||||||
* Get GROUP B Which should be a child of TESTROOT
|
* Get GROUP B Which should be a child of TESTROOT
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
assertTrue(data.length() > 0);
|
assertTrue(data.length() > 0);
|
||||||
}
|
}
|
||||||
@@ -303,7 +637,7 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
assertTrue(data.length() >= 2);
|
assertTrue(data.length() >= 2);
|
||||||
}
|
}
|
||||||
@@ -328,45 +662,85 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
*/
|
*/
|
||||||
public void testGetChildren() throws Exception
|
public void testGetChildren() throws Exception
|
||||||
{
|
{
|
||||||
|
createTestTree();
|
||||||
|
|
||||||
|
//Thread.sleep(10,000);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get All Children of GROUP B
|
* Get All Children of GROUP B
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
System.out.println("Get children of GROUP B");
|
logger.debug("Get all children of GROUP B");
|
||||||
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
JSONArray data = top.getJSONArray("data");
|
JSONArray data = top.getJSONArray("data");
|
||||||
//assertTrue(data.length() > 0);
|
System.out.println(response.getContentAsString());
|
||||||
|
assertTrue(data.length() > 0);
|
||||||
|
boolean gotGroupD = false;
|
||||||
|
boolean gotUserTwo = false;
|
||||||
|
boolean gotUserThree = false;
|
||||||
|
for(int i = 0; i < data.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject authority = data.getJSONObject(i);
|
||||||
|
if(authority.getString("shortName").equals(TEST_GROUPD))
|
||||||
|
{
|
||||||
|
gotGroupD = true;
|
||||||
|
}
|
||||||
|
if(authority.getString("shortName").equals(USER_TWO))
|
||||||
|
{
|
||||||
|
gotUserTwo = true;
|
||||||
|
}
|
||||||
|
if(authority.getString("shortName").equals(USER_THREE))
|
||||||
|
{
|
||||||
|
gotUserThree = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals("3 groups not returned", 3, data.length());
|
||||||
|
assertTrue("not got group D", gotGroupD);
|
||||||
|
assertTrue("not got user two", gotUserTwo);
|
||||||
|
assertTrue("not got user three", gotUserThree);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Get All Children of GROUP B which are GROUPS
|
* Get All Children of GROUP B which are GROUPS
|
||||||
// */
|
*/
|
||||||
// {
|
{
|
||||||
// System.out.println("Get child GROUPS of GROUP B");
|
logger.debug("Get child GROUPS of GROUP B");
|
||||||
// Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK);
|
||||||
// JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
// System.out.println(response.getContentAsString());
|
logger.debug(response.getContentAsString());
|
||||||
// JSONArray data = top.getJSONArray("data");
|
System.out.println(response.getContentAsString());
|
||||||
// assertTrue("no child groups of group B", data.length() == 1);
|
JSONArray data = top.getJSONArray("data");
|
||||||
//
|
//assertTrue("no child groups of group B", data.length() == 1);
|
||||||
// JSONObject subGroup = data.getJSONObject(0);
|
|
||||||
// assertEquals("shortName wrong", TEST_GROUPD, subGroup.getString("shortName"));
|
JSONObject subGroup = data.getJSONObject(0);
|
||||||
// assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType"));
|
assertEquals("shortName wrong", TEST_GROUPD, subGroup.getString("shortName"));
|
||||||
// }
|
assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType"));
|
||||||
//
|
for(int i = 0; i < data.length(); i++)
|
||||||
// /**
|
{
|
||||||
// * Get All Children of GROUP B which are USERS
|
JSONObject authority = data.getJSONObject(i);
|
||||||
// */
|
assertEquals("authorityType wrong", "GROUP", authority.getString("authorityType"));
|
||||||
// {
|
}
|
||||||
// System.out.println("Get Child Users of Group B");
|
}
|
||||||
// Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=USER"), Status.STATUS_OK);
|
|
||||||
// JSONObject top = new JSONObject(response.getContentAsString());
|
/**
|
||||||
// System.out.println(response.getContentAsString());
|
* Get All Children of GROUP B which are USERS
|
||||||
// JSONArray data = top.getJSONArray("data");
|
*/
|
||||||
// //assertTrue(data.length() > 0);
|
{
|
||||||
// }
|
logger.debug("Get Child Users of Group B");
|
||||||
|
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=USER"), Status.STATUS_OK);
|
||||||
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
logger.debug(response.getContentAsString());
|
||||||
|
JSONArray data = top.getJSONArray("data");
|
||||||
|
assertTrue(data.length() > 0);
|
||||||
|
for(int i = 0; i < data.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject authority = data.getJSONObject(i);
|
||||||
|
assertEquals("authorityType wrong", "USER", authority.getString("authorityType"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test All Children of GROUP B, bad authorityType
|
* Negative test All Children of GROUP B, bad authorityType
|
||||||
@@ -374,14 +748,12 @@ public class GroupsTest extends BaseWebScriptTest
|
|||||||
{
|
{
|
||||||
sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST);
|
sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Negative test GROUP(Rubbish) does not exist
|
* Negative test GROUP(Rubbish) does not exist
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND);
|
sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user