/** * RequestMapping to delete an invitation as admin * * @param request {@link javax.servlet.http.HttpServletRequest} * @return redirect to detailteam if everything is okay * @throws UnsupportedEncodingException in the rare condition utf-8 is not supported */ @RequestMapping(value = "/deleteInvitation.shtml") public RedirectView deleteInvitation( HttpServletRequest request, @ModelAttribute(TokenUtil.TOKENCHECK) String sessionToken, @RequestParam() String token, SessionStatus status, ModelMap modelMap) throws UnsupportedEncodingException { TokenUtil.checkTokens(sessionToken, token, status); Person person = (Person) request.getSession().getAttribute(LoginInterceptor.PERSON_SESSION_KEY); if (person == null) { status.setComplete(); return new RedirectView("landingpage.shtml"); } Invitation invitation = getAllInvitationByRequest(request); String teamId = invitation.getTeamId(); teamInviteService.delete(invitation); AuditLog.log( "User {} deleted invitation for email {} for team {} with intended role {}", person.getId(), invitation.getEmail(), invitation.getTeamId(), invitation.getIntendedRole()); status.setComplete(); modelMap.clear(); return new RedirectView( "detailteam.shtml?team=" + URLEncoder.encode(teamId, "utf-8") + "&view=" + ViewUtil.getView(request)); }
@Test(expected = RuntimeException.class) public void testEditTeamNoId() throws Exception { MockHttpServletRequest request = getRequest(); String token = TokenUtil.generateSessionToken(); // do NOT add the team id, but do add the team name, team description & token request.addParameter("team", "Team 1"); request.addParameter("description", "description"); request.addParameter("token", token); autoWireMock(editTeamController, new Returns(mockTeam), GrouperTeamService.class); autoWireMock(editTeamController, new Returns(true), ControllerUtil.class); autoWireRemainingResources(editTeamController); editTeamController.editTeam(getModelMap(), request, token, token, new SimpleSessionStatus()); }
@Test(expected = RuntimeException.class) public void testEditTeamNoMember() throws Exception { MockHttpServletRequest request = getRequest(); String token = TokenUtil.generateSessionToken(); // Add the teamId, team name, description & token request.addParameter("teamName", "Team 1"); request.addParameter("team", "team-1"); request.addParameter("description", "description"); request.addParameter("token", token); GrouperTeamService grouperTeamService = mock(GrouperTeamService.class); when(grouperTeamService.findTeamById("team-1")).thenReturn(null); when(grouperTeamService.findMember("team-1", "member-1")).thenReturn(mockAdminMember); autoWireMock(editTeamController, grouperTeamService, GrouperTeamService.class); autoWireMock(editTeamController, new Returns(true), ControllerUtil.class); autoWireRemainingResources(editTeamController); editTeamController.editTeam(getModelMap(), request, token, token, new SimpleSessionStatus()); }
@Test public void testEditTeamHappyFlow() throws Exception { MockHttpServletRequest request = getRequest(); String token = TokenUtil.generateSessionToken(); // Add the teamId, team name, description & token request.addParameter("teamName", "Team 1"); request.addParameter("team", "team-1"); request.addParameter("description", "description"); request.addParameter("token", token); GrouperTeamService grouperTeamService = mock(GrouperTeamService.class); when(grouperTeamService.findTeamById("team-1")).thenReturn(mockTeam); when(grouperTeamService.findMember("team-1", "member-1")).thenReturn(mockAdminMember); autoWireMock(editTeamController, grouperTeamService, GrouperTeamService.class); autoWireMock(editTeamController, new Returns(true), ControllerUtil.class); autoWireRemainingResources(editTeamController); RedirectView result = editTeamController.editTeam( getModelMap(), request, token, token, new SimpleSessionStatus()); assertEquals("detailteam.shtml?team=team-1&view=app", result.getUrl()); }