@Test(dataProvider = "basicInfo")
  public void testExecuteNoAction(
      ArticleList expectedArticleList,
      Map<String, Integer> indices,
      Set<String> validDois,
      Set<String> orphanDois)
      throws Exception {
    action.setListKey(expectedArticleList.getListKey());
    String result = action.execute();
    assertEquals(result, Action.SUCCESS, "Action didn't return success");

    assertEquals(action.getActionErrors().size(), 0, "Action returned error messages");
    assertEquals(
        action.getActionMessages().size(), 0, "Action returned messages on default request");

    ArticleList actualArticleList = action.getArticleList();
    assertEquals(
        actualArticleList.getListKey(),
        expectedArticleList.getListKey(),
        "Action returned incorrect issue");
    assertEquals(
        actualArticleList.getDisplayName(),
        expectedArticleList.getDisplayName(),
        "Action returned issue with incorrect display name");
    assertEquals(
        actualArticleList.getArticles(),
        expectedArticleList.getArticles(),
        "Action returned wrong Dois in articleList");

    assertEquals(
        Arrays.asList(action.getArticleOrderCSV().split(",")),
        getDois(expectedArticleList.getArticles()),
        "Action returned different articleOrderCSV");

    // the action should show the article csv in order of the valid articles
    assertEquals(
        isSorted(action.getArticleOrderCSV().split(","), indices),
        true,
        "Action returned unsorted articles");

    for (ArticleInfo articleInfo : action.getArticleInfoList()) {
      String doi = articleInfo.getDoi();
      assertEquals(
          validDois.contains(doi), true, "Action returned orphan articles in articleInfoList");
    }
  }
  @DataProvider(name = "basicInfo")
  public Object[][] getBasicInfo() {
    dummyDataStore.deleteAll(Article.class);
    dummyDataStore.deleteAll(ArticleList.class);

    Map<String, Integer> indices = new HashMap<String, Integer>();
    Set<String> validDois = new HashSet<String>();
    Set<String> orphanDois = new HashSet<String>();

    ArticleList articleList = new ArticleList();
    articleList.setListType(ArticleManagementAction.ARTICLE_LIST_TYPE);
    articleList.setListKey("id:testArticleListForArticleManagement");
    articleList.setDisplayName("News");
    int articlesCount = 8;
    articleList.setArticles(new ArrayList<Article>());

    for (int i = 0; i < articlesCount; i++) {
      String doi;

      // two articles are invalid at index 3 and 4
      if (i != 3 && i != 4) {
        doi = "id:valid-article-" + i;
        Article article = new Article();
        article.setDoi(doi);
        article.setTitle("Title for Valid Article " + i);
        dummyDataStore.store(article);
        articleList.getArticles().add(article);
        validDois.add(doi);
      } else {
        doi = "id:orphan-article-" + i;
        orphanDois.add(doi);
      }

      indices.put(doi, i);
    }

    dummyDataStore.store(articleList);

    return new Object[][] {{articleList, indices, validDois, orphanDois}};
  }
  @Test(
      dataProvider = "basicInfo",
      dependsOnMethods = {"testExecuteNoAction"},
      alwaysRun = true)
  public void testUpdateArticleList(
      ArticleList articleList,
      Map<String, Integer> indices,
      Set<String> validDois,
      Set<String> orphanDois)
      throws Exception {
    // execute the action to get the current CSV
    action.setCommand("foo");
    action.setListKey(articleList.getListKey());
    action.execute();
    clearMessages();

    List<Article> existingArticles =
        dummyDataStore.get(ArticleList.class, articleList.getID()).getArticles();

    // move first doi to last in reorder
    String reorderedArticleCsv = action.getArticleOrderCSV();
    String articleToReorder = reorderedArticleCsv.substring(0, reorderedArticleCsv.indexOf(","));
    reorderedArticleCsv = reorderedArticleCsv.replaceFirst(articleToReorder + ",", "");
    reorderedArticleCsv += ("," + articleToReorder);
    List<String> orderedArticlesForDb = Arrays.asList(reorderedArticleCsv.split(","));
    Map<String, Integer> newIndices = new HashMap<String, Integer>();
    for (int i = 0; i < orderedArticlesForDb.size(); ++i) {
      newIndices.put(orderedArticlesForDb.get(i), i);
    }

    String displayName = "Spam";

    action.setCommand("UPDATE_LIST");
    action.setListKey(articleList.getListKey());
    action.setArticleOrderCSV(reorderedArticleCsv);
    action.setDisplayName(displayName);

    String result = action.execute();
    assertEquals(result, Action.SUCCESS, "Action didn't return success");

    assertEquals(action.getActionErrors().size(), 0, "Action returned error messages");
    assertTrue(
        action.getActionMessages().size() > 0, "Action didn't return messages indicating success");

    // check properties on action
    assertEquals(
        action.getArticleList().getListKey(),
        articleList.getListKey(),
        "action changed article list after update");
    assertEquals(action.getDisplayName(), displayName, "action had incorrect display name");

    assertEquals(
        getDois(action.getArticleList().getArticles()),
        orderedArticlesForDb,
        "Action returned wrong Dois in articleList");

    assertEquals(
        action.getArticleOrderCSV(),
        reorderedArticleCsv,
        "Action returned different articleOrderCSV");

    // the action should show the article csv in order of the valid articles
    assertEquals(
        isSorted(action.getArticleOrderCSV().split(","), newIndices),
        true,
        "Action returned wrong order after update articles");

    for (ArticleInfo articleInfo : action.getArticleInfoList()) {
      String doi = articleInfo.getDoi();
      assertEquals(
          validDois.contains(doi), true, "Action returned orphan articles in articleInfoList");
    }

    // check what got stored to the database
    ArticleList storedArticleList = dummyDataStore.get(ArticleList.class, articleList.getID());

    assertEquals(
        storedArticleList.getDisplayName(),
        displayName,
        "Article List got saved to the database with incorrect display name");

    assertEqualsNoOrder(
        storedArticleList.getArticles().toArray(),
        existingArticles.toArray(),
        "Articles got removed or added from the list on reordering");
  }