TabbedTargetInstanceController extends TabbedController { @Override protected ModelAndView showForm(HttpServletRequest req, HttpServletResponse res, Object comm, BindException errors) throws Exception { return processInitial(req, res, comm, errors); }  void setTargetInstanceManager(TargetInstanceManager targetInstanceManager); void setHarvestCoordinator(HarvestCoordinator harvestCoordinator); void setAuthorityManager(AuthorityManager authorityManager); void setQueueController(QueueController queueController); void setMessageSource(MessageSource messageSource);  }
@Test public final void testShowForm() { try { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); TargetInstanceCommand comm = new TargetInstanceCommand(); comm.setCmd(TargetInstanceCommand.ACTION_EDIT); comm.setTargetInstanceId(5000L); BindException aError = new BindException(new DefaultSiteCommand(), null); ModelAndView mav = testInstance.showForm(request, response, comm, aError); assertTrue(mav != null); assertTrue(mav.getViewName().equals("target-instance")); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
@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((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((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); } }