use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testCanonicalLinkWhenSeoApiUnavailable.
@Test
public void testCanonicalLinkWhenSeoApiUnavailable() {
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
doThrow(new NoClassDefFoundError()).when(seoTags).getCanonicalUrl();
return seoTags;
});
Page page = getPageUnderTest(PAGE);
assertEquals("https://example.org/content/page/templated-page.html", page.getCanonicalLink());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testNoRobotsTags.
@Test
public void testNoRobotsTags() {
Page page = getPageUnderTest(PAGE);
// without adapter
assertTrue(page.getRobotsTags().isEmpty());
// with adapter
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
when(seoTags.getRobotsTags()).thenReturn(Collections.emptyList());
return seoTags;
});
assertTrue(page.getRobotsTags().isEmpty());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testNoAlternateLanguageLinks.
@Test
public void testNoAlternateLanguageLinks() {
Page page = getPageUnderTest(PAGE, PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS, true);
// without adapter
assertTrue(page.getAlternateLanguageLinks().isEmpty());
// with adapter
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
when(seoTags.getAlternateLanguages()).thenReturn(Collections.emptyMap());
return seoTags;
});
assertTrue(page.getAlternateLanguageLinks().isEmpty());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testAlternateLanguageLinksWhenSeoApiUnavailable.
@Test
public void testAlternateLanguageLinksWhenSeoApiUnavailable() {
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
doThrow(new NoClassDefFoundError()).when(seoTags).getAlternateLanguages();
return seoTags;
});
Page page = getPageUnderTest(PAGE, PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS, true);
assertTrue(page.getAlternateLanguageLinks().isEmpty());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testAlternateLanguageLinks.
@ParameterizedTest(name = PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS + " = {0}")
@ValueSource(strings = { "true", "false" })
public void testAlternateLanguageLinks(String renderProperty) {
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
Map<Locale, String> expectedAlternates = ImmutableMap.of(Locale.ENGLISH, "http://foo.bar/content/en/templated-page", Locale.GERMAN, "http://foo.bar/content/de/templated-page");
when(seoTags.getAlternateLanguages()).thenReturn(expectedAlternates);
return seoTags;
});
boolean renderAlternateLanguages = Boolean.parseBoolean(renderProperty);
Page page = getPageUnderTest(PAGE, PageImpl.PN_STYLE_RENDER_ALTERNATE_LANGUAGE_LINKS, renderProperty);
Map<Locale, String> alternateLanguageLinks = page.getAlternateLanguageLinks();
if (renderAlternateLanguages) {
assertEquals(2, alternateLanguageLinks.size());
assertEquals("http://foo.bar/content/en/templated-page", page.getAlternateLanguageLinks().get(Locale.ENGLISH));
assertEquals("http://foo.bar/content/de/templated-page", page.getAlternateLanguageLinks().get(Locale.GERMAN));
} else {
assertTrue(alternateLanguageLinks.isEmpty());
}
// assert that the returned object is cached by the instance
assertSame(alternateLanguageLinks, page.getAlternateLanguageLinks());
}
Aggregations