Search in sources :

Example 1 with SiteSet

use of org.ambraproject.wombat.config.site.SiteSet in project wombat by PLOS.

the class TestTheme method testResolveForeignJournalKey.

@Test(dataProvider = "booleans")
public void testResolveForeignJournalKey(final boolean useJournalKeyMap) throws Exception {
    SiteRequestScheme dummyScheme = SiteRequestScheme.builder().build();
    Theme homeTheme = new StubTheme("homeTheme", "homeJournal") {

        @Override
        protected Map<String, Object> getJournalConfigMap() {
            Map<String, Object> map = super.getJournalConfigMap();
            if (useJournalKeyMap) {
                ImmutableMap<String, String> otherJournals = ImmutableMap.of("targetJournal", "targetSite");
                map.put("otherJournals", otherJournals);
            }
            return map;
        }
    };
    Site homeSite = new Site("homeSite", homeTheme, dummyScheme, "");
    Theme targetTheme = new StubTheme("targetTheme", "targetJournal");
    Site targetSite = new Site("targetSite", targetTheme, dummyScheme, "");
    SiteSet siteSet = new SiteSet(ImmutableList.of(homeSite, targetSite));
    Site resolved = homeTheme.resolveForeignJournalKey(siteSet, "targetJournal");
    assertEquals(resolved, targetSite);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) SiteSet(org.ambraproject.wombat.config.site.SiteSet) Test(org.testng.annotations.Test)

Example 2 with SiteSet

use of org.ambraproject.wombat.config.site.SiteSet in project wombat by PLOS.

the class ControllerTestConfiguration method siteSet.

@Bean
protected SiteSet siteSet(Site site) {
    final SiteSet siteSet = mock(SiteSet.class);
    when(siteSet.getSites()).thenReturn(ImmutableSet.of(site));
    return siteSet;
}
Also used : SiteSet(org.ambraproject.wombat.config.site.SiteSet) Bean(org.springframework.context.annotation.Bean)

Example 3 with SiteSet

use of org.ambraproject.wombat.config.site.SiteSet in project wombat by PLOS.

the class HtmlElementTransformationTest method testApply.

@Test
public void testApply() {
    SitePageContext sitePageContext = mock(SitePageContext.class);
    SiteSet siteset = mock(SiteSet.class);
    when(sitePageContext.buildLink(anyString())).thenReturn("path/to/an/internal/page");
    when(sitePageContext.buildLink(any(SiteSet.class), anyString(), anyString())).thenReturn("path/to/another/journal/page");
    String testHtml = "<img data-lemur-key=\"content_1234\"/>" + "<a data-lemur-key=\"file_4321\"/>" + "<a data-lemur-link=\"s/lorum_ipsum\" data-lemur-link-suffix=\"#anchor_string\">Lorem Ipsum</a>" + "<a data-lemur-link=\"s/test-page\" data-lemur-link-journal=\"PLoSCompBiol\">test cross-journal link</a>" + "<a data-lemur-doi=\"10.1371/journal.pone.0008083\">article link</a>";
    Document document = Jsoup.parseBodyFragment(testHtml);
    HtmlElementTransformation.LINK.apply(sitePageContext, siteset, document);
    HtmlElementTransformation.ASSET.apply(sitePageContext, siteset, document);
    HtmlElementTransformation.IMAGE.apply(sitePageContext, siteset, document);
    HtmlElementTransformation.ARTICLE.apply(sitePageContext, siteset, document);
    ArgumentCaptor<String> pathArg = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> journalKeyArg = ArgumentCaptor.forClass(String.class);
    verify(sitePageContext, times(4)).buildLink(pathArg.capture());
    verify(sitePageContext).buildLink(any(SiteSet.class), journalKeyArg.capture(), pathArg.capture());
    List<String> pathArgs = pathArg.getAllValues();
    assertEquals("s/lorum_ipsum", pathArgs.get(0));
    assertEquals("s/file?id=file_4321", pathArgs.get(1));
    assertEquals("indirect/content_1234", pathArgs.get(2));
    assertEquals("article?id=10.1371/journal.pone.0008083", pathArgs.get(3));
    assertEquals("s/test-page", pathArgs.get(4));
    assertEquals("PLoSCompBiol", journalKeyArg.getValue());
    assertEquals(document.toString(), "<html>\n" + " <head></head>\n" + " <body>\n" + "  <img src=\"path/to/an/internal/page\">\n" + "  <a href=\"path/to/an/internal/page\"></a>\n" + "  <a href=\"path/to/an/internal/page#anchor_string\">Lorem Ipsum</a>\n" + "  <a href=\"path/to/another/journal/page\">test cross-journal link</a>\n" + "  <a href=\"path/to/an/internal/page\">article link</a>\n" + " </body>\n" + "</html>");
}
Also used : SiteSet(org.ambraproject.wombat.config.site.SiteSet) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 4 with SiteSet

use of org.ambraproject.wombat.config.site.SiteSet in project wombat by PLOS.

the class WombatControllerTestConfig method siteSetDependency.

@Bean
public SiteSet siteSetDependency() {
    Site mockSite = mock(Site.class);
    ImmutableSet<Site> sitesSet = new ImmutableSet.Builder<Site>().add(mockSite).build();
    when(mockSite.getJournalKey()).thenReturn("daJournalKey");
    SiteRequestScheme mockRequestScheme = mock(SiteRequestScheme.class);
    when(mockRequestScheme.isForSite(any(HttpServletRequest.class))).thenReturn(true);
    when(mockSite.getRequestScheme()).thenReturn(mockRequestScheme);
    when(mockSite.toString()).thenReturn(MOCK_SITE_URL);
    SiteSet mockSet = mock(SiteSet.class);
    when(mockSet.getSites()).thenReturn(sitesSet);
    return mockSet;
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HttpServletRequest(javax.servlet.http.HttpServletRequest) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) SiteSet(org.ambraproject.wombat.config.site.SiteSet) Bean(org.springframework.context.annotation.Bean)

Example 5 with SiteSet

use of org.ambraproject.wombat.config.site.SiteSet in project wombat by PLOS.

the class TestTheme method testResolveForeignJournalKey.

@Test
public void testResolveForeignJournalKey() throws Exception {
    SiteRequestScheme dummyScheme = SiteRequestScheme.builder().build();
    Theme homeTheme = new StubTheme("homeTheme", "homeJournal") {

        @Override
        protected Map<String, Object> getJournalConfigMap() {
            Map<String, Object> map = super.getJournalConfigMap();
            if (useJournalKeyMap) {
                ImmutableMap<String, String> otherJournals = ImmutableMap.of("targetJournal", "targetSite");
                map.put("otherJournals", otherJournals);
            }
            return map;
        }
    };
    Site homeSite = new Site("homeSite", homeTheme, dummyScheme, "");
    Theme targetTheme = new StubTheme("targetTheme", "targetJournal");
    Site targetSite = new Site("targetSite", targetTheme, dummyScheme, "");
    SiteSet siteSet = new SiteSet(ImmutableList.of(homeSite, targetSite));
    Site resolved = homeTheme.resolveForeignJournalKey(siteSet, "targetJournal");
    assertEquals(targetSite, resolved);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) SiteSet(org.ambraproject.wombat.config.site.SiteSet) Test(org.junit.Test)

Aggregations

SiteSet (org.ambraproject.wombat.config.site.SiteSet)5 Site (org.ambraproject.wombat.config.site.Site)3 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)3 Test (org.junit.Test)2 Bean (org.springframework.context.annotation.Bean)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Document (org.jsoup.nodes.Document)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Test (org.testng.annotations.Test)1