@Test public void saveMembersToAdHocGroupTest() throws Exception { AcmGroup group = new AcmGroup(); group.setName("A"); group.setType(AcmGroupType.ADHOC_GROUP); group.setStatus(AcmGroupStatus.ACTIVE); AcmUser user = new AcmUser(); user.setUserId("ann-acm"); AcmUser user1 = new AcmUser(); user1.setUserId("sally-acm"); group.addUserMember(user); group.addUserMember(user1); expect(groupService.addUserMembersToGroup(Arrays.asList("ann-acm", "sally-acm"), "A")) .andReturn(group); expect(mockAuthentication.getName()).andReturn("ann-acm"); replayAll(); MvcResult result = mockMvc.perform( post("/api/latest/users/group/{groupId}/members/save", Base64.getUrlEncoder().encodeToString(group.getName().getBytes())) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) .content(new JSONArray(Arrays.asList("ann-acm", "sally-acm")).toString()) .principal(mockAuthentication)) .andExpect(status().isOk()) .andReturn(); verifyAll(); log.info("Results: {}", result.getResponse().getContentAsString()); ObjectMapper om = new ObjectMapper(); AcmGroup acmGroup = om.readValue(result.getResponse().getContentAsString(), AcmGroup.class); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertThat(acmGroup.getUserMemberIds().collect(Collectors.toList()), everyItem(isIn(Arrays.asList("ann-acm", "sally-acm")))); }
@RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members, @PathVariable("groupId") String groupId) throws AcmAppErrorJsonMsg { LOG.info("Add user members group: [{}]", groupId); try { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); return groupService.addUserMembersToGroup(members, groupId); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Failed to add user members to Ad Hoc Group", "ADHOC_GROUP", e); } }
AdHocGroupMembersAPIController { @RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members, @PathVariable("groupId") String groupId) throws AcmAppErrorJsonMsg { LOG.info("Add user members group: [{}]", groupId); try { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); return groupService.addUserMembersToGroup(members, groupId); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Failed to add user members to Ad Hoc Group", "ADHOC_GROUP", e); } } }
AdHocGroupMembersAPIController { @RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members, @PathVariable("groupId") String groupId) throws AcmAppErrorJsonMsg { LOG.info("Add user members group: [{}]", groupId); try { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); return groupService.addUserMembersToGroup(members, groupId); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Failed to add user members to Ad Hoc Group", "ADHOC_GROUP", e); } }  }
AdHocGroupMembersAPIController { @RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members, @PathVariable("groupId") String groupId) throws AcmAppErrorJsonMsg { LOG.info("Add user members group: [{}]", groupId); try { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); return groupService.addUserMembersToGroup(members, groupId); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Failed to add user members to Ad Hoc Group", "ADHOC_GROUP", e); } }  @RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members,
            @PathVariable("groupId") String groupId); @RequestMapping(value = "/group/{groupId}/members/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup removeMembersFromAdHocGroup(@RequestBody List<String> members,
            @PathVariable("groupId") String groupId); void setGroupService(GroupService groupService); }
AdHocGroupMembersAPIController { @RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members, @PathVariable("groupId") String groupId) throws AcmAppErrorJsonMsg { LOG.info("Add user members group: [{}]", groupId); try { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); return groupService.addUserMembersToGroup(members, groupId); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Failed to add user members to Ad Hoc Group", "ADHOC_GROUP", e); } }  @RequestMapping(value = "/group/{groupId}/members/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup saveMembersToAdHocGroup(@RequestBody List<String> members,
            @PathVariable("groupId") String groupId); @RequestMapping(value = "/group/{groupId}/members/remove", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup removeMembersFromAdHocGroup(@RequestBody List<String> members,
            @PathVariable("groupId") String groupId); void setGroupService(GroupService groupService);  }