use of org.ambraproject.wombat.config.site.url.SiteRequestScheme 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);
}
use of org.ambraproject.wombat.config.site.url.SiteRequestScheme 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;
}
use of org.ambraproject.wombat.config.site.url.SiteRequestScheme in project wombat by PLOS.
the class SiteSet method validateSchemes.
/**
* @throws RuntimeConfigurationException if there a detectable collision between site config values
*/
private static void validateSchemes(Collection<Site> sites) {
Map<String, Site> keys = Maps.newHashMapWithExpectedSize(sites.size());
Map<SiteRequestScheme, Site> requestSchemes = Maps.newHashMapWithExpectedSize(sites.size());
for (Site site : sites) {
Site previous;
String key = site.getKey();
previous = keys.put(key, site);
if (previous != null) {
throw new RuntimeConfigurationException("Multiple sites have the same key: " + key);
}
/*
* Depends on the equals and hashCode implementations of the SiteRequestPredicate implementations contained in
* the SiteRequestScheme. If they don't provide good overrides, this check is still safe against false positives
* but may not catch all error conditions.
*/
SiteRequestScheme requestScheme = site.getRequestScheme();
previous = requestSchemes.put(requestScheme, site);
if (previous != null) {
String message = String.format("Multiple sites (%s, %s) have the same request scheme: %s", key, previous.getKey(), requestScheme);
throw new RuntimeConfigurationException(message);
}
}
}
use of org.ambraproject.wombat.config.site.url.SiteRequestScheme in project wombat by PLOS.
the class SiteSet method create.
public static SiteSet create(List<? extends Map<String, ?>> siteSpecifications, ThemeGraph themeGraph) {
List<Site> sites = Lists.newArrayListWithCapacity(siteSpecifications.size());
for (Map<String, ?> siteSpec : siteSpecifications) {
String siteKey = (String) siteSpec.get("key");
String themeKey = (String) siteSpec.get("theme");
String siteType = (String) siteSpec.get("type");
Theme theme = themeGraph.getTheme(themeKey);
if (theme == null) {
throw new RuntimeException(String.format("No theme with key=\"%s\" found (for site: %s)", themeKey, siteKey));
}
Map<String, ?> resolveDefinition = (Map<String, ?>) siteSpec.get("resolve");
SiteRequestScheme requestScheme = resolveDefinition != null ? parseRequestScheme(resolveDefinition) : SiteRequestScheme.builder().setPathToken(siteKey).build();
sites.add(new Site(siteKey, theme, requestScheme, siteType));
}
validateSchemes(sites);
return new SiteSet(sites);
}
use of org.ambraproject.wombat.config.site.url.SiteRequestScheme 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;
}
Aggregations