MakeDefaultProfileController 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); ModelAndView mav = null; try { profileManager.setProfileAsDefault(profile); mav = getView(pcomm); } catch (WCTInvalidStateRuntimeException e) { Object[] vals = new Object[] {profile.getName(), profile.getOwningAgency().getName()}; errors.reject("profile.inactive", vals, "The profile is inactive"); mav = getView(pcomm); mav.addObject(Constants.GBL_ERRORS, errors); } return mav; } else { return CommonViews.AUTHORISATION_FAILURE; } } MakeDefaultProfileController(); ProfileManager getProfileManager();  }
@Test public final void testHandle() { ModelAndView mav = null; ProfileListCommand command = null; ProfileManager profileManager = new MockProfileManager(testFile); testInstance.setProfileManager(profileManager); testInstance.setAuthorityManager(new AuthorityManagerImpl()); testInstance.setAgencyUserManager(new MockAgencyUserManagerImpl(testFile)); try { this.removeAllCurrentUserPrivileges(); mav = performTestHandle("",13001L); assertTrue(mav.getViewName().equals("authorisation-failure")); assertTrue(profileManager.load(13000L).isDefaultProfile()); this.addCurrentUserPrivilege(Privilege.SCOPE_ALL, Privilege.MANAGE_PROFILES); 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_ERRORS)!= null); assertTrue(profileManager.load(13000L).isDefaultProfile()); mav = performTestHandle("",13004L); command = (ProfileListCommand)mav.getModel().get("command"); assertTrue(command != null); assertTrue(command.getDefaultAgency().equals("")); assertTrue(mav.getViewName().equals("profile-list")); assertFalse(profileManager.load(13000L).isDefaultProfile()); assertTrue(profileManager.load(13004L).isDefaultProfile()); } catch(Exception e) { fail(e.getClass().getName()+": "+e.getMessage()); } }