Replace invite and subscribe to add member, remove unsubscribe (#764).
Change-Id: I07f3ff872c19a0246d49c402f4359f8ea24b843f
diff --git a/Changes b/Changes
index 00bcacb..85d9ba2 100644
--- a/Changes
+++ b/Changes
@@ -10,6 +10,11 @@
- Remove soft delete group and group status deleted (#765)
- Remove soft delete group member and member status deleted (#765)
- Removed SearchResourceFilters and UserGroupJson
+- Removed deleted_by from user_group and user_group_member tables (#764)
+- Removed created_by, status and status_date from user_group_member table (#764)
+- Removed GroupMemberStatus (#764)
+- Replace invite and subscribe to add member (#764)
+- Remove unsubscribe member (#764)
# version 0.74
diff --git a/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java b/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
index fedd573..5026b6e 100644
--- a/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
+++ b/src/main/java/de/ids_mannheim/korap/service/UserGroupService.java
@@ -15,7 +15,6 @@
import org.springframework.stereotype.Service;
import de.ids_mannheim.korap.config.FullConfiguration;
-import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
import de.ids_mannheim.korap.constant.PrivilegeType;
import de.ids_mannheim.korap.constant.UserGroupStatus;
@@ -306,11 +305,12 @@
* the status of the membership
* @throws KustvaktException
*/
+ @Deprecated
public void inviteGroupMember (String username, UserGroup userGroup,
String createdBy)
throws KustvaktException {
- addGroupMember(username, userGroup, createdBy);
+ addGroupMember(username, userGroup, createdBy,null);
if (config.isMailEnabled()
&& userGroup.getStatus() != UserGroupStatus.HIDDEN) {
@@ -320,41 +320,45 @@
}
public void addGroupMember (String username, UserGroup userGroup,
- String createdBy)
- throws KustvaktException {
- addGroupMember(username, userGroup, createdBy, null);
- }
-
- public void addGroupMember (String username, UserGroup userGroup,
String createdBy, Set<Role> roles)
throws KustvaktException {
- int groupId = userGroup.getId();
- ParameterChecker.checkIntegerValue(groupId, "userGroupId");
-
- UserGroupMember member = new UserGroupMember();
- member.setGroup(userGroup);
- member.setUserId(username);
- if (roles !=null) {
- member.setRoles(roles);
+
+ if (!isMember(username, userGroup)) {
+ int groupId = userGroup.getId();
+ ParameterChecker.checkIntegerValue(groupId, "userGroupId");
+
+ UserGroupMember member = new UserGroupMember();
+ member.setGroup(userGroup);
+ member.setUserId(username);
+ if (roles !=null) {
+ member.setRoles(roles);
+ }
+ groupMemberDao.addMember(member);
}
- groupMemberDao.addMember(member);
+ else {
+ throw new KustvaktException(StatusCodes.GROUP_MEMBER_EXISTS,
+ "Username: "+username+" exists in the user-group: "+
+ userGroup.getName(), username, userGroup.getName());
+ }
}
- public void inviteGroupMembers (String groupName, String groupMembers,
- String inviter) throws KustvaktException {
+ public void addGroupMembers (String groupName, String groupMembers,
+ String username) throws KustvaktException {
String[] members = groupMembers.split(",");
ParameterChecker.checkStringValue(groupName, "group name");
ParameterChecker.checkStringValue(groupMembers, "members");
UserGroup userGroup = retrieveUserGroupByName(groupName);
- if (isUserGroupAdmin(inviter, userGroup) || adminDao.isAdmin(inviter)) {
+ if (isUserGroupAdmin(username, userGroup)
+ || adminDao.isAdmin(username)) {
+ Set<Role> memberRoles = prepareMemberRoles(userGroup);
for (String memberName : members) {
- inviteGroupMember(memberName, userGroup, inviter);
+ addGroupMember(memberName, userGroup, username,memberRoles);
}
}
else {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
- "Unauthorized operation for user: " + inviter, inviter);
+ "Unauthorized operation for user: " + username, username);
}
}
@@ -396,6 +400,7 @@
* the username of the group member
* @throws KustvaktException
*/
+ @Deprecated
public void acceptInvitation (String groupName, String username)
throws KustvaktException {
@@ -418,9 +423,9 @@
//
// if (expiration.isAfter(now)) {
// member.setStatus(GroupMemberStatus.ACTIVE);
-// Set<Role> memberRoles = prepareMemberRoles(userGroup);
-// member.setRoles(memberRoles);
-// groupMemberDao.updateMember(member);
+ Set<Role> memberRoles = prepareMemberRoles(userGroup);
+ member.setRoles(memberRoles);
+ groupMemberDao.updateMember(member);
// }
// else {
// throw new KustvaktException(StatusCodes.INVITATION_EXPIRED);
diff --git a/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java b/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java
index 33db5f6..c0325b8 100644
--- a/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java
+++ b/src/main/java/de/ids_mannheim/korap/web/controller/UserGroupController.java
@@ -201,10 +201,10 @@
* usernames separated by comma
* @return if successful, HTTP response status OK
*/
- @POST
- @Path("@{groupName}/invite")
+ @PUT
+ @Path("@{groupName}/member")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- public Response inviteGroupMembers (
+ public Response addGroupMembers (
@Context SecurityContext securityContext,
@PathParam("groupName") String groupName,
@FormParam("members") String members) {
@@ -213,8 +213,7 @@
try {
scopeService.verifyScope(context,
OAuth2Scope.ADD_USER_GROUP_MEMBER);
- service.inviteGroupMembers(groupName, members,
- context.getUsername());
+ service.addGroupMembers(groupName, members, context.getUsername());
return Response.ok("SUCCESS").build();
}
catch (KustvaktException e) {
@@ -295,6 +294,7 @@
* a group name
* @return if successful, HTTP response status OK
*/
+ @Deprecated
@POST
@Path("@{groupName}/subscribe")
public Response subscribeToGroup (@Context SecurityContext securityContext,
@@ -323,6 +323,7 @@
* @param groupName
* @return if successful, HTTP response status OK
*/
+ @Deprecated
@DELETE
@Path("@{groupName}/unsubscribe")
public Response unsubscribeFromGroup (
diff --git a/src/test/java/de/ids_mannheim/korap/dao/DaoTestBase.java b/src/test/java/de/ids_mannheim/korap/dao/DaoTestBase.java
index 019ecda..d282c17 100644
--- a/src/test/java/de/ids_mannheim/korap/dao/DaoTestBase.java
+++ b/src/test/java/de/ids_mannheim/korap/dao/DaoTestBase.java
@@ -34,8 +34,8 @@
protected UserGroup createDoryGroup () throws KustvaktException {
UserGroup group = createUserGroup("dory-group", "dory");
- userGroupService.addGroupMember("nemo", group, "dory");
- userGroupService.addGroupMember("marlin", group, "dory");
+ userGroupService.addGroupMember("nemo", group, "dory",null);
+ userGroupService.addGroupMember("marlin", group, "dory",null);
return group;
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
index d8dff83..4f0f2cc 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
@@ -50,8 +50,7 @@
createDoryGroup();
createMarlinGroup();
- inviteMember(marlinGroupName, "marlin", "dory");
- subscribe(marlinGroupName, "dory");
+ addMember(marlinGroupName, "dory", "marlin");
// test list user group
response = target().path(API_VERSION).path("group").request()
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
index 27c8512..3a0c7c4 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
@@ -2,22 +2,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.net.URI;
-
-import jakarta.ws.rs.ProcessingException;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.Response.Status;
-
import org.junit.jupiter.api.Test;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.util.UriComponentsBuilder;
+
import com.fasterxml.jackson.databind.JsonNode;
+
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.oauth2.constant.OAuth2ClientType;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.input.OAuth2ClientJson;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.core.Response.Status;
public class UserControllerTest extends OAuth2TestBase {
@@ -40,7 +36,7 @@
}
private String registerClient ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
OAuth2ClientJson clientJson = createOAuth2Client();
Response response = registerClient(username, clientJson);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
@@ -63,7 +59,7 @@
}
@Test
- public void getUsername () throws ProcessingException, KustvaktException {
+ public void getUsername () throws KustvaktException {
String clientId = registerClient();
String accessToken = requestOAuth2AccessToken(clientId);
Response response = target().path(API_VERSION).path("user").path("info")
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java
index 7cedc2b..13fa68a 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerAdminTest.java
@@ -14,7 +14,6 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.service.UserGroupService;
import de.ids_mannheim.korap.utils.JsonUtils;
-import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.MediaType;
@@ -29,7 +28,7 @@
private String testUser = "group-admin";
private JsonNode listGroup (String username)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("group").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(testUser, "pass"))
@@ -45,13 +44,11 @@
createDoryGroup();
createMarlinGroup();
- inviteMember(marlinGroupName, "marlin", "dory");
- subscribe(marlinGroupName, "dory");
+ addMember(marlinGroupName, "dory", "marlin");
String testGroup = "test-group";
createUserGroup("test-group", "Test group to be deleted.", "marlin");
- inviteMember(testGroup, "marlin", "dory");
- subscribe(testGroup, "dory");
+ addMember(testGroup, "dory", "marlin");
deleteGroupByName("test-group", "marlin");
@@ -138,7 +135,7 @@
// same as list user-groups of the admin
@Test
public void testListWithoutUsername ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("group").request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
@@ -152,7 +149,7 @@
@Test
public void testListByStatusAll ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("admin")
.path("group").path("list").request()
.header(Attributes.AUTHORIZATION,
@@ -176,14 +173,14 @@
@Test
public void testListHiddenGroups ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
JsonNode node = listHiddenGroup();
assertEquals(1, node.size());
}
@Test
public void testUserGroupAdmin ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
String groupName = "admin-test-group";
Response response = createUserGroup(groupName, "test group", testUser);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -192,8 +189,7 @@
assertEquals(1, node.size());
node = node.get(0);
assertEquals(groupName, node.get("name").asText());
- testInviteMember(groupName);
- subscribe(groupName, "marlin");
+ testAddMember(groupName);
testAddAdminRole(groupName, "marlin");
testDeleteMemberRoles(groupName, "marlin");
testDeleteMember(groupName);
@@ -207,7 +203,7 @@
private void testAddAdminRole (String groupName, String memberUsername)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = addAdminRole(groupName, memberUsername, admin);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -223,7 +219,7 @@
}
private void testDeleteMemberRoles (String groupName, String memberUsername)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Form form = new Form();
form.param("memberUsername", memberUsername);
// USER_GROUP_ADMIN
@@ -248,7 +244,7 @@
}
private JsonNode retrieveGroup (String groupName)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("admin")
.path("group").path("@" + groupName).request()
.header(Attributes.AUTHORIZATION,
@@ -263,7 +259,7 @@
}
private void testDeleteMember (String groupName)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
// delete marlin from group
Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).path("~marlin").request()
@@ -280,24 +276,23 @@
assertEquals(node.at("/members/1/userId").asText(), "nemo");
}
- private void testInviteMember (String groupName)
- throws ProcessingException, KustvaktException {
+ private void testAddMember (String groupName)
+ throws KustvaktException {
Form form = new Form();
form.param("members", "marlin,nemo,darla");
Response response = target().path(API_VERSION).path("group")
- .path("@" + groupName).path("invite").request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .path("@" + groupName).path("member").request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(
admin, "pass"))
- .post(Entity.form(form));
+ .put(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list group
JsonNode node = listGroup(testUser);
node = node.get(0);
assertEquals(4, node.get("members").size());
assertEquals(node.at("/members/3/userId").asText(), "darla");
- assertEquals(0, node.at("/members/1/privileges").size());
+ assertEquals(1, node.at("/members/1/privileges").size());
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
index 673fbfc..919c3c0 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupControllerTest.java
@@ -12,7 +12,6 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
-import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.Response;
@@ -27,7 +26,7 @@
@Test
public void testCreateGroupEmptyDescription ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
String groupName = "empty_group";
Response response = createUserGroup(groupName, "", username);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -36,7 +35,7 @@
@Test
public void testCreateGroupMissingDescription ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
String groupName = "missing-desc-group";
Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -44,7 +43,7 @@
}
private Response testCreateGroupWithoutDescription (String groupName)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("group")
.path("@" + groupName).request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -56,7 +55,7 @@
@Test
public void testCreateGroupInvalidName ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
String groupName = "invalid-group-name$";
Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -70,7 +69,7 @@
@Test
public void testCreateGroupNameTooShort ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
String groupName = "a";
Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -83,7 +82,7 @@
}
@Test
- public void testUserGroup () throws ProcessingException, KustvaktException {
+ public void testUserGroup () throws KustvaktException {
String groupName = "new-user-group";
String description = "This is new-user-group.";
Response response = createUserGroup(groupName, description, username);
@@ -103,19 +102,14 @@
assertEquals(5, node.at("/members/0/privileges").size());
testUpdateUserGroup(groupName);
- testInviteMember(groupName, username, "darla");
-
- testDeleteMemberUnauthorizedByNonMember(groupName,"darla");
- testDeleteMemberUnauthorizedByMember(groupName, "darla");
-
- testDeleteMember(groupName, username);
+ testAddMember(groupName, username, "darla");
testDeleteGroup(groupName,username);
// testSubscribeToDeletedGroup(groupName);
// testUnsubscribeToDeletedGroup(groupName);
}
private void testUpdateUserGroup (String groupName)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
String description = "Description is updated.";
Response response = createUserGroup(groupName, description, username);
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -124,82 +118,9 @@
assertEquals(description, node.get(0).get("description").asText());
}
- private void testDeleteMember (String groupName, String username)
- throws ProcessingException, KustvaktException {
- // delete darla from group
- deleteMember(groupName, "darla", username);
- // check group member
- JsonNode node = listUserGroups(username);
- node = node.get(0);
- assertEquals(1, node.get("members").size());
- }
-
- private void testDeleteMemberUnauthorizedByNonMember (String groupName,
- String memberName) throws ProcessingException, KustvaktException {
-
- Response response = deleteMember(groupName, memberName, "nemo");
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED,
- node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(),
- "Unauthorized operation for user: nemo");
- }
-
- private void testDeleteMemberUnauthorizedByMember (String groupName,
- String memberName) throws ProcessingException, KustvaktException {
- inviteMember(groupName, "dory", "nemo");
- subscribe(groupName, "nemo");
- // nemo is a group member
- Response response = deleteMember(groupName, memberName, "nemo");
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED,
- node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(),
- "Unauthorized operation for user: nemo");
- }
-
- @Test
- public void testDeletePendingMember ()
- throws ProcessingException, KustvaktException {
- createDoryGroup();
- inviteMember(doryGroupName, "dory", "pearl");
- // dory delete pearl
- Response response = deleteMember(doryGroupName, "pearl", "dory");
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- // check member
- JsonNode node = listUserGroups("pearl");
- assertEquals(0, node.size());
-
- deleteGroupByName(doryGroupName, "dory");
- }
-
- @Test
- public void testDeleteDeletedMember ()
- throws ProcessingException, KustvaktException {
- createDoryGroup();
- inviteMember(doryGroupName, "dory", "pearl");
- subscribe(doryGroupName, "pearl");
- deleteMember(doryGroupName, "pearl", "pearl");
-
- Response response = deleteMember(doryGroupName, "pearl", "pearl");
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
- node.at("/errors/0/0").asInt());
- assertEquals("pearl is not found in the group",
- node.at("/errors/0/1").asText());
- assertEquals("pearl",node.at("/errors/0/2").asText());
-
- deleteGroupByName(doryGroupName, "dory");
- }
-
+
private void testDeleteGroup (String groupName, String username)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
deleteGroupByName(groupName, username);
JsonNode node = listUserGroups(username);
assertEquals(0, node.size());
@@ -207,10 +128,9 @@
@Test
public void testDeleteGroupUnauthorized ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
createMarlinGroup();
- inviteMember(marlinGroupName, "marlin", "dory");
- subscribe(marlinGroupName, "dory");
+ addMember(marlinGroupName, "dory", "marlin");
addAdminRole(marlinGroupName, "dory", "marlin");
@@ -234,7 +154,7 @@
@Test
public void testDeleteDeletedGroup ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
createMarlinGroup();
deleteGroupByName(marlinGroupName, "marlin");
Response response = deleteGroupByName(marlinGroupName, "marlin");
@@ -243,7 +163,7 @@
@Test
public void testDeleteGroupOwner ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
createMarlinGroup();
// delete marlin from marlin-group
// dory is a group admin in marlin-group
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java
index ac03ff5..b96467a 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupListTest.java
@@ -19,8 +19,8 @@
@Test
public void testListDoryGroups () throws KustvaktException {
createDoryGroup();
- inviteMember(doryGroupName, "dory", "marlin");
- inviteMember(doryGroupName, "dory", "nemo");
+ addMember(doryGroupName, "marlin", "dory");
+ addMember(doryGroupName, "nemo", "dory");
JsonNode node = listUserGroups("dory");
JsonNode group = node.get(0);
@@ -36,8 +36,6 @@
}
public void testListNemoGroups () throws KustvaktException {
- Response response = subscribe(doryGroupName, "nemo");
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = listUserGroups("nemo");
assertEquals(node.at("/0/name").asText(), "dory-group");
assertEquals(node.at("/0/owner").asText(), "dory");
@@ -49,8 +47,6 @@
// marlin has 2 groups
public void testListMarlinGroups () throws KustvaktException {
createMarlinGroup();
- Response response = subscribe(doryGroupName, "marlin");
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = listUserGroups("marlin");
assertEquals(2, node.size());
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java
index b12ff69..10ce9ba 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupMemberTest.java
@@ -4,11 +4,11 @@
import java.util.Set;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.net.HttpHeaders;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
@@ -19,7 +19,6 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
-import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.Response;
@@ -31,71 +30,261 @@
private UserGroupMemberDao memberDao;
@Test
- public void testInvitePendingMember ()
- throws ProcessingException, KustvaktException {
+ public void testAddMultipleMembers ()
+ throws KustvaktException {
createDoryGroup();
- inviteMember(doryGroupName, "dory", "marlin");
+ addMember(doryGroupName, "nemo,marlin,pearl", "dory");
- // marlin has status PENDING in dory-group
- Response response = inviteMember(doryGroupName, "dory", "marlin");
- String entity = response.readEntity(String.class);
- // System.out.println(entity);
- JsonNode node = JsonUtils.readTree(entity);
+ JsonNode node = listUserGroups("dory");
+ node = node.get(0);
+ assertEquals(4, node.get("members").size());
+
+ testAddExistingMember();
+
+ deleteGroupByName(doryGroupName, "dory");
+
+ testAddMemberToDeletedGroup();
+ }
+
+ private void testAddExistingMember () throws KustvaktException {
+ Response response = addMember(doryGroupName, "nemo", "dory");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_MEMBER_EXISTS,
node.at("/errors/0/0").asInt());
assertEquals(
- "Username marlin with status PENDING exists in the user-group "
+ "Username: nemo exists in the user-group: "
+ "dory-group",
node.at("/errors/0/1").asText());
assertEquals(node.at("/errors/0/2").asText(),
- "[marlin, PENDING, dory-group]");
+ "[nemo, dory-group]");
+ }
+
+ private void testAddMemberToDeletedGroup () throws KustvaktException {
+ Response response = addMember(doryGroupName, "pearl", "dory");
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Group dory-group is not found",
+ node.at("/errors/0/1").asText());
+ }
+
+ @Test
+ public void testAddMemberMissingGroupName () throws KustvaktException {
+ Response response = addMember("", "pearl","dory");
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+
+ @Test
+ public void testAddMemberNonExistentGroup () throws KustvaktException {
+ Response response = addMember("non-existent", "pearl","dory");
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Group non-existent is not found",
+ node.at("/errors/0/1").asText());
+ }
+
+ // if username is not found in LDAP
+ @Disabled
+ @Test
+ public void testMemberAddNonExistent () throws KustvaktException {
+ createDoryGroup();
+
+ Response response = addMember(doryGroupName, "bruce", "dory");
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("bruce is not found in the group",
+ node.at("/errors/0/1").asText());
+
+ testAddDeletedMember();
+ deleteGroupByName(doryGroupName, "dory");
+ }
+
+ @Test
+ public void testAddDeletedMember () throws KustvaktException {
+ createDoryGroup();
+ addMember(doryGroupName, "pearl", "dory");
+ deleteMember(doryGroupName, "pearl", "dory");
+
+ Response response = addMember(doryGroupName, "pearl", "dory");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ JsonNode node = listUserGroups("pearl");
+ assertEquals(1, node.size());
deleteGroupByName(doryGroupName, "dory");
}
@Test
- public void testInviteActiveMember ()
- throws ProcessingException, KustvaktException {
+ public void testDeleteMemberByGroupOwner ()
+ throws KustvaktException {
createDoryGroup();
- inviteMember(doryGroupName, "dory", "nemo");
- subscribe(doryGroupName, "nemo");
- // nemo has status active in dory-group
- Form form = new Form();
- form.param("members", "nemo");
- Response response = target().path(API_VERSION).path("group")
- .path("@dory-group").path("invite").request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("dory", "pass"))
- .post(Entity.form(form));
- assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ addMember(doryGroupName, "pearl", "dory");
+ addMember(doryGroupName, "marlin", "dory");
+
+ testDeleteMemberUnauthorizedByNonMember(doryGroupName, "pearl", "nemo");
+ testDeleteMemberUnauthorizedByMember(doryGroupName, "pearl", "marlin");
+ deleteMember(doryGroupName, "pearl", "dory");
+
+ // check group member
+ JsonNode node = listUserGroups("dory");
+ node = node.get(0);
+ assertEquals(2, node.get("members").size());
+
+ deleteGroupByName(doryGroupName, "dory");
+ }
+
+ private void testDeleteMemberUnauthorizedByNonMember (String groupName,
+ String memberName, String deletedBy)
+ throws KustvaktException {
+ Response response = deleteMember(groupName, memberName, deletedBy);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.GROUP_MEMBER_EXISTS,
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
- assertEquals(
- "Username nemo with status ACTIVE exists in the user-group "
- + "dory-group",
- node.at("/errors/0/1").asText());
- assertEquals(node.at("/errors/0/2").asText(),
- "[nemo, ACTIVE, dory-group]");
-
- deleteGroupByName(doryGroupName, "dory");
-
- testInviteMemberToDeletedGroup();
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: "+deletedBy);
+ }
+
+ private void testDeleteMemberUnauthorizedByMember (String groupName,
+ String memberName, String deletedBy)
+ throws KustvaktException {
+ Response response = deleteMember(groupName, memberName, deletedBy);
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: "+deletedBy);
}
- private void testInviteMemberToDeletedGroup () throws KustvaktException {
- Response response = inviteMember(doryGroupName, "dory", "nemo");
+ @Test
+ public void testDeleteMemberByGroupAdmin ()
+ throws KustvaktException {
+ createDoryGroup();
+ addMember(doryGroupName, "pearl", "dory");
+ addMember(doryGroupName, "nemo", "dory");
+ addAdminRole(doryGroupName, "nemo", "dory");
+ // check group member
+ JsonNode node = listUserGroups("dory");
+ node = node.get(0);
+ assertEquals(3, node.get("members").size());
+
+ Response response = deleteMember(doryGroupName, "pearl", "nemo");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ // check group member
+ node = listUserGroups("dory");
+ node = node.get(0);
+ assertEquals(2, node.get("members").size());
+
+ deleteGroupByName(doryGroupName, "dory");
+ }
+
+ @Test
+ public void testDeleteMemberBySelf ()
+ throws KustvaktException {
+ createDoryGroup();
+ addMember(doryGroupName, "pearl", "dory");
+
+ // check group member
+ JsonNode node = listUserGroups("dory");
+ node = node.get(0);
+ assertEquals(2, node.get("members").size());
+
+ Response response = deleteMember(doryGroupName, "pearl", "pearl");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ // check group member
+ node = listUserGroups("dory");
+ node = node.get(0);
+ assertEquals(1, node.get("members").size());
+
+ deleteGroupByName(doryGroupName, "dory");
+ }
+
+ @Test
+ public void testDeleteMemberDeletedGroup ()
+ throws KustvaktException {
+ createDoryGroup();
+ addMember(doryGroupName, "pearl", "dory");
+ deleteGroupByName(doryGroupName, "dory");
+
+ Response response = deleteMember(doryGroupName, "pearl", "dory");
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
-// String entity = response.readEntity(String.class);
-// JsonNode node = JsonUtils.readTree(entity);
-// assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
-// assertEquals(node.at("/errors/0/1").asText(),
-// "Group deleted-group has been deleted.");
-// assertEquals(node.at("/errors/0/2").asText(), "deleted-group");
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Group "+doryGroupName+" is not found",
+ node.at("/errors/0/1").asText());
+ }
+
+ @Test
+ public void testDeleteMemberAlreadyDeleted ()
+ throws KustvaktException {
+ createDoryGroup();
+ addMember(doryGroupName, "pearl", "dory");
+ deleteMember(doryGroupName, "pearl", "pearl");
+
+ Response response = deleteMember(doryGroupName, "pearl", "pearl");
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("pearl is not found in the group",
+ node.at("/errors/0/1").asText());
+ assertEquals("pearl",node.at("/errors/0/2").asText());
+
+ deleteGroupByName(doryGroupName, "dory");
+ }
+
+ @Test
+ public void testDeleteMemberMissingGroupName () throws KustvaktException {
+ Response response = deleteMember("", "pearl","dory");
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ public void testDeleteMemberNonExistent () throws KustvaktException {
+ createDoryGroup();
+ Response response = deleteMember(doryGroupName, "pearl", "dory");
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+ assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("pearl is not found in the group",
+ node.at("/errors/0/1").asText());
+ assertEquals("pearl",node.at("/errors/0/2").asText());
+
+ deleteGroupByName(doryGroupName, "dory");
+ }
+
+ @Test
+ public void testDeleteMemberNonExistentGroup () throws KustvaktException {
+ Response response = deleteMember("non-existent", "pearl","dory");
+ String entity = response.readEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Group non-existent is not found",
+ node.at("/errors/0/1").asText());
}
// @Deprecated
@@ -124,8 +313,8 @@
@Test
public void testAddMemberRole () throws KustvaktException {
createMarlinGroup();
- inviteMember(marlinGroupName, "marlin", "dory");
- subscribe(marlinGroupName, "dory");
+ addMember(marlinGroupName, "dory", "marlin");
+
JsonNode marlinGroup = listUserGroups("marlin");
int groupId = marlinGroup.at("/0/id").asInt();
@@ -147,7 +336,7 @@
}
private void testAddSameMemberRole (int groupId)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = addAdminRole(marlinGroupName, "dory", "marlin");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -162,7 +351,7 @@
}
private void testDeleteMemberRole (int groupId)
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Form form = new Form();
form.param("memberUsername", "dory");
form.param("role", PredefinedRole.GROUP_ADMIN.name());
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java
deleted file mode 100644
index b0c80a5..0000000
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupSubscriptionTest.java
+++ /dev/null
@@ -1,256 +0,0 @@
-package de.ids_mannheim.korap.web.controller.usergroup;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.junit.jupiter.api.Test;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.net.HttpHeaders;
-
-import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.utils.JsonUtils;
-import jakarta.ws.rs.ProcessingException;
-import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.core.Form;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.Response.Status;
-
-public class UserGroupSubscriptionTest extends UserGroupTestBase {
-
- @Test
- public void testSubscribeNonExistentMember () throws KustvaktException {
- createDoryGroup();
-
- Response response = subscribe(doryGroupName, "bruce");
- assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
-
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
- node.at("/errors/0/0").asInt());
- assertEquals("bruce is not found in the group",
- node.at("/errors/0/1").asText());
-
- testSubscribeDeletedMember();
- deleteGroupByName(doryGroupName, "dory");
- }
-
- // pearl has GroupMemberStatus.DELETED in dory-group
- private void testSubscribeDeletedMember () throws KustvaktException {
- inviteMember(doryGroupName, "dory", "pearl");
- // delete pending member
- deleteMember(doryGroupName, "pearl", "dory");
-
- Response response = subscribe(doryGroupName, "pearl");
- assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
-
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
- node.at("/errors/0/0").asInt());
-
- testUnsubscribeDeletedMember();
- testInviteDeletedMember("pearl", "dory");
- }
-
- // marlin has GroupMemberStatus.PENDING in dory-group
- @Test
- public void testSubscribePendingMember () throws KustvaktException {
- createDoryGroup();
- testInviteMember(doryGroupName, "dory", "marlin");
- Response response = subscribe(doryGroupName, "marlin");
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
- // retrieve marlin group
- JsonNode node = listUserGroups("marlin");
- assertEquals(1, node.size());
- JsonNode group = node.get(0);
- assertEquals(group.at("/name").asText(), "dory-group");
- assertEquals(group.at("/owner").asText(), "dory");
- // group members are not allowed to see other members
- assertEquals(0, group.at("/members").size());
-
- assertEquals(1, group.at("/userPrivileges").size());
-
- // unsubscribe marlin from dory-group
- testUnsubscribeActiveMember("dory-group");
- checkGroupMemberRole("dory-group", "marlin");
- testInviteDeletedMember("marlin", "dory");
-
- deleteGroupByName(doryGroupName, "dory");
- }
-
- private void testInviteDeletedMember (String invitee, String invitor)
- throws ProcessingException, KustvaktException {
-
- Response response = inviteMember(doryGroupName, invitor, invitee);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- // check member
- JsonNode node = listUserGroups(invitee);
- assertEquals(1, node.size());
- }
-
- private void checkGroupMemberRole (String groupName,
- String deletedMemberName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("admin")
- .path("group").path("@" + groupName).request()
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("admin", "pass"))
- .post(null);
- String entity = response.readEntity(String.class);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = JsonUtils.readTree(entity).at("/members");
- JsonNode member;
- for (int i = 0; i < node.size(); i++) {
- member = node.get(i);
- if (deletedMemberName.equals(member.at("/userId").asText())) {
- assertEquals(0, node.at("/privileges").size());
- break;
- }
- }
- }
-
-
- @Test
- public void testSubscribeMissingGroupName () throws KustvaktException {
- Response response = target().path(API_VERSION).path("group")
- .path("subscribe").request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("bruce", "pass"))
- .post(Entity.form(new Form()));
- assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- }
-
-
- @Test
- public void testSubscribeToNonExistentGroup () throws KustvaktException {
- Response response = subscribe("non-existent", "pearl");
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.NO_RESOURCE_FOUND,
- node.at("/errors/0/0").asInt());
- assertEquals("Group non-existent is not found",
- node.at("/errors/0/1").asText());
- }
-
- @Test
- public void testSubscribeToDeletedGroup ()
- throws ProcessingException, KustvaktException {
- createDoryGroup();
- // hard delete
- deleteGroupByName(doryGroupName, "dory");
-
- Response response = subscribe(doryGroupName, "nemo");
- assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
-// String entity = response.readEntity(String.class);
-// JsonNode node = JsonUtils.readTree(entity);
-// assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
-// assertEquals(node.at("/errors/0/1").asText(),
-// "Group new-user-group has been deleted.");
- testUnsubscribeToDeletedGroup(doryGroupName);
-
- }
-
- private void testUnsubscribeToDeletedGroup (String groupName)
- throws ProcessingException, KustvaktException {
- Response response = unsubscribe(doryGroupName, "nemo");
- assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
-// assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
-// String entity = response.readEntity(String.class);
-// JsonNode node = JsonUtils.readTree(entity);
-// assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
-// assertEquals(node.at("/errors/0/1").asText(),
-// "Group new-user-group has been deleted.");
- }
-
- private void testUnsubscribeActiveMember (String groupName)
- throws ProcessingException, KustvaktException {
- Response response = unsubscribe(groupName, "marlin");
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = listUserGroups("marlin");
- assertEquals(0, node.size());
- }
-
- @Test
- public void testUnsubscribePendingMember ()
- throws ProcessingException, KustvaktException {
- createDoryGroup();
- testInviteMember(doryGroupName, "dory", "marlin");
- JsonNode node = listUserGroups("marlin");
- assertEquals(1, node.size());
-
- Response response = unsubscribe(doryGroupName, "marlin");
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
- node = listUserGroups("marlin");
- assertEquals(0, node.size());
- // invite marlin to dory-group to set back the
- // GroupMemberStatus.PENDING
- testInviteDeletedMember("marlin","dory");
- deleteGroupByName(doryGroupName, "dory");
- }
-
- private void testUnsubscribeDeletedMember ()
- throws ProcessingException, KustvaktException {
- // pearl unsubscribes from dory-group
- Response response = unsubscribe(doryGroupName, "pearl");
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
- node.at("/errors/0/0").asInt());
- }
-
-
- @Test
- public void testUnsubscribeMissingGroupName () throws KustvaktException {
- Response response = target().path(API_VERSION).path("group")
- .path("unsubscribe").request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("marlin", "pass"))
- .delete();
- assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- }
-
- @Test
- public void testUnsubscribeNonExistentMember () throws KustvaktException {
- createDoryGroup();
- Response response = target().path(API_VERSION).path("group")
- .path("@dory-group").path("unsubscribe").request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("bruce", "pass"))
- .delete();
- assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
- node.at("/errors/0/0").asInt());
- assertEquals("bruce is not found in the group",
- node.at("/errors/0/1").asText());
- deleteGroupByName(doryGroupName, "dory");
- }
-
- @Test
- public void testUnsubscribeToNonExistentGroup () throws KustvaktException {
- Response response = target().path(API_VERSION).path("group")
- .path("@tralala-group").path("unsubscribe").request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("pearl", "pass"))
- .delete();
- assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- String entity = response.readEntity(String.class);
- JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND,
- node.at("/errors/0/0").asInt());
- assertEquals("Group tralala-group is not found",
- node.at("/errors/0/1").asText());
- }
-
-}
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
index 81df9a5..b8f3bc1 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/usergroup/UserGroupTestBase.java
@@ -11,7 +11,6 @@
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.web.controller.OAuth2TestBase;
-import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.MediaType;
@@ -25,7 +24,7 @@
protected String admin = "admin";
protected Response createUserGroup (String groupName, String description,
- String username) throws ProcessingException, KustvaktException {
+ String username) throws KustvaktException {
Form form = new Form();
form.param("description", description);
Response response = target().path(API_VERSION).path("group")
@@ -59,53 +58,46 @@
return node;
}
- protected Response inviteMember (String groupName, String invitor,
- String invitee) throws KustvaktException {
+
+ protected Response addMember (String groupName, String memberUsername,
+ String username) throws KustvaktException {
Form form = new Form();
- form.param("members", invitee);
+ form.param("members", memberUsername);
Response response = target().path(API_VERSION).path("group")
- .path("@" + groupName).path("invite").request()
+ .path("@" + groupName).path("member").request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue(invitor, "pass"))
- .post(Entity.form(form));
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .put(Entity.form(form));
// assertEquals(Status.OK.getStatusCode(), response.getStatus());
return response;
}
- protected void testInviteMember (String groupName, String invitor,
- String invitee)
- throws ProcessingException, KustvaktException {
- Response response = inviteMember(groupName, invitor, invitee);
+// protected Response inviteMember (String groupName, String invitor,
+// String invitee) throws KustvaktException {
+// Form form = new Form();
+// form.param("members", invitee);
+// Response response = target().path(API_VERSION).path("group")
+// .path("@" + groupName).path("invite").request()
+// .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+// .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+// .createBasicAuthorizationHeaderValue(invitor, "pass"))
+// .post(Entity.form(form));
+//// assertEquals(Status.OK.getStatusCode(), response.getStatus());
+// return response;
+// }
+
+ protected void testAddMember (String groupName, String username,
+ String memberUsername)
+ throws KustvaktException {
+ Response response = addMember(groupName, memberUsername, username);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list group
- JsonNode node = listUserGroups(invitor);
+ JsonNode node = listUserGroups(username);
node = node.get(0);
assertEquals(2, node.get("members").size());
- assertEquals(node.at("/members/1/userId").asText(), invitee);
- assertEquals(0, node.at("/members/1/privileges").size());
- }
-
- protected Response subscribe (String groupName, String username)
- throws KustvaktException {
- Response response = target().path(API_VERSION).path("group")
- .path("@"+groupName).path("subscribe").request()
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue(username, "pass"))
- .post(Entity.form(new Form()));
-// assertEquals(Status.OK.getStatusCode(), response.getStatus());
- return response;
- }
-
- protected Response unsubscribe (String groupName, String username)
- throws KustvaktException {
- Response response = target().path(API_VERSION).path("group")
- .path("@" + groupName).path("unsubscribe").request()
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue(username, "pass"))
- .delete();
- return response;
-// assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(node.at("/members/1/userId").asText(), memberUsername);
+ assertEquals(1, node.at("/members/1/privileges").size());
}
protected Response addAdminRole (String groupName, String memberName,
@@ -134,8 +126,7 @@
return response;
}
- protected JsonNode createDoryGroup ()
- throws ProcessingException, KustvaktException {
+ protected JsonNode createDoryGroup () throws KustvaktException {
Response response = createUserGroup(doryGroupName,
"This is dory-group.", "dory");
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerAdminTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerAdminTest.java
index 673e1cd..08ca16e 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerAdminTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusControllerAdminTest.java
@@ -2,6 +2,17 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.apache.http.entity.ContentType;
+import org.junit.jupiter.api.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.net.HttpHeaders;
+
+import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.constant.ResourceType;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Form;
@@ -9,16 +20,6 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
-import org.apache.http.entity.ContentType;
-import org.junit.jupiter.api.Test;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.net.HttpHeaders;
-import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.utils.JsonUtils;
-
/**
* @author margaretha
*/
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusInfoTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusInfoTest.java
index 6d98009..9495660 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusInfoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusInfoTest.java
@@ -12,7 +12,6 @@
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.utils.JsonUtils;
-import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
@@ -24,7 +23,7 @@
@Test
public void testRetrieveSystemVC ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
JsonNode node = retrieveVCInfo(testUser, "system", "system-vc");
assertEquals(node.at("/name").asText(), "system-vc");
assertEquals(ResourceType.SYSTEM.displayName(),
@@ -36,7 +35,7 @@
@Test
public void testRetrieveSystemVC_guest ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("vc")
.path("~system").path("system-vc").request().get();
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
@@ -47,7 +46,7 @@
@Test
public void testRetrievePrivateVC ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
JsonNode node = retrieveVCInfo("dory", "dory", "dory-vc");
assertEquals(node.at("/name").asText(), "dory-vc");
assertEquals(ResourceType.PRIVATE.displayName(),
@@ -56,7 +55,7 @@
@Test
public void testRetrievePrivateVC_unauthorized ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("vc").path("~dory")
.path("dory-vc").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -67,10 +66,9 @@
@Test
public void testRetrieveProjectVC_member ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
createDoryGroup();
- inviteMember(doryGroupName, "dory", "nemo");
- subscribe(doryGroupName, "nemo");
+ addMember(doryGroupName, "nemo", "dory");
createAccess("dory", "group-vc", doryGroupName, "dory");
@@ -79,8 +77,7 @@
assertEquals(ResourceType.PROJECT.displayName(),
node.at("/type").asText());
- inviteMember(doryGroupName, "dory", "pearl");
- subscribe(doryGroupName, "pearl");
+ addMember(doryGroupName, "pearl", "dory");
node = retrieveVCInfo("pearl", "dory", "group-vc");
assertEquals(node.at("/name").asText(), "group-vc");
@@ -92,7 +89,7 @@
@Test
public void testRetrieveProjectVC_unauthorized ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("vc").path("~dory")
.path("group-vc").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -103,7 +100,7 @@
@Test
public void testRetrieveProjectVC_nonActiveMember ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("vc").path("~dory")
.path("group-vc").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -114,7 +111,7 @@
@Test
public void testRetrievePrivateVC_admin ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("vc").path("~dory")
.path("dory-vc").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -129,7 +126,7 @@
@Test
public void testRetrieveProjectVC_admin ()
- throws ProcessingException, KustvaktException {
+ throws KustvaktException {
Response response = target().path(API_VERSION).path("vc").path("~dory")
.path("group-vc").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java
index 9615fef..6fad6d7 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusPublishedTest.java
@@ -41,7 +41,7 @@
}
private void testRetrievePublishedVC (String username, String vcCreator,
- String vcName) throws ProcessingException, KustvaktException {
+ String vcName) throws KustvaktException {
retrieveVCInfo(username, vcCreator, vcName);
JsonNode node = getHiddenGroup(vcName);
@@ -127,8 +127,7 @@
private String testSharePublishedVC (String vcName) throws KustvaktException {
createMarlinGroup();
- inviteMember(marlinGroupName, "marlin", "dory");
- subscribe(marlinGroupName, "dory");
+ addMember(marlinGroupName, "dory", "marlin");
JsonNode node = listVC("dory");
assertEquals(3, node.size());
@@ -163,8 +162,7 @@
JsonNode node = listVC("nemo");
assertEquals(2, node.size());
- inviteMember(marlinGroupName, "marlin", "nemo");
- subscribe(marlinGroupName, "nemo");
+ addMember(marlinGroupName, "nemo", "marlin");
node = listVC("nemo");
assertEquals(3, node.size());
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
index 52d6b7f..3f1c8c0 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/vc/VirtualCorpusSharingTest.java
@@ -57,9 +57,8 @@
@Test
public void testShareVC_ByGroupAdmin () throws KustvaktException {
createMarlinGroup();
- inviteMember(marlinGroupName, "marlin", "nemo");
- subscribe(marlinGroupName, "nemo");
-
+ addMember(marlinGroupName, "nemo", "marlin");
+
JsonNode node = listRolesByGroup("marlin", marlinGroupName);
assertEquals(0, node.size());
@@ -101,9 +100,8 @@
assertEquals(5, roleNodes.size());
String memberName = "darla";
- testInviteMember(groupName, testUser, memberName);
- subscribe(groupName, memberName);
-
+ testAddMember(groupName, testUser, memberName);
+
roleNodes = listRolesByGroup(testUser, groupName, false);
assertEquals(6, roleNodes.size());
@@ -150,8 +148,7 @@
response = createUserGroup(groupName, "Owid users", testUser);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testInviteMember(groupName, testUser, memberName);
- subscribe(groupName, memberName);
+ testAddMember(groupName, testUser, memberName);
checkMemberInGroup(memberName, testUser, groupName);
// share vc to group
@@ -193,8 +190,7 @@
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
String memberName = "darla";
- testInviteMember(groupName, testUser, memberName);
- subscribe(groupName, memberName);
+ testAddMember(groupName, testUser, memberName);
shareVC(testUser, vc1, groupName, testUser);
shareVC(testUser, vc2, groupName, testUser);