コード例 #1
0
ファイル: BaseTest.java プロジェクト: rskonnord-plos/ambra
  protected void checkArticleInfo(
      ArticleInfo actual, Article expectedArticle, Article[] expectedRelatedArticles) {
    // basic properties
    assertEquals(
        actual.getDoi(), expectedArticle.getDoi(), "returned article info with incorrect id");
    assertEquals(
        actual.getTitle(),
        expectedArticle.getTitle(),
        "returned article info with incorrect title");
    assertEquals(
        actual.getDate(), expectedArticle.getDate(), "returned article info with incorrect date");
    assertEquals(
        actual.getDescription(), expectedArticle.getDescription(), "incorrect description");
    assertEquals(actual.getRights(), expectedArticle.getRights(), "incorrect rights");
    // check collaborative authors
    if (expectedArticle.getCollaborativeAuthors() != null) {
      assertNotNull(actual.getCollaborativeAuthors(), "returned null collaborative authors");
      assertEqualsNoOrder(
          actual.getCollaborativeAuthors().toArray(),
          expectedArticle.getCollaborativeAuthors().toArray(),
          "incorrect collaborative authors");
    }
    // check categories
    if (expectedArticle.getCategories() == null || expectedArticle.getCategories().size() == 0) {
      assertTrue(
          actual.getCategories() == null || actual.getCategories().size() == 0,
          "returned subjects when none were expected");
    } else {
      assertNotNull(actual.getCategories(), "returned null subjects");

      Set<String> collapsedCategories = new HashSet<String>(expectedArticle.getCategories().size());

      for (Category category : expectedArticle.getCategories()) {
        boolean foundCategory = false;

        collapsedCategories.add(category.getMainCategory());
        collapsedCategories.add(category.getSubCategory());

        for (ArticleCategory cat : actual.getCategories()) {
          if (cat.getMainCategory().equals(category.getMainCategory())) {
            if (cat.getSubCategory().equals(category.getSubCategory())) {
              foundCategory = true;
            }
          }
        }

        assertTrue(foundCategory, "Didn't return category: " + category.getMainCategory());
      }
    }

    // check authors
    if (expectedArticle.getAuthors() != null) {
      assertNotNull(actual.getAuthors(), "returned null list of authors");
      assertEquals(
          actual.getAuthors().size(),
          expectedArticle.getAuthors().size(),
          "returned incorrect number of authors");
      for (ArticleAuthor author : expectedArticle.getAuthors()) {
        assertTrue(
            actual.getAuthors().contains(author.getFullName()),
            "didn't return author: " + author.getFullName());
      }
    }

    // check related articles
    if (expectedRelatedArticles == null || expectedRelatedArticles.length == 0) {
      assertTrue(
          actual.getRelatedArticles() == null || actual.getRelatedArticles().size() == 0,
          "returned related articles when none were expected");
    } else {
      assertNotNull(actual.getRelatedArticles(), "returned null list of related articles");
      assertEquals(
          actual.getRelatedArticles().size(),
          expectedRelatedArticles.length,
          "returned incorrect number of related articles");
      for (Article otherArticle : expectedRelatedArticles) {
        boolean foundMatch = false;

        for (RelatedArticleInfo actualRelatedArticle : actual.getRelatedArticles()) {

          assertNotNull(otherArticle.getTitle(), "Title value of other article is null");
          assertNotNull(otherArticle.getDoi(), "DOI value of other article is null");
          assertNotNull(otherArticle.getTypes(), "Types value of other article is null");

          assertNotNull(actualRelatedArticle.getTitle(), "Title value of actual article is null");
          assertNotNull(actualRelatedArticle.getUri(), "URI value of actual article is null");
          assertNotNull(actualRelatedArticle.getTypes(), "Types value of actual article is null");

          if (otherArticle.getTitle().equals(actualRelatedArticle.getTitle())
              && otherArticle.getDoi().equals(actualRelatedArticle.getUri().toString())
              && otherArticle.getTypes().equals(actualRelatedArticle.getTypes())) {
            foundMatch = true;
            break;
          }
        }
        if (!foundMatch) {
          fail("Didn't include an entry for related article: " + otherArticle.getDoi());
        }
      }
    }
  }
