diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl
index 6e514848a6..31d88392fb 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl
@@ -6,7 +6,22 @@
"shortName" : "${authority.shortName}",
"fullName" : "${authority.fullName}",
"displayName" : "${authority.displayName}",
+
+ <#-- Group specific properties -->
+ <#if authority.rootGroup??>"isRootGroup": ${authority.rootGroup?string("true", "false")}, #if>
+ <#if authority.adminGroup??>"isAdminGroup": ${authority.adminGroup?string("true", "false")}, #if>
+ <#if authority.internalGroup??>"isInternalGroup": ${authority.internalGroup?string("true", "false")}, #if>
+ <#if authority.groupCount??>"groupCount": ${authority.groupCount}, #if>
+ <#if authority.userCount??>"userCount": ${authority.userCount}, #if>
+ <#-- end of group specific properties -->
+
+ <#if authority.authorityType = "GROUP" >
"url" : "/api/groups/${authority.shortName}"
+ #if>
+
+ <#if authority.authorityType = "USER" >
+ "url" : "/api/people/${authority.shortName}"
+ #if>
}
#escape>
#macro>
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.desc.xml
index bd7c9d6835..2364001421 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.desc.xml
@@ -2,8 +2,8 @@
Get the list of child authorities for a group.
+ The authorityType parameter can be used to specify to return authorities of the given type. Valid values are GROUP and USER.
]]>
/api/groups/{shortName}/children?authorityType={authorityType?}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.js
index bbb4436636..88e0e6908f 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.js
@@ -1 +1,42 @@
-// get rootgroups
\ No newline at end of file
+// get children
+function main ()
+{
+
+ var urlElements = url.extension.split("/");
+ var shortName = urlElements[0];
+
+ var authorityType = args["authorityType"];
+
+ 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;
+ }
+
+ model.group = group;
+
+ if(authorityType != null)
+ {
+ if(!authorityType.match("[GROUP|USER]"))
+ {
+ status.setCode(status.STATUS_BAD_REQUEST, "The authorityType argument has does not have a correct value.");
+ return;
+ }
+ if(authorityType == "GROUP")
+ {
+ model.children = group.getChildGroups();
+ }
+ if(authorityType == "USER")
+ {
+ model.children = group.getChildUsers();
+ }
+ }
+ else
+ {
+ model.children = group.getAllChildren();
+ }
+}
+
+main();
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.json.ftl
index a418c831ce..b8883c64fd 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.get.json.ftl
@@ -1 +1,13 @@
-<#import "authority.lib.ftl" as authorityLib/>
\ No newline at end of file
+<#-- get children -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data": [
+
+ <#list children as wibble>
+ <@authorityLib.authorityJSON authority=wibble />
+ <#if wibble_has_next>,#if>
+ #list>
+
+ ]
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.desc.xml
index e0b4db89de..f544bc98a0 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.desc.xml
@@ -2,6 +2,9 @@
Add group or user to a group
+ you must have "administrator" privileges to add a group.
+
If the provided group does not exist then it is created.
]]>
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.js
index bbb4436636..b202c3074f 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.js
@@ -1 +1 @@
-// get rootgroups
\ No newline at end of file
+// post groups
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.json.ftl
index e69de29bb2..318e6c62ea 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.post.json.ftl
@@ -0,0 +1,13 @@
+<#-- post children -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data": [
+
+ <#list children as wibble>
+ <@authorityLib.authorityJSON authority=wibble />
+ <#if wibble_has_next>,#if>
+ #list>
+
+ ]
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.js
index bbb4436636..54325f8102 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.js
@@ -1 +1,21 @@
-// get rootgroups
\ No newline at end of file
+/**
+ * Get 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;
+ }
+
+ model.group = group;
+}
+
+main();
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.json.ftl
index e69de29bb2..8d896efb40 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.get.json.ftl
@@ -0,0 +1,6 @@
+<#-- Get Group -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data":<@authorityLib.authorityJSON authority=group />
+}
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.desc.xml
index cb504873db..97ccdf54d1 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.desc.xml
@@ -2,7 +2,9 @@
Update the details of a group
+ you must have "administrator" privileges to change the name of a group.
+
The follwong properties may be updated.
- displayName
- The display name
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.ftl
index e69de29bb2..95294f1782 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.ftl
@@ -0,0 +1,6 @@
+<#-- Update Group -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data":<@authorityLib.authorityJSON authority=group />
+}
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.desc.xml
index 32a529619b..222dab22d5 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.desc.xml
@@ -2,6 +2,9 @@
Delete a group.
+ You must have "administrator" privileges to delete a group.
+
]]>
/api/groups/{shortName}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.json.ftl
index e69de29bb2..725b6ba804 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.json.ftl
@@ -0,0 +1,6 @@
+<#-- Delete Group -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+
+}
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.js
index bbb4436636..b181d194dc 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.js
@@ -1 +1,22 @@
-// get rootgroups
\ No newline at end of file
+/**
+ * List/Search groups
+ */
+
+function main ()
+{
+ // Get the args
+ var shortNameFilter = args["shortNameFilter"];
+ var includeInternalStr = args["includeInternal"];
+
+ if(shortNameFilter == null)
+ {
+ shortNameFilter = "";
+ }
+
+ var includeInternal = includeInternalStr == "true" ? true : false;
+
+ // Do the search
+ model.groups = groups.searchGroups(shortNameFilter, includeInternal);
+}
+
+main();
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.json.ftl
index e69de29bb2..cf056f7a61 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.get.json.ftl
@@ -0,0 +1,11 @@
+<#-- list / search / groups -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data": [
+ <#list groups as group>
+ <@authorityLib.authorityJSON authority=group />
+ <#if group_has_next>,#if>
+ #list>
+ ]
+}
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.desc.xml
index b2ca586cd2..ef615a7951 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.desc.xml
@@ -2,8 +2,8 @@
Get the list of child authorities for a group.
+ The optional level attribute can be "ALL" in which case all parents are returned.
]]>
/api/groups/{shortName}/parents?level={level?}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.js
index bbb4436636..93c6af56e8 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.js
@@ -1 +1,37 @@
-// get rootgroups
\ No newline at end of file
+// get parents
+function main ()
+{
+
+ var urlElements = url.extension.split("/");
+ var shortName = urlElements[0];
+
+ var level = args["level"];
+
+
+
+ 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;
+ }
+
+ model.group = group;
+
+ if(level != null)
+ {
+ if(!level.match("[ALL]"))
+ {
+ status.setCode(status.STATUS_BAD_REQUEST, "The level argument has does not have a correct value.");
+ return;
+ }
+ model.parents = group.getAllParentGroups();
+ }
+ else
+ {
+ model.parents = group.getParentGroups();
+ }
+}
+
+main();
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.json.ftl
index a418c831ce..51930c974f 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/parent.get.json.ftl
@@ -1 +1,11 @@
-<#import "authority.lib.ftl" as authorityLib/>
\ No newline at end of file
+<#-- get parents -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data": [
+ <#list parents as thegroup>
+ <@authorityLib.authorityJSON authority=thegroup />
+ <#if thegroup_has_next>,#if>
+ #list>
+ ]
+}
\ No newline at end of file
diff --git a/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
index 4217649bff..66d212470e 100644
--- a/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
@@ -40,6 +40,8 @@ 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.AuthorityService;
+import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
@@ -57,16 +59,24 @@ import org.json.JSONArray;
import org.json.JSONObject;
/**
- * Unit test of Groups REST APIs.
+ * Unit test of Groups REST APIs. /api/groups
*
* @author Mark Rogers
*/
public class GroupsTest extends BaseWebScriptTest
{
private AuthenticationService authenticationService;
+ private AuthorityService authorityService;
private AuthenticationComponent authenticationComponent;
private PersonService personService;
- private NodeService nodeService;
+
+ private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS";
+ private String TEST_ROOTGROUP = "GROUPS_TESTROOT";
+ private String TEST_GROUPA = "TestA";
+ private String TEST_GROUPB = "TESTB";
+ private String TEST_GROUPC = "TesTC";
+ private String TEST_GROUPD = "TESTD";
+ private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName";
private static final String USER_ONE = "GroupTestOne";
private static final String USER_TWO = "GroupTestTwo";
@@ -75,6 +85,19 @@ public class GroupsTest extends BaseWebScriptTest
private static final String URL_GROUPS = "/api/groups";
private static final String URL_ROOTGROUPS = "/api/rootgroups";
+ /**
+ * Test Tree for all group tests
+ *
+ * TEST_ROOTGROUP
+ * GROUPA
+ * GROUPB
+ * GROUPD
+ * USER_TWO
+ * USER_THREE
+ * GROUPC
+ * USER_TWO
+ */
+
@Override
protected void setUp() throws Exception
{
@@ -83,7 +106,7 @@ public class GroupsTest extends BaseWebScriptTest
this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
- this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
+ this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService");
this.authenticationComponent.setSystemUserAsCurrentUser();
@@ -92,8 +115,21 @@ public class GroupsTest extends BaseWebScriptTest
createUser(USER_TWO);
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
this.authenticationComponent.setCurrentUser(USER_ONE);
+
+ Thread.sleep(10);
}
private void createUser(String userName)
@@ -127,21 +163,72 @@ public class GroupsTest extends BaseWebScriptTest
public void testGetRootGroup() throws Exception
{
/**
- * Get all root groups
+ * Get all root groups should be at least the ALFRESCO_ADMINISTRATORS groups
*/
{
- Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), 200);
+ Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
System.out.println(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
+ assertTrue(data.length() > 0);
+
+ for(int i = 0; i < data.length(); i++)
+ {
+ JSONObject rootGroup = data.getJSONObject(i);
+ if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP))
+ {
+ // This is our test rootgroup
+ assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName"));
+ assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName"));
+ assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType"));
+ assertFalse("test rootgroup is admin group", rootGroup.getBoolean("isAdminGroup"));
+ }
+ if(rootGroup.getString("shortName").equals(ADMIN_GROUP))
+ {
+ //assertTrue("admin group is not admin group", rootGroup.getBoolean("isAdminGroup"));
+ }
+ }
}
-
}
/**
* Detailed test of get group
*/
- public void testGetGroup()
+ public void testGetGroup() throws Exception
+ {
+ {
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONObject data = top.getJSONObject("data");
+ assertTrue(data.length() > 0);
+ //assertTrue("admin group is not admin group", data.getBoolean("isAdminGroup"));
+ assertTrue("admin group is not root group", data.getBoolean("isRootGroup"));
+ }
+
+ {
+ sendRequest(new GetRequest(URL_GROUPS + "/" + "crap"), Status.STATUS_NOT_FOUND);
+ }
+
+ /**
+ * Get GROUP B
+ */
+ {
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONObject data = top.getJSONObject("data");
+ assertTrue(data.length() > 0);
+ assertFalse("group B is not admin group", data.getBoolean("isAdminGroup"));
+ assertFalse("group B is not root group", data.getBoolean("isRootGroup"));
+ }
+
+ }
+
+ /**
+ * Detailed test of create root group
+ */
+ public void testCreateRootGroup() throws Exception
{
}
@@ -149,18 +236,152 @@ public class GroupsTest extends BaseWebScriptTest
/**
* Detailed test of create group
*/
- public void testCreateGroup()
+ public void testCreateGroup() throws Exception
{
}
/**
* Detailed test of search groups
+ *
if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.
+ If the optional shortNameFilter parameter is set then returns those root groups with a partial match on shortName.
*/
- public void testSearchGroups()
+ public void testSearchGroups() throws Exception
{
+ // Search on partial short name
+ {
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "*ADMIN*"), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ assertTrue(data.length() > 0);
+ }
+
+ // Search on full shortName
+ {
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ assertTrue(data.length() > 0);
+ }
}
-
+ /**
+ * Detailed test of get Parents
+ */
+ public void testGetParents() throws Exception
+ {
+ /**
+ * 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);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ // Top level group has no parents
+ assertTrue("top level group has no parents", data.length() == 0);
+ }
+
+ /**synetics
+ *
+ * Get GROUP B Which should be a child of TESTROOT
+ */
+ {
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ assertTrue(data.length() > 0);
+ }
+
+ /**
+ * Get GROUP D Which should be a child of GROUPB child of TESTROOT
+ */
+ {
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ assertTrue(data.length() >= 2);
+ }
+ /**
+ * Negative test Get GROUP D level="rubbish"
+ */
+ {
+ sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=rubbish"), Status.STATUS_BAD_REQUEST);
+ }
+
+ /**
+ * Negative test GROUP(Rubbish) does not exist
+ */
+ {
+ sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/parents?level=all"), Status.STATUS_NOT_FOUND);
+
+ }
+ }
+
+ /**
+ * Detailed test of get Children
+ */
+ public void testGetChildren() throws Exception
+ {
+ /**
+ * Get All Children of GROUP B
+ */
+ {
+ System.out.println("Get children of GROUP B");
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ //assertTrue(data.length() > 0);
+ }
+
+ /**
+ * Get All Children of GROUP B which are GROUPS
+ */
+ {
+ System.out.println("Get child GROUPS of GROUP B");
+ Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ JSONArray data = top.getJSONArray("data");
+ assertTrue(data.length() == 1);
+
+ JSONObject subGroup = data.getJSONObject(0);
+ assertEquals("shortName wrong", TEST_GROUPD, subGroup.getString("shortName"));
+ assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType"));
+ }
+
+ /**
+ * Get All Children of GROUP B which are USERS
+ */
+ {
+ 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());
+ JSONArray data = top.getJSONArray("data");
+ //assertTrue(data.length() > 0);
+ }
+
+ /**
+ * Negative test All Children of GROUP B, bad authorityType
+ */
+ {
+ sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST);
+ }
+
+
+ /**
+ * Negative test GROUP(Rubbish) does not exist
+ */
+ {
+ sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND);
+ }
+
+ }
}