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());
}
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());
}
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());
}
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());
}
Aggregations