Loading gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java +3 −4 Original line number Diff line number Diff line Loading @@ -118,6 +118,7 @@ public class JWTWebServiceController { String groupNamesString = getGroupFromRequest(request, "/ws/jwt/search/", "/vo/search/"); List<String> groupNames = groupNameService.extractGroupNames(groupNamesString); List<String> existingGroupNames = new ArrayList<>(); GroupEntity group = null; Loading @@ -127,19 +128,17 @@ public class JWTWebServiceController { if (optionalGroup.isPresent()) { GroupEntity groupEntity = optionalGroup.get(); parentPath = groupEntity.getPath(); existingGroupNames.add(groupName); boolean isMember = membershipManager.isCurrentUserMemberOf(groupEntity.getId()); if (isMember) { group = groupEntity; } } else { group = null; break; } } if (group != null) { try ( PrintWriter pw = new PrintWriter(response.getOutputStream())) { pw.println(groupNameService.getCompleteName(groupNames)); pw.println(groupNameService.getCompleteName(existingGroupNames)); } } // else: empty response (as defined by GMS standard) Loading gms/src/test/java/it/inaf/ia2/gms/controller/JWTWebServiceControllerTest.java +55 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,61 @@ public class JWTWebServiceControllerTest { .andExpect(content().string("")); } @Test public void testIsMemberOfParentButChildDoesntExist() throws Exception { GroupEntity group1 = new GroupEntity(); group1.setId("1"); group1.setPath("1"); group1.setName("LBT"); GroupEntity group2 = new GroupEntity(); group2.setId("2"); group2.setPath("1.2"); group2.setName("OTHERS"); when(groupsDAO.findGroupByParentAndName(eq(""), eq("LBT"))) .thenReturn(Optional.of(group1)); when(groupsDAO.findGroupByParentAndName(eq("1"), eq("OTHERS"))) .thenReturn(Optional.of(group2)); when(membershipManager.isCurrentUserMemberOf(eq(group2.getId()))).thenReturn(true); String group = "LBT.OTHERS.UNKNOWN"; mockMvc.perform(get("/vo/search/" + group).principal(principal)) .andExpect(status().isOk()) .andExpect(content().string("LBT.OTHERS\n")); } @Test public void testIsMemberOfSuperParentButChildDoesntExist() throws Exception { GroupEntity group1 = new GroupEntity(); group1.setId("1"); group1.setPath("1"); group1.setName("LBT"); GroupEntity group2 = new GroupEntity(); group2.setId("2"); group2.setPath("1.2"); group2.setName("OTHERS"); when(groupsDAO.findGroupByParentAndName(eq(""), eq("LBT"))) .thenReturn(Optional.of(group1)); when(groupsDAO.findGroupByParentAndName(eq("1"), eq("OTHERS"))) .thenReturn(Optional.of(group2)); when(membershipManager.isCurrentUserMemberOf(eq(group1.getId()))).thenReturn(true); when(membershipManager.isCurrentUserMemberOf(eq(group2.getId()))).thenReturn(true); String group = "LBT.OTHERS.UNKNOWN"; mockMvc.perform(get("/vo/search/" + group).principal(principal)) .andExpect(status().isOk()) .andExpect(content().string("LBT.OTHERS\n")); } @Test public void testCreateGroup() throws Exception { Loading Loading
gms/src/main/java/it/inaf/ia2/gms/controller/JWTWebServiceController.java +3 −4 Original line number Diff line number Diff line Loading @@ -118,6 +118,7 @@ public class JWTWebServiceController { String groupNamesString = getGroupFromRequest(request, "/ws/jwt/search/", "/vo/search/"); List<String> groupNames = groupNameService.extractGroupNames(groupNamesString); List<String> existingGroupNames = new ArrayList<>(); GroupEntity group = null; Loading @@ -127,19 +128,17 @@ public class JWTWebServiceController { if (optionalGroup.isPresent()) { GroupEntity groupEntity = optionalGroup.get(); parentPath = groupEntity.getPath(); existingGroupNames.add(groupName); boolean isMember = membershipManager.isCurrentUserMemberOf(groupEntity.getId()); if (isMember) { group = groupEntity; } } else { group = null; break; } } if (group != null) { try ( PrintWriter pw = new PrintWriter(response.getOutputStream())) { pw.println(groupNameService.getCompleteName(groupNames)); pw.println(groupNameService.getCompleteName(existingGroupNames)); } } // else: empty response (as defined by GMS standard) Loading
gms/src/test/java/it/inaf/ia2/gms/controller/JWTWebServiceControllerTest.java +55 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,61 @@ public class JWTWebServiceControllerTest { .andExpect(content().string("")); } @Test public void testIsMemberOfParentButChildDoesntExist() throws Exception { GroupEntity group1 = new GroupEntity(); group1.setId("1"); group1.setPath("1"); group1.setName("LBT"); GroupEntity group2 = new GroupEntity(); group2.setId("2"); group2.setPath("1.2"); group2.setName("OTHERS"); when(groupsDAO.findGroupByParentAndName(eq(""), eq("LBT"))) .thenReturn(Optional.of(group1)); when(groupsDAO.findGroupByParentAndName(eq("1"), eq("OTHERS"))) .thenReturn(Optional.of(group2)); when(membershipManager.isCurrentUserMemberOf(eq(group2.getId()))).thenReturn(true); String group = "LBT.OTHERS.UNKNOWN"; mockMvc.perform(get("/vo/search/" + group).principal(principal)) .andExpect(status().isOk()) .andExpect(content().string("LBT.OTHERS\n")); } @Test public void testIsMemberOfSuperParentButChildDoesntExist() throws Exception { GroupEntity group1 = new GroupEntity(); group1.setId("1"); group1.setPath("1"); group1.setName("LBT"); GroupEntity group2 = new GroupEntity(); group2.setId("2"); group2.setPath("1.2"); group2.setName("OTHERS"); when(groupsDAO.findGroupByParentAndName(eq(""), eq("LBT"))) .thenReturn(Optional.of(group1)); when(groupsDAO.findGroupByParentAndName(eq("1"), eq("OTHERS"))) .thenReturn(Optional.of(group2)); when(membershipManager.isCurrentUserMemberOf(eq(group1.getId()))).thenReturn(true); when(membershipManager.isCurrentUserMemberOf(eq(group2.getId()))).thenReturn(true); String group = "LBT.OTHERS.UNKNOWN"; mockMvc.perform(get("/vo/search/" + group).principal(principal)) .andExpect(status().isOk()) .andExpect(content().string("LBT.OTHERS\n")); } @Test public void testCreateGroup() throws Exception { Loading