@Override protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception { ModelAndView mav = new ModelAndView(); User user = AuthUtil.getRemoteUserObject(); int notificationCount = inTrayManager.countNotifications(user); int taskCount = inTrayManager.countTasks(user); int siteCount = siteManager.countSites(); int targetCount = targetManager.countTargets(user); int groupCount = targetManager.countTargetGroups(user); ArrayList<String> states = new ArrayList<String>(); states.add(TargetInstance.STATE_SCHEDULED); int schedCount = targetInstanceManager.countTargetInstances(user, states); states.clear(); states.add(TargetInstance.STATE_HARVESTED); int qaCount = targetInstanceManager.countTargetInstances(user, states); mav.addObject(MDL_CNT_NOTIFICATION, new Integer(notificationCount)); mav.addObject(MDL_CNT_TASK, new Integer(taskCount)); mav.addObject(MDL_CNT_SITE, new Integer(siteCount)); mav.addObject(MDL_CNT_TARGET, new Integer(targetCount)); mav.addObject(MDL_CNT_GROUPS, new Integer(groupCount)); mav.addObject(MDL_CNT_SCHEDULED, new Integer(schedCount)); mav.addObject(MDL_CNT_QR, new Integer(qaCount)); if (!enableQaModule) { mav.setViewName(Constants.VIEW_HOME); } else { mav.setViewName(Constants.VIEW_QA_HOME); } return mav; }
@Test public final void testEditButtonVisiblity() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); TargetInstanceCommand comm = new TargetInstanceCommand(); comm.setCmd(TargetInstanceCommand.ACTION_VIEW); comm.setTargetInstanceId(5000L); TargetInstance ti = manager.getTargetInstance(comm.getTargetInstanceId(), true); removeAllCurrentUserPrivileges(); String[] privs = {Privilege.MANAGE_TARGET_INSTANCES, Privilege.MANAGE_WEB_HARVESTER}; assertFalse(authorityManager.hasAtLeastOnePrivilege(ti, privs)); BindException aError = new BindException(new DefaultSiteCommand(), null); ModelAndView mav = testInstance.showForm(request, response, comm, aError); assertFalse((Boolean) request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); addCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MANAGE_TARGET_INSTANCES); assertTrue(authorityManager.hasAtLeastOnePrivilege(ti, privs)); mav = testInstance.showForm(request, response, comm, aError); // assertTrue(mav != null); // assertTrue(mav.getViewName().equals("site")); assertTrue((Boolean) request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); removeCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MANAGE_TARGET_INSTANCES); assertFalse(authorityManager.hasAtLeastOnePrivilege(ti, privs)); addCurrentUserPrivilege(Privilege.SCOPE_ALL, Privilege.MANAGE_TARGET_INSTANCES); assertTrue(authorityManager.hasAtLeastOnePrivilege(ti, privs)); mav = testInstance.showForm(request, response, comm, aError); assertTrue((Boolean) request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); removeAllCurrentUserPrivileges(); assertFalse(authorityManager.hasAtLeastOnePrivilege(ti, privs)); addCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MANAGE_WEB_HARVESTER); assertTrue(authorityManager.hasAtLeastOnePrivilege(ti, privs)); mav = testInstance.showForm(request, response, comm, aError); // assertTrue(mav != null); // assertTrue(mav.getViewName().equals("site")); assertTrue((Boolean) request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); removeCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MANAGE_WEB_HARVESTER); assertFalse(authorityManager.hasAtLeastOnePrivilege(ti, privs)); addCurrentUserPrivilege(Privilege.SCOPE_ALL, Privilege.MANAGE_WEB_HARVESTER); assertTrue(authorityManager.hasAtLeastOnePrivilege(ti, privs)); mav = testInstance.showForm(request, response, comm, aError); assertTrue((Boolean) request.getSession().getAttribute(Constants.GBL_SESS_CAN_EDIT)); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }