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:
Mark Rogers
2009-04-14 17:13:47 +00:00
parent 2e1bb8dece
commit 4c99493d79
18 changed files with 702 additions and 102 deletions

View File

@@ -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
*<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
{
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);
}
}
}