Skip to content

Commit

Permalink
Merge pull request #2035 from Alfresco/feature/ACS-5506-be-handling-a…
Browse files Browse the repository at this point in the history
…-description-of-the-group-and-flag-for-subgroups

ACS-5506 Add description and hasSubgroups to groups API
  • Loading branch information
MichalKinas authored Feb 8, 2024
2 parents 448d2c9 + f737c3e commit 3d1cc09
Show file tree
Hide file tree
Showing 14 changed files with 509 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
package org.alfresco.rest.model;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand All @@ -38,13 +38,17 @@ public class RestGroupsModel extends TestModel implements IRestModel<RestGroupsM
private String id;
@JsonProperty(required = true)
private String displayName;
@JsonProperty()
private String description;
@JsonProperty(required = true)
private Boolean isRoot;
@JsonProperty()
private Boolean hasSubgroups;

@JsonProperty("parentIds")
private ArrayList<String> parentIds;
private List<String> parentIds;
@JsonProperty("zones")
private ArrayList<String> zones;
private List<String> zones;

@JsonProperty(value = "entry")
RestGroupsModel model;
Expand Down Expand Up @@ -75,6 +79,22 @@ public void setDisplayName(String displayName)
this.displayName = displayName;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Boolean getHasSubgroups() {
return hasSubgroups;
}

public void setHasSubgroups(Boolean hasSubgroups) {
this.hasSubgroups = hasSubgroups;
}

public Boolean getIsRoot()
{
return isRoot;
Expand All @@ -85,22 +105,22 @@ public void setIsRoot(Boolean isRoot)
this.isRoot = isRoot;
}

public ArrayList<String> getParentIds()
public List<String> getParentIds()
{
return parentIds;
}

public void setParentIds(ArrayList<String> parentIds)
public void setParentIds(List<String> parentIds)
{
this.parentIds = parentIds;
}

public ArrayList<String> getZones()
public List<String> getZones()
{
return zones;
}

public void setZones(ArrayList<String> zones)
public void setZones(List<String> zones)
{
this.zones = zones;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,73 @@ public void dataPreparation() throws Exception
@Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY })
@TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY,
description = "Verify creation, listing, updating and deletion of groups.")
public void createListUpdateAndDeleteGroup() throws Exception
public void createListUpdateAndDeleteGroup()
{
String groupName = "ZtestGroup" + UUID.randomUUID().toString();
JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build();
String groupName = "ZtestGroup" + UUID.randomUUID();
String subGroupName = "ZtestSubgroup" + UUID.randomUUID();
String groupDescription = "ZtestGroup description" + UUID.randomUUID();
JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).add("description", groupDescription).build();
JsonObject subgroupBody = Json.createObjectBuilder().add("id", subGroupName).add("displayName", subGroupName).build();
String groupBodyCreate = groupBody.toString();
String subgroupBodyCreate = subgroupBody.toString();

//GroupCreation:
//-ve
restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroup(groupBodyCreate);
restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN);
//+ve
restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate)
restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones,hasSubgroups,description").usingGroups().createGroup(groupBodyCreate)
.assertThat().field("zones").contains("APP.DEFAULT")
.and().field("isRoot").is(true)
.and().field("displayName").is(groupName);
.and().field("displayName").is(groupName)
.and().field("description").is(groupDescription)
.and().field("hasSubgroups").is(false);
restClient.assertStatusCodeIs(HttpStatus.CREATED);

//AddChildGroup
restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(subgroupBodyCreate);
restClient.assertStatusCodeIs(HttpStatus.CREATED);

//LinkChildGroupToParent
JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build();
String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString();
restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate);
restClient.assertStatusCodeIs(HttpStatus.CREATED);

//ListGroups:
restClient.withCoreAPI().usingParams("orderBy=displayName DESC&maxItems=10").usingGroups().listGroups()
.assertThat().entriesListContains("id", "GROUP_"+groupName)
.and().entriesListContains("id", "GROUP_"+subGroupName)
.and().entriesListDoesNotContain("zones")
.and().paginationField("maxItems").is("10");
restClient.assertStatusCodeIs(HttpStatus.OK);

