@Test public void addSupervisorToGroupTest() throws Exception { String content = "{\"userId\":\"ann-acm\"}"; AcmUser supervisor = new AcmUser(); supervisor.setUserId("ann-acm"); AcmGroup group = new AcmGroup(); group.setName("A"); group.setSupervisor(supervisor); expect(groupService.setSupervisor(supervisor, "A", false)).andReturn(group); expect(mockAuthentication.getName()).andReturn("ann-acm"); replayAll(); MvcResult result = mockMvc.perform( post("/api/latest/users/group/{groupId}/supervisor/save/false", Base64.getUrlEncoder().encodeToString(group.getName().getBytes())) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON) .principal(mockAuthentication) .content(content)) .andReturn(); log.info("Results: {}", result.getResponse().getContentAsString()); verifyAll(); ObjectMapper objectMapper = new ObjectMapper(); AcmGroup resultGroup = objectMapper.readValue(result.getResponse().getContentAsString(), AcmGroup.class); assertEquals(supervisor.getUserId(), resultGroup.getSupervisor().getUserId()); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); }
@RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor, @PathVariable("groupId") String groupId, @PathVariable("applyToAll") boolean applyToAll) throws AcmUserActionFailedException { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); LOG.info("Saving supervisor to the group with ID = [{}]", groupId); return groupService.setSupervisor(supervisor, groupId, applyToAll); }
SupervisorGroupAPIController { @RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor, @PathVariable("groupId") String groupId, @PathVariable("applyToAll") boolean applyToAll) throws AcmUserActionFailedException { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); LOG.info("Saving supervisor to the group with ID = [{}]", groupId); return groupService.setSupervisor(supervisor, groupId, applyToAll); } }
SupervisorGroupAPIController { @RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor, @PathVariable("groupId") String groupId, @PathVariable("applyToAll") boolean applyToAll) throws AcmUserActionFailedException { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); LOG.info("Saving supervisor to the group with ID = [{}]", groupId); return groupService.setSupervisor(supervisor, groupId, applyToAll); }  }
SupervisorGroupAPIController { @RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor, @PathVariable("groupId") String groupId, @PathVariable("applyToAll") boolean applyToAll) throws AcmUserActionFailedException { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); LOG.info("Saving supervisor to the group with ID = [{}]", groupId); return groupService.setSupervisor(supervisor, groupId, applyToAll); }  @RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor,
            @PathVariable("groupId") String groupId,
            @PathVariable("applyToAll") boolean applyToAll); @RequestMapping(value = "/group/{groupId}/supervisor/remove/{applyToAll}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup removeSupervisorFromGroup(@PathVariable("groupId") String groupId,
            @PathVariable("applyToAll") boolean applyToAll); void setGroupService(GroupService groupService); }
SupervisorGroupAPIController { @RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor, @PathVariable("groupId") String groupId, @PathVariable("applyToAll") boolean applyToAll) throws AcmUserActionFailedException { groupId = new String(Base64.getUrlDecoder().decode(groupId.getBytes())); LOG.info("Saving supervisor to the group with ID = [{}]", groupId); return groupService.setSupervisor(supervisor, groupId, applyToAll); }  @RequestMapping(value = "/group/{groupId}/supervisor/save/{applyToAll}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup addSupervisorToGroup(@RequestBody AcmUser supervisor,
            @PathVariable("groupId") String groupId,
            @PathVariable("applyToAll") boolean applyToAll); @RequestMapping(value = "/group/{groupId}/supervisor/remove/{applyToAll}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup removeSupervisorFromGroup(@PathVariable("groupId") String groupId,
            @PathVariable("applyToAll") boolean applyToAll); void setGroupService(GroupService groupService);  }