Search in sources :

Example 6 with Site

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

the class ThemeGraphTest method testInheritPropertyFromRoot.

@Test
public void testInheritPropertyFromRoot() throws IOException {
    Site site = MockSiteUtil.getByUniqueJournalKey(siteSet, "journal1Key");
    Map<String, Object> journal = site.getTheme().getConfigMap("homepage");
    Object inheritedValue = journal.get("defaultSelection");
    // expected to match src/main/webapp/WEB-INF/themes/root/config/homepage.yaml
    assertEquals(inheritedValue, null);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) Test(org.junit.Test)

Example 7 with Site

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

the class ArticleMetadataTest method testValidateVisibility.

@Test
public void testValidateVisibility() {
    HashMap<String, String> journalMetadata = new HashMap<>();
    journalMetadata.put("journalKey", "fakeKey");
    HashMap<String, HashMap<String, String>> ingestionMetadata = new HashMap<>();
    ingestionMetadata.put("journal", journalMetadata);
    Theme theme = mock(Theme.class);
    HashMap<String, Object> journalAttrs = new HashMap<>();
    journalAttrs.put("journalKey", "fakeKey");
    journalAttrs.put("journalName", "fakeName");
    when(theme.getConfigMap(any())).thenReturn(journalAttrs);
    Site site = new Site("foo", theme, mock(SiteRequestScheme.class), "foo");
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(site, mock(RequestedDoiVersion.class), mock(ArticlePointer.class), ingestionMetadata, new HashMap(), new ArrayList());
    articleMetadata.validateVisibility("whatever");
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) ArrayList(java.util.ArrayList) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) Theme(org.ambraproject.wombat.config.theme.Theme) Test(org.junit.Test)

Example 8 with Site

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

the class ArticleMetadataTest method testValidateVisibilityFail.

@Test(expected = InternalRedirectException.class)
public void testValidateVisibilityFail() {
    HashMap<String, String> journalMetadata = new HashMap<>();
    journalMetadata.put("journalKey", "someKey");
    HashMap<String, HashMap<String, String>> ingestionMetadata = new HashMap<>();
    ingestionMetadata.put("journal", journalMetadata);
    Theme theme = mock(Theme.class);
    HashMap<String, Object> journalAttrs = new HashMap<>();
    journalAttrs.put("journalKey", "fakeKey");
    journalAttrs.put("journalName", "fakeName");
    when(theme.getConfigMap(any())).thenReturn(journalAttrs);
    Site site = new Site("foo", theme, mock(SiteRequestScheme.class), "foo");
    when(theme.resolveForeignJournalKey(any(), any())).thenReturn(site);
    ArticleMetadata articleMetadata = spy(articleMetadataFactory.newInstance(site, mock(RequestedDoiVersion.class), mock(ArticlePointer.class), ingestionMetadata, new HashMap(), new ArrayList()));
    Link mockLink = mock(Link.class);
    doReturn(mockLink).when(articleMetadata).buildCrossSiteRedirect(any(), any());
    articleMetadata.validateVisibility("whatever");
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) ArrayList(java.util.ArrayList) Theme(org.ambraproject.wombat.config.theme.Theme) Link(org.ambraproject.wombat.config.site.url.Link) Test(org.junit.Test)

Example 9 with Site

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

the class ControllerTestConfiguration method activeSite.

/**
 *  Unit test can only work with a single site.
 */
@Bean
protected Site activeSite(Theme theme) {
    final SiteRequestScheme mockRequestScheme = mock(SiteRequestScheme.class);
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        final HttpServletRequest request = (HttpServletRequest) args[0];
        return true;
    }).when(mockRequestScheme).isForSite(any(HttpServletRequest.class));
    final Site mockSite = mock(Site.class);
    when(mockSite.getRequestScheme()).thenReturn(mockRequestScheme);
    when(mockSite.getTheme()).thenReturn(theme);
    when(mockSite.getKey()).thenReturn(DESKTOP_PLOS_ONE);
    when(mockSite.toString()).thenReturn(DESKTOP_PLOS_ONE);
    when(mockSite.getJournalKey()).thenReturn(DESKTOP_PLOS_ONE);
    return mockSite;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Site(org.ambraproject.wombat.config.site.Site) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) Bean(org.springframework.context.annotation.Bean)

Example 10 with Site

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

the class ArticleMetadataTest method testGetFigureView.

@Test
public void testGetFigureView() {
    Map<String, String> asset = new HashMap<>();
    asset.put("doi", "fakeDoi");
    List<Map<String, String>> assets = new ArrayList<>();
    assets.add(asset);
    HashMap<String, List<Map<String, String>>> ingestionMetadata = new HashMap<>();
    ingestionMetadata.put("assetsLinkedFromManuscript", assets);
    Map<String, String> item = new HashMap<>();
    item.put("itemType", "figure");
    Map<String, Map<String, String>> itemTable = new HashMap<>();
    itemTable.put("fakeDoi", item);
    Theme theme = mock(Theme.class);
    HashMap<String, Object> journalAttrs = new HashMap<>();
    journalAttrs.put("journalKey", "fakeKey");
    journalAttrs.put("journalName", "fakeName");
    when(theme.getConfigMap(any())).thenReturn(journalAttrs);
    Site site = new Site("foo", theme, mock(SiteRequestScheme.class), "foo");
    ArticleMetadata articleMetadata = articleMetadataFactory.newInstance(site, mock(RequestedDoiVersion.class), mock(ArticlePointer.class), ingestionMetadata, itemTable, new ArrayList());
    HashMap<String, String> expected = new HashMap<>();
    expected.put("type", "figure");
    expected.put("doi", "fakeDoi");
    List<Map<String, ?>> expectedFigureView = new ArrayList<>();
    expectedFigureView.add(expected);
    assertEquals(articleMetadata.getFigureView(), expectedFigureView);
}
Also used : Site(org.ambraproject.wombat.config.site.Site) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SiteRequestScheme(org.ambraproject.wombat.config.site.url.SiteRequestScheme) ArticlePointer(org.ambraproject.wombat.identity.ArticlePointer) RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) Theme(org.ambraproject.wombat.config.theme.Theme) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Test(org.junit.Test)

Aggregations

Site (org.ambraproject.wombat.config.site.Site)27 HashMap (java.util.HashMap)11 Map (java.util.Map)10 ArrayList (java.util.ArrayList)9 List (java.util.List)7 SiteRequestScheme (org.ambraproject.wombat.config.site.url.SiteRequestScheme)7 Test (org.junit.Test)7 Link (org.ambraproject.wombat.config.site.url.Link)6 ImmutableList (com.google.common.collect.ImmutableList)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 SiteSet (org.ambraproject.wombat.config.site.SiteSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 StringWriter (java.io.StringWriter)4 ArticlePointer (org.ambraproject.wombat.identity.ArticlePointer)4 RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 RequestMappingContextDictionary (org.ambraproject.wombat.config.site.RequestMappingContextDictionary)3 Theme (org.ambraproject.wombat.config.theme.Theme)3 Logger (org.slf4j.Logger)3