DeleteProfileController extends ProfileListController { @Override protected ModelAndView handle(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { ViewCommand command = (ViewCommand) comm; Profile profile = profileManager.load(command.getProfileOid()); if(authorityManager.hasPrivilege(profile, Privilege.MANAGE_PROFILES)) { boolean showInactive = (Boolean) req.getSession().getAttribute(ProfileListController.SESSION_KEY_SHOW_INACTIVE); String defaultAgency = (String)req.getSession().getAttribute(ProfileListController.SESSION_AGENCY_FILTER); if(defaultAgency == null) { defaultAgency = AuthUtil.getRemoteUserObject().getAgency().getName(); } ProfileListCommand pcomm = new ProfileListCommand(); pcomm.setShowInactive(showInactive); pcomm.setDefaultAgency(defaultAgency); if(profileManager.isProfileInUse(profile)) { errors.reject("profile.errors.delete.inuse", new Object[] { profile.getName() }, "Profile '" + profile.getName() + "' is in use"); ModelAndView mav = getView(pcomm); mav.addObject(Constants.GBL_ERRORS, errors); return mav; } else { profileManager.delete(profile); ModelAndView mav = getView(pcomm); String message = messageSource.getMessage("profile.message.delete.success", new Object[] { profile.getName() }, Locale.getDefault()); mav.addObject(Constants.GBL_MESSAGES, message); return mav; } } else { return CommonViews.AUTHORISATION_FAILURE; } } DeleteProfileController(); ProfileManager getProfileManager(); void setMessageSource(MessageSource messageSource);  }
@Test public final void testHandle() { ModelAndView mav = null; ProfileListCommand command = null; this.testSetMessageSource(); testInstance.setAuthorityManager(new AuthorityManagerImpl()); testInstance.setProfileManager(new MockProfileManager(testFile)); testInstance.setAgencyUserManager(new MockAgencyUserManagerImpl(testFile)); try { this.removeAllCurrentUserPrivileges(); mav = performTestHandle("", 13000L); assertTrue(mav.getViewName().equals("authorisation-failure")); this.addCurrentUserPrivilege(Privilege.SCOPE_ALL, Privilege.MANAGE_PROFILES); mav = performTestHandle("", 13000L); command = (ProfileListCommand)mav.getModel().get("command"); assertTrue(command != null); assertTrue(command.getDefaultAgency().equals("")); assertTrue(mav.getViewName().equals("profile-list")); assertTrue(mav.getModel().get(Constants.GBL_ERRORS)!= null); mav = performTestHandle("", 13001L); command = (ProfileListCommand)mav.getModel().get("command"); assertTrue(command != null); assertTrue(command.getDefaultAgency().equals("")); assertTrue(mav.getViewName().equals("profile-list")); assertTrue(mav.getModel().get(Constants.GBL_MESSAGES)!= null); } catch(Exception e) { fail(e.getClass().getName()+": "+e.getMessage()); } }