Exemplo n.º 1
0
  /**
   * 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());
  }
Exemplo n.º 2
0
  private Annotation createAnnotation(String note, String date) throws ParseException {
    Annotation ann = new Annotation();

    ann.setDate(sdf.parse(date));
    ann.setNote(note);
    ann.setUser(AuthUtil.getRemoteUserObject());
    return ann;
  }