Loading gms/src/main/java/it/inaf/ia2/gms/controller/GroupsController.java +6 −2 Original line number Original line Diff line number Diff line Loading @@ -55,7 +55,9 @@ public class GroupsController { @PostMapping(value = "/group", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @PostMapping(value = "/group", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<PaginatedData<GroupNode>> createGroup(@Valid @RequestBody AddGroupRequest request) { public ResponseEntity<PaginatedData<GroupNode>> createGroup(@Valid @RequestBody AddGroupRequest request) { GroupEntity parent = groupsManager.createGroup(request.getParentGroupId(), request.getNewGroupName(), request.isLeaf()); GroupEntity parent = groupsManager.getGroupById(request.getParentGroupId()); groupsManager.createGroup(parent, request.getNewGroupName(), request.isLeaf()); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); Loading @@ -65,7 +67,9 @@ public class GroupsController { @PutMapping(value = "/group/{groupId}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @PutMapping(value = "/group/{groupId}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<PaginatedData<GroupNode>> updateGroup(@PathVariable("groupId") String groupId, @Valid @RequestBody RenameGroupRequest request) { public ResponseEntity<PaginatedData<GroupNode>> updateGroup(@PathVariable("groupId") String groupId, @Valid @RequestBody RenameGroupRequest request) { GroupEntity parent = groupsManager.updateGroup(groupId, request.getNewGroupName(), request.isLeaf()); GroupEntity updatedGroup = groupsManager.updateGroup(groupId, request.getNewGroupName(), request.isLeaf()); GroupEntity parent = groupsManager.getGroupByPath(updatedGroup.getParentPath()); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); Loading gms/src/main/java/it/inaf/ia2/gms/manager/GroupsManager.java +6 −9 Original line number Original line Diff line number Diff line Loading @@ -31,9 +31,10 @@ public class GroupsManager { return group; return group; } } public GroupEntity createGroup(String parentGroupId, String childGroupName, boolean leaf) { public GroupEntity getGroupByPath(String path) { GroupEntity parent = groupsService.getGroupById(parentGroupId); GroupEntity group = groupsService.getGroupByPath(path); return createGroup(parent, childGroupName, leaf); verifyUserCanReadGroup(group); return group; } } public GroupEntity createGroup(GroupEntity parent, String childGroupName, boolean leaf) { public GroupEntity createGroup(GroupEntity parent, String childGroupName, boolean leaf) { Loading @@ -44,9 +45,7 @@ public class GroupsManager { verifyUserCanManageGroup(parent); verifyUserCanManageGroup(parent); groupsService.addGroup(parent, childGroupName, leaf); return groupsService.addGroup(parent, childGroupName, leaf); return parent; } } public GroupEntity updateGroup(String groupId, String newGroupName, boolean leaf) { public GroupEntity updateGroup(String groupId, String newGroupName, boolean leaf) { Loading @@ -54,9 +53,7 @@ public class GroupsManager { GroupEntity group = groupsService.getGroupById(groupId); GroupEntity group = groupsService.getGroupById(groupId); verifyUserCanManageGroup(group); verifyUserCanManageGroup(group); GroupEntity updatedGroup = groupsService.updateGroup(group, newGroupName, leaf); return groupsService.updateGroup(group, newGroupName, leaf); return groupsService.getGroupByPath(updatedGroup.getParentPath()); } } public GroupEntity deleteGroup(String groupId) { public GroupEntity deleteGroup(String groupId) { Loading gms/src/test/java/it/inaf/ia2/gms/controller/JWTWebServiceControllerTest.java +14 −3 Original line number Original line Diff line number Diff line Loading @@ -19,7 +19,8 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Ignore; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq; import org.mockito.InjectMocks; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mock; Loading Loading @@ -122,11 +123,21 @@ public class JWTWebServiceControllerTest { public void testCreateGroup() throws Exception { public void testCreateGroup() throws Exception { when(groupsManager.getRoot()).thenReturn(root); when(groupsManager.getRoot()).thenReturn(root); when(groupsManager.createGroup(any(GroupEntity.class), eq("LBT"), eq(false))).thenReturn(lbt); when(groupsManager.createGroup(any(GroupEntity.class), eq("INAF"), eq(true))).thenReturn(inaf); mockMvc.perform(post("/ws/jwt/group") mockMvc.perform(post("/ws/jwt/LBT.INAF") .param("leaf", "false") .param("leaf", "true") .contentType(MediaType.APPLICATION_FORM_URLENCODED)) .contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(status().isCreated()); .andExpect(status().isCreated()); verify(groupsService, times(2)).findGroupByParentAndName(any(GroupEntity.class), any()); verify(groupsManager, times(1)).createGroup(argGroupIdEq(GroupsService.ROOT), eq("LBT"), eq(false)); verify(groupsManager, times(1)).createGroup(argGroupIdEq("lbt_id"), eq("INAF"), eq(true)); } private GroupEntity argGroupIdEq(String groupId) { return argThat(g -> g.getId().equals(groupId)); } } @Test @Test Loading Loading
gms/src/main/java/it/inaf/ia2/gms/controller/GroupsController.java +6 −2 Original line number Original line Diff line number Diff line Loading @@ -55,7 +55,9 @@ public class GroupsController { @PostMapping(value = "/group", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @PostMapping(value = "/group", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<PaginatedData<GroupNode>> createGroup(@Valid @RequestBody AddGroupRequest request) { public ResponseEntity<PaginatedData<GroupNode>> createGroup(@Valid @RequestBody AddGroupRequest request) { GroupEntity parent = groupsManager.createGroup(request.getParentGroupId(), request.getNewGroupName(), request.isLeaf()); GroupEntity parent = groupsManager.getGroupById(request.getParentGroupId()); groupsManager.createGroup(parent, request.getNewGroupName(), request.isLeaf()); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); Loading @@ -65,7 +67,9 @@ public class GroupsController { @PutMapping(value = "/group/{groupId}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @PutMapping(value = "/group/{groupId}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<PaginatedData<GroupNode>> updateGroup(@PathVariable("groupId") String groupId, @Valid @RequestBody RenameGroupRequest request) { public ResponseEntity<PaginatedData<GroupNode>> updateGroup(@PathVariable("groupId") String groupId, @Valid @RequestBody RenameGroupRequest request) { GroupEntity parent = groupsManager.updateGroup(groupId, request.getNewGroupName(), request.isLeaf()); GroupEntity updatedGroup = groupsManager.updateGroup(groupId, request.getNewGroupName(), request.isLeaf()); GroupEntity parent = groupsManager.getGroupByPath(updatedGroup.getParentPath()); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); PaginatedData<GroupNode> groupsPanel = getGroupsPanel(parent, request); Loading
gms/src/main/java/it/inaf/ia2/gms/manager/GroupsManager.java +6 −9 Original line number Original line Diff line number Diff line Loading @@ -31,9 +31,10 @@ public class GroupsManager { return group; return group; } } public GroupEntity createGroup(String parentGroupId, String childGroupName, boolean leaf) { public GroupEntity getGroupByPath(String path) { GroupEntity parent = groupsService.getGroupById(parentGroupId); GroupEntity group = groupsService.getGroupByPath(path); return createGroup(parent, childGroupName, leaf); verifyUserCanReadGroup(group); return group; } } public GroupEntity createGroup(GroupEntity parent, String childGroupName, boolean leaf) { public GroupEntity createGroup(GroupEntity parent, String childGroupName, boolean leaf) { Loading @@ -44,9 +45,7 @@ public class GroupsManager { verifyUserCanManageGroup(parent); verifyUserCanManageGroup(parent); groupsService.addGroup(parent, childGroupName, leaf); return groupsService.addGroup(parent, childGroupName, leaf); return parent; } } public GroupEntity updateGroup(String groupId, String newGroupName, boolean leaf) { public GroupEntity updateGroup(String groupId, String newGroupName, boolean leaf) { Loading @@ -54,9 +53,7 @@ public class GroupsManager { GroupEntity group = groupsService.getGroupById(groupId); GroupEntity group = groupsService.getGroupById(groupId); verifyUserCanManageGroup(group); verifyUserCanManageGroup(group); GroupEntity updatedGroup = groupsService.updateGroup(group, newGroupName, leaf); return groupsService.updateGroup(group, newGroupName, leaf); return groupsService.getGroupByPath(updatedGroup.getParentPath()); } } public GroupEntity deleteGroup(String groupId) { public GroupEntity deleteGroup(String groupId) { Loading
gms/src/test/java/it/inaf/ia2/gms/controller/JWTWebServiceControllerTest.java +14 −3 Original line number Original line Diff line number Diff line Loading @@ -19,7 +19,8 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Ignore; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq; import org.mockito.InjectMocks; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mock; Loading Loading @@ -122,11 +123,21 @@ public class JWTWebServiceControllerTest { public void testCreateGroup() throws Exception { public void testCreateGroup() throws Exception { when(groupsManager.getRoot()).thenReturn(root); when(groupsManager.getRoot()).thenReturn(root); when(groupsManager.createGroup(any(GroupEntity.class), eq("LBT"), eq(false))).thenReturn(lbt); when(groupsManager.createGroup(any(GroupEntity.class), eq("INAF"), eq(true))).thenReturn(inaf); mockMvc.perform(post("/ws/jwt/group") mockMvc.perform(post("/ws/jwt/LBT.INAF") .param("leaf", "false") .param("leaf", "true") .contentType(MediaType.APPLICATION_FORM_URLENCODED)) .contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(status().isCreated()); .andExpect(status().isCreated()); verify(groupsService, times(2)).findGroupByParentAndName(any(GroupEntity.class), any()); verify(groupsManager, times(1)).createGroup(argGroupIdEq(GroupsService.ROOT), eq("LBT"), eq(false)); verify(groupsManager, times(1)).createGroup(argGroupIdEq("lbt_id"), eq("INAF"), eq(true)); } private GroupEntity argGroupIdEq(String groupId) { return argThat(g -> g.getId().equals(groupId)); } } @Test @Test Loading