groupBody = Json.createObjectBuilder().add("displayName", "Z"+groupName).build();
groupBody = Json.createObjectBuilder().add("displayName", "Z"+groupName).add("description", "Z"+groupDescription).build();
String groupBodyUpdate = groupBody.toString();
//UpdateGroup:
restClient.withCoreAPI().usingGroups().updateGroupDetails("GROUP_"+groupName, groupBodyUpdate)
restClient.withCoreAPI().usingParams("include=description").usingGroups().updateGroupDetails("GROUP_"+groupName, groupBodyUpdate)
.assertThat().field("displayName").is("Z"+groupName)
.and().field("description").is("Z"+groupDescription)
.and().field("id").is("GROUP_"+groupName)
.and().field("zones").isNull();
restClient.assertStatusCodeIs(HttpStatus.OK);

//GetGroupDetails:
restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName)
restClient.withCoreAPI().usingParams("include=zones,hasSubgroups").usingGroups().getGroupDetail("GROUP_"+groupName)
.assertThat().field("id").is("GROUP_"+groupName)
.and().field("zones").contains("APP.DEFAULT")
.and().field("isRoot").is(true);
.and().field("isRoot").is(true)
.and().field("hasSubgroups").is(true);
restClient.assertStatusCodeIs(HttpStatus.OK);

//DeleteChildGroup:
restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().deleteGroup("GROUP_"+subGroupName);
restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT);

//VerifyIfParentHasNoSubgroups:
restClient.withCoreAPI().usingParams("include=zones,hasSubgroups").usingGroups().getGroupDetail("GROUP_"+groupName)
.assertThat().field("id").is("GROUP_"+groupName)
.and().field("hasSubgroups").is(false);
restClient.assertStatusCodeIs(HttpStatus.OK);

//DeleteGroup:
Expand All @@ -83,9 +112,9 @@ public void createListUpdateAndDeleteGroup() throws Exception
@Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY })
@TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY,
description = "Verify creation, listing(only for person) and deletion of group memberships. ")
public void createListDeleteGroupMembership() throws Exception
public void createListDeleteGroupMembership()
{
String groupName = "ZtestGroup" + UUID.randomUUID().toString();
String groupName = "ZtestGroup" + UUID.randomUUID();
JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build();
String groupBodyCreate = groupBody.toString();

Expand All @@ -95,6 +124,7 @@ public void createListDeleteGroupMembership() throws Exception

JsonObject groupMembershipBody = Json.createObjectBuilder().add("id", userModel.getUsername()).add("memberType", "PERSON").build();
String groupMembershipBodyCreate = groupMembershipBody.toString();

//MembershipCreation:
//-ve
restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate);
Expand Down Expand Up @@ -127,7 +157,7 @@ public void createListDeleteGroupMembership() throws Exception
description = "Verify listing of group memberships.")
public void listGroupMembership() throws Exception
{
String groupName = "testGroup" + UUID.randomUUID().toString();
String groupName = "testGroup" + UUID.randomUUID();
JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build();
String groupBodyCreate = groupBody.toString();

Expand All @@ -146,12 +176,10 @@ public void listGroupMembership() throws Exception
restClient.assertStatusCodeIs(HttpStatus.CREATED);

//ListGroupMembership
RetryOperation op = new RetryOperation(){
public void execute() throws Exception{
restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName)
.assertThat().entriesListContains("id", userModel.getUsername());
restClient.assertStatusCodeIs(HttpStatus.OK);
}
RetryOperation op = () -> {
restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName)
.assertThat().entriesListContains("id", userModel.getUsername());
restClient.assertStatusCodeIs(HttpStatus.OK);
};
Utility.sleep(500, 35000, op);// Allow indexing to complete.
}
Expand Down
2 changes: 2 additions & 0 deletions remote-api/src/main/java/org/alfresco/rest/api/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public interface Groups
{
String PARAM_ID = "id";
String PARAM_DISPLAY_NAME = "displayName";
String PARAM_INCLUDE_DESCRIPTION = "description";
String PARAM_INCLUDE_PARENT_IDS = "parentIds";
String PARAM_INCLUDE_ZONES = "zones";
String PARAM_INCLUDE_HAS_SUBGROUPS = "hasSubgroups";
String PARAM_IS_ROOT = "isRoot";
String PARAM_CASCADE = "cascade";
String PARAM_MEMBER_TYPE = "memberType";
Expand Down
Loading

0 comments on commit 3d1cc09

Please sign in to comment.