@Test(
      dataProvider = "basicInfo",
      dependsOnMethods = {"testExecuteNoAction"},
      alwaysRun = true)
  public void testActionDoesNotAllowRemovingArticleFromCsv(
      ArticleList articleList,
      Map<String, Integer> indices,
      Set<String> validDois,
      Set<String> orphanDois)
      throws Exception {
    // execute the action to get the original csv
    action.setListKey(articleList.getListKey());
    action.execute();
    String originalCsv = action.getArticleOrderCSV();

    String articleToRemove = originalCsv.substring(0, originalCsv.indexOf(","));
    String incorrectCsv = originalCsv.replace(articleToRemove + ",", "");

    action.setCommand("UPDATE_LIST");
    action.setArticleOrderCSV(incorrectCsv);
    action.setDisplayName(articleList.getDisplayName());

    // should fail
    String result = action.execute();
    assertEquals(result, Action.SUCCESS, "Action didn't return success");
    assertTrue(action.getActionErrors().size() > 0, "Action didn't return error messages");
  }
  @Test(
      dataProvider = "basicInfo",
      dependsOnMethods = {"testExecuteNoAction"},
      alwaysRun = true)
  public void testActionDoesNotAllowChangingArticlesInCsv(
      ArticleList articleList,
      Map<String, Integer> indices,
      Set<String> validDois,
      Set<String> orphanDois)
      throws Exception {
    // execute the action to get the original csv
    action.setListKey(articleList.getListKey());
    action.execute();
    String originalCsv = action.getArticleOrderCSV();

    String changedCsv = originalCsv.substring(originalCsv.indexOf(",") + 1);
    changedCsv = "id:this-article-was-not-in-original-csv," + changedCsv;

    assertEquals(
        changedCsv.split(",").length,
        originalCsv.split(",").length,
        "test added or removed articles instead of just changing one");

    action.setCommand("UPDATE_LIST");
    action.setArticleOrderCSV(changedCsv);
    action.setDisplayName(articleList.getDisplayName());

    // should fail
    String result = action.execute();
    assertEquals(result, Action.SUCCESS, "Action didn't return success");
    assertTrue(action.getActionErrors().size() > 0, "Action didn't return error messages");
  }
  @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");
  }