use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testRobotsTags.
@Test
public void testRobotsTags() {
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
String[] robotsTags = resource.getValueMap().get(SeoTags.PN_ROBOTS_TAGS, new String[0]);
when(seoTags.getRobotsTags()).thenReturn(Arrays.asList(robotsTags));
return seoTags;
});
Page page = getPageUnderTest(PAGE);
List<String> robotsTags = page.getRobotsTags();
assertEquals(2, robotsTags.size());
assertThat(page.getRobotsTags(), hasItems("index", "nofollow"));
// assert that the returned object is cached by the instance
assertSame(robotsTags, page.getRobotsTags());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImpl method getCanonicalLink.
@Override
@Nullable
public String getCanonicalLink() {
if (this.canonicalUrl == null) {
String canonicalUrl;
try {
SeoTags seoTags = resource.adaptTo(SeoTags.class);
canonicalUrl = seoTags != null ? seoTags.getCanonicalUrl() : null;
} catch (NoClassDefFoundError ex) {
canonicalUrl = null;
}
this.canonicalUrl = canonicalUrl != null ? canonicalUrl : linkHandler.getLink(currentPage).map(Link::getExternalizedURL).orElse(null);
}
return canonicalUrl;
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testCanonicalLink.
@Test
public void testCanonicalLink() {
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
when(seoTags.getCanonicalUrl()).thenReturn("http://foo.bar" + resource.getParent().getPath() + ".html");
return seoTags;
});
Page page = getPageUnderTest(PAGE);
String canonicalLink = page.getCanonicalLink();
assertEquals("http://foo.bar/content/page/templated-page.html", canonicalLink);
// assert that the returned object is cached by the instance
assertSame(canonicalLink, page.getCanonicalLink());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImplTest method testRobotsTagsEmptyWhenSeoApiUnavailable.
@Test
public void testRobotsTagsEmptyWhenSeoApiUnavailable() {
context.registerAdapter(Resource.class, SeoTags.class, (Function<Resource, SeoTags>) resource -> {
SeoTags seoTags = mock(SeoTags.class, "seoTags of " + resource.getPath());
doThrow(new NoClassDefFoundError()).when(seoTags).getRobotsTags();
return seoTags;
});
Page page = getPageUnderTest(PAGE);
assertTrue(page.getRobotsTags().isEmpty());
}
use of com.adobe.aem.wcm.seo.SeoTags in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImpl method getRobotsTags.
@Override
@NotNull
public List<String> getRobotsTags() {
if (robotsTags == null) {
try {
SeoTags seoTags = resource.adaptTo(SeoTags.class);
robotsTags = seoTags != null && seoTags.getRobotsTags().size() > 0 ? Collections.unmodifiableList(seoTags.getRobotsTags()) : Collections.emptyList();
} catch (NoClassDefFoundError ex) {
robotsTags = Collections.emptyList();
}
}
return robotsTags;
}
Aggregations