diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.desc.xml
new file mode 100644
index 0000000000..12c95c5742
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.desc.xml
@@ -0,0 +1,15 @@
+
+ Remove an authority from a group.
+
+ You must have "administrator" privileges to alter a group.
+
+ ]]>
+
+ /api/groups/{shortGroupName}/children/{fullAuthorityName}
+ argument
+ user
+ required
+ draft_public_api
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.js
new file mode 100644
index 0000000000..6dbe2a20d6
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.js
@@ -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();
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.json.ftl
new file mode 100644
index 0000000000..ff8aa9e65a
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/children.delete.json.ftl
@@ -0,0 +1,6 @@
+<#-- Remove Group -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+
+}
\ No newline at end of file
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 88e0e6908f..8654745dda 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
@@ -35,7 +35,7 @@ function main ()
}
else
{
- model.children = group.getAllChildren();
+ model.children = group.getChildAuthorities();
}
}
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 f544bc98a0..50ad47c642 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
@@ -1,15 +1,15 @@
Add group or user to a group
- you must have "administrator" privileges to add a group.
-
+ Add a group or user to a group. Will create a sub group if one does not already exist with the fullAuthorityName.
- If the provided group does not exist then it is created.
+
You must have "administrator" privileges to modify groups.
+
If the authority is for a group and doe not exist then it is created.
+
Returns Status_Created if a new group is created, else Status_OK.
+ If Status_Created returns the new sub group, else returns the group.
]]>
- /api/groups/{shortName}/children
+ /api/groups/{shortName}/children/{fullAuthorityName}
argument
user
required
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 b202c3074f..02988e4671 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,46 @@
-// post groups
\ No newline at end of file
+/**
+ * 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();
\ 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 318e6c62ea..a12129ba84 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
@@ -1,13 +1,13 @@
-<#-- post children -->
+<#-- post children - add group or user to a group -->
<#import "authority.lib.ftl" as authorityLib/>
+
{
- "data": [
-
- <#list children as wibble>
- <@authorityLib.authorityJSON authority=wibble />
- <#if wibble_has_next>,#if>
- #list>
-
- ]
+ <#if group??>
+ "data": <@authorityLib.authorityJSON authority=group />
+ <#else>
+ "data" : { }
+ #if>
}
+
+
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 97ccdf54d1..02bdff01d8 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
@@ -5,7 +5,7 @@
you must have "administrator" privileges to change the name of a group.
- The follwong properties may be updated.
+ The following properties may be updated.
- displayName
- The display name
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.js
deleted file mode 100644
index bbb4436636..0000000000
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.js
+++ /dev/null
@@ -1 +0,0 @@
-// get rootgroups
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.js
new file mode 100644
index 0000000000..64ad2f3866
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/group.put.json.js
@@ -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();
+
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.js
index bbb4436636..8d49b14bcd 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/groups.delete.js
@@ -1 +1,21 @@
-// get rootgroups
\ No newline at end of file
+// 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();
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.desc.xml
new file mode 100644
index 0000000000..6f50936c20
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.desc.xml
@@ -0,0 +1,15 @@
+
+ Delete a root group.
+
+ You must have "administrator" privileges to delete a group.
+
+ ]]>
+
+ /api/rootgroups/{shortName}
+ argument
+ user
+ required
+ draft_public_api
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.js
new file mode 100644
index 0000000000..8d49b14bcd
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.js
@@ -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();
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.delete.json.ftl
new file mode 100644
index 0000000000..725b6ba804
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.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/rootgroups.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.desc.xml
new file mode 100644
index 0000000000..4502290954
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.desc.xml
@@ -0,0 +1,20 @@
+
+ Add a rootgroup
+ You must have "administrator" privileges to add a root group.
+
Returns STATUS_CREATED if a new group is created.
+
If the group already exists returns BAD_REQUEST.
+
+ The following properties may be specified for the new root group.
+
+ - displayName
- The display name
+
+ ]]>
+
+ /api/rootgroups/{shortName}
+ argument
+ user
+ required
+ draft_public_api
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.json.ftl
new file mode 100644
index 0000000000..f568491533
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.json.ftl
@@ -0,0 +1,6 @@
+<#-- create root group -->
+
+<#import "authority.lib.ftl" as authorityLib/>
+{
+ "data":<@authorityLib.authorityJSON authority=group />
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.json.js
new file mode 100644
index 0000000000..e0f1352368
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.post.json.js
@@ -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();
\ 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 c87707c06e..48bf4373b9 100644
--- a/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java
@@ -24,30 +24,16 @@
*/
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.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
-import org.alfresco.repo.site.SiteModel;
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;
-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.web.scripts.Status;
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.PutRequest;
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.JSONObject;
/**
- * Unit test of Groups REST APIs. /api/groups
+ * Unit test of Groups REST APIs.
+ *
+ * /api/groups
+ * /api/rootgroups
*
* @author Mark Rogers
*/
public class GroupsTest extends BaseWebScriptTest
{
+ private static final Log logger = LogFactory.getLog(BaseWebScriptTest.class);
+
private AuthenticationService authenticationService;
private AuthorityService authorityService;
private AuthenticationComponent authenticationComponent;
private PersonService personService;
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_GROUPB = "TESTB";
private String TEST_GROUPC = "TesTC";
private String TEST_GROUPD = "TESTD";
+ private String TEST_LINK = "TESTLINK";
private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName";
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_ROOTGROUPS = "/api/rootgroups";
-
+
/**
* Test Tree for all group tests
*
@@ -96,8 +90,39 @@ public class GroupsTest extends BaseWebScriptTest
* USER_THREE
* GROUPC
* 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
protected void setUp() throws Exception
{
@@ -115,21 +140,8 @@ 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)
@@ -154,21 +166,24 @@ public class GroupsTest extends BaseWebScriptTest
{
super.tearDown();
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
-
+ //if(rootGroupName != null)
+ //{
+ // authorityService.deleteAuthority(rootGroupName);
+ //}
}
/**
* Detailed test of get root groups
*/
public void testGetRootGroup() throws Exception
- {
+ {
/**
* Get all root groups should be at least the ALFRESCO_ADMINISTRATORS groups
*/
{
Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK);
JSONObject top = new JSONObject(response.getContentAsString());
- System.out.println(response.getContentAsString());
+ logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertTrue(data.length() > 0);
@@ -196,10 +211,12 @@ public class GroupsTest extends BaseWebScriptTest
*/
public void testGetGroup() throws Exception
{
+ createTestTree();
+
{
Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200);
JSONObject top = new JSONObject(response.getContentAsString());
- System.out.println(response.getContentAsString());
+ logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertTrue(data.length() > 0);
//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);
JSONObject top = new JSONObject(response.getContentAsString());
- System.out.println(response.getContentAsString());
+ logger.debug(response.getContentAsString());
JSONObject data = top.getJSONObject("data");
assertTrue(data.length() > 0);
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 delete root group
*/
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
*if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.
@@ -248,11 +567,13 @@ public class GroupsTest extends BaseWebScriptTest
*/
public void testSearchGroups() throws Exception
{
+ createTestTree();
+
// 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());
+ logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
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);
JSONObject top = new JSONObject(response.getContentAsString());
- System.out.println(response.getContentAsString());
+ logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
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
{
+ createTestTree();
+
/**
* 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());
+ logger.debug(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());
+ logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
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);
JSONObject top = new JSONObject(response.getContentAsString());
- System.out.println(response.getContentAsString());
+ logger.debug(response.getContentAsString());
JSONArray data = top.getJSONArray("data");
assertTrue(data.length() >= 2);
}
@@ -328,45 +662,85 @@ public class GroupsTest extends BaseWebScriptTest
*/
public void testGetChildren() throws Exception
{
+ createTestTree();
+
+ //Thread.sleep(10,000);
+
/**
* 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);
JSONObject top = new JSONObject(response.getContentAsString());
- System.out.println(response.getContentAsString());
+ logger.debug(response.getContentAsString());
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
-// */
-// {
-// 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("no child groups of group B", 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);
-// }
+ /**
+ * Get All Children of GROUP B which are GROUPS
+ */
+ {
+ logger.debug("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());
+ logger.debug(response.getContentAsString());
+ System.out.println(response.getContentAsString());
+ 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"));
+ assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType"));
+ for(int i = 0; i < data.length(); i++)
+ {
+ JSONObject authority = data.getJSONObject(i);
+ assertEquals("authorityType wrong", "GROUP", authority.getString("authorityType"));
+ }
+ }
+
+ /**
+ * Get All Children of GROUP B which are USERS
+ */
+ {
+ 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
@@ -374,14 +748,12 @@ public class GroupsTest extends BaseWebScriptTest
{
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);
}
-
}
}