@Test
  public final void testProcessSave() {
    try {

      MockHttpServletRequest request = new MockHttpServletRequest();
      MockHttpServletResponse response = new MockHttpServletResponse();

      // TargetInstance target = manager.getTargetInstance(5000L);

      request.getSession().setAttribute(TargetInstanceCommand.SESSION_MODE, true);
      request.getSession().setAttribute(Constants.GBL_SESS_EDIT_MODE, true);

      TargetInstanceCommand comm = new TargetInstanceCommand();
      comm.setCmd(TargetInstanceCommand.ACTION_EDIT);
      comm.setTargetInstanceId(5000L);

      Tab currTab = testInstance.getTabConfig().getTabs().get(0);
      assertTrue(currTab != null);
      BindException aError = new BindException(new TargetDefaultCommand(), null);
      testInstance.showForm(request, response, comm, aError);
      // context = testInstance.getEditorContext(request);
      // context.getTarget().setName("Test Target");
      // context.setParents(new ArrayList<GroupMemberDTO>());
      ModelAndView mav = testInstance.processSave(currTab, request, response, comm, aError);
      assertTrue(mav != null);
      assertTrue(mav.getViewName().equals("TargetInstanceQueue"));
      assertTrue(mav.getModel().get("page_message") != null);
      assertTrue(((String) mav.getModel().get("page_message")).startsWith("targetInstance.saved"));
    } catch (Exception e) {
      String message = e.getClass().toString() + " - " + e.getMessage();
      log.debug(message);
      fail(message);
    }
  }
  @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"));
      // TargetEditorContext context = testInstance.getEditorContext(request);
      // assertSame(context.getTarget().getOwningUser(), AuthUtil.getRemoteUserObject().getUser());
    } catch (Exception e) {
      String message = e.getClass().toString() + " - " + e.getMessage();
      log.debug(message);
      fail(message);
    }
  }
  @Test
  public final void testProcessCancel() {
    try {
      MockHttpServletRequest request = new MockHttpServletRequest();
      MockHttpServletResponse response = new MockHttpServletResponse();

      TargetInstanceCommand comm = new TargetInstanceCommand();
      comm.setCmd(TargetInstanceCommand.ACTION_EDIT);
      comm.setTargetInstanceId(5000L);

      Tab currTab = testInstance.getTabConfig().getTabs().get(0);
      assertTrue(currTab != null);
      BindException aError = new BindException(new DefaultSiteCommand(), null);
      ModelAndView mav = testInstance.processCancel(currTab, request, response, comm, aError);
      assertTrue(mav != null);
      assertTrue(mav.getViewName().equals("redirect:/curator/target/queue.html"));
    } 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(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);
    }
  }