public void testSearchWithNoResults() {
   table.setFiltered(true);
   table.setKeywordFilter("zzz");
   table.computeDisplay();
   ArrayList rows = table.getRows();
   assertEquals("got right number of rows", rows.size(), 0);
 }
  public void testPaginationSecondPage() {
    table.setPaginated(true);
    table.setCurrPageNumber(2);

    table.computeDisplay();

    ArrayList rows = table.getRows();
    assertEquals("got right number of rows", rows.size(), 8);
  }
  public void testPaginationFirstPage() {
    table.setPaginated(true);
    table.setCurrPageNumber(1);

    table.computeDisplay();

    ArrayList rows = table.getRows();
    assertEquals("got right number of rows", rows.size(), EntityBeanTable.NUM_ROWS_PER_PAGE);
  }
  public void testSortByUserNameDESC() {
    table.setAscendingSort(false);
    table.setSortingColumnInd(UserAccountRow.COL_USERNAME);

    table.computeDisplay();
    ArrayList rows = table.getRows();

    UserAccountRow first = (UserAccountRow) rows.get(0);
    assertEquals("got first row right", first.getBean().getName(), "ghi");
  }
  public void testSortByFirstNameASC() {
    table.setAscendingSort(true);
    table.setSortingColumnInd(UserAccountRow.COL_FIRSTNAME);

    table.computeDisplay();
    ArrayList rows = table.getRows();

    UserAccountRow first = (UserAccountRow) rows.get(0);
    assertEquals("got first row right", first.getBean().getName(), "def");
  }
  public void testSearchMultipleKeywords() {
    // we will use the multi-keyword search feature, searching for "def" and "ghi"
    // this should return only users def and ghi, no one else
    // so we expect exactly two rows

    table.setFiltered(true);
    table.setKeywordFilter("def ghi");
    table.computeDisplay();

    ArrayList rows = table.getRows();
    assertEquals("got right number of rows", rows.size(), 2);
  }
  /** Finds all the studies */
  @Override
  public void processRequest() throws Exception {

    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    ArrayList studies = (ArrayList) sdao.findAll();
    // find all parent studies
    ArrayList parents = (ArrayList) sdao.findAllParents();
    ArrayList displayStudies = new ArrayList();

    for (int i = 0; i < parents.size(); i++) {
      StudyBean parent = (StudyBean) parents.get(i);
      ArrayList children = (ArrayList) sdao.findAllByParent(parent.getId());
      DisplayStudyBean displayStudy = new DisplayStudyBean();
      displayStudy.setParent(parent);
      displayStudy.setChildren(children);
      displayStudies.add(displayStudy);
    }

    FormProcessor fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudyRow.generateRowsFromBeans(displayStudies);

    String[] columns = {
      resword.getString("name"),
      resword.getString("unique_identifier"),
      resword.getString("OID"),
      resword.getString("principal_investigator"),
      resword.getString("facility_name"),
      resword.getString("date_created"),
      resword.getString("status"),
      resword.getString("actions")
    };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.hideColumnLink(2);
    table.hideColumnLink(6);
    table.setQuery("ListStudy", new HashMap());
    table.addLink(resword.getString("create_a_new_study"), "CreateStudy");
    table.setRows(allStudyRows);
    table.computeDisplay();

    request.setAttribute("table", table);
    // request.setAttribute("studies", studies);
    session.setAttribute("fromListSite", "no");

    resetPanel();
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);
    setToPanel(resword.getString("in_the_application"), "");
    if (parents.size() > 0) {
      setToPanel(resword.getString("studies"), new Integer(parents.size()).toString());
    }
    if (studies.size() > 0) {
      setToPanel(
          resword.getString("sites"), new Integer(studies.size() - parents.size()).toString());
    }
    forwardPage(Page.STUDY_LIST);
  }
  private void populateRows() {
    UserAccountBean a = new UserAccountBean();
    UserAccountBean b = new UserAccountBean();
    UserAccountBean c = new UserAccountBean();

    // order the beans a,b,c by username
    a.setName("abc");
    b.setName("def");
    c.setName("ghi");

    // order the beans b,c,a by first name
    a.setFirstName("Zack");
    b.setFirstName("Bob abc");
    c.setFirstName("Cindy");

    // order the beans c,b,a by last name
    a.setLastName("Xerxes");
    b.setLastName("Zuckerman");
    c.setLastName("Connor");

    UserAccountRow rowA = new UserAccountRow();
    rowA.setBean(a);
    UserAccountRow rowB = new UserAccountRow();
    rowB.setBean(b);
    UserAccountRow rowC = new UserAccountRow();
    rowC.setBean(c);
    UserAccountRow[] rows = {rowA, rowB, rowC};

    ArrayList tempRows = new ArrayList(Arrays.asList(rows));

    // add 15 dummy rows so we can test out pagination
    for (int i = 0; i < 15; i++) {
      UserAccountBean uab = new UserAccountBean();
      // force these beans into the middle of the alphabet so they don't
      // ruin the sorting results
      uab.setName("efg");
      uab.setFirstName("jjj");
      uab.setLastName("jjj");
      UserAccountRow uar = new UserAccountRow();
      uar.setBean(uab);
      tempRows.add(uar);
    }

    table.setRows(tempRows);
  }
  public void testPaginationWithSearchSecondPage() {
    table.setFiltered(true);
    table.setPaginated(true);
    table.setKeywordFilter("efg");
    table.setCurrPageNumber(2);

    table.computeDisplay();

    ArrayList rows = table.getRows();
    assertEquals("got right number of rows", rows.size(), 5);

    UserAccountRow head = (UserAccountRow) rows.get(0);
    UserAccountRow tail = (UserAccountRow) rows.get(rows.size() - 1);
    assertEquals("correct bean at top of the list", head.getBean().getName(), "efg");
    assertEquals("correct bean at end of the list", tail.getBean().getName(), "efg");
  }
  public void testSearchAndSortingCombined() {
    table.setFiltered(true);
    table.setKeywordFilter("abc");
    table.setAscendingSort(true);
    table.setSortingColumnInd(UserAccountRow.COL_FIRSTNAME);
    table.computeDisplay();

    // users abc and def should have been returned.
    // since we are sorting on the first name, def should show up first

    ArrayList rows = table.getRows();
    assertEquals("got right number of rows", rows.size(), 2);

    UserAccountRow row = (UserAccountRow) rows.get(0);
    assertEquals("got first row right", row.getBean().getName(), "def");
  }
  public void testPaginationSecondPageWithSortDESC() {
    // we're going to sort by username DESC, then paginate and go to page 2
    // since user efg is in the middle by username,
    // the first element of rows should be that user

    table.setSortingColumnInd(UserAccountRow.COL_USERNAME);
    table.setAscendingSort(false);
    table.setPaginated(true);
    table.setCurrPageNumber(2);

    table.computeDisplay();

    ArrayList rows = table.getRows();
    assertEquals("got right number of rows", rows.size(), 8);

    UserAccountRow head = (UserAccountRow) rows.get(0);
    UserAccountRow tail = (UserAccountRow) rows.get(rows.size() - 1);
    assertEquals("correct bean at top of the list", head.getBean().getName(), "efg");
    assertEquals("correct bean at end of the list", tail.getBean().getName(), "abc");
  }