// Override BaseWCTTest setup method
  public void setUp() throws Exception {
    // call the overridden method as well
    super.setUp();

    // add the extra bits
    authorityManager = new AuthorityManagerImpl();
    testInstance.setAuthorityManager(authorityManager);
    BusinessObjectFactory factory = new BusinessObjectFactory();
    factory.setProfileManager(new MockProfileManager(testFile));
    // testInstance.setBusinessObjectFactory(factory);
    testInstance.setMessageSource(new MockMessageSource());
    manager = new MockTargetInstanceManager(testFile);
    testInstance.setTargetInstanceManager(manager);
    TabConfig tabConfig = new TabConfig();
    tabConfig.setViewName("target-instance");
    List<Tab> tabs = getTabList(manager);
    tabConfig.setTabs(tabs);
    testInstance.setTabConfig(tabConfig);
    QueueController queueController = new QueueController();
    queueController.setEnvironment(new EnvironmentImpl());
    queueController.setAgencyUserManager(new MockAgencyUserManagerImpl(testFile));
    queueController.setTargetInstanceManager(manager);
    queueController.setHarvestCoordinator(new MockHarvestCoordinator());
    // MockTargetDAO targetDao = new MockTargetDAO(testFile);
    // searchController.setTargetDao(targetDao);
    testInstance.setQueueController(queueController);
  }
Exemplo n.º 2
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.º 3
0
  @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());
    }
  }
Exemplo n.º 4
0
  @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());
    }
  }