Search in sources :

Example 1 with RelatedArticle

use of org.ambraproject.wombat.model.RelatedArticle in project wombat by PLOS.

the class ArticleMetadataTest method testFetchRelatedArticles.

@Test
public void testFetchRelatedArticles() throws Exception {
    String doi = "10.9999/journal.xxxx.0";
    List<RelatedArticle> map = new Gson().fromJson(read("articleMeta/ppat.1005446.related.json"), ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE);
    ApiAddress address = ApiAddress.builder("articles").embedDoi(doi).addToken("relationships").build();
    when(articleApi.requestObject(address, ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE)).thenReturn(map);
    List<RelatedArticle> raList = articleMetadataFactory.fetchRelatedArticles(doi);
    assertEquals(1, raList.size());
    RelatedArticle ra = raList.get(0);
    assertEquals("10.1371/journal.ppat.1006021", ra.getDoi());
    assertEquals(null, ra.getType().getSpecificUse());
}
Also used : RelatedArticle(org.ambraproject.wombat.model.RelatedArticle) Gson(com.google.gson.Gson) ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) Test(org.junit.Test)

Example 2 with RelatedArticle

use of org.ambraproject.wombat.model.RelatedArticle in project wombat by PLOS.

the class ArticleMetadataTest method testGetRelatedArticleByType.

@Test
public void testGetRelatedArticleByType() throws IOException {
    RelatedArticle rel1 = mock(RelatedArticle.class);
    RelatedArticle rel2 = mock(RelatedArticle.class);
    RelatedArticleType type1 = RelatedArticleType.get("retracted-article");
    RelatedArticleType type2 = RelatedArticleType.get("retraction-forward");
    when(rel1.isPublished()).thenReturn(true);
    when(rel1.getPublicationDate()).thenReturn(LocalDate.of(2018, 1, 1));
    when(rel1.getType()).thenReturn(type1);
    when(rel2.isPublished()).thenReturn(true);
    when(rel2.getPublicationDate()).thenReturn(LocalDate.of(2019, 1, 1));
    when(rel2.getType()).thenReturn(type2);
    List<RelatedArticle> relations = ImmutableList.of(rel1, rel2);
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(mock(Site.class), mock(RequestedDoiVersion.class), mock(ArticlePointer.class), new HashMap(), new HashMap(), relations);
    SortedMap<RelatedArticleType, List<RelatedArticle>> map = articleMetadata.getRelatedArticlesByType();
    assertEquals(ImmutableSet.of(type1, type2), map.keySet());
}
Also used : Site(org.ambraproject.wombat.config.site.Site) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) RelatedArticleType(org.ambraproject.wombat.model.RelatedArticleType) HashMap(java.util.HashMap) RelatedArticle(org.ambraproject.wombat.model.RelatedArticle) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) Test(org.junit.Test)

Example 3 with RelatedArticle

use of org.ambraproject.wombat.model.RelatedArticle in project wombat by PLOS.

the class ArticleMetadataTest method testFetchRelatedArticlesWithSpecificUse.

@Test
public void testFetchRelatedArticlesWithSpecificUse() throws Exception {
    String doi = "10.9999/journal.xxxx.0";
    List<RelatedArticle> map = new Gson().fromJson(read("articleMeta/ppat.1005446.related2.json"), ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE);
    ApiAddress address = ApiAddress.builder("articles").embedDoi(doi).addToken("relationships").build();
    when(articleApi.requestObject(address, ArticleMetadata.Factory.RELATED_ARTICLE_GSON_TYPE)).thenReturn(map);
    List<RelatedArticle> raList = articleMetadataFactory.fetchRelatedArticles(doi);
    assertEquals(1, raList.size());
    RelatedArticle ra = raList.get(0);
    assertEquals("foo", ra.getType().getSpecificUse());
}
Also used : RelatedArticle(org.ambraproject.wombat.model.RelatedArticle) Gson(com.google.gson.Gson) ApiAddress(org.ambraproject.wombat.service.remote.ApiAddress) Test(org.junit.Test)

Example 4 with RelatedArticle

use of org.ambraproject.wombat.model.RelatedArticle in project wombat by PLOS.

the class ArticleMetadataTest method testGetRelatedArticlesSortInReversePublicationOrder.

@Test
public void testGetRelatedArticlesSortInReversePublicationOrder() throws IOException {
    RelatedArticle rel1 = mock(RelatedArticle.class);
    RelatedArticle rel2 = mock(RelatedArticle.class);
    when(rel1.isPublished()).thenReturn(true);
    when(rel1.getPublicationDate()).thenReturn(LocalDate.of(2018, 1, 1));
    when(rel2.isPublished()).thenReturn(true);
    when(rel2.getPublicationDate()).thenReturn(LocalDate.of(2019, 1, 1));
    List<RelatedArticle> relations = ImmutableList.of(rel1, rel2);
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(mock(Site.class), mock(RequestedDoiVersion.class), mock(ArticlePointer.class), new HashMap(), new HashMap(), relations);
    assertEquals(ImmutableList.of(rel2, rel1), articleMetadata.getRelatedArticles());
}
Also used : Site(org.ambraproject.wombat.config.site.Site) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) HashMap(java.util.HashMap) RelatedArticle(org.ambraproject.wombat.model.RelatedArticle) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) Test(org.junit.Test)

Aggregations

RelatedArticle (org.ambraproject.wombat.model.RelatedArticle)4 Test (org.junit.Test)4 Gson (com.google.gson.Gson)2 HashMap (java.util.HashMap)2 Site (org.ambraproject.wombat.config.site.Site)2 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)2 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)2 ApiAddress (org.ambraproject.wombat.service.remote.ApiAddress)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RelatedArticleType (org.ambraproject.wombat.model.RelatedArticleType)1