コード例 #2
0
ファイル: BaseTest.java プロジェクト: rskonnord-plos/ambra
  /**
   * Helper method to compare article properties
   *
   * @param actual - actual article
   * @param expected - article with expected properties
   */
  protected void compareArticles(Article actual, Article expected) {
    assertNotNull(actual, "returned null article");
    assertEquals(actual.getDoi(), expected.getDoi(), "Article had incorrect doi");

    assertEquals(actual.geteIssn(), expected.geteIssn(), "returned incorrect eIssn");
    assertEquals(actual.getUrl(), expected.getUrl(), "returned incorrect url");

    assertEquals(actual.getRights(), expected.getRights(), "Article had incorrect rights");
    assertEquals(actual.getLanguage(), expected.getLanguage(), "Article had incorrect language");
    assertEquals(
        actual.getPublisherLocation(),
        expected.getPublisherLocation(),
        "Article had incorrect publisher");
    assertEquals(actual.getFormat(), expected.getFormat(), "Article had incorrect format");
    assertEquals(actual.getTitle(), expected.getTitle(), "Article had incorrect Title");
    assertEquals(
        actual.getDescription(), expected.getDescription(), "Article had incorrect description");
    assertEquals(
        actual.getArchiveName(), expected.getArchiveName(), "Article had incorrect archive name");

    assertEqualsNoOrder(
        actual.getCategories().toArray(),
        expected.getCategories().toArray(),
        "Incorrect categories");

    if (expected.getAssets() != null) {
      assertEquals(
          actual.getAssets().size(), expected.getAssets().size(), "incorrect number of assets");
      for (int i = 0; i < actual.getAssets().size(); i++) {
        compareAssets(actual.getAssets().get(i), expected.getAssets().get(i));
      }
    }
    if (expected.getCitedArticles() != null) {
      assertEquals(
          actual.getCitedArticles().size(),
          expected.getCitedArticles().size(),
          "Returned incorrect number of references");
      for (int i = 0; i < actual.getCitedArticles().size(); i++) {
        compareCitedArticles(actual.getCitedArticles().get(i), expected.getCitedArticles().get(i));
      }
    } else {
      assertTrue(
          actual.getCitedArticles() == null || actual.getCitedArticles().size() == 0,
          "Returned non-empty references when none were expected");
    }

    if (expected.getAuthors() != null) {
      assertNotNull(actual.getAuthors(), "returned null author list");
      assertEquals(
          actual.getAuthors().size(),
          expected.getAuthors().size(),
          "returned incorrect number of authors");
      for (int i = 0; i < expected.getAuthors().size(); i++) {
        ArticleAuthor actualAuthor = actual.getAuthors().get(i);
        ArticleAuthor expectedAuthor = expected.getAuthors().get(i);
        assertEquals(
            actualAuthor.getFullName(),
            expectedAuthor.getFullName(),
            "Article Author had incorrect Real Name");
        assertEquals(
            actualAuthor.getGivenNames(),
            expectedAuthor.getGivenNames(),
            "Article Author had incorrect given name");
        assertEquals(
            actualAuthor.getSurnames(),
            expectedAuthor.getSurnames(),
            "Article Author had incorrect surname");
      }
    }
    if (expected.getEditors() != null) {
      assertNotNull(actual.getEditors(), "returned null editor list");
      assertEquals(
          actual.getEditors().size(),
          expected.getEditors().size(),
          "returned incorrect number of editors");
      for (int i = 0; i < expected.getEditors().size(); i++) {
        ArticleEditor actuaEditor = actual.getEditors().get(i);
        ArticleEditor expectedEditor = expected.getEditors().get(i);
        assertEquals(
            actuaEditor.getFullName(),
            expectedEditor.getFullName(),
            "Article Editor had incorrect Real Name");
        assertEquals(
            actuaEditor.getGivenNames(),
            expectedEditor.getGivenNames(),
            "Article Editor had incorrect given name");
        assertEquals(
            actuaEditor.getSurnames(),
            expectedEditor.getSurnames(),
            "Article Editor had incorrect surname");
      }
    }
    if (expected.getRelatedArticles() != null) {
      assertNotNull(actual.getRelatedArticles(), "null list of related articles");
      assertEquals(
          actual.getRelatedArticles().size(),
          expected.getRelatedArticles().size(),
          "Incorrect number of related articles");
      for (int i = 0; i < actual.getRelatedArticles().size(); i++) {
        ArticleRelationship actualRelatedArticle = actual.getRelatedArticles().get(i);
        ArticleRelationship expectedRelatedArticle = expected.getRelatedArticles().get(i);
        assertEquals(
            actualRelatedArticle.getOtherArticleDoi(),
            expectedRelatedArticle.getOtherArticleDoi(),
            "related article " + i + " had incorrect otherArticleDoi");
        assertEquals(
            actualRelatedArticle.getType(),
            expectedRelatedArticle.getType(),
            "related article " + i + " had incorrect type");
        assertTrue(
            actualRelatedArticle.getParentArticle() == actual,
            "related article had incorrect parent article");
      }
    }
  }