/**
   * This test ensures that the "processTab" method correctly adds an annotation. This function is
   * required to support the new prompt for saving the record when the user clicks "add" for
   * annotations. Refer to https://sourceforge.net/p/webcurator/enhancements/84/
   *
   * @throws Exception
   */
  @Test
  public final void testProcessTab() throws Exception {
    HttpServletRequest aReq = new MockHttpServletRequest();
    SiteManager siteManager = new MockSiteManagerImpl(testFile);
    testInstance.setSiteManager(siteManager);
    Site site = siteManager.getSite(9000L, true);
    List<Annotation> list = createAnnotationList();
    assertFalse(checkSortedList(list));
    site.setAnnotations(list);
    SiteEditorContext ctx = new SiteEditorContext(site);
    aReq.getSession().setAttribute(SiteController.EDITOR_CONTEXT, ctx);
    HttpServletResponse aResp = new MockHttpServletResponse();
    SiteCommand aCmd = new SiteCommand();
    TabbedController tc = new SiteController();

    TabConfig tabConfig = new TabConfig();
    tabConfig.setViewName("site");
    List<Tab> tabs = getTabList(siteManager);
    tabConfig.setTabs(tabs);

    tc.setTabConfig(tabConfig);

    Tab currentTab = tabs.get(0);
    aCmd.setCmdAction(SiteCommand.ACTION_ADD_NOTE);
    aCmd.setAnnotation("A note");
    BindException aErrors = new BindException(aCmd, aCmd.getCmdAction());

    List<Annotation> resultAnnotations = site.getAnnotations();
    int numAnnotations = resultAnnotations.size();

    testInstance.processTab(tc, currentTab, aReq, aResp, aCmd, aErrors);
    assertEquals(resultAnnotations.size(), numAnnotations + 1);
    Annotation resultAnnotation = resultAnnotations.get(resultAnnotations.size() - 1);
    assertEquals("A note", resultAnnotation.getNote());
  }
  @Test
  public final void testPreProcessNextTab() {

    try {
      HttpServletRequest aReq = new MockHttpServletRequest();
      SiteManager siteManager = new MockSiteManagerImpl(testFile);
      testInstance.setSiteManager(siteManager);
      Site site = siteManager.getSite(9000L, true);
      List<Annotation> list = createAnnotationList();
      assertFalse(checkSortedList(list));
      site.setAnnotations(list);
      SiteEditorContext ctx = new SiteEditorContext(site);
      aReq.getSession().setAttribute(SiteController.EDITOR_CONTEXT, ctx);
      HttpServletResponse aResp = new MockHttpServletResponse();
      SiteCommand aCmd = new SiteCommand();
      TabbedController tc = new SiteController();

      TabConfig tabConfig = new TabConfig();
      tabConfig.setViewName("site");
      List<Tab> tabs = getTabList(siteManager);
      tabConfig.setTabs(tabs);

      tc.setTabConfig(tabConfig);

      Tab currentTab = tabs.get(0);
      BindException aErrors = new BindException(aCmd, aCmd.getCmdAction());

      ModelAndView mav = testInstance.preProcessNextTab(tc, currentTab, aReq, aResp, aCmd, aErrors);
      assertNotNull(mav);
      assertTrue(checkSortedList(site.getAnnotations()));
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
Beispiel #3
0
  @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 testProcessOther() {
    try {
      HttpServletRequest aReq = new MockHttpServletRequest();
      SiteManager siteManager = new MockSiteManagerImpl(testFile);
      testInstance.setSiteManager(siteManager);
      Site site = siteManager.getSite(9000L, true);
      List<Annotation> list = createAnnotationList();
      assertFalse(checkSortedList(list));
      site.setAnnotations(list);
      SiteEditorContext ctx = new SiteEditorContext(site);
      aReq.getSession().setAttribute(SiteController.EDITOR_CONTEXT, ctx);
      HttpServletResponse aResp = new MockHttpServletResponse();
      SiteCommand aCmd = new SiteCommand();
      TabbedController tc = new SiteController();

      TabConfig tabConfig = new TabConfig();
      tabConfig.setViewName("site");
      List<Tab> tabs = getTabList(siteManager);
      tabConfig.setTabs(tabs);

      tc.setTabConfig(tabConfig);

      Tab currentTab = tabs.get(0);
      aCmd.setCmdAction(SiteCommand.ACTION_ADD_NOTE);
      aCmd.setAnnotation("A note");
      BindException aErrors = new BindException(aCmd, aCmd.getCmdAction());

      int numAnnotations = site.getAnnotations().size();

      ModelAndView mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors);
      assertTrue(mav != null);
      assertTrue(mav.getViewName().equals("site"));
      assertTrue(
          ((TabStatus) mav.getModel().get("tabStatus"))
              .getCurrentTab()
              .getPageId()
              .equals("GENERAL"));
      int listSize = site.getAnnotations().size();
      assertTrue(listSize > 0);
      int noteIndex = 0;
      assertTrue(site.getAnnotations().size() == (numAnnotations + 1));
      assertTrue(site.getAnnotations().get(noteIndex).getNote().equals("A note"));
      assertTrue(checkSortedList(site.getAnnotations()));

      currentTab = tabs.get(0);
      aCmd.setCmdAction(SiteCommand.ACTION_MODIFY_NOTE);
      aCmd.setAnnotation("A new note");
      aCmd.setAnnotationIndex(noteIndex);
      aErrors = new BindException(aCmd, aCmd.getCmdAction());

      mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors);
      assertTrue(mav != null);
      assertTrue(mav.getViewName().equals("site"));
      assertTrue(
          ((TabStatus) mav.getModel().get("tabStatus"))
              .getCurrentTab()
              .getPageId()
              .equals("GENERAL"));
      listSize = site.getAnnotations().size();
      assertTrue(listSize > 0);
      int newNoteIndex = 0;
      assertTrue(newNoteIndex == noteIndex);
      assertTrue(site.getAnnotations().size() == (numAnnotations + 1));
      assertFalse(site.getAnnotations().get(noteIndex).getNote().equals("A note"));
      assertTrue(site.getAnnotations().get(noteIndex).getNote().equals("A new note"));
      assertTrue(checkSortedList(site.getAnnotations()));

      currentTab = tabs.get(0);
      aCmd.setCmdAction(SiteCommand.ACTION_DELETE_NOTE);
      aCmd.setAnnotationIndex(noteIndex);
      aErrors = new BindException(aCmd, aCmd.getCmdAction());

      mav = testInstance.processOther(tc, currentTab, aReq, aResp, aCmd, aErrors);
      assertTrue(mav != null);
      assertTrue(mav.getViewName().equals("site"));
      assertTrue(
          ((TabStatus) mav.getModel().get("tabStatus"))
              .getCurrentTab()
              .getPageId()
              .equals("GENERAL"));
      int newListSize = site.getAnnotations().size();
      assertTrue(newListSize == (listSize - 1));
      assertTrue(site.getAnnotations().size() == numAnnotations);
      assertTrue(checkSortedList(site.getAnnotations()));
